On Tue, 17 Nov 2026 19:52:38 GMT, Markus Grönlund <[email protected]> wrote:
>> Greetings, >> >> Repeated class retransformation can cause lambda invokedynamic call sites to >> be linked again, generating additional hidden lambda proxy classes. These >> classes are defined with STRONG_LOADER_LINK, preventing them from unloading >> independently of their defining class loader. Consequently, obsolete proxy >> classes accumulate across retransformation cycles, causing continued >> class-count and HotSpot Metaspace growth when the class loader remains >> alive. For built-in class loaders, that means for the lifetime of the JVM. >> >> The problem is independent of the instrumentation mechanism that triggers >> retransformation. It can be reproduced without a third-party agent by >> repeatedly starting and stopping JFR recordings with method tracing enabled, >> while executing methods containing lambda call sites. >> >> The fix introduces a necessary condition for lambda proxy classes to be >> defined with STRONG_LOADER_LINK: the caller class has not been >> redefined/retransformed. >> >> The reproducers, before-and-after comparisons, and improvements are all >> detailed in the JIRA issue. >> >> Testing: >> >> - Tier 1 - 6 >> - Newly introduced test LambdaClassUnloading repeated 400 times. >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Markus Grönlund has updated the pull request incrementally with one > additional commit since the last revision: > > Allow obsolete record and type-switch helper classes to unload This looks good to me. I've posted several nits and questions though. src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java line 354: > 352: > 353: try { > 354: // this class is linked at the indy callsite; so define a > hidden nestmate Nit: I'd suggest to keep the original comment at line 354 (should start with capital and and with a dot.) src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 767: > 765: > 766: try { > 767: // this class is linked at the indy callsite; so define a > hidden nestmate Nit: I'd suggest to keep the original comment at line 767 (should start with capital and and with a dot.) test/jdk/java/lang/instrument/LambdaClassUnloading.java line 113: > 111: testHelpers(retransform, "recordHashCode"); > 112: testHelpers(retransform, "typeSwitch"); > 113: } Q: What is the reason to avoid the same testing for the "redefine" case? test/jdk/java/lang/instrument/LambdaClassUnloading.java line 173: > 171: // Transform before the first link too, avoiding an initial > STRONG helper. > 172: transform(retransform, host, originalBytes); > 173: runHelperWorkload(kind); Q: Lines 118 and 172: Does the test ever check that helpers are generated before transformation? test/jdk/java/lang/instrument/LambdaClassUnloading.java line 243: > 241: Asserts.assertTrue(instance.getClass().isHidden(), "Expected a > hidden lambda implementation class"); > 242: classes.add(new WeakReference<>(instance.getClass())); > 243: } Q: Lines: 124-126, 239-242: Does the test verify it actually exercises multiple proxy generations? ------------- PR Review: https://git.openjdk.org/jdk/pull/33921#pullrequestreview-5952518274 PR Review Comment: https://git.openjdk.org/jdk/pull/33921#discussion_r4610562376 PR Review Comment: https://git.openjdk.org/jdk/pull/33921#discussion_r4610580635 PR Review Comment: https://git.openjdk.org/jdk/pull/33921#discussion_r4610614434 PR Review Comment: https://git.openjdk.org/jdk/pull/33921#discussion_r4610663650 PR Review Comment: https://git.openjdk.org/jdk/pull/33921#discussion_r4610697485
