Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8261160: Add a deserialization JFR event #2479

Closed
wants to merge 8 commits into from

Conversation

ChrisHegarty
Copy link
Member

@ChrisHegarty ChrisHegarty commented Feb 9, 2021

This issue adds a new event to improve diagnostic information of Java deserialization. The event captures the details of deserialization activity from ObjectInputStream. The event details are similar to that of the serial filter, but is agnostic of whether a filter is installed or not. The event also captures the filter status, if there is one.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

Reviewers

Contributors

  • Sean Coffey <coffeys@openjdk.org>
  • Chris Hegarty <chegar@openjdk.org>

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2479/head:pull/2479
$ git checkout pull/2479

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 9, 2021

👋 Welcome back chegar! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@ChrisHegarty
Copy link
Member Author

/contributor add @coffeys

@openjdk
Copy link

openjdk bot commented Feb 9, 2021

@ChrisHegarty The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot-jfr
  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added security security-dev@openjdk.org core-libs core-libs-dev@openjdk.org hotspot-jfr hotspot-jfr-dev@openjdk.org labels Feb 9, 2021
@openjdk
Copy link

openjdk bot commented Feb 9, 2021

@ChrisHegarty
Contributor Sean Coffey <coffeys@openjdk.org> successfully added.

@ChrisHegarty
Copy link
Member Author

/contributor add @ChrisHegarty

@openjdk
Copy link

openjdk bot commented Feb 9, 2021

@ChrisHegarty
Contributor Chris Hegarty <chegar@openjdk.org> successfully added.

@ChrisHegarty ChrisHegarty marked this pull request as ready for review February 10, 2021 15:50
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 10, 2021
@mlbridge
Copy link

mlbridge bot commented Feb 10, 2021

Webrevs

@ChrisHegarty
Copy link
Member Author

The logging in ObjectInputStream remains conditional on whether a filter is installed, which that seems reasonable since the logging is filter specific, while the JRF event is not (but both carry effectively the same information).

The new jdk.Deserialization event uses a String to carry the filterStatus value. The value could be represented by its enum ordinal, but then the tool consuming the event would need to map that back to its string value to be meaningful.

@@ -48,6 +48,7 @@
* -Dexpected-jdk.serialFilter=java.** GlobalFilterTest
* @run testng/othervm/policy=security.policy GlobalFilterTest
* @run testng/othervm/policy=security.policy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to add a "@requires vm.hasJFR" condition to this test

@openjdk
Copy link

openjdk bot commented Feb 10, 2021

@ChrisHegarty This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8261160: Add a deserialization JFR event

Co-authored-by: Sean Coffey <coffeys@openjdk.org>
Co-authored-by: Chris Hegarty <chegar@openjdk.org>
Reviewed-by: coffeys, rriggs, dfuchs, egahlin

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 353 new commits pushed to the master branch:

  • 6675775: 8253702: BigSur version number reported as 10.16, should be 11.nn
  • 33fcd32: 8261659: JDK-8261027 causes a Tier1 validate-source failure
  • 3aa1b4c: 8261623: reference to javac internals in Extern class
  • 350303d: 8260221: java.util.Formatter throws wrong exception for mismatched flags in %% conversion
  • 6475d47: 8261655: [PPC64] Build broken after JDK-8260941
  • c0e805a: 8261654: Missing license header in Signatures.java
  • b670efd: 8261072: AArch64: Fix MacroAssembler::get_thread convention
  • 59b8d59: 8261481: Cannot read Kerberos settings in dynamic store on macOS Big Sur
  • 9f81ca8: 8261230: GC tracing of page sizes are wrong in a few places
  • 40ae993: 8261027: AArch64: Support for LSE atomics C++ HotSpot code
  • ... and 343 more: https://git.openjdk.java.net/jdk/compare/0785147460934ee2aa413ab7872837094824bd3d...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 10, 2021
import jdk.jfr.internal.MirrorEvent;

@Category({"Java Development Kit", "Serialization"})
@Label("Deserialization events")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to differ from the format of other event labels defined in this package, e.g:

@Label("Process Start")
@Label("File Read")
...

