On Thu, 19 Nov 2026 17:28:05 GMT, Markus Grönlund <[email protected]> wrote:
> Greetings, > > ClassLoadingService records a class load during > ClassFileParser::fill_instance_klass(), before the parsed class has been > accepted into the class hierarchy. > > Consequently, its counters include implementation artifacts that are not > newly loaded classes: > > * Scratch classes created during redefinition and retransformation. > * Discarded class definitions, such as losing candidates from competing > parallel class-loading attempts. > > These artifacts are reclaimed without corresponding class-unload accounting. > The cumulative loaded-class count is therefore inflated, and the reported > currently loaded count can grow even when the underlying metadata is > reclaimed. > This affects consumers such as ClassLoadingMXBean and JFR’s class-loading > statistics, potentially giving a false indication of a class leak. > > Fix > Move the tally into InstanceKlass::add_to_hierarchy(), where only accepted > classes enter the hierarchy. Remove the separate CDS load notification to > avoid double-counting, while preserving shared class counts through > in_aot_cache(). > > This corresponds to the actual installation of loaded classes, rather than > class-file parsing. > > Noticed while working on > [JDK-8392362](https://bugs.openjdk.org/browse/JDK-8392362) > > Testing: > > - tiers 1, 2, 3 > - jdk_svc > - jdk_jfr > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). This looks pretty good in general. I've posted a couple of nits/questions. test/jdk/java/lang/management/ClassLoadingMXBean/RedefinitionCounts.java line 1: > 1: /* The copyright header is missed. test/jdk/java/lang/management/ClassLoadingMXBean/RedefinitionCounts.java line 81: > 79: return new Counts(CLASS_LOADING.getLoadedClassCount(), > 80: CLASS_LOADING.getTotalLoadedClassCount(), > 81: CLASS_LOADING.getUnloadedClassCount()); Does the `readCounts()` method need any kind of sync? Can a class unload happen between these three separate MXBean calls? If so, we may observe intermittent failures. You could read `Total` and `Unloaded` counts before and after read of `Loaded` count and retry it if the counts before and after are not equal. ------------- PR Review: https://git.openjdk.org/jdk/pull/33973#pullrequestreview-5989123527 PR Review Comment: https://git.openjdk.org/jdk/pull/33973#discussion_r4639770711 PR Review Comment: https://git.openjdk.org/jdk/pull/33973#discussion_r4639861295
