RFR: 8377339: Implement AOTCacheAccess::get_archived_object using heap roots [v2]
Dan Heidinga
heidinga at openjdk.org
Mon Feb 9 21:59:00 UTC 2026
On Mon, 9 Feb 2026 17:49:40 GMT, Ioi Lam <iklam at openjdk.org> wrote:
>> The API `oop AOTCacheAccess::get_archived_object(int)` is used by the AOT compiler to access heap objects in the AOT cache.
>>
>> Because the objects can move in the production run, there's currently a complicated way to keep them alive using OopHandles.
>>
>> https://github.com/openjdk/leyden/blob/6ce1832147ef3f01602b8fac02160038422a77bf/src/hotspot/share/cds/heapShared.cpp#L545-L610
>>
>> However, we already have a mechanism for this: `oop HeapShared::get_root(int index, ...)`
>>
>> So we just need to make sure that all oops needed by the AOT compiler are all stored as heap roots.
>>
>> This PR is intended to provide an acceptable solution in the short run to be used by the initial AOT compiler integration into the mainline.
>>
>> The AOT compiler only needs the following objects
>>
>> - a few common exception objects
>> - class loaders
>> - class mirrors
>> - interned strings
>> - method handles
>>
>> Most of these objects are in the roots already. We just need to add interned strings and method handles into the heap roots.
>>
>> (In the future, we should move the AOT compilation before we dump the heap. This way we know exactly what oops should be stored into the heap roots.)
>>
>> Notes to reviewers
>> - `HeapShared::archived_object_cache()` can now survive GCs that might happen during AOT compilation. I added a new function `HeapShared::archived_object_cache_hash()` with comments about how it uses `oop::identity_hash()`.
>> - This code is added to make sure interned strings and method handles are roots
>>
>> if (AOTCodeCache::is_dumping_code() &&
>> (java_lang_invoke_MethodHandle::is_instance(obj) || is_interned_string(obj))) {
>> // Needed by AOT compiler.
>> append_root(obj);
>> }
>>
>> - Also some clean up that's not necessary but nice to have:
>> - I removed the `DumpedInternedStrings` and replaced it with much simpler code.
>
> Ioi Lam has updated the pull request incrementally with four additional commits since the last revision:
>
> - @DanHeidinga review comment
> - @DanHeidinga review comment
> - @DanHeidinga review comment
> - fixed typo
Minor comments, overall looks good
src/hotspot/share/cds/heapShared.cpp line 256:
> 254: // copying the objects into the cache. This will allow the hashcode to be
> 255: // dynamically and randomly computed in each production, which generally
> 256: // desirable for security reasons.
Suggestion:
// desirable to make the hashcodes more random between runs.
src/hotspot/share/cds/heapShared.cpp line 2468:
> 2466:
> 2467: ResourceMark rm;
> 2468: int len;
Suggestion:
int len = 0;
Nitpick: default values make the code easier to reason about.
-------------
PR Review: https://git.openjdk.org/leyden/pull/108#pullrequestreview-3765087080
PR Review Comment: https://git.openjdk.org/leyden/pull/108#discussion_r2775979090
PR Review Comment: https://git.openjdk.org/leyden/pull/108#discussion_r2775995306
More information about the leyden-dev
mailing list