From d3359417f3cb853b078041d07b8459b7b29a0a94 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Mon, 16 Dec 2024 17:46:43 +0000 Subject: [PATCH] 8345678: compute_modifiers should not be in create_mirror Reviewed-by: fparain, dholmes --- src/hotspot/share/classfile/classFileParser.cpp | 7 ++++++- src/hotspot/share/classfile/javaClasses.cpp | 6 ------ src/hotspot/share/oops/arrayKlass.cpp | 4 ---- src/hotspot/share/oops/arrayKlass.hpp | 4 ---- src/hotspot/share/oops/objArrayKlass.cpp | 9 +++++---- src/hotspot/share/oops/typeArrayKlass.cpp | 7 +++++++ src/hotspot/share/oops/typeArrayKlass.hpp | 4 +++- src/hotspot/share/prims/jvmtiEnv.cpp | 2 +- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/hotspot/share/classfile/classFileParser.cpp b/src/hotspot/share/classfile/classFileParser.cpp index a26831cd78328..050359056ee84 100644 --- a/src/hotspot/share/classfile/classFileParser.cpp +++ b/src/hotspot/share/classfile/classFileParser.cpp @@ -3747,6 +3747,12 @@ void ClassFileParser::apply_parsed_class_metadata( this_klass->set_annotations(_combined_annotations); this_klass->set_permitted_subclasses(_permitted_subclasses); this_klass->set_record_components(_record_components); + + // Initialize cached modifier_flags to support Class.getModifiers(). + // This must follow setting inner_class attributes. + int computed_modifiers = this_klass->compute_modifier_flags(); + this_klass->set_modifier_flags(computed_modifiers); + // Delay the setting of _local_interfaces and _transitive_interfaces until after // initialize_supers() in fill_instance_klass(). It is because the _local_interfaces could // be shared with _transitive_interfaces and _transitive_interfaces may be shared with @@ -5167,7 +5173,6 @@ void ClassFileParser::fill_instance_klass(InstanceKlass* ik, Handle module_handle(THREAD, module_entry->module()); // Allocate mirror and initialize static fields - // The create_mirror() call will also call compute_modifiers() java_lang_Class::create_mirror(ik, Handle(THREAD, _loader_data->class_loader()), module_handle, diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index c8f6276cb012d..1aedb43973c57 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -1113,12 +1113,6 @@ void java_lang_Class::create_mirror(Klass* k, Handle class_loader, assert(k != nullptr, "Use create_basic_type_mirror for primitive types"); assert(k->java_mirror() == nullptr, "should only assign mirror once"); - // Use this moment of initialization to cache modifier_flags also, - // to support Class.getModifiers(). Instance classes recalculate - // the cached flags after the class file is parsed, but before the - // class is put into the system dictionary. - int computed_modifiers = k->compute_modifier_flags(); - k->set_modifier_flags(computed_modifiers); // Class_klass has to be loaded because it is used to allocate // the mirror. if (vmClasses::Class_klass_loaded()) { diff --git a/src/hotspot/share/oops/arrayKlass.cpp b/src/hotspot/share/oops/arrayKlass.cpp index fd362ae8a0669..54b02cfd948d0 100644 --- a/src/hotspot/share/oops/arrayKlass.cpp +++ b/src/hotspot/share/oops/arrayKlass.cpp @@ -198,10 +198,6 @@ objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) { return o; } -jint ArrayKlass::compute_modifier_flags() const { - return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; -} - // JVMTI support jint ArrayKlass::jvmti_class_status() const { diff --git a/src/hotspot/share/oops/arrayKlass.hpp b/src/hotspot/share/oops/arrayKlass.hpp index 1c1d01fc32aec..5bfe46573d3f5 100644 --- a/src/hotspot/share/oops/arrayKlass.hpp +++ b/src/hotspot/share/oops/arrayKlass.hpp @@ -118,10 +118,6 @@ class ArrayKlass: public Klass { // Return a handle. static void complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module, TRAPS); - - // jvm support - jint compute_modifier_flags() const; - // JVMTI support jint jvmti_class_status() const; diff --git a/src/hotspot/share/oops/objArrayKlass.cpp b/src/hotspot/share/oops/objArrayKlass.cpp index 0697901d17427..04bc374e5226c 100644 --- a/src/hotspot/share/oops/objArrayKlass.cpp +++ b/src/hotspot/share/oops/objArrayKlass.cpp @@ -140,6 +140,9 @@ ObjArrayKlass::ObjArrayKlass(int n, Klass* element_klass, Symbol* name) : ArrayK set_layout_helper(array_layout_helper(T_OBJECT)); assert(is_array_klass(), "sanity"); assert(is_objArray_klass(), "sanity"); + + // Compute modifier flags after bottom_klass and element_klass are initialized. + set_modifier_flags(compute_modifier_flags()); } size_t ObjArrayKlass::oop_size(oop obj) const { @@ -340,10 +343,8 @@ void ObjArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) { jint ObjArrayKlass::compute_modifier_flags() const { // The modifier for an objectArray is the same as its element - if (element_klass() == nullptr) { - assert(Universe::is_bootstrapping(), "partial objArray only at startup"); - return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; - } + assert (element_klass() != nullptr, "should be initialized"); + // Return the flags of the bottom element type. jint element_flags = bottom_klass()->compute_modifier_flags(); diff --git a/src/hotspot/share/oops/typeArrayKlass.cpp b/src/hotspot/share/oops/typeArrayKlass.cpp index ddf60d4382e51..8ca6a49fc46a4 100644 --- a/src/hotspot/share/oops/typeArrayKlass.cpp +++ b/src/hotspot/share/oops/typeArrayKlass.cpp @@ -75,6 +75,10 @@ TypeArrayKlass* TypeArrayKlass::allocate(ClassLoaderData* loader_data, BasicType return new (loader_data, size, THREAD) TypeArrayKlass(type, name); } +jint TypeArrayKlass::compute_modifier_flags() const { + return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; +} + TypeArrayKlass::TypeArrayKlass(BasicType type, Symbol* name) : ArrayKlass(name, Kind) { set_layout_helper(array_layout_helper(type)); assert(is_array_klass(), "sanity"); @@ -84,6 +88,9 @@ TypeArrayKlass::TypeArrayKlass(BasicType type, Symbol* name) : ArrayKlass(name, assert(size() >= TypeArrayKlass::header_size(), "bad size"); set_class_loader_data(ClassLoaderData::the_null_class_loader_data()); + + // Compute modifier flags. + set_modifier_flags(compute_modifier_flags()); } typeArrayOop TypeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) { diff --git a/src/hotspot/share/oops/typeArrayKlass.hpp b/src/hotspot/share/oops/typeArrayKlass.hpp index ae23c5324afd9..9dc3ed607fe3a 100644 --- a/src/hotspot/share/oops/typeArrayKlass.hpp +++ b/src/hotspot/share/oops/typeArrayKlass.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -73,6 +73,8 @@ class TypeArrayKlass : public ArrayKlass { // Copying void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS); + jint compute_modifier_flags() const; + // Oop iterators. Since there are no oops in TypeArrayKlasses, // these functions only return the size of the object. diff --git a/src/hotspot/share/prims/jvmtiEnv.cpp b/src/hotspot/share/prims/jvmtiEnv.cpp index ff3dad679606c..554b4baf7b2a3 100644 --- a/src/hotspot/share/prims/jvmtiEnv.cpp +++ b/src/hotspot/share/prims/jvmtiEnv.cpp @@ -2696,7 +2696,7 @@ JvmtiEnv::GetClassModifiers(oop k_mirror, jint* modifiers_ptr) { if (!java_lang_Class::is_primitive(k_mirror)) { Klass* k = java_lang_Class::as_Klass(k_mirror); NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); - result = k->compute_modifier_flags(); + result = k->modifier_flags(); // Reset the deleted ACC_SUPER bit (deleted in compute_modifier_flags()). if (k->is_super()) {