Skip to content

Commit

Permalink
8345678: compute_modifiers should not be in create_mirror
Browse files Browse the repository at this point in the history
Reviewed-by: fparain, dholmes
  • Loading branch information
coleenp committed Dec 16, 2024
1 parent 57adf64 commit d335941
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
7 changes: 6 additions & 1 deletion src/hotspot/share/classfile/classFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/share/oops/arrayKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/share/oops/arrayKlass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 5 additions & 4 deletions src/hotspot/share/oops/objArrayKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/oops/typeArrayKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/oops/typeArrayKlass.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/prims/jvmtiEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

1 comment on commit d335941

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.