Skip to content

Commit 72e32a7

Browse files
committed
Add an option to retain JNI IDs after class unloading
In order to measure the impact of keeping jmethodIDs valid for users of AsyncGetCallTrace, add a command line option to retain the JNI ID pools on class unload. New option is `-XX:[+|-]KeepJNIIDs` Related: #17466 Signed-off-by: Graham Chapman <[email protected]>
1 parent aa5cf33 commit 72e32a7

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

Diff for: runtime/oti/j9consts.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ extern "C" {
337337
#define J9_EXTENDED_RUNTIME_REDUCE_CPU_MONITOR_OVERHEAD 0x80000000
338338

339339
/* constants for J9JavaVM.extendedRuntimeFlags2 */
340-
/* Bit 0x1 is free to use. */
341-
#define J9_EXTENDED_RUNTIME2_UNUSED_0x1 0x1
340+
#define J9_EXTENDED_RUNTIME2_KEEP_JNI_IDS 0x1
342341
#define J9_EXTENDED_RUNTIME2_COMPRESS_OBJECT_REFERENCES 0x2
343342
#define J9_EXTENDED_RUNTIME2_ENABLE_PREVIEW 0x4
344343
#define J9_EXTENDED_RUNTIME2_LOAD_AGENT_MODULE 0x8

Diff for: runtime/oti/jvminit.h

+2
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ enum INIT_STAGE {
355355
#define VMOPT_XXHANDLESIGUSR2 "-XX:+HandleSIGUSR2"
356356
#define VMOPT_XXHEAPDUMPONOOM "-XX:+HeapDumpOnOutOfMemoryError"
357357
#define VMOPT_XXNOHEAPDUMPONOOM "-XX:-HeapDumpOnOutOfMemoryError"
358+
#define VMOPT_XXKEEPJNIIDS "-XX:+KeepJNIIDs"
359+
#define VMOPT_XXNOKEEPJNIIDS "-XX:-KeepJNIIDs"
358360
#define VMOPT_XDUMP_EXIT_OUTOFMEMORYERROR "-Xdump:exit:events=systhrow,filter=java/lang/OutOfMemoryError"
359361
#define VMOPT_XDUMP_EXIT_OUTOFMEMORYERROR_DISABLE "-Xdump:exit:none:events=systhrow,filter=java/lang/OutOfMemoryError"
360362

Diff for: runtime/vm/classallocation.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,11 @@ freeClassLoader(J9ClassLoader *classLoader, J9JavaVM *javaVM, J9VMThread *vmThre
376376
RELEASE_CLASS_LOADER_BLOCKS_MUTEX(javaVM);
377377
}
378378

379-
if (classLoader->jniIDs != NULL) {
380-
pool_kill(classLoader->jniIDs);
379+
if (NULL != classLoader->jniIDs) {
380+
if (J9_ARE_NO_BITS_SET(javaVM->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_KEEP_JNI_IDS)) {
381+
pool_kill(classLoader->jniIDs);
382+
}
383+
classLoader->jniIDs = NULL;
381384
}
382385

383386
if (NULL != classLoader->classHashTable) {

Diff for: runtime/vm/jvminit.c

+10
Original file line numberDiff line numberDiff line change
@@ -4074,6 +4074,16 @@ processVMArgsFromFirstToLast(J9JavaVM * vm)
40744074
}
40754075
#endif /* JAVA_SPEC_VERSION >= 19 */
40764076

4077+
{
4078+
IDATA keepJNIIDs = FIND_AND_CONSUME_VMARG(EXACT_MATCH, VMOPT_XXKEEPJNIIDS, NULL);
4079+
IDATA noKeepJNIIDs = FIND_AND_CONSUME_VMARG(EXACT_MATCH, VMOPT_XXNOKEEPJNIIDS, NULL);
4080+
if (keepJNIIDs > noKeepJNIIDs) {
4081+
vm->extendedRuntimeFlags2 |= J9_EXTENDED_RUNTIME2_KEEP_JNI_IDS;
4082+
} else if (keepJNIIDs < noKeepJNIIDs) {
4083+
vm->extendedRuntimeFlags2 &= ~(UDATA)J9_EXTENDED_RUNTIME2_KEEP_JNI_IDS;
4084+
}
4085+
}
4086+
40774087
return JNI_OK;
40784088
}
40794089

0 commit comments

Comments
 (0)