From 409a39ec8da83d6a0895e7e213604455ebf50485 Mon Sep 17 00:00:00 2001 From: Matias Saavedra Silva Date: Wed, 3 Jan 2024 20:10:59 +0000 Subject: [PATCH] 8320276: Improve class initialization barrier in TemplateTable::_new Reviewed-by: dholmes, fparain --- src/hotspot/cpu/aarch64/templateTable_aarch64.cpp | 8 +++----- src/hotspot/cpu/aarch64/vm_version_aarch64.hpp | 1 + src/hotspot/cpu/ppc/vm_version_ppc.hpp | 2 +- src/hotspot/cpu/s390/vm_version_s390.hpp | 2 +- src/hotspot/cpu/x86/templateTable_x86.cpp | 9 +++++++-- src/hotspot/cpu/x86/vm_version_x86.hpp | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp index 6fc6be7a5b3..1a567049a46 100644 --- a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp @@ -3603,11 +3603,9 @@ void TemplateTable::_new() { // get InstanceKlass __ load_resolved_klass_at_offset(r4, r3, r4, rscratch1); - // make sure klass is initialized & doesn't have finalizer - // make sure klass is fully initialized - __ ldrb(rscratch1, Address(r4, InstanceKlass::init_state_offset())); - __ cmp(rscratch1, (u1)InstanceKlass::fully_initialized); - __ br(Assembler::NE, slow_case); + // make sure klass is initialized + assert(VM_Version::supports_fast_class_init_checks(), "Optimization requires support for fast class initialization checks"); + __ clinit_barrier(r4, rscratch1, nullptr /*L_fast_path*/, &slow_case); // get instance_size in InstanceKlass (scaled to a count of bytes) __ ldrw(r3, diff --git a/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp b/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp index 8b67a207cf9..4b2e5cc5a4d 100644 --- a/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp @@ -165,6 +165,7 @@ enum Ampere_CPU_Model { static int dcache_line_size() { return _dcache_line_size; } static int get_initial_sve_vector_length() { return _initial_sve_vector_length; }; + // Aarch64 supports fast class initialization checks static bool supports_fast_class_init_checks() { return true; } constexpr static bool supports_stack_watermark_barrier() { return true; } diff --git a/src/hotspot/cpu/ppc/vm_version_ppc.hpp b/src/hotspot/cpu/ppc/vm_version_ppc.hpp index b1168ded456..a5831ef1590 100644 --- a/src/hotspot/cpu/ppc/vm_version_ppc.hpp +++ b/src/hotspot/cpu/ppc/vm_version_ppc.hpp @@ -91,7 +91,7 @@ public: // Override Abstract_VM_Version implementation static void print_platform_virtualization_info(outputStream*); - // PPC64 supports fast class initialization checks for static methods. + // PPC64 supports fast class initialization checks static bool supports_fast_class_init_checks() { return true; } constexpr static bool supports_stack_watermark_barrier() { return true; } diff --git a/src/hotspot/cpu/s390/vm_version_s390.hpp b/src/hotspot/cpu/s390/vm_version_s390.hpp index d72e2712a40..93d5b11c473 100644 --- a/src/hotspot/cpu/s390/vm_version_s390.hpp +++ b/src/hotspot/cpu/s390/vm_version_s390.hpp @@ -410,7 +410,7 @@ class VM_Version: public Abstract_VM_Version { // Override Abstract_VM_Version implementation static void print_platform_virtualization_info(outputStream*); - // s390 supports fast class initialization checks for static methods. + // s390 supports fast class initialization checks static bool supports_fast_class_init_checks() { return true; } // CPU feature query functions diff --git a/src/hotspot/cpu/x86/templateTable_x86.cpp b/src/hotspot/cpu/x86/templateTable_x86.cpp index b17fc43032c..f53a7872451 100644 --- a/src/hotspot/cpu/x86/templateTable_x86.cpp +++ b/src/hotspot/cpu/x86/templateTable_x86.cpp @@ -4048,11 +4048,16 @@ void TemplateTable::_new() { __ load_resolved_klass_at_index(rcx, rcx, rdx); __ push(rcx); // save the contexts of klass for initializing the header - // make sure klass is initialized & doesn't have finalizer - // make sure klass is fully initialized + // make sure klass is initialized +#ifdef _LP64 + assert(VM_Version::supports_fast_class_init_checks(), "must support fast class initialization checks"); + __ clinit_barrier(rcx, r15_thread, nullptr /*L_fast_path*/, &slow_case); +#else __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized); __ jcc(Assembler::notEqual, slow_case); +#endif + // make sure klass doesn't have finalizer // get instance_size in InstanceKlass (scaled to a count of bytes) __ movl(rdx, Address(rcx, Klass::layout_helper_offset())); // test to see if it has a finalizer or is malformed in some way diff --git a/src/hotspot/cpu/x86/vm_version_x86.hpp b/src/hotspot/cpu/x86/vm_version_x86.hpp index 454a8f31255..e521a6ee3bc 100644 --- a/src/hotspot/cpu/x86/vm_version_x86.hpp +++ b/src/hotspot/cpu/x86/vm_version_x86.hpp @@ -756,7 +756,7 @@ public: // the intrinsic for java.lang.Thread.onSpinWait() static bool supports_on_spin_wait() { return supports_sse2(); } - // x86_64 supports fast class initialization checks for static methods. + // x86_64 supports fast class initialization checks static bool supports_fast_class_init_checks() { return LP64_ONLY(true) NOT_LP64(false); // not implemented on x86_32 }