On Wed, 18 Nov 2026 06:43:35 GMT, Markus Grönlund <[email protected]> wrote:

>>> I don't quite follow the logic here. Isn't it the old proxy classes that 
>>> you want to be able to reclaim now that they are being replaced by new ones 
>>> due to the redefinition?
>> 
>> Yes—the obsolete proxy classes are precisely what we want to reclaim. This 
>> change enables that for subsequent generations. It cannot retroactively 
>> remove `STRONG_LOADER_LINK` from classes that were already defined with it. 
>> Those remain retained for the lifetime of their defining loader; for the 
>> built-in loaders, effectively the lifetime of the JVM.
>> 
>> The distinction is between that initial strongly linked generation and the 
>> additional generations produced by repeated instrumentation:
>> 
>> 1. JFR Method Tracing targets a specific method, instrumenting it through 
>> class retransformation.
>> 2. Retransformation runs the rewriter over **all methods** of the 
>> replacement class, including methods whose bytecodes were unchanged. Each 
>> `invokedynamic` instruction receives a fresh, initially unresolved entry.
>> 3. When execution reaches those sites, resolution invokes their bootstrap 
>> methods again. Newly generated lambda proxy classes are now defined without 
>> `STRONG_LOADER_LINK`, because the caller satisfies the redefinition 
>> predicate.
>> 4. Stopping tracing retransforms the class again to remove the 
>> instrumentation. This again replaces the methods and their linkage state. 
>> Proxy classes from the preceding generation can now unload once they are 
>> otherwise unreachable, because they were defined without the strong loader 
>> link.
>> 5. Further instrumentation cycles follow the same pattern: subsequent 
>> obsolete generations can be reclaimed.
>> 
>> The initial strongly linked generation remains. This change prevents 
>> repeated instrumentation from continually adding further generations that 
>> must remain alive for the lifetime of the loader.
>
> Another mechanism allows this lifetime choice to retain unnecessary 
> implementation classes without retransformation. When multiple threads 
> concurrently attempt to resolve the same invokedynamic instruction, the 
> bootstrap method may be invoked several times. The Java Virtual Machine (JVM) 
> selects the result of one invocation, while disregarding the results of other 
> invocations. [JVMS 
> §5.4.3.6](https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-5.html#jvms-5.4.3.6)
> 
> If each of these competing invocations generates implementation classes with 
> STRONG_LOADER_LINK, discarding their linkage results does not permit the 
> classes to be unloaded. These classes remain associated with the defining 
> loader, including those whose implementations were never selected for the 
> call site.
> 
> This means even the initial resolution process can leave redundant 
> implementation classes for the lifetime of the loader. As additional 
> core-library functionality adopts class-generating bootstraps, more sites 
> become susceptible to this retention.
> 
> The current change addresses subsequent generations following redefinition or 
> retransformation, but does not modify the initial-resolution scenario.

Thanks for clarifying the expectation here. I still have a concern though:

> 3. When execution reaches those sites, resolution invokes their bootstrap 
> methods again. Newly generated lambda proxy classes are now defined without 
> STRONG_LOADER_LINK, because the caller satisfies the redefinition predicate.

So what now ensures the strong link to these temporary proxy classes whilst 
tracing is enabled?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33921#discussion_r4610122974

Reply via email to