RFR: 8311071: Avoid SoftReferences in LambdaFormEditor and MethodTypeForm when storing heap objects into AOT cache
David Holmes
dholmes at openjdk.org
Wed Sep 18 01:05:15 UTC 2024
On Tue, 17 Sep 2024 23:48:11 GMT, Ioi Lam <iklam at openjdk.org> wrote:
> This is the 6th PR for [JEP 483: Ahead-of-Time Class Loading & Linking](https://bugs.openjdk.org/browse/JDK-8315737).
>
> The implementation of java.lang.invoke uses SoftReferences so that unused MethodHandles, LambdaForms, etc, can be garbage collected.
>
> However, if we want to store java.lang.invoke objects in the AOT cache ([JDK-8293336](https://bugs.openjdk.org/browse/JDK-8293336), the final step in JEP 493), it's difficult to cache these SoftReferences -- SoftReferences in turn point to ReferenceQueues, etc, which have dependencies on the current execution state (Threads, etc) which are difficult to cache.
>
> The proposal is to add a new flag: `MethodHandleStatics.NO_SOFT_CACHE`. When this flag is true, we avoid using SoftReferences, and store a direct reference to the target object instead.
>
> [JDK-8293336](https://bugs.openjdk.org/browse/JDK-8293336) stores only java.lang.invoke objects that refer to classes loaded by the boot/platform/app loaders. These classes are never unloaded, so it's not necessary to point to them using SoftReferences.
>
> This RFE modifies only the LambdaFormEditor and MethodTypeForm classes, as that's the minimal modification required by [JDK-8293336](https://bugs.openjdk.org/browse/JDK-8293336).
>
> ---
> See [here](https://bugs.openjdk.org/browse/JDK-8315737) for the sequence of dependent RFEs for implementing JEP 483.
This seems quite reasonable for dumping the static archive.
A couple of typos.
Thanks
src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java line 62:
> 60: static final boolean PROFILE_GWT;
> 61: static final int CUSTOMIZE_THRESHOLD;
> 62: static final boolean NO_SOFT_CACHE; // Don't use SoftReference in LambdaFormEditor and MethodTypeForm so they can archived by CDS.
Suggestion:
static final boolean NO_SOFT_CACHE; // Don't use SoftReference in LambdaFormEditor and MethodTypeForm so they can be archived by CDS.
src/java.base/share/classes/jdk/internal/misc/CDS.java line 81:
> 79: /*
> 80: * Wwhen dumping the static archive, CDS is able to archive MethodHandles.
> 81: * However, CDS cannot archive SoftReferences objects, so we need to
Suggestion:
* However, CDS cannot archive SoftReference objects, so we need to
-------------
Marked as reviewed by dholmes (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/21049#pullrequestreview-2311403651
PR Review Comment: https://git.openjdk.org/jdk/pull/21049#discussion_r1764251342
PR Review Comment: https://git.openjdk.org/jdk/pull/21049#discussion_r1764253505
More information about the core-libs-dev
mailing list