Skip to content

Conversation

@RealLucy
Copy link
Contributor

@RealLucy RealLucy commented Nov 10, 2022

This small change fixes a warning that may pop up during runtime. May I please request reviews? Thank you!


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-8296709: WARNING: JNI call made without checking exceptions

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11083

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 10, 2022

👋 Welcome back lucy! 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 Nov 10, 2022
@openjdk
Copy link

openjdk bot commented Nov 10, 2022

@RealLucy The following label will be automatically applied to this pull request:

  • serviceability

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 serviceability serviceability-dev@openjdk.org label Nov 10, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 10, 2022

Copy link
Contributor

@kevinjwalls kevinjwalls left a comment

Choose a reason for hiding this comment

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

Looks good I think. Got to check for those exceptions!

The example invocation also shows the me "exceeds capacity" warning, which must relate to the above WITH_LOCAL_REFS and call to createLocalRefSpace. Another time maybe. 8-)

@RealLucy
Copy link
Contributor Author

Thanks for the review, Kevin!
I'm looking into the "exceeds capacity" warning separately. Need to find out who is holding so many local references, just for a java -version. Once I have enough knowledge, I'll file a separate bug.

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

Looks good.
Thank you for taking care about this.
Serguei

@openjdk
Copy link

openjdk bot commented Nov 10, 2022

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

8296709: WARNING: JNI call made without checking exceptions

Reviewed-by: kevinw, sspitsyn, clanger

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

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 Nov 10, 2022
@dholmes-ora
Copy link
Member

Can the test be augmented to catch this case too?

@RealLucy
Copy link
Contributor Author

Can the test be augmented to catch this case too?

David,
the test already catches both warnings. The warnings are only issued under special circumstances. That's why everything looks fine in most cases. SAP's commercial vm has a feature called "debugging on demand" which is active by default. Therefore we see the warnings in our tests.

@RealCLanger
Copy link
Contributor

Maybe you could also call "bin/java -Xcheck:jni -agentlib:jdwp=transport=dt_socket,server=y,suspend=n -version" which would show the error? Or add this as another test for serviceability?

@dholmes-ora
Copy link
Member

I was suggesting what @RealCLanger suggests in regards to the test - add a new case.

@RealLucy
Copy link
Contributor Author

I was suggesting what @RealCLanger suggests in regards to the test - add a new case.

Ahh, now I understand. I will add the suggested test modification to this PR.

@RealLucy
Copy link
Contributor Author

I've added a separate test which does the same but with an active jdwp agent. The test will fail until the warning
WARNING: JNI local refs: 921, exceeds capacity: 32
is fixed. I'm not sure how to do this. Just increasing the capacity doesn't seem to be the right thing.

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

Looks good. I commented on two nits.

If you don't have a quick idea on how to fix WARNING: JNI local refs: 921, exceeds capacity: 32, you could open a bug for it (if there isn't one already) and right away exclude the test with reference to the new bug.
The alternative would be to filter out the local refs warning but then I guess this will be forgotten.
After all, either way is not perfect...

@dholmes-ora
Copy link
Member

Couldn't you simply add a second doExec statement in the existing test rather than copy the entire test file?

@RealLucy
Copy link
Contributor Author

Couldn't you simply add a second doExec statement in the existing test rather than copy the entire test file?

Actually, I first did it that way. And I did not like it. It's not just the doExec, you need to duplicate the checks as well. So far, it's just personal preference.

The test case with active jdwp agent produces two warnings, but I have a fix for only one of the warnings. @RealCLanger suggested to create a bug for the unresolved warning and problem-list the test case until the bug is fixed. If this is the way to go, I need a separate test file.

@RealCLanger
Copy link
Contributor

Couldn't you simply add a second doExec statement in the existing test rather than copy the entire test file?

Actually, I first did it that way. And I did not like it. It's not just the doExec, you need to duplicate the checks as well. So far, it's just personal preference.

The test case with active jdwp agent produces two warnings, but I have a fix for only one of the warnings. @RealCLanger suggested to create a bug for the unresolved warning and problem-list the test case until the bug is fixed. If this is the way to go, I need a separate test file.

Hm, I also don't like the code duplication...

You could use 2 @run tags. Via the run tags you can create two runs of the test, one like the current "default" and antoher one passing the debugging agent option as additional parameter which you have to hand to the the java child process then, too. Generally you'd expect the same results, e.g. good return code, the hello world and no warnings.

With that approach you can then exclude the failing run via exclude list.

@RealLucy
Copy link
Contributor Author

Hm, I also don't like the code duplication...

Code duplication is gone. Just one test file with two @run tags.

@kevinjwalls
Copy link
Contributor

kevinjwalls commented Nov 14, 2022

To see where the JNI local refs warning comes from, I set a breakpoint in JavaThread::print_stack_on as that is called when the warning happens, although it doesn't print anything as there is no Java frame.
...
(gdb) cont
Continuing.
WARNING: JNI local refs: 442, exceeds capacity: 32

