On Wed, 18 Nov 2026 11:02:20 GMT, Markus Grönlund <[email protected]> wrote:

>> It is some extra complexity and a little bit ugly that we use different 
>> bookkeeping policy before and after retransformation. At least, this needs 
>> to be well commented.
>
> Ugly is what the underlying implementation is.
> 
> It forces a memory leak onto the user, and an engineer trying to fix that 
> must take into account if the intentional memory leak is warranted, because 
> the alternative to having a memory leak might be worse.

The crucial point is that the class containing the invokedynamic instruction 
determines the defining loader of implementation classes generated through the 
supplied lookup. When that host is a Java SE core class loaded by a built-in 
loader, defining those generated classes with STRONG linkage effectively gives 
them JVM lifetime—even after they have ceased to serve any purpose.

Retransformation causes these call sites to be resolved again when execution 
next reaches them. HotSpot creates fresh resolution entries for invokedynamic 
instructions throughout the replacement class, including methods whose 
bytecodes were unchanged. For sites whose bootstraps generate fresh 
implementation classes, that renewed resolution produces another generation 
under the same loader. Under unconditional STRONG linkage, its obsolete 
predecessors remain retained.

Instrumenting one method can therefore cause permanent retention of 
implementation classes generated by other, unchanged methods in the same class. 
Repeating the instrumentation repeats the accumulation.

The retention is by design. The accumulating leak is its consequence.

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

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

Reply via email to