|
29 | 29 |
|
30 | 30 | import org.graalvm.nativeimage.CurrentIsolate; |
31 | 31 | import org.graalvm.nativeimage.IsolateThread; |
| 32 | +import com.oracle.svm.core.hub.PredefinedClassesSupport; |
32 | 33 | import org.graalvm.nativeimage.Platform; |
33 | 34 | import org.graalvm.nativeimage.Platforms; |
34 | 35 | import org.graalvm.nativeimage.c.function.CFunctionPointer; |
|
44 | 45 | import com.oracle.svm.core.util.VMError; |
45 | 46 |
|
46 | 47 | import jdk.internal.misc.Unsafe; |
| 48 | +import jdk.internal.reflect.Reflection; |
47 | 49 |
|
48 | 50 | /** |
49 | 51 | * Information about the runtime class initialization state of a {@link DynamicHub class}, and |
@@ -184,6 +186,21 @@ private boolean isReentrantInitialization(IsolateThread thread) { |
184 | 186 | private static void initialize(ClassInitializationInfo info, DynamicHub hub) { |
185 | 187 | IsolateThread self = CurrentIsolate.getCurrentThread(); |
186 | 188 |
|
| 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 | + |
187 | 204 | /* |
188 | 205 | * Step 1: Synchronize on the initialization lock, LC, for C. This involves waiting until |
189 | 206 | * the current thread can acquire LC |
|
0 commit comments