What would you think of changing it to one of:

 @Label("Deserialization")
 @Label("Deserialized Object")

}
DeserializationEvent event = new DeserializationEvent();
if (event.shouldCommit()) {
event.filterStatus = status == null ? "n/a" : status.name();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use null for missing value, so no need to have "n/a"

event.totalObjectRefs = totalObjectRefs;
event.depth = depth;
event.bytesRead = bytesRead;
event.exception = Objects.toString(ex, "n/a");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to change the name of the field to "exceptionMessage" to make it clear it's the message, not the class.

public String filterStatus;

@Label ("Class")
public String clazz;
Copy link
Member

@egahlin egahlin Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically use "type" when referring to a class (instead of clazz), or we prefix it, i.e exceptionClass

public String filterStatus;

@Label ("Class")
public String clazz;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make the field of type Class?

public int arrayLength;

@Label ("Reference count")
public long totalObjectRefs;
Copy link
Member

@egahlin egahlin Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Reference count" sounds a bit like resource counter? Is that the case? If not, perhaps "Object References" is better. We try to avoid abbreviations. How about naming the field "totalObjectReferences" or just "objectReferences"?

@RogerRiggs
Copy link
Contributor

As proposed, events are only created if there is a serialFilter in effect (and enabled by JFR configuration).
Being able to create the events without a serialFilter in effect would be useful for monitoring, especially if it could be controlled by a separate JFR configuration option. (always, never, serial-filter , etc.)

@ChrisHegarty
Copy link
Member Author

I updated the PR and addressed all comments so far. Specifically:

@RogerRiggs The generation of the event is independent of whether the filter is set or not. I also added a piece of state to determine if a filter is set or not. I think it could be useful to analyse all Deserialisation events to, say, ensure that there are none operating without a filter ( and the filterStatus state is ambitious in the null case ).

@coffeys I would like GlobalFilterTest to run regardless of whether or not the jfr module is present, but of course running the test with jfr enabled is desirable too, so I added a separate at test tag for that case.

@egahlin Excellent suggestions on the naming, etc. I adopted all. And added a test to ensure that the creation and generation of the event does not inadvertently trigger class initialization if the filter rejects the attempt ( thanks @dfuch )

@dfuch Thanks for the improved label suggestion, it is now merged in.

Comment on lines 41 to 42
@Label("Filter configured")
public boolean filterConfigured;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that be "Filter Configured" for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed.

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ChrisHegarty
Copy link
Member Author

Speaking to Erik offline, he suggested to split the exceptionMessage into exceptionType and exceptionMessage ( since the code was somewhat overloading the existing Sting field by using toString to force the exception class name and message into a single sting ). While the exceptionXXX field should rarely be non-null, they add very little overhead.

@ChrisHegarty
Copy link
Member Author

/integrate

@openjdk openjdk bot closed this Feb 12, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 12, 2021
@openjdk
Copy link

openjdk bot commented Feb 12, 2021

@ChrisHegarty Since your change was applied there have been 355 commits pushed to the master branch:

  • a305743: 8261660: AArch64: Race condition in stub code generation for LSE Atomics
  • 28163a9: 8261652: Remove some dead comments from os_bsd_x86
  • 6675775: 8253702: BigSur version number reported as 10.16, should be 11.nn
  • 33fcd32: 8261659: JDK-8261027 causes a Tier1 validate-source failure
  • 3aa1b4c: 8261623: reference to javac internals in Extern class
  • 350303d: 8260221: java.util.Formatter throws wrong exception for mismatched flags in %% conversion
  • 6475d47: 8261655: [PPC64] Build broken after JDK-8260941
  • c0e805a: 8261654: Missing license header in Signatures.java
  • b670efd: 8261072: AArch64: Fix MacroAssembler::get_thread convention
  • 59b8d59: 8261481: Cannot read Kerberos settings in dynamic store on macOS Big Sur
  • ... and 345 more: https://git.openjdk.java.net/jdk/compare/0785147460934ee2aa413ab7872837094824bd3d...master

Your commit was automatically rebased without conflicts.

Pushed as commit 3dc6f52.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org hotspot-jfr hotspot-jfr-dev@openjdk.org integrated Pull request has been integrated security security-dev@openjdk.org
5 participants