Skip to content

Conversation

@larry-cable
Copy link
Contributor

@larry-cable larry-cable commented Oct 9, 2025

the existing jdk.classDefine and jdk.ClassLoad events do not include metadata regarding the location/source of the ClassFile.

The location of the class file for a class defined can be of utility in both debugging and auditing.

this addition introduces a new jdk.ClassFileDefine event which records the class defined and the location (path/url) of the class file that contained the implementation thereof


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Warning

 ⚠️ Found leading lowercase letter in issue title for 8365400: enhance JFR to emit file and module metadata for class loading

Issue

  • JDK-8365400: enhance JFR to emit file and module metadata for class loading (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27738/head:pull/27738
$ git checkout pull/27738

Update a local copy of the PR:
$ git checkout pull/27738
$ git pull https://git.openjdk.org/jdk.git pull/27738/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27738

View PR using the GUI difftool:
$ git pr show -t 27738

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27738.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 9, 2025

👋 Welcome back larry-cable! 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.

@openjdk
Copy link

openjdk bot commented Oct 9, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title JDK-8365400: enhance JFR to emit file and module metadata for class loading 8365400: enhance JFR to emit file and module metadata for class loading Oct 9, 2025
@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Oct 9, 2025
@openjdk
Copy link

openjdk bot commented Oct 9, 2025

@larry-cable The following label will be automatically applied to this pull request:

  • hotspot

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

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 9, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 9, 2025

Webrevs

@AlanBateman
Copy link
Contributor

The evolution of JFR events isn't clear to me so I don't know if adding a field is compatible or not for programs that are processing recordings. (I'm just trying to understand why a new not-enabled-by-default event is added instead of adding a field to the existing ClassDefine event.

The existing event is emitted in SystemDictionary::define_instance_class, the new event emits it from JVM_DefineClassXXX. Is this because it was awkward to get at cfs->source from the SD code?

I assume that a test will be added as it would be easy to refactor code and not record the event if enabled.

Using "jvm" as the URI scheme when there is no source is a bit strange. There will be custom class loaders that don't provide a code source, do you really want these to use this source in the event?

@mgronlun
Copy link

Why is this change not getting a hotspot-jfr label?

@mgronlun
Copy link

/label add hotspot-jfr

@openjdk openjdk bot added the hotspot-jfr hotspot-jfr-dev@openjdk.org label Oct 10, 2025
@openjdk
Copy link

openjdk bot commented Oct 10, 2025

@mgronlun
The hotspot-jfr label was successfully added.

@mgronlun
Copy link

mgronlun commented Oct 10, 2025

Introducing a separate jdk.ClassFileDefine event seems gratuitous. Why is it not enabled by default?

What problem is being addressed again?

@mgronlun
Copy link

The evolution of JFR events isn't clear to me so I don't know if adding a field is compatible or not for programs that are processing recordings. (I'm just trying to understand why a new not-enabled-by-default event is added instead of adding a field to the existing ClassDefine event.

The existing event is emitted in SystemDictionary::define_instance_class, the new event emits it from JVM_DefineClassXXX. Is this because it was awkward to get at cfs->source from the SD code?

I assume that a test will be added as it would be easy to refactor code and not record the event if enabled.

Using "jvm" as the URI scheme when there is no source is a bit strange. There will be custom class loaders that don't provide a code source, do you really want these to use this source in the event?

Adding a field to an existing event is non-detrimental, equivalent to extending a table with a new column in a database.

@larry-cable
Copy link
Contributor Author

in previous discussions regarding adding fields to existing JFR (jdk) events I concluded (based on feedback from the JFR team) that this was undesirable hence the new event.

I will investigate the feasibility of adding this metadata to the existing event(s)

knowing where a class originated from, in addition to the knowledge that it has been loaded etc is of particular value in pre-existing auditing and debugging scenarios.

@mgronlun
Copy link

mgronlun commented Oct 10, 2025

Can you please give an example URL for a class definition? I am concerned about whether this is high cardinality strings (for path/name.class) or a lot of reuse (for paths). We should only represent a URL once, which makes me think that the field type should be symbol instead of string.

For that, we would need a concurrent symbol table, which I have already planned in other changes.

@AlanBateman
Copy link
Contributor

AlanBateman commented Oct 10, 2025

Can you please give an example URL for a class definition? I am concerned about whether this is high cardinality strings (for path/name.class) or a lot of reuse (for paths). We should only represent a URL once, which makes me think that the field type should be symbol instead of string.

Run with -Xlog:class+load to see examples of the code source. For classes loaded from modules in the run-time image then you'll see values of the form jrt:/$MODULE, e.g. jrt:/java.base or jrt:/java.destop (classes loaded from the AOT have something like "shared objects file"). The code source for classes loaded from JAR files is the path to the JAR file, e.g.
file:/lib/foo.jar. When classes loaded from the file system then it will be the directory specified to the class path, e.g. file:/d/classes/.

@mgronlun
Copy link

Can you please give an example URL for a class definition? I am concerned about whether this is high cardinality strings (for path/name.class) or a lot of reuse (for paths). We should only represent a URL once, which makes me think that the field type should be symbol instead of string.

Run with -Xlog:class+load to see examples of the code source. For classes loaded from modules in the run-time image then you'll see values of the form jrt:/$MODULE, e.g. jrt:/java.base or jrt:/java.destop (classes loaded from the AOT have something like "shared objects file"). The code source for classes loaded from JAR files is the path to the JAR file, e.g. file:/lib/foo.jar. When classes loaded from the file system then it will be the directory specified to the class path, e.g. file:/d/classes/.

Thanks.

Looks like the source is a low cardinality property.

@larry-cable
Copy link
Contributor Author

looking at the current implementation for both jdk.ClassDefine and jdk.ClassLoad events, the "source" metadata recorded by the new event is not available in the (current) calling context for either of the pre-existing events.

In my opinion adding a new event to capture this information is less intrusive than adding fields(s) to the existing event(s) and contriving to provide the necessary state to those at their current call sites (or by relocating those to a calling context where the "source" is available)

@AlanBateman
Copy link
Contributor

@larry-cable Are you sure adding a new event is the right thing to do? Is it just the implementation challenge? If jdk.ClassDefine were being added today then it seems useful to add the module and the code source (no need for the package as the definedClass gives the fully qualified class name).

@mgronlun
Copy link

mgronlun commented Oct 19, 2025

Package and Module information is implicitly included in the JFR model for a class (its transitive dependencies), so you do not need to include them explicitly.

I prefer if the design address how the source information is to be included for the existing events (ClassLoad and ClassDefine).

I am working on a symbol table implementation to help you out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org hotspot-jfr hotspot-jfr-dev@openjdk.org rfr Pull request is ready for review

4 participants