From dbf4ffffe3fbbb513122081bbcc04c543473082e Mon Sep 17 00:00:00 2001 From: Ioi Lam Date: Fri, 5 Sep 2025 23:55:13 +0000 Subject: [PATCH] 8366477: Refactor AOT-related flag bits in klass.hpp Reviewed-by: liach, asmehra, kvn --- src/hotspot/share/cds/archiveBuilder.cpp | 2 +- src/hotspot/share/cds/lambdaFormInvokers.cpp | 4 +- .../classfile/systemDictionaryShared.cpp | 2 +- src/hotspot/share/oops/instanceKlass.hpp | 8 --- src/hotspot/share/oops/instanceKlassFlags.hpp | 2 - src/hotspot/share/oops/klass.cpp | 2 +- src/hotspot/share/oops/klass.hpp | 70 ++++++++++++------- 7 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/hotspot/share/cds/archiveBuilder.cpp b/src/hotspot/share/cds/archiveBuilder.cpp index 7a6c91e503e..42d575a012f 100644 --- a/src/hotspot/share/cds/archiveBuilder.cpp +++ b/src/hotspot/share/cds/archiveBuilder.cpp @@ -942,7 +942,7 @@ void ArchiveBuilder::make_klasses_shareable() { old = " old"; } - if (ik->is_generated_shared_class()) { + if (ik->is_aot_generated_class()) { generated = " generated"; } if (aotlinked) { diff --git a/src/hotspot/share/cds/lambdaFormInvokers.cpp b/src/hotspot/share/cds/lambdaFormInvokers.cpp index 966b3eab298..e8900f43d43 100644 --- a/src/hotspot/share/cds/lambdaFormInvokers.cpp +++ b/src/hotspot/share/cds/lambdaFormInvokers.cpp @@ -184,7 +184,7 @@ void LambdaFormInvokers::regenerate_holder_classes(TRAPS) { klass->set_shared_classpath_index(0); // Set the "generated" bit, so it won't interfere with JVMTI. // See SystemDictionaryShared::find_builtin_class(). - klass->set_is_generated_shared_class(); + klass->set_is_aot_generated_class(); } } else { int len = h_bytes->length(); @@ -222,7 +222,7 @@ void LambdaFormInvokers::regenerate_class(char* class_name, ClassFileStream& st, AOTMetaspace::try_link_class(THREAD, result); assert(!HAS_PENDING_EXCEPTION, "Invariant"); - result->set_is_generated_shared_class(); + result->set_is_aot_generated_class(); if (!klass->in_aot_cache()) { log_info(aot, lambda)("regenerate_class excluding klass %s %s", class_name, klass->name()->as_C_string()); SystemDictionaryShared::set_excluded(InstanceKlass::cast(klass)); // exclude the existing class from dump diff --git a/src/hotspot/share/classfile/systemDictionaryShared.cpp b/src/hotspot/share/classfile/systemDictionaryShared.cpp index df22db82165..45a5dc2328c 100644 --- a/src/hotspot/share/classfile/systemDictionaryShared.cpp +++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp @@ -1146,7 +1146,7 @@ InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) { DEBUG_ONLY(check_klass_after_loading(record->klass());) // We did not save the classfile data of the generated LambdaForm invoker classes, // so we cannot support CLFH for such classes. - if (record->klass()->is_generated_shared_class() && JvmtiExport::should_post_class_file_load_hook()) { + if (record->klass()->is_aot_generated_class() && JvmtiExport::should_post_class_file_load_hook()) { return nullptr; } return record->klass(); diff --git a/src/hotspot/share/oops/instanceKlass.hpp b/src/hotspot/share/oops/instanceKlass.hpp index 3338b5cd446..dfd134857b8 100644 --- a/src/hotspot/share/oops/instanceKlass.hpp +++ b/src/hotspot/share/oops/instanceKlass.hpp @@ -764,14 +764,6 @@ public: bool has_final_method() const { return _misc_flags.has_final_method(); } void set_has_final_method() { _misc_flags.set_has_final_method(true); } - // Indicates presence of @AOTSafeClassInitializer. Also see AOTClassInitializer for more details. - bool has_aot_safe_initializer() const { return _misc_flags.has_aot_safe_initializer(); } - void set_has_aot_safe_initializer() { _misc_flags.set_has_aot_safe_initializer(true); } - - // Indicates @AOTRuntimeSetup private static void runtimeSetup() presence. - bool is_runtime_setup_required() const { return _misc_flags.is_runtime_setup_required(); } - void set_is_runtime_setup_required() { _misc_flags.set_is_runtime_setup_required(true); } - // for adding methods, ConstMethod::UNSET_IDNUM means no more ids available inline u2 next_method_idnum(); void set_initial_method_idnum(u2 value) { _idnum_allocated_count = value; } diff --git a/src/hotspot/share/oops/instanceKlassFlags.hpp b/src/hotspot/share/oops/instanceKlassFlags.hpp index 1872c3bc998..18a9c76103d 100644 --- a/src/hotspot/share/oops/instanceKlassFlags.hpp +++ b/src/hotspot/share/oops/instanceKlassFlags.hpp @@ -54,8 +54,6 @@ class InstanceKlassFlags { flag(has_localvariable_table , 1 << 11) /* has localvariable information */ \ flag(has_miranda_methods , 1 << 12) /* True if this class has miranda methods in it's vtable */ \ flag(has_final_method , 1 << 13) /* True if klass has final method */ \ - flag(has_aot_safe_initializer , 1 << 14) /* has @AOTSafeClassInitializer annotation */ \ - flag(is_runtime_setup_required , 1 << 15) /* has a runtimeSetup method to be called */ \ /* end of list */ #define IK_FLAGS_ENUM_NAME(name, value) _misc_##name = value, diff --git a/src/hotspot/share/oops/klass.cpp b/src/hotspot/share/oops/klass.cpp index f4ae128aef7..92bcaebec4a 100644 --- a/src/hotspot/share/oops/klass.cpp +++ b/src/hotspot/share/oops/klass.cpp @@ -302,7 +302,7 @@ Klass::Klass() : _kind(UnknownKlassKind) { Klass::Klass(KlassKind kind) : _kind(kind), _prototype_header(make_prototype(this)), _shared_class_path_index(-1) { - CDS_ONLY(_shared_class_flags = 0;) + CDS_ONLY(_aot_class_flags = 0;) CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;) _primary_supers[0] = this; set_super_check_offset(in_bytes(primary_supers_offset())); diff --git a/src/hotspot/share/oops/klass.hpp b/src/hotspot/share/oops/klass.hpp index d62f3f21ee2..ad03c1e2ed6 100644 --- a/src/hotspot/share/oops/klass.hpp +++ b/src/hotspot/share/oops/klass.hpp @@ -174,18 +174,20 @@ private: #if INCLUDE_CDS // Various attributes for shared classes. Should be zero for a non-shared class. - u2 _shared_class_flags; - enum CDSSharedClassFlags { + u2 _aot_class_flags; + enum { _in_aot_cache = 1 << 0, _archived_lambda_proxy_is_available = 1 << 1, _has_value_based_class_annotation = 1 << 2, _verified_at_dump_time = 1 << 3, _has_archived_enum_objs = 1 << 4, - // This class was not loaded from a classfile in the module image - // or classpath. - _is_generated_shared_class = 1 << 5, - // archived mirror already initialized by AOT-cache assembly: no further need to call - _has_aot_initialized_mirror = 1 << 6, + _is_aot_generated_class = 1 << 5, // this class was not loaded from a classfile in the module image + // or classpath, but was generated during AOT cache assembly. + _has_aot_initialized_mirror = 1 << 6, // archived mirror already initialized by AOT cache assembly. + // no further need to call + _has_aot_safe_initializer = 1 << 7, // has @AOTSafeClassInitializer annotation + _is_runtime_setup_required = 1 << 8, // has a runtimeSetup method to be called when + // this class is loaded from AOT cache }; #endif @@ -325,66 +327,84 @@ protected: void clear_archived_mirror_index() NOT_CDS_JAVA_HEAP_RETURN; void set_lambda_proxy_is_available() { - CDS_ONLY(_shared_class_flags |= _archived_lambda_proxy_is_available;) + CDS_ONLY(_aot_class_flags |= _archived_lambda_proxy_is_available;) } void clear_lambda_proxy_is_available() { - CDS_ONLY(_shared_class_flags &= (u2)(~_archived_lambda_proxy_is_available);) + CDS_ONLY(_aot_class_flags &= (u2)(~_archived_lambda_proxy_is_available);) } bool lambda_proxy_is_available() const { - CDS_ONLY(return (_shared_class_flags & _archived_lambda_proxy_is_available) != 0;) + CDS_ONLY(return (_aot_class_flags & _archived_lambda_proxy_is_available) != 0;) NOT_CDS(return false;) } void set_has_value_based_class_annotation() { - CDS_ONLY(_shared_class_flags |= _has_value_based_class_annotation;) + CDS_ONLY(_aot_class_flags |= _has_value_based_class_annotation;) } void clear_has_value_based_class_annotation() { - CDS_ONLY(_shared_class_flags &= (u2)(~_has_value_based_class_annotation);) + CDS_ONLY(_aot_class_flags &= (u2)(~_has_value_based_class_annotation);) } bool has_value_based_class_annotation() const { - CDS_ONLY(return (_shared_class_flags & _has_value_based_class_annotation) != 0;) + CDS_ONLY(return (_aot_class_flags & _has_value_based_class_annotation) != 0;) NOT_CDS(return false;) } void set_verified_at_dump_time() { - CDS_ONLY(_shared_class_flags |= _verified_at_dump_time;) + CDS_ONLY(_aot_class_flags |= _verified_at_dump_time;) } bool verified_at_dump_time() const { - CDS_ONLY(return (_shared_class_flags & _verified_at_dump_time) != 0;) + CDS_ONLY(return (_aot_class_flags & _verified_at_dump_time) != 0;) NOT_CDS(return false;) } void set_has_archived_enum_objs() { - CDS_ONLY(_shared_class_flags |= _has_archived_enum_objs;) + CDS_ONLY(_aot_class_flags |= _has_archived_enum_objs;) } bool has_archived_enum_objs() const { - CDS_ONLY(return (_shared_class_flags & _has_archived_enum_objs) != 0;) + CDS_ONLY(return (_aot_class_flags & _has_archived_enum_objs) != 0;) NOT_CDS(return false;) } - void set_is_generated_shared_class() { - CDS_ONLY(_shared_class_flags |= _is_generated_shared_class;) + void set_is_aot_generated_class() { + CDS_ONLY(_aot_class_flags |= _is_aot_generated_class;) } - bool is_generated_shared_class() const { - CDS_ONLY(return (_shared_class_flags & _is_generated_shared_class) != 0;) + bool is_aot_generated_class() const { + CDS_ONLY(return (_aot_class_flags & _is_aot_generated_class) != 0;) NOT_CDS(return false;) } void set_has_aot_initialized_mirror() { - CDS_ONLY(_shared_class_flags |= _has_aot_initialized_mirror;) + CDS_ONLY(_aot_class_flags |= _has_aot_initialized_mirror;) } bool has_aot_initialized_mirror() const { - CDS_ONLY(return (_shared_class_flags & _has_aot_initialized_mirror) != 0;) + CDS_ONLY(return (_aot_class_flags & _has_aot_initialized_mirror) != 0;) + NOT_CDS(return false;) + } + + // Indicates presence of @AOTSafeClassInitializer. Also see AOTClassInitializer for more details. + void set_has_aot_safe_initializer() { + CDS_ONLY(_aot_class_flags |= _has_aot_safe_initializer;) + } + bool has_aot_safe_initializer() const { + CDS_ONLY(return (_aot_class_flags & _has_aot_safe_initializer) != 0;) + NOT_CDS(return false;) + } + + // Indicates @AOTRuntimeSetup private static void runtimeSetup() presence. + void set_is_runtime_setup_required() { + CDS_ONLY(_aot_class_flags |= _is_runtime_setup_required;) + } + bool is_runtime_setup_required() const { + CDS_ONLY(return (_aot_class_flags & _is_runtime_setup_required) != 0;) NOT_CDS(return false;) } bool in_aot_cache() const { // shadows MetaspaceObj::in_aot_cache)() - CDS_ONLY(return (_shared_class_flags & _in_aot_cache) != 0;) + CDS_ONLY(return (_aot_class_flags & _in_aot_cache) != 0;) NOT_CDS(return false;) } void set_in_aot_cache() { - CDS_ONLY(_shared_class_flags |= _in_aot_cache;) + CDS_ONLY(_aot_class_flags |= _in_aot_cache;) } // Obtain the module or package for this class