Skip to content

Commit

Permalink
Properly initialize the extensionClassLoader from the VM snapshot
Browse files Browse the repository at this point in the history
This patch properly initializes the extensionClassLoader on
restore runs through the paths in BytecodeInterpreter.hpp and
FastJNI_com_ibm_oti_vm_VM.cpp rather than, incorrectly, allocating
a new class loader.

Fixes: #20861
Signed-off-by: Nathan Henderson <[email protected]>
  • Loading branch information
ThanHenderson committed Dec 19, 2024
1 parent f806233 commit 767a9d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
25 changes: 16 additions & 9 deletions runtime/vm/BytecodeInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4748,15 +4748,22 @@ class INTERPRETER_CLASS
allClassesEndDo(&classWalkState);
} else {
updateVMStruct(REGISTER_ARGS);
J9ClassLoader* result = internalAllocateClassLoader(_vm, classLoaderObject);
VMStructHasBeenUpdated(REGISTER_ARGS); // likely unnecessary - no code runs in internalAllocateClassLoader
if (NULL == result) {
rc = GOTO_THROW_CURRENT_EXCEPTION;
goto done;
}
if (J9_CLASSLOADER_TYPE_PLATFORM == loaderType) {
/* extensionClassLoader holds the platform class loader in Java 11+ */
_vm->extensionClassLoader = result;
#if defined(J9VM_OPT_SNAPSHOTS)
if (IS_RESTORE_RUN(_vm) && (J9_CLASSLOADER_TYPE_PLATFORM == loaderType)) {
_vm->internalVMFunctions->initializeSnapshotClassLoaderObject(_vm, _vm->extensionClassLoader, classLoaderObject);
} else
#endif /* defined(J9VM_OPT_SNAPSHOTS) */
{
J9ClassLoader *result = internalAllocateClassLoader(_vm, classLoaderObject);
VMStructHasBeenUpdated(REGISTER_ARGS); // likely unnecessary - no code runs in internalAllocateClassLoader
if (NULL == result) {
rc = GOTO_THROW_CURRENT_EXCEPTION;
goto done;
}
if (J9_CLASSLOADER_TYPE_PLATFORM == loaderType) {
/* extensionClassLoader holds the platform class loader in Java 11+ */
_vm->extensionClassLoader = result;
}
}
}
restoreInternalNativeStackFrame(REGISTER_ARGS);
Expand Down
15 changes: 11 additions & 4 deletions runtime/vm/FastJNI_com_ibm_oti_vm_VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,17 @@ Fast_com_ibm_oti_vm_VM_initializeClassLoader(J9VMThread *currentThread, j9object
}
allClassesEndDo(&classWalkState);
} else {
J9ClassLoader *classLoaderStruct = internalAllocateClassLoader(vm, classLoaderObject);
if (J9_CLASSLOADER_TYPE_PLATFORM == loaderType) {
/* extensionClassLoader holds the platform class loader in Java 11+ */
vm->extensionClassLoader = classLoaderStruct;
#if defined(J9VM_OPT_SNAPSHOTS)
if (IS_RESTORE_RUN(vm) && (J9_CLASSLOADER_TYPE_PLATFORM == loaderType)) {
vm->internalVMFunctions->initializeSnapshotClassLoaderObject(vm, vm->extensionClassLoader, classLoaderObject);
} else
#endif /* defined(J9VM_OPT_SNAPSHOTS) */
{
J9ClassLoader *classLoaderStruct = internalAllocateClassLoader(vm, classLoaderObject);
if (J9_CLASSLOADER_TYPE_PLATFORM == loaderType) {
/* extensionClassLoader holds the platform class loader in Java 11+ */
vm->extensionClassLoader = classLoaderStruct;
}
}
}
}
Expand Down

0 comments on commit 767a9d8

Please sign in to comment.