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

JDK-8313251: Add NativeLibraryLoad event #15065

Closed
wants to merge 6 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Jul 28, 2023

Add a NativeLibraryLoad event that provides us more detail about shared lib/dll loads. This gives a time stamp and success + error details of the load operation. It enhances the already existing information we get from the existing NativeLibrary event (that periodically samples the native modules of the jvm process).


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

Issue

  • JDK-8313251: Add NativeLibraryLoad event (Enhancement - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15065

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 28, 2023

👋 Welcome back mbaesken! 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 openjdk bot added the rfr Pull request is ready for review label Jul 28, 2023
@openjdk
Copy link

openjdk bot commented Jul 28, 2023

@MBaesken 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 hotspot hotspot-dev@openjdk.org label Jul 28, 2023
@mlbridge
Copy link

mlbridge bot commented Jul 28, 2023

Webrevs

@dholmes-ora
Copy link
Member

/label add hotspot-jfr

@openjdk openjdk bot added the hotspot-jfr hotspot-jfr-dev@openjdk.org label Jul 30, 2023
@openjdk
Copy link

openjdk bot commented Jul 30, 2023

@dholmes-ora
The hotspot-jfr label was successfully added.

@MBaesken
Copy link
Member Author

MBaesken commented Aug 1, 2023

Hi Johannes, thanks for the review !

May I get a second review please?

@egahlin
Copy link
Member

egahlin commented Aug 1, 2023

Hi Johannes, thanks for the review !

May I get a second review please?

I can review, but I like replies to my comments first.

@MBaesken
Copy link
Member Author

MBaesken commented Aug 2, 2023

Hi Johannes, thanks for the review !
May I get a second review please?

I can review, but I like replies to my comments first.

Hi Erik , maybe I miss something? What comment(s) are you referring to ?

@@ -939,6 +939,13 @@
<Field type="ulong" contentType="address" name="topAddress" label="Top Address" description="Ending address of the module, if available" />
</Event>

<Event name="NativeLibraryLoad" category="Java Virtual Machine, Runtime" label="Native Library Load Operation" thread="false" stackTrace="true" startTime="true"
Copy link
Member

Choose a reason for hiding this comment

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

I think "Native Library Load" is sufficient as an event label and "Success" for the success field.

I think "error" is sufficient for the error field. We could use "errorMessage", if you believe there are other error related information we may want to add in the future.

The "name" label could changed to "Name", similar to the NativeLibrary event,

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi Erik, I will adjust. I will use errorMessage because on some platforms we have already coding to describe shared lib load error situations in more detail (see for example os_linux.cpp).

} else {
Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
log_info(os)("shared library load of %s was successful", filename);
#if INCLUDE_JFR
event.set_success(true);
event.set_errorDescription("");
Copy link
Member

Choose a reason for hiding this comment

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

Use null if there is no error message

@@ -1008,11 +1023,22 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
return os::get_default_process_handle();
#else
log_info(os)("attempting shared library load of %s", filename);

#if INCLUDE_JFR
Copy link
Member

Choose a reason for hiding this comment

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

We typically skip INCLUDE_JFR for events and rely on empty stubs in the code generation. This to make the code more easy to read.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi Erik , I removed the JFR with configure and attempted this (however on Linux) but for some reason I got build errors. So I better added the macros. (not sure why this happened, with some other JFR event living without INCLUDE_JFR seemed to work as expected)

Copy link
Member

Choose a reason for hiding this comment

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

OK

Copy link
Member

Choose a reason for hiding this comment

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

Just for completeness the various os_xxx.cpp files all use INCLUDE_JFR around event code.

private final static String EVENT_NAME = EventNames.NativeLibraryLoad;

public static void main(String[] args) throws Throwable {
Recording recording = new Recording();
Copy link
Member

Choose a reason for hiding this comment

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

Use try-with-resources.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi Erik, this was taken from test/jdk/jdk/jfr/event/runtime/TestNativeLibrariesEvent.java , I do not see in main there a try with resources. What do you want to put in the try block exactly ? The new Recording() ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.
try (Recording r = new Recording()) {
...
}
It's not used everywhere, but it seems proper to release chunk resources when the test is finished.

(I should probably go over all tests and change to avoid the pattern being copied.)

Copy link
Member Author

Choose a reason for hiding this comment

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

HI Erik, I adjusted the test as recommended .

@egahlin
Copy link
Member

egahlin commented Aug 2, 2023

Hi Johannes, thanks for the review !
May I get a second review please?

I can review, but I like replies to my comments first.

Hi Erik , maybe I miss something? What comment(s) are you referring to ?

Hi Matthias. Sorry, I forgot to press submit.

@openjdk
Copy link

openjdk bot commented Aug 2, 2023

@MBaesken 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:

8313251: Add NativeLibraryLoad event

Reviewed-by: jbechberger, egahlin, dholmes

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 69 new commits pushed to the master branch:

  • 10a2605: 8294979: test/jdk/tools/jlink 3 test classes use ASM library
  • e8c325d: 8313394: Array Elements in OldObjectSample event has the incorrect description
  • d60352e: 8311006: missing @SInCE info in jdk.xml.dom
  • 4577147: 8313712: [BACKOUT] 8313632: ciEnv::dump_replay_data use fclose
  • bb3aac6: 8301606: JFileChooser file chooser details view "size" label cut off in Metal Look&Feel
  • 0f2fce7: 8313632: ciEnv::dump_replay_data use fclose
  • ab1c212: 8312909: C1 should not inline through interface calls with non-subtype receiver
  • c386091: 8312984: javac may crash on a record pattern with too few components
  • 3212b64: 8313582: Problemlist failing test on linux x86
  • bdac348: 8313602: increase timeout for jdk/classfile/CorpusTest.java
  • ... and 59 more: https://git.openjdk.org/jdk/compare/ba645da97b00a7cc9d5a9d4dd58b1cd6737b4822...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 Aug 2, 2023
@MBaesken
Copy link
Member Author

MBaesken commented Aug 2, 2023

Hi Erik, thanks for the review !

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Overall looks okay but I have a request for the test. Thanks.

@@ -1008,11 +1023,22 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
return os::get_default_process_handle();
#else
log_info(os)("attempting shared library load of %s", filename);

#if INCLUDE_JFR
Copy link
Member

Choose a reason for hiding this comment

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

Just for completeness the various os_xxx.cpp files all use INCLUDE_JFR around event code.

Comment on lines +74 to +77
if (Platform.isWindows()) {
libTemplate = "%s.dll";
} else if (Platform.isOSX()) {
libTemplate = "lib%s.dylib";
Copy link
Member

Choose a reason for hiding this comment

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

We have Platform.sharedLibraryExt() to simplify this a bit. Unfortunately we don't have a sharedLibraryPrefix() to reduce it to one line. :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi David, that coding can indeed be improved. But let's do it in a follow-up. And in the follow-up also for existing https://github.com/openjdk/jdk/blob/master/test/jdk/jdk/jfr/event/runtime/TestNativeLibrariesEvent.java where the same/similar code is present. The follow-up should also introduce 'sharedLibraryPrefix' .

Copy link
Member

Choose a reason for hiding this comment

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

Okay

Copy link
Member Author

Choose a reason for hiding this comment

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

try (Recording recording = new Recording()) {
recording.enable(EVENT_NAME);
recording.start();
System.loadLibrary("awt");
Copy link
Member

Choose a reason for hiding this comment

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

I don't think loading libawt is a good choice - maybe libnet or libnio? Headless builds may not have libawt and I'd be concerned about loading it directly and running the OnLoad hooks.

Copy link
Member Author

Choose a reason for hiding this comment

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

libnet does not work, it gives us the error 'Native Library /testdir/images/jdk/lib/libnet.so already loaded in another classloader' . So we have to load something that is not there already. But I agree, awt might not be the best choice. What about libinstrument ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that might work. If worse comes to worst, you could create a trivial library just or the test.

@MBaesken
Copy link
Member Author

MBaesken commented Aug 3, 2023

David are you fine with the latest version?
I checked the GHA build errors and they are not related.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Looks okay. Thanks

@MBaesken
Copy link
Member Author

MBaesken commented Aug 4, 2023

Hi David , thanks for the review !

/integrate

@openjdk
Copy link

openjdk bot commented Aug 4, 2023

Going to push as commit 5d23295.
Since your change was applied there have been 70 commits pushed to the master branch:

  • c4b8574: 8311938: Add default cups include location for configure on AIX
  • 10a2605: 8294979: test/jdk/tools/jlink 3 test classes use ASM library
  • e8c325d: 8313394: Array Elements in OldObjectSample event has the incorrect description
  • d60352e: 8311006: missing @SInCE info in jdk.xml.dom
  • 4577147: 8313712: [BACKOUT] 8313632: ciEnv::dump_replay_data use fclose
  • bb3aac6: 8301606: JFileChooser file chooser details view "size" label cut off in Metal Look&Feel
  • 0f2fce7: 8313632: ciEnv::dump_replay_data use fclose
  • ab1c212: 8312909: C1 should not inline through interface calls with non-subtype receiver
  • c386091: 8312984: javac may crash on a record pattern with too few components
  • 3212b64: 8313582: Problemlist failing test on linux x86
  • ... and 60 more: https://git.openjdk.org/jdk/compare/ba645da97b00a7cc9d5a9d4dd58b1cd6737b4822...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 4, 2023
@openjdk openjdk bot closed this Aug 4, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 4, 2023
@openjdk
Copy link

openjdk bot commented Aug 4, 2023

@MBaesken Pushed as commit 5d23295.

💡 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
hotspot hotspot-dev@openjdk.org hotspot-jfr hotspot-jfr-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants