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);
}
}