RFR: 8268139: CDS ArchiveBuilder may reference unloaded classes

Ioi Lam iklam at openjdk.java.net
Wed Jun 2 21:50:56 UTC 2021


During CDS dump, we enter a safepoint (e.g., `VM_PopulateDynamicDumpSharedSpace`) and run `ArchiveBuilder::gather_source_objs()` to collect all classes to be dumped. However, some of these classes may belong to custom class loaders that are no longer alive. While we are still inside the safepoint, concurrent GC operations may free these class loaders (see https://github.com/openjdk/jdk/pull/4286). Thus `ArchiveBuilder` may end up referencing unloaded classes.

The fix:

(1) Add a class `k` to ArchiveBuilder only if `k->class_loader_data()->is_alive()`

(2) All the classes added to `ArchiveBuilder` are taken from `DumpTimeSharedClassTable`. When a class is loaded, it's added to this table. When a class is unloaded, it's removed from this table (via `SystemDictionaryShared::remove_dumptime_info`). This table is protected by `DumpTimeTable_lock`. To make sure that this table is not changed during the CDS safepoint, we grab this lock before calling `ArchiveBuilder::gather_source_objs()`, and release this lock only when the CDS dump is finished. As a result, in step (1) above, when we call `k->class_loader_data()->is_alive()`, we are sure that `k` itself has not been deallocated and is still a valid pointer.

Testing -- Mach5 tiers 1-4 in progress

-------------

Commit messages:
 - 8268139: CDS ArchiveBuilder may reference unloaded classes

Changes: https://git.openjdk.java.net/jdk/pull/4322/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=4322&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8268139
  Stats: 25 lines in 4 files changed: 18 ins; 0 del; 7 mod
  Patch: https://git.openjdk.java.net/jdk/pull/4322.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/4322/head:pull/4322

PR: https://git.openjdk.java.net/jdk/pull/4322


More information about the hotspot-runtime-dev mailing list