On Fri, 29 May 2026 16:44:57 GMT, Patricio Chilano Mateo <[email protected]> wrote:
> For calls where value type arguments are passed in scalarized form, the c2 > compiler adds the `Method*` to the relocation metadata > [[1]](https://github.com/openjdk/valhalla/blob/4c23f0ed5d6a89cd1e7ab8550b367bca296a9f30/src/hotspot/share/opto/graphKit.cpp#L2059), > so it can later be recovered in `SharedRuntime::resolve_xxx_call_C` as > `attached_method` instead of resolving normally through the constant pool > (but only if the callee holder is an inline klass > [[2]](https://github.com/openjdk/valhalla/blob/4c23f0ed5d6a89cd1e7ab8550b367bca296a9f30/src/hotspot/share/runtime/sharedRuntime.cpp#L1297)). > > When resolving static calls, before the thread returns back to Java either > the holder class should be already initialized or the thread should be the > one currently initializing it. But the `LinkResolver` path we take for the > `attached_method` case doesn’t try to initialize the holder klass, i.e. there > is an assumption that it’s already initialized. Since c2 doesn’t generate an > uncommon trap in the caller if the callee holder class is being initialized, > a thread can reach the static resolution case of a method from an inline > klass as described above while the class is still being initialized, leading > to the reported assert failure. > > The attached method is needed when the receiver may be scalarized as no > receiver oop might be available to resolve against. Since that doesn’t apply > to static calls the proposed fix is to also ignore the attached method in > those cases. > > I added a reproducer test that crashes with the same assert failure without > this fix. Also tested the patch in mach5 tier1-3 and valhalla-comp-stress. > > Thanks, > Patricio > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). This pull request has now been integrated. Changeset: 071157bf Author: Patricio Chilano Mateo <[email protected]> Committer: Tobias Hartmann <[email protected]> URL: https://git.openjdk.org/valhalla/commit/071157bfa86b9363a5c3d0ee6a64b4658ef01994 Stats: 70 lines in 2 files changed: 69 ins; 0 del; 1 mod 8385469: [lworld] compiler/valhalla/inlinetypes/TestVirtualThreads.java#xcomp-co-test failed with invalid class initialization state for invoke_static Reviewed-by: fparain, thartmann ------------- PR: https://git.openjdk.org/valhalla/pull/2490
