Please review a fix in heap dumper that emits a synthetic <classes> instance field in java.lang.ClassLoader (and subclasses).
[JDK-8391308](https://bugs.openjdk.org/browse/JDK-8391308) removed ClassLoader.classes. All non-bootstrap class loaders (PlatformClassLoader, AppClassLoader and custom ClassLoaders) are affected whenever a loaded Class has no live instances (or subclass instances) on the heap. This can cause undetected leaks because objects referenced only by static fields have no GC root path in the heap dump. This PR adds a synthetic <classes> field descriptor to j.l.ClassLoader. The dumped ClassLoader.<classes> instance field references a synthetic HPROF_GC_OBJ_ARRAY_DUMP, which holds the mirrors of the loaded, non-hidden classes. The synthetic array IDs are generated by the FlatObjectDumper. No Java heap array objects are created for dumping the synthetic <classes>. This avoids potential allocation failures if Java heap is full, which may be the reason the heap dump was triggered. Fixing heap dumper avoids requiring changes to existing HPROF parser tools. With the fix, the new ClassStaticFieldReachabilityTest.java passes. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - Add try-with-resource block for snapshot in - Add a comment to explain why skipping past the array's byte size for - Add DumperSupport::dump_classloader_classes_array() for dumping - Write synthetic <classes> array for ClassLoader (and subclass) instances Changes: https://git.openjdk.org/jdk/pull/34078/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=34078&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8398305 Stats: 235 lines in 3 files changed: 219 ins; 6 del; 10 mod Patch: https://git.openjdk.org/jdk/pull/34078.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/34078/head:pull/34078 PR: https://git.openjdk.org/jdk/pull/34078
