RFR: 8374549: Extend MetaspaceClosure to cover non-MetaspaceObj types

Ashutosh Mehra asmehra at openjdk.org
Fri Jan 23 19:55:27 UTC 2026


On Mon, 5 Jan 2026 20:32:46 GMT, Ioi Lam <iklam at openjdk.org> wrote:

> Previously, `MetaspaceClosure` could iterate only `MetaspaceObject`, using its four member functions:
> 
> - `is_read_only_by_default()`
> - `metaspace_pointers_do()`
> - `size()`
> - `type()`
> 
> `PackageEntry`, `ModuleEntry` and `GrowableArray` cannot be subclasses from `MetaspaceObject` due to various constraints.  As a result, they were copied with ad-hoc code.
> 
> This PR updates the templates in `MetaspaceClosure` so that it can iterate any classes  that have the above four functions. This allows new types of data to be uniformly copied into the AOT cache (aka CDS archive) without ad-hoc copiers.
> 
> This PR is necessary for future evolution of AOT as more types of data will be copied into the AOT cache. For example, in Valhalla we have a `GrowableArray` that needs to be copied along with `AdapterHandleEntry`.

lgtm

src/hotspot/share/utilities/growableArray.hpp line 302:

> 300: 
> 301:   // MetaspaceClosure support.
> 302:   E** data_addr() {

My only concern is that it is marked public which breaks encapsulation. I think we can mark it as protected if only `AOTGrowableArray` is accessing it but gtest also uses it so I am not sure if anything can be done here.

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

PR Comment: https://git.openjdk.org/jdk/pull/29049#issuecomment-3792099008
PR Review Comment: https://git.openjdk.org/jdk/pull/29049#discussion_r2722622911


More information about the hotspot-dev mailing list