JDK-8311078 : API for archiving Java objects that need special clean up/restore
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • Submitted: 2023-06-29
  • Updated: 2024-06-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
A general solution for JDK-8311071 may be new API to clean up and restore archived Java objects. 

For example, something like this can be used:

- dump time: remove SoftReferences before the object is archived
- run time: recreate the SoftReferences after the object is materialized

class LambdaFormEditor$Transform implements CDSCleaner, CDSRestorer {
    Object cache;

    private Transform(long packedBytes, byte[] fullBytes, LambdaForm result) {
        cache = new SoftReference<LambdaForm>(result);
        this.packedBytes = packedBytes;
        this.fullBytes = fullBytes;
        CDSCleaner.register(this);
    }

    public void cleanForCDS() { // CDSCleaner
        SoftReference<LambdaForm> ref = (SoftReference<LambdaForm>)cache;
        cache = ref.get();
    }

    public void restoreFromCDS() { // CDSRestorer
        cache = new SoftReference<LambdaForm>((LambdaForm)cache);
    }
}