- Fix GC bug in G1 (JDK-8253081)to support archiving the full module graph (https://bugs.openjdk.java.net/browse/JDK-8244778)
- This requires the Archived Heap to maintain a Root List.
- Support CDS Archived Heap for other collectors
- Phase 1: ParallelGC and SerialGC (which support compressed oops)
- Phase 2: ZGC (which requires non-compressed oops)
- It contains objects that are not reachable at VM bootstrap, but may become reachable later.
- For example, archived mirror objects (instances of java.lang.Class) are stored in the Open Region. An archived mirror become reachable only when its corresponding C++ Klass object is loaded by the SystemDictionary.
- As a result, G1 cannot conclude that an archived object is garbage just because it's unreachable.
- Moreover, there's no way for G1 to distinguish between unreachable objects that
- Type A: will later become reachable
- Type B: were once reachable, but have become unreachable
Luckily, in JDK 15, all unreachable objects in the Open Region are of type Type A. I.e., once we have made an archived object reachable, it will always be reachable.
Challenges in JDK 16
In JDK 16, we have implemented JDK-8244778 (Archive full module graph in CDS). With this change, we have introduced objects of Type B into the Open Region:
- The full module graph contains HashMaps (of the currently loaded packages, etc) which are backed by Object arrays.
- Initially, all of these backing arrays are in the Open Region.
- When new classes are loaded, these HashMaps are updated
- As a result, a non-archived object may be stored in to an archived backing array ARR.
- i.e., Object OBJ = new Object(); ARR[n] = OBJ;
- Under some circumstances, ARR becomes garbage (e.g., when the HashMap is expanded)
- ARR is now a Type B object.
- Later, a GC happens, and OBJ is relocated due to GC
- However, ARR[n] is not relocated (because ARR is not reachable??). As a result, ARR[n] becomes invalid (points to garbage)
- Under some circumstances (GC verification – and possibly other situations as well??), ARR[n] is dereferenced and we would get an assert or crash in the GC.