On Wed, 25 Nov 2026 22:38:11 GMT, Jiangli Zhou <[email protected]> wrote:

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

This came up in Coleen's original PR on the issue (pull/32519). When Dan took 
it over then most of the discussion moved to the impact to JVMTI based agents 
using FollowReferences.

I agree it's a bit of a forced move to synthesize the array field and keep 
existing tool working. The other option is just declare the incompatibility and 
ask HPROF tooling to reconstruct the loader-to-class mapping by indexing the 
CLASS_DUMP records.

I was surprised by the naming the field "<classes>". It doesn't matter of 
course and maybe it's just because we are more used to javac injected fields 
like $assertionsDisabled or local capture val$name. Someone thing like $classes 
might be more obvious to developers.

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

PR Comment: https://git.openjdk.org/jdk/pull/34078#issuecomment-7258419151

Reply via email to