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). ------------- Commit messages: - v1 Changes: https://git.openjdk.org/valhalla/pull/2490/files Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=2490&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8385469 Stats: 70 lines in 2 files changed: 69 ins; 0 del; 1 mod Patch: https://git.openjdk.org/valhalla/pull/2490.diff Fetch: git fetch https://git.openjdk.org/valhalla.git pull/2490/head:pull/2490 PR: https://git.openjdk.org/valhalla/pull/2490
