RFR: 8293187: Store initialized Enum classes in AOTCache [v3]

Ashutosh Mehra asmehra at openjdk.org
Thu Sep 19 14:19:43 UTC 2024


On Thu, 19 Sep 2024 02:23:32 GMT, Ioi Lam <iklam at openjdk.org> wrote:

>>> That's why there's no check for k to be aot-initialized.
>> 
>> I was actually referring to the missing aot-initialized check for the Fruit class.
>> As it stands, this method initializes the classes required by the archive mirrors as the _runtime_default_subgraph_info has all the archived mirrors. But not all classes that have archived mirror are aot-initialized. And from the Fruit class example in the comment it seems this method should only be initializing the classes that are required by archived mirrors of _aot-initialized classes_:
>> 
>> 
>> // For example, if this enum class is initialized at AOT cache assembly time:
>> //
>> //    enum Fruit {
>> //       APPLE, ORANGE, BANANA;
>> //       static final Set<Fruit> HAVE_SEEDS = new HashSet<>(Arrays.asList(APPLE, ORANGE));
>> //   }
>> //
>> // the pre-inited mirror of Fruit references HashSet, which should be initialized
>> // before any Java code can access the Fruit class.
>> 
>> 
>> So based on the comment there should be a way to identify the subgraph_object_klasses of only the aot-initialized classes and initialize only those classes.
>> Am I reading this wrong?
>
>> I was actually referring to the missing aot-initialized check for the Fruit class. As it stands, this method initializes the classes required by the archive mirrors as the _runtime_default_subgraph_info has all the archived mirrors.
> 
> `_runtime_default_subgraph_info` is not recording the mirrors. It records all the classes of all the objects that can are reachable from the archived mirrors.
> 
> For example, if the following three classes are aot-initialized:
> 
> 
> class A { static Object foo = new X(); }
> class B { static Object foo = new Y(); }
> class C { static Object foo = new Y(); }
> 
> 
> `_runtime_default_subgraph_info`  records `X` and `Y`. It doesn't record `A`, `B`, or `C`.
> 
>> But not all classes that have archived mirror are aot-initialized. 
> 
> If a class is not AOT initialized, its mirror is filled with zeros (plus a few native pointers) so the mirror doesn't point to any object.

Expanding on the above example, lets say A is aot- initialized, but B and C are not.
So this function should initialize only X not Y, is that correct? If so, then how does it prevent initialization of Y? It iterates through all the subgraph_object_klasses which includes both X and Y.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20958#discussion_r1766924948


More information about the hotspot-dev mailing list