RFR: 8375314: Parallel: Crash iterating over unloaded classes for ObjectCountAfterGC event
Stefan Johansson
sjohanss at openjdk.org
Wed Jan 21 09:21:05 UTC 2026
On Tue, 20 Jan 2026 13:08:07 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:
> Hi all,
>
> please review this change that avoids crashes when gathering `ObjectCountAfterGC` JFR statisics.
>
> The cause for the crash is that the code purges metaspace after class unloading/purging after https://bugs.openjdk.org/browse/JDK-8361404. The heap iteration code walks the heap with classes that were unloaded and purged, eventually crashing if for some reason the data is invalid due to metaspace purging potentially uncommitting memory.
>
> Since it is somewhat ugly that we walk objects with dead klasses in them (as it was before the mentioned change), I moved the iteration to after the heap has been compacted, skipping filler objects that might be in there.
>
> Unfortunately I did not manage to write a good reproducer.
>
> Testing: gha, tier1-5, test case succeeding
>
> Thanks,
> Thomas
Looks good, thanks for handling this.
Just a small suggestion.
src/hotspot/share/gc/parallel/psParallelCompact.cpp line 1041:
> 1039: _gc_tracer.report_object_count_after_gc(&cl, &ParallelScavengeHeap::heap()->workers());
> 1040: }
> 1041:
What do you think about extracting this to a helper to avoid the closure definition in the middle of this already very long function?
-------------
Marked as reviewed by sjohanss (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/29318#pullrequestreview-3685962200
PR Review Comment: https://git.openjdk.org/jdk/pull/29318#discussion_r2711511941
More information about the hotspot-gc-dev
mailing list