On Wed, 25 Nov 2026 11:53:52 GMT, Markus Grönlund <[email protected]> wrote:

>> The raw `Method*` stored in `_all_mirandas` were unsafe as the `Method` 
>> could be reclaimed when class redefinition occurs. Using the code from 
>> `JfrMethodProcessor` we extracted a new helper class, `ProtectedMethods` to 
>> preserve the lifetime of the `Method`s whilst they are in use. This is used 
>> across classfile parsing, and was also needed in 
>> `JfrClassTransformer::create_new_instance_klass`.
>> 
>> The new test easily demonstrated the crash prior to the fix, running 
>> concurrent loads and redefinitions, over a 60 second timeframe. Due to the 
>> length of the test it is not run in tier1 but in tier2.
>> 
>> Testing:
>>  - tiers 1-3 general testing
>>  - tier 5 for JFR
>>  - local testing
>> 
>> I ran some of the classloading microbenchmarks and did not see any signs of 
>> there being additional overhead associated with the new code - of course it 
>> will be highly dependent on the number of interfaces encountered with 
>> default methods. I'm also running some tests through our performance system.
>> 
>> Thanks
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Hi David,
> 
> `_all_mirandas` can follow the same lifetime invariant as `_super_klass`. The 
> parser keeps the resolved `InstanceKlass*` for each candidate's declaring 
> interface across the safepoint and can then read its current method table 
> when required.
> 
> The loader defining the class being parsed initiates the interface lookup. If 
> a different loader outside of its parent chain defined the resolved 
> interface, then `ClassLoaderData::record_dependency()` will store a reference 
> to that loader in the initiating loader's `ClassLoaderData`. That keeps the 
> interface's defining loader alive whilst the parser is using the interface. 
> Therefore, we can use direct `InstanceKlass*` pointers.
> 
> Each candidate can store `(InstanceKlass*, orig_method_idnum)` and use 
> `iface->method_with_idnum(orig_method_idnum)` when populating the candidate 
> vtable slots. Redefinition and retransformation will preserve the original ID 
> for those methods. JFR method tracing uses `orig_method_idnum()` to match the 
> old and new method versions when moving the trace tags. `is_miranda()` will 
> exclude private and static methods so every candidate stored is a public 
> interface instance method. That means JVMTI can't delete it.
> 
> This trades metadata handle registration and release for one method ID lookup 
> per candidate, retaining the same number of hierarchy walks. Most 
> importantly, it follows the same form as `_super_klass`.

I am currently exploring the alternate approach suggested by @mgronlun . It 
does seem simpler to not store the raw Method ptr in the first place. My only 
concern is whether the method lookup by id may be too slow with large classes 
(as it can degrade to a linear search).

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

PR Comment: https://git.openjdk.org/jdk/pull/34016#issuecomment-7210566094

Reply via email to