RFR: 8369296: Add fast class init checks in interpreter for resolving ConstantPool entries for static field [v2]
Vladimir Kozlov
kvn at openjdk.org
Wed Oct 8 19:21:27 UTC 2025
On Tue, 7 Oct 2025 19:02:13 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
>>> First, what do you mean "blocks"? It wait something with lock?
>>
>>> Second, my question was that slow path in clinit_barrier will jump to L_clinit_barrier_slow which is before clinit_barrier there are no branch there so after call_VM we again will call clinit_barrier? what I am missing?
>>
>> `clinit_barrier` itself doesn't block. Its a quick check for class fully initialized or the current thread is the init thread. If not, then it jumps to the slow path. In this case slow path is the call to `InterpreterRuntime::resolve_from_cache` which may initialize the klass or get blocked if the klass is being initialized by another thread.
>> After returning it again executes `clinit_barrier`. But this time the class should have initialized, so it just falls through.
>>
>> Also, I think `clinit_barrier` is not a very accurate name because it doesn't cause initialization of the klass. I think `fast_clinit_check` better conveys what it is doing, but that renaming can be done later if required.
>
>> After returning it again executes clinit_barrier. But this time the class should have initialized, so it just falls through.
>
> There are no guarantees that the class is initialized. But the only case when it doesn't hold is when the class is being initialized and current thread is initializing one. So, it is guaranteed that slow path is taken at most once.
>
>> I think fast_clinit_check better conveys what it is doing
>
> `clinit_barrier` implements a fast path check, so `clinit_barrier_fast_path` maybe a more accurate variant.
@iwanowww I see next changes in Leyden repo only for aarch64. Do we need it?
diff --git a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp
index 2ccde98d98d..6fbe6a3a89d 100644
--- a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp
@@ -352,6 +352,18 @@ void TemplateTable::ldc(LdcType type)
__ cmp(r3, (u1)JVM_CONSTANT_Class);
__ br(Assembler::NE, notClass);
+ __ load_resolved_klass_at_offset(r2, r1, r3, rscratch1); // kills r3=tag
+
+ __ cmp(r3, zr); // resolved_klass ?= null
+ __ br(Assembler::EQ, call_ldc);
+
+ const int mirror_offset = in_bytes(Klass::java_mirror_offset());
+ __ ldr(r3, Address(r3, mirror_offset));
+ __ resolve_oop_handle(r3, rscratch1, rscratch2);
+ __ push_ptr(r3);
+
+ __ b(Done);
+
__ bind(call_ldc);
__ mov(c_rarg1, is_ldc_wide(type) ? 1 : 0);
call_VM(r0, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), c_rarg1);
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27676#issuecomment-3382890408
More information about the hotspot-dev
mailing list