Summary:
Implement "Class Preloading", a new mode of introducing classes into the JVM to ensure that AOT artifacts are in a consistent state.
Background:
An AOT cache contains various types of pre-computed artifacts for a set of Java classes. E.g.,
- The C++ and Java representation of the Java classes and their bytecodes. E.g., InstanceKlass in C++ or java.lang.invoke.MethodHandle in Java.
- Java heap objects (instances of Java classes)
- AOT execution profile (upcoming in JDK-8325147)
- AOT compiled Java methods (upcoming in JDK-8335368)
For these artifacts to be valid, the corresponding Java classes (InstanceKlasses) must be already in at least the loaded state in the HotSpot SystemDictionary. In addition, some artifacts require their corresponding Java classes to be in the linked state.
In JDK 24, the set of classes managed by aotLinkedClassBulkLoader.cpp are programmatically loaded, in 4 different stages, into the system dictionary
- classes in java.base
- boot loader classes in other packages
- platform loader classes
- app loader classes
During the loading of these classes, Java methods may be executed (e.g., to initialize ProtectionDomain objects). This already requires a workaround in [1] to allow object instances of not-yet-loaded classes. When we add AOT compiled Java methods, we would need to introduce extra checks to avoid executing code of classes not yet loaded. Such checks complicates the GC and compiler subsystems, and slows down VM start-up.
==========
Proposal -- Class Preloading
- In the AOT cache assembly phase -- when caching a class from the boot/platform/app loaders, we also cache the Package, Module and ProtectionDomain objects for this class (including both the C++ and Java objects).
- When running the JVM with an AOT cache, at the beginning of vmClasses::resolve_all(), add all classes from the boot/platform/app loaders are added into their SystemDictionary, and set them in the "linked" state. This is done with a new C++ method SystemDictionary::preload_class(InstanceKlass* ik, TRAPS).
As a result, before any Java code is executed, and before a GC can happen, the JVM already contains a self-consistent snapshot of AOT-computed set of Java classes and objects.
This RFE will be implemented in multiple steps (as subtasks -- to be filed).
==========
[1] https://github.com/openjdk/jdk/blame/302bed055c3b4881f97c584d5953273b9dbc2969/src/hotspot/share/memory/iterator.inline.hpp#L53-L60
Implement "Class Preloading", a new mode of introducing classes into the JVM to ensure that AOT artifacts are in a consistent state.
Background:
An AOT cache contains various types of pre-computed artifacts for a set of Java classes. E.g.,
- The C++ and Java representation of the Java classes and their bytecodes. E.g., InstanceKlass in C++ or java.lang.invoke.MethodHandle in Java.
- Java heap objects (instances of Java classes)
- AOT execution profile (upcoming in JDK-8325147)
- AOT compiled Java methods (upcoming in JDK-8335368)
For these artifacts to be valid, the corresponding Java classes (InstanceKlasses) must be already in at least the loaded state in the HotSpot SystemDictionary. In addition, some artifacts require their corresponding Java classes to be in the linked state.
In JDK 24, the set of classes managed by aotLinkedClassBulkLoader.cpp are programmatically loaded, in 4 different stages, into the system dictionary
- classes in java.base
- boot loader classes in other packages
- platform loader classes
- app loader classes
During the loading of these classes, Java methods may be executed (e.g., to initialize ProtectionDomain objects). This already requires a workaround in [1] to allow object instances of not-yet-loaded classes. When we add AOT compiled Java methods, we would need to introduce extra checks to avoid executing code of classes not yet loaded. Such checks complicates the GC and compiler subsystems, and slows down VM start-up.
==========
Proposal -- Class Preloading
- In the AOT cache assembly phase -- when caching a class from the boot/platform/app loaders, we also cache the Package, Module and ProtectionDomain objects for this class (including both the C++ and Java objects).
- When running the JVM with an AOT cache, at the beginning of vmClasses::resolve_all(), add all classes from the boot/platform/app loaders are added into their SystemDictionary, and set them in the "linked" state. This is done with a new C++ method SystemDictionary::preload_class(InstanceKlass* ik, TRAPS).
As a result, before any Java code is executed, and before a GC can happen, the JVM already contains a self-consistent snapshot of AOT-computed set of Java classes and objects.
This RFE will be implemented in multiple steps (as subtasks -- to be filed).
==========
[1] https://github.com/openjdk/jdk/blame/302bed055c3b4881f97c584d5953273b9dbc2969/src/hotspot/share/memory/iterator.inline.hpp#L53-L60