Site will be down for Maintenance on Tuesday December 01st from 8-10 AM PT (4-6 PM GMT, Tuesday)
Child pages
  • CDS Archived Heap Improvements

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

1. Overview

In the JDK 16 and 17 timeframe, we plan to enhance the CDS Archived Heap to implement the following:

...

As shown below, the Root List makes it easy to support other collectors.

2. Archived Heap in JDK 15

This section describes the implementation, and the problems, of the Archived Heap in JDK 15.

...

Luckily, in JDK 15, all unreachable objects in the Open Region are of Type A. I.e., once we have made an archived object reachable, it will always be reachable.

...

3. 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.

...

4. Root List - Distinguishing Live and Dead Objects in Open Region

In JDK 16, we will implement a Root List in the Archived Heap to allow the GC to reliably determine whether an archived object is alive or dead:

...

  • At VM bootstrap, the ARR array is referenced indirectly by an ArchivedKlassSubGraphInfoRecord, whose root object is stored in the Root List, so it's reachable.
  • Later, when the ArchivedKlassSubGraphInfoRecord is initialized, its root object is removed from the Root List and stored into Java static field (e.g., ArchivedBootLayer. archivedBootLayer), and ARR will be indirectly referenced from there.
  • Later, when ARR is discarded by the HashMap due to table expansion, it is no longer reachable. G1 knows that ARR is dead and will never dereference ARR[n].

...

5. Support Archived Heap for other collectors

With the Root List, it should be fairly easy to support Archived Heap for SerialGC and ParallelGC. See JDK-8234679 - Support CDS shared heap in non-G1 garbage collectors.

  • At VM bootstrap, reserve enough space in the old generation
  • Copy objects in the Open Region and Closed Region into the old generation
    • Relocation may be necessary, since the Open/Closed regions assume that they are mapped to a pre-determined address, which may be different than the location of the old generation
    • There's already code for doing this kind of relocation (see HeapShared::patch_archived_heap_embedded_pointers)
    • The Open/Closed regions may be divided into at most 4 blocks with gaps in between. The easiest way to handle the gaps is to fill them with a dummy array.
  • Even with the copying/patching, the start up time should still be much faster than running without the Archived Heap. Without the Archived Heap, we need to create many expensive data structures (such as the module graph) from scratch, which is very time consuming.
    • G1 with Archived Heap = 32ms
    • G1 without Archived Heap = 57ms
    • Copying/patching = less than 1ms.

...

6. Support Uncompressed Oops for the Archived Heap

In JDK 15, the class metadata references archived heap objects using narrowOop (e.g. Klass::_archived_mirror). With the Root List, these references are changed to be integer indices. As a result, most of the Archived Heap code should be agnostic to oop encoding. This will make it easier to support uncompressed oops in Archived Heap.

...