On Mon, 14 Nov 2022 14:19:48 GMT, Lutz Schmidt <l...@openjdk.org> wrote:
>> This small change fixes a warning that may pop up during runtime. May I >> please request reviews? Thank you! > > Lutz Schmidt has updated the pull request incrementally with one additional > commit since the last revision: > > 8296709: use multiple @run tags instead of multiple files 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) } ``` ------------- PR: https://git.openjdk.org/jdk/pull/11083