Skip to content

Commit 7f1c621

Browse files
committed
[GR-42628] Load predefined classes during class initialization.
PullRequest: graal/13350
2 parents 3f170be + 1276511 commit 7f1c621

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/classinitialization/ClassInitializationInfo.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.graalvm.nativeimage.CurrentIsolate;
3131
import org.graalvm.nativeimage.IsolateThread;
32+
import com.oracle.svm.core.hub.PredefinedClassesSupport;
3233
import org.graalvm.nativeimage.Platform;
3334
import org.graalvm.nativeimage.Platforms;
3435
import org.graalvm.nativeimage.c.function.CFunctionPointer;
@@ -44,6 +45,7 @@
4445
import com.oracle.svm.core.util.VMError;
4546

4647
import jdk.internal.misc.Unsafe;
48+
import jdk.internal.reflect.Reflection;
4749

4850
/**
4951
* Information about the runtime class initialization state of a {@link DynamicHub class}, and
@@ -184,6 +186,21 @@ private boolean isReentrantInitialization(IsolateThread thread) {
184186
private static void initialize(ClassInitializationInfo info, DynamicHub hub) {
185187
IsolateThread self = CurrentIsolate.getCurrentThread();
186188

189+
/*
190+
* GR-43118: If a predefined class is not loaded, and the caller class is loaded, set the
191+
* classloader of the initialized class to the class loader of the caller class.
192+
*
193+
* This does not work in general as class loading happens in more places than class
194+
* initialization, e.g., on class literals. However, this workaround makes most of the cases
195+
* work until we have a proper implementation of class loading.
196+
*/
197+
if (!hub.isLoaded()) {
198+
Class<?> callerClass = Reflection.getCallerClass();
199+
if (DynamicHub.fromClass(callerClass).isLoaded()) {
200+
PredefinedClassesSupport.loadClassIfNotLoaded(callerClass.getClassLoader(), null, DynamicHub.toClass(hub));
201+
}
202+
}
203+
187204
/*
188205
* Step 1: Synchronize on the initialization lock, LC, for C. This involves waiting until
189206
* the current thread can acquire LC

0 commit comments

Comments
 (0)