Skip to content

Conversation

larry-cable
Copy link
Contributor

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

while existing class loading JFR events exist, none of these provide the path (if available) from which a class is loaded/defined, nor are they easily modified to do so from a compatibility standpoint.

therefore this ER/PR adds a simple JFR event that encapsulates a tuple of class and path that can be enabled in order to provide an audit/debug trail of locations (path, if available) from which a particular class is loaded/defined.

this association can be used for various "applications" such as basic auditing etc


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/27656/head:pull/27656
$ git checkout pull/27656

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27656

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 6, 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 6, 2025

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

@openjdk
Copy link

openjdk bot commented Oct 6, 2025

@larry-cable 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 the rfr Pull request is ready for review label Oct 6, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 6, 2025

Webrevs

@larry-cable larry-cable changed the title JDK-8365400: add JFR event to capture location (if available) of class files loaded JDK-8365400: enhance JFR to emit file and module metadata for class loading Oct 6, 2025
@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 6, 2025
@lmesnik
Copy link
Member

lmesnik commented Oct 6, 2025

Can you please a new test for the added functionality?

@egahlin
Copy link
Member

egahlin commented Oct 6, 2025

I have not reviewed SecureClassLoader, as this is better done by people who are more knowledgeable in the area. That said, toExternalForm() appears to be a somewhat expensive function, so you may want to add a guard. Also check for null.

    ClassFileDefineEvent event = new ClassFileDefineEvent();
    if (event.isEnabled()) {
        event.definedClass = cls;
        if (cs != null) {
            URL location = cs.getLocation();
            if (location != null) {
                event.path = location.toExternalForm();
            }
        }
        event.commit();   
    }

Could you also add the event to profile.jfc? Please remove "Name" from the label "Defined Class Name," as the whole class is serialized, and add a test to test/jdk/jdk/jfr/event/runtime.

@larry-cable
Copy link
Contributor Author

larry-cable commented Oct 6, 2025 via email

@egahlin
Copy link
Member

egahlin commented Oct 6, 2025

What is the scope of the event? I assume it will not work for all classes. Could more be added, or could the limitation be stated somewhere, e.g. Label("Secure Class File Define")? The event name can still be generic.

@AlanBateman
Copy link
Contributor

@larry-cable would it be possible to provide a summary on why the existing ClassLoad/ClassDefine events can't be updated to add the additional fields?

I think it would also be useful to understand why SecureClassLoader has been chosen as the place to record this event. The class loading part of the boot loader is in the VM, not Java. The modified code paths will get used for the platform and app class loaders but it's coin toss with custom class loaders as they might extend ClassLoader directly.

Have you looked at the defineClass implementation in the base class (java.lang.ClassLoader)? It already extracts the location from the protection domain so that the VM has the code source. For classes loaded by the boot loader, the VM will generate a code source that is the string representation of a "jrt" or "file" URL. That code source is mostly used by logging (e.g. -Xlog:class+load) and CDS/AOT but I suspect what you are looking for it to get at these in the VM when recording an event.

@larry-cable larry-cable closed this Oct 7, 2025
@larry-cable larry-cable deleted the JDK-8365400 branch October 7, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants