On Wed, 18 Nov 2026 10:43:06 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:
> 
>   Serguei feedback

A summary of this fix:

When a class is redefined or retransformed, HotSpot creates new resolution 
entries for every `invokedynamic` instruction in the replacement class, 
**including methods with unchanged bytecodes**. The original `STRONG` proxy 
classes remain attached to their defining loader even after they are no longer 
needed. These form the “lost generation,” including any initial bootstrap race 
losers.

With the fix, newly generated proxies use weak linkage. **GC can unload them 
once unreachable**, including proxies from losing concurrent bootstrap 
invocations. Repeated retransformation allows obsolete replacement generations 
to be reclaimed, while the initial strongly linked population remains attached 
to the loader.

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

PR Comment: https://git.openjdk.org/jdk/pull/33921#issuecomment-7003130367

Reply via email to