@@ -102,6 +102,9 @@ public abstract class ClassLoader {
102102 private final static String DELEGATING_CL = "sun.reflect.DelegatingClassLoader" ; //$NON-NLS-1$
103103 /*[ENDIF] JAVA_SPEC_VERSION >= 9 */
104104 private boolean isDelegatingCL = false ;
105+ /*[IF JAVA_SPEC_VERSION > 8]*/
106+ private static boolean applicationClassLoaderInited ;
107+ /*[ENDIF] JAVA_SPEC_VERSION > 8 */
105108
106109 /*
107110 * This is the application ClassLoader
@@ -163,7 +166,9 @@ private static final class ClassNameBasedLock { ClassNameBasedLock() {} }
163166 private NativeLibraries nativelibs = null ;
164167/*[ENDIF] JAVA_SPEC_VERSION >= 15 */
165168 private static native void initAnonClassLoader (InternalAnonymousClassLoader anonClassLoader );
166-
169+ /*[IF RAM_CLASS_CACHE_SUPPORT] */
170+ private static final boolean isRCPRestoreRun = VM .isRCPRestoreRun ();
171+ /*[ENDIF] RAM_CLASS_CACHE_SUPPORT */
167172 /*[PR JAZZ 73143]: ClassLoader incorrectly discards class loading locks*/
168173 static final class ClassNameLockRef extends WeakReference <Object > implements Runnable {
169174 private static final ReferenceQueue <Object > queue = new ReferenceQueue <>();
@@ -425,8 +430,21 @@ private ClassLoader(Void staticMethodHolder, String classLoaderName, ClassLoader
425430 specialLoaderInited = (bootstrapClassLoader != null );
426431/*[ENDIF] JAVA_SPEC_VERSION == 8 */
427432 if (specialLoaderInited ) {
428- if (!lazyClassLoaderInit ) {
429- VM .initializeClassLoader (this , VM .J9_CLASSLOADER_TYPE_OTHERS , isParallelCapable );
433+ /*[IF JAVA_SPEC_VERSION > 8]*/
434+ /*
435+ * Assuming the 3rd classloader initialized is application class loader as the order
436+ * to initialize builtin class loaders is defined in the static block of
437+ * openjdk/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java.
438+ */
439+ if (!applicationClassLoaderInited ) {
440+ assignImmortalClassLoader (VM .J9_CLASSLOADER_TYPE_APP , isParallelCapable );
441+ applicationClassLoaderInited = true ;
442+ } else
443+ /*[ENDIF] JAVA_SPEC_VERSION > 8 */
444+ {
445+ if (!lazyClassLoaderInit ) {
446+ VM .initializeClassLoader (this , VM .J9_CLASSLOADER_TYPE_OTHERS , isParallelCapable );
447+ }
430448 }
431449/*[IF JAVA_SPEC_VERSION > 8]*/
432450 unnamedModule = new Module (this );
@@ -438,10 +456,10 @@ private ClassLoader(Void staticMethodHolder, String classLoaderName, ClassLoader
438456 // BootstrapClassLoader.unnamedModule is set by JVM_SetBootLoaderUnnamedModule
439457 unnamedModule = null ;
440458 bootstrapClassLoader = this ;
441- VM . initializeClassLoader ( bootstrapClassLoader , VM .J9_CLASSLOADER_TYPE_BOOT , false );
459+ assignImmortalClassLoader ( VM .J9_CLASSLOADER_TYPE_BOOT , false );
442460 } else {
443461 // Assuming the second classloader initialized is platform classloader
444- VM . initializeClassLoader ( this , VM .J9_CLASSLOADER_TYPE_PLATFORM , false );
462+ assignImmortalClassLoader ( VM .J9_CLASSLOADER_TYPE_PLATFORM , false );
445463 specialLoaderInited = true ;
446464 unnamedModule = new Module (this );
447465 }
@@ -2646,4 +2664,24 @@ static NativeLibraries nativeLibrariesFor(ClassLoader loader) {
26462664 return (loader == null ) ? BootLoader .getNativeLibraries () : loader .nativelibs ;
26472665}
26482666/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
2667+
2668+ /*[IF JAVA_SPEC_VERSION > 8]*/
2669+ /**
2670+ * Assign immortal class loaders for restore run.
2671+ *
2672+ * @param id class loader type
2673+ * @param isParallelCapable true if the loader has registered as parallel capable
2674+ */
2675+ private final void assignImmortalClassLoader (int id , boolean isParallelCapable ) {
2676+ /*[IF RAM_CLASS_CACHE_SUPPORT] */
2677+ if (isRCPRestoreRun ) {
2678+ VM .rcpAssignClassLoader (this , id );
2679+ } else
2680+ /*[ENDIF] RAM_CLASS_CACHE_SUPPORT */
2681+ {
2682+ VM .initializeClassLoader (this , id , isParallelCapable );
2683+ }
2684+ }
2685+ /*[ENDIF] JAVA_SPEC_VERSION > 8 */
2686+
26492687}
0 commit comments