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

Ioi Lam iklam at openjdk.org
Thu Sep 19 16:28:40 UTC 2024


On Thu, 19 Sep 2024 14:17:16 GMT, Ashutosh Mehra <asmehra at openjdk.org> wrote:

>>> 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.

The `subgraph_object_klasses` are built during assembly phase when each mirror is added to the cache. Note that we don't add the "real" mirror of the classes, but we add the scratch mirror:


void HeapShared::archive_java_mirrors() {
    ...
    oop m = scratch_java_mirror(orig_k);
    if (m != nullptr) {
      Klass* buffered_k = ArchiveBuilder::get_buffered_klass(orig_k);
      bool success = archive_reachable_objects_from(1, _default_subgraph_info, m);


So the scratch mirrors of `B` and `C` will be empty when they are being archived.

Because `A` is marked as aot-initialized, we copy the fields of the "real" mirror of `A` into its scratch mirror. See `HeapShared::copy_aot_initialized_mirror()`. That's why we are able to add `X` into the subgraph_object_klasses (when `A`'s scratch mirror is scanned inside `archive_reachable_objects_from()`)

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

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


More information about the hotspot-dev mailing list