diff a/src/java.base/share/classes/java/lang/ClassLoader.java b/src/java.base/share/classes/java/lang/ClassLoader.java
--- a/src/java.base/share/classes/java/lang/ClassLoader.java
+++ b/src/java.base/share/classes/java/lang/ClassLoader.java
@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2019, Azul Systems, Inc. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
@@ -56,10 +56,11 @@
 import jdk.internal.loader.BuiltinClassLoader;
 import jdk.internal.loader.ClassLoaders;
 import jdk.internal.loader.NativeLibrary;
 import jdk.internal.loader.NativeLibraries;
 import jdk.internal.perf.PerfCounter;
+import jdk.internal.misc.CDS;
 import jdk.internal.misc.Unsafe;
 import jdk.internal.misc.VM;
 import jdk.internal.reflect.CallerSensitive;
 import jdk.internal.reflect.CallerSensitiveAdapter;
 import jdk.internal.reflect.Reflection;
@@ -1838,12 +1839,12 @@
             case 3:
                 String msg = "getSystemClassLoader cannot be called during the system class loader instantiation";
                 throw new IllegalStateException(msg);
             default:
                 // system fully initialized
-                assert VM.isBooted() && scl != null;
-                return scl;
+                assert VM.isBooted() && Holder.scl != null;
+                return Holder.scl;
         }
     }
 
     static ClassLoader getBuiltinPlatformClassLoader() {
         return ClassLoaders.platformClassLoader();
@@ -1864,22 +1865,22 @@
             throw new InternalError("system class loader cannot be set at initLevel " +
                                     VM.initLevel());
         }
 
         // detect recursive initialization
-        if (scl != null) {
+        if (Holder.scl != null) {
             throw new IllegalStateException("recursive invocation");
         }
 
         ClassLoader builtinLoader = getBuiltinAppClassLoader();
         String cn = System.getProperty("java.system.class.loader");
         if (cn != null) {
             try {
                 // custom class loader is only supported to be loaded from unnamed module
                 Constructor<?> ctor = Class.forName(cn, false, builtinLoader)
                                            .getDeclaredConstructor(ClassLoader.class);
-                scl = (ClassLoader) ctor.newInstance(builtinLoader);
+                Holder.scl = (ClassLoader) ctor.newInstance(builtinLoader);
             } catch (Exception e) {
                 Throwable cause = e;
                 if (e instanceof InvocationTargetException) {
                     cause = e.getCause();
                     if (cause instanceof Error) {
@@ -1890,13 +1891,13 @@
                     throw (RuntimeException) cause;
                 }
                 throw new Error(cause.getMessage(), cause);
             }
         } else {
-            scl = builtinLoader;
+            Holder.scl = builtinLoader;
         }
-        return scl;
+        return Holder.scl;
     }
 
     // Returns the class's class loader, or null if none.
     static ClassLoader getClassLoader(Class<?> caller) {
         // This can be null if the VM is requesting it
@@ -1905,13 +1906,17 @@
         }
         // Circumvent security check since this is package-private
         return caller.getClassLoader0();
     }
 
-    // The system class loader
-    // @GuardedBy("ClassLoader.class")
-    private static volatile ClassLoader scl;
+    // Holder has the field(s) that need to be initialized during JVM bootstrap even if
+    // the outer is aot-initialized.
+    private static class Holder {
+        // The system class loader
+        // @GuardedBy("ClassLoader.class")
+        private static volatile ClassLoader scl;
+    }
 
     // -- Package --
 
     /**
      * Define a Package of the given Class object.
@@ -2567,14 +2572,28 @@
      */
     private void resetArchivedStates() {
         if (parallelLockMap != null) {
             parallelLockMap.clear();
         }
-        packages.clear();
-        package2certs.clear();
+
+        if (CDS.isDumpingPackages()) {
+            if (System.getProperty("cds.debug.archived.packages") != null) {
+                for (Map.Entry<String, NamedPackage> entry : packages.entrySet()) {
+                    String key = entry.getKey();
+                    NamedPackage value = entry.getValue();
+                    System.out.println("Archiving " + 
+                                       (value instanceof Package ? "Package" : "NamedPackage") +
+                                       " \"" + key + "\" for " + this);
+                }
+            }
+        } else {
+            packages.clear();
+            package2certs.clear();
+        }
         classes.clear();
         classLoaderValueMap = null;
+        libraries.clear();
     }
 }
 
 /*
  * A utility class that will enumerate over an array of enumerations.
