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. >> >> The original proposed fix was as follows: 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`. >> >> @mgronlun then suggested an alternative approach, used elsewhere in CFP and >> in JFR: track the klass and method id and only resolve the `Method*` when >> needed. That is the current approach and avoids touching any JFR code. >> >> 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 >> - 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 and the size of the classes involved. 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 switched to @mgronlun 's suggested fix as I think it is simpler and cleaner to avoid the problem in the first place - thanks Markus. I still have some performance tests running and will be away this week. ------------- PR Comment: https://git.openjdk.org/jdk/pull/34016#issuecomment-7264233117