Breakpoint 1, 0x00007ffff6efb8c0 in JavaThread::print_stack_on(outputStream*) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
(gdb) bt
#0 0x00007ffff6efb8c0 in JavaThread::print_stack_on(outputStream*) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#1 0x00007ffff6a0f38c in checked_jni_GetJavaVM () from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#2 0x00007ffff7e8dfa8 in transport_startTransport () from /scratch/kwalls/jdk/jdk-17.0.3/lib/libjdwp.so
#3 0x00007ffff7e76f77 in startTransport () from /scratch/kwalls/jdk/jdk-17.0.3/lib/libjdwp.so
#4 0x00007ffff7e75069 in bagEnumerateOver () from /scratch/kwalls/jdk/jdk-17.0.3/lib/libjdwp.so
#5 0x00007ffff7e77948 in initialize () from /scratch/kwalls/jdk/jdk-17.0.3/lib/libjdwp.so
#6 0x00007ffff7e783f0 in cbEarlyVMInit () from /scratch/kwalls/jdk/jdk-17.0.3/lib/libjdwp.so
#7 0x00007ffff6b5e756 in JvmtiExport::post_vm_initialized() ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#8 0x00007ffff6f00f54 in Threads::create_vm(JavaVMInitArgs*, bool*) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#9 0x00007ffff6a007d1 in JNI_CreateJavaVM () from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
...

Specifically breaking in JNIHandles::make_local I see a lot of activity like:

Breakpoint 2, 0x00007ffff6a240c4 in JNIHandles::make_local(oopDesc*) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#0 0x00007ffff6a240c4 in JNIHandles::make_local(oopDesc*) () from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#1 0x00007ffff6b6d1ed in LoadedClassesClosure::do_klass(Klass*) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#2 0x00007ffff66c6016 in ClassLoaderData::loaded_classes_do(KlassClosure*) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#3 0x00007ffff66c9dd8 in ClassLoaderDataGraph::loaded_classes_do(KlassClosure*) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#4 0x00007ffff6b6ce6f in JvmtiGetLoadedClasses::getLoadedClasses(JvmtiEnv*, int*, _jclass***) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#5 0x00007ffff6afa426 in jvmti_GetLoadedClasses () from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#6 0x00007ffff7e7561b in classTrack_initialize () from /scratch/kwalls/jdk/jdk-17.0.3/lib/libjdwp.so
#7 0x00007ffff7e778f1 in initialize () from /scratch/kwalls/jdk/jdk-17.0.3/lib/libjdwp.so
#8 0x00007ffff7e783f0 in cbEarlyVMInit () from /scratch/kwalls/jdk/jdk-17.0.3/lib/libjdwp.so
#9 0x00007ffff6b5e756 in JvmtiExport::post_vm_initialized() ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#10 0x00007ffff6f00f54 in Threads::create_vm(JavaVMInitArgs*, bool*) ()
from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
#11 0x00007ffff6a007d1 in JNI_CreateJavaVM () from /scratch/kwalls/jdk/jdk-17.0.3/lib/server/libjvm.so
...

LoadedClassesClosure::do_klass does indeed call make_local many times.
If this is the cause of the warning for >400 references, not sure how the code should know how many references to expect (the number of loaded classes..).

If I do make classTrack_initialize state it wants a large number of local references, that warning disappears:

$ git diff src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
diff --git a/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c b/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
index e3b30282daa..7dfb9ec01c4 100644
--- a/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/classTrack.c
@@ -171,6 +171,7 @@ setupEvents()
 void
 classTrack_initialize(JNIEnv *env)
 {
+    WITH_LOCAL_REFS(env, 500) {
     trackingEnv = getSpecialJvmti();
     if (trackingEnv == NULL) {
         EXIT_ERROR(AGENT_ERROR_INTERNAL, "Failed to allocate tag-tracking jvmtiEnv");
@@ -201,4 +202,5 @@ classTrack_initialize(JNIEnv *env)
     } else {
         EXIT_ERROR(error,"loaded classes array");
     }
+    } END_WITH_LOCAL_REFS(env)
 }

@plummercj
Copy link
Contributor

This is the problematic code:

/* Get all loaded classes (must be inside a WITH_LOCAL_REFS) */
jvmtiError
allLoadedClasses(jclass **ppclasses, jint *pcount)
{
    jvmtiError error;

    *pcount = 0;
    *ppclasses = NULL;
    error = JVMTI_FUNC_PTR(gdata->jvmti,GetLoadedClasses)
                (gdata->jvmti, pcount, ppclasses);
    return error;
}

It seems there are a few places where allLoadedClasses() is called with either no WITH_LOCAL_REFS, or with an inadequate one. However, given that the number of jni localrefs to be allocated is unknown a potentially very large, I'm not sure how callers of JVMTI GetLoadedClasses() are suppose to defend against an excess be allocated.

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

I think we're getting there. A few further nits and now you also need to update the copyright year.

* @summary Launching app with or without jdwp agent shouldn't produce any jni warnings.
* @modules jdk.compiler
* jdk.zipfs
* @compile TestXcheckJNIWarnings.java
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the @compile directive is not necessary

* @summary Launching app with or without jdwp agent shouldn't produce any jni warnings.
* @modules jdk.compiler
* jdk.zipfs
* @compile TestXcheckJNIWarnings.java
Copy link
Contributor

Choose a reason for hiding this comment

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

@compile can be removed.

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

Looks great now 😄

@RealLucy
Copy link
Contributor Author

Thank you all for your valuable feedback and for the reviews. Once the "still in progress" tests have completed successfully, I'll integrate. The failing linux-x86 tier1 test does not look related. It is a c2 compiler test.

@kevinjwalls
Copy link
Contributor

Sounds good. Comment above showing jvmti_GetLoadedClasses as the cause of the references was just to make sure we knew the cause of that other warning, but I see there is JDK-8296936 to follow up that issue.

@RealLucy
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 16, 2022

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 16, 2022

@RealLucy Pushed as commit eac26f4.

💡 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

integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

6 participants