Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions src/hotspot/share/c1/c1_Canonicalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,22 +547,6 @@ void Canonicalizer::do_Intrinsic (Intrinsic* x) {
}
break;
}
case vmIntrinsics::_getModifiers: {
assert(x->number_of_arguments() == 1, "wrong type");

// Optimize for Foo.class.getModifier()
InstanceConstant* c = x->argument_at(0)->type()->as_InstanceConstant();
if (c != nullptr && !c->value()->is_null_object()) {
ciType* t = c->value()->java_mirror_type();
if (t->is_klass()) {
set_constant(t->as_klass()->modifier_flags());
} else {
assert(t->is_primitive_type(), "should be a primitive type");
set_constant(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
}
}
break;
}
default:
break;
}
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/c1/c1_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ bool Compiler::is_intrinsic_supported(vmIntrinsics::ID id) {
case vmIntrinsics::_getClass:
case vmIntrinsics::_isInstance:
case vmIntrinsics::_isPrimitive:
case vmIntrinsics::_getModifiers:
case vmIntrinsics::_currentCarrierThread:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_scopedValueCache:
Expand Down
37 changes: 0 additions & 37 deletions src/hotspot/share/c1/c1_LIRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,42 +1303,6 @@ void LIRGenerator::do_isPrimitive(Intrinsic* x) {
__ cmove(lir_cond_notEqual, LIR_OprFact::intConst(0), LIR_OprFact::intConst(1), result, T_BOOLEAN);
}

// Example: Foo.class.getModifiers()
void LIRGenerator::do_getModifiers(Intrinsic* x) {
assert(x->number_of_arguments() == 1, "wrong type");

LIRItem receiver(x->argument_at(0), this);
receiver.load_item();
LIR_Opr result = rlock_result(x);

CodeEmitInfo* info = nullptr;
if (x->needs_null_check()) {
info = state_for(x);
}

// While reading off the universal constant mirror is less efficient than doing
// another branch and returning the constant answer, this branchless code runs into
// much less risk of confusion for C1 register allocator. The choice of the universe
// object here is correct as long as it returns the same modifiers we would expect
// from the primitive class itself. See spec for Class.getModifiers that provides
// the typed array klasses with similar modifiers as their component types.

Klass* univ_klass = Universe::byteArrayKlass();
assert(univ_klass->modifier_flags() == (JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC), "Sanity");
LIR_Opr prim_klass = LIR_OprFact::metadataConst(univ_klass);

LIR_Opr recv_klass = new_register(T_METADATA);
__ move(new LIR_Address(receiver.result(), java_lang_Class::klass_offset(), T_ADDRESS), recv_klass, info);

// Check if this is a Java mirror of primitive type, and select the appropriate klass.
LIR_Opr klass = new_register(T_METADATA);
__ cmp(lir_cond_equal, recv_klass, LIR_OprFact::metadataConst(nullptr));
__ cmove(lir_cond_equal, prim_klass, recv_klass, klass, T_ADDRESS);

// Get the answer.
__ move(new LIR_Address(klass, in_bytes(Klass::modifier_flags_offset()), T_CHAR), result);
}

void LIRGenerator::do_getObjectSize(Intrinsic* x) {
assert(x->number_of_arguments() == 3, "wrong type");
LIR_Opr result_reg = rlock_result(x);
Expand Down Expand Up @@ -2957,7 +2921,6 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break;
case vmIntrinsics::_isInstance: do_isInstance(x); break;
case vmIntrinsics::_isPrimitive: do_isPrimitive(x); break;
case vmIntrinsics::_getModifiers: do_getModifiers(x); break;
case vmIntrinsics::_getClass: do_getClass(x); break;
case vmIntrinsics::_getObjectSize: do_getObjectSize(x); break;
case vmIntrinsics::_currentCarrierThread: do_currentCarrierThread(x); break;
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/c1/c1_LIRGenerator.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, 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 @@ -255,7 +255,6 @@ class LIRGenerator: public InstructionVisitor, public BlockClosure {
void do_RegisterFinalizer(Intrinsic* x);
void do_isInstance(Intrinsic* x);
void do_isPrimitive(Intrinsic* x);
void do_getModifiers(Intrinsic* x);
void do_getClass(Intrinsic* x);
void do_getObjectSize(Intrinsic* x);
void do_currentCarrierThread(Intrinsic* x);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/ci/ciKlass.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2025, 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 @@ -122,7 +122,7 @@ class ciKlass : public ciType {
// Get the instance of java.lang.Class corresponding to this klass.
ciInstance* java_mirror();

// Fetch Klass::modifier_flags.
// Fetch modifier flags.
jint modifier_flags();

// Fetch Klass::access_flags.
Expand Down
5 changes: 0 additions & 5 deletions src/hotspot/share/classfile/classFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3747,11 +3747,6 @@ void ClassFileParser::apply_parsed_class_metadata(
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.
u2 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
19 changes: 18 additions & 1 deletion src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ int java_lang_Class::_source_file_offset;
int java_lang_Class::_classData_offset;
int java_lang_Class::_classRedefinedCount_offset;
int java_lang_Class::_reflectionData_offset;
int java_lang_Class::_modifiers_offset;

bool java_lang_Class::_offsets_computed = false;
GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = nullptr;
Expand Down Expand Up @@ -1060,6 +1061,10 @@ void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protecti
// Setup indirection from mirror->klass
set_klass(mirror(), k);

// Set the modifiers flag.
int computed_modifiers = k->compute_modifier_flags();
set_modifiers(mirror(), computed_modifiers);

InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");

Expand Down Expand Up @@ -1355,6 +1360,7 @@ oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, Basic
InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(vmClasses::Class_klass());
assert(static_oop_field_count(java_class) == 0, "should have been zeroed by allocation");
#endif
set_modifiers(java_class, JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
return java_class;
}

Expand Down Expand Up @@ -1493,7 +1499,8 @@ oop java_lang_Class::primitive_mirror(BasicType t) {
macro(_name_offset, k, "name", string_signature, false); \
macro(_classData_offset, k, "classData", object_signature, false); \
macro(_reflectionData_offset, k, "reflectionData", java_lang_ref_SoftReference_signature, false); \
macro(_signers_offset, k, "signers", object_array_signature, false);
macro(_signers_offset, k, "signers", object_array_signature, false); \
macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false);

void java_lang_Class::compute_offsets() {
if (_offsets_computed) {
Expand Down Expand Up @@ -1527,6 +1534,16 @@ void java_lang_Class::set_classRedefinedCount(oop the_class_mirror, int value) {
the_class_mirror->int_field_put(_classRedefinedCount_offset, value);
}

int java_lang_Class::modifiers(oop the_class_mirror) {
assert(_modifiers_offset != 0, "offsets should have been initialized");
return the_class_mirror->int_field(_modifiers_offset);
}

void java_lang_Class::set_modifiers(oop the_class_mirror, int value) {
assert(_modifiers_offset != 0, "offsets should have been initialized");
the_class_mirror->int_field_put(_modifiers_offset, value);
}


// Note: JDK1.1 and before had a privateInfo_offset field which was used for the
// platform thread structure, and a eetop offset which was used for thread
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/classfile/javaClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class java_lang_Class : AllStatic {
static int _classData_offset;
static int _classRedefinedCount_offset;
static int _reflectionData_offset;
static int _modifiers_offset;

static bool _offsets_computed;

Expand Down Expand Up @@ -337,6 +338,9 @@ class java_lang_Class : AllStatic {
static oop source_file(oop java_class);
static void set_source_file(oop java_class, oop source_file);

static int modifiers(oop java_class);
static void set_modifiers(oop java_class, int value);

static size_t oop_size(oop java_class);
static void set_oop_size(HeapWord* java_class, size_t size);
static int static_oop_field_count(oop java_class);
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/classfile/vmIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ bool vmIntrinsics::disabled_by_jvm_flags(vmIntrinsics::ID id) {
switch (id) {
case vmIntrinsics::_isInstance:
case vmIntrinsics::_isAssignableFrom:
case vmIntrinsics::_getModifiers:
case vmIntrinsics::_isInterface:
case vmIntrinsics::_isArray:
case vmIntrinsics::_isPrimitive:
Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/share/classfile/vmIntrinsics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ class methodHandle;
do_name( isAssignableFrom_name, "isAssignableFrom") \
do_intrinsic(_isInstance, java_lang_Class, isInstance_name, object_boolean_signature, F_RN) \
do_name( isInstance_name, "isInstance") \
do_intrinsic(_getModifiers, java_lang_Class, getModifiers_name, void_int_signature, F_RN) \
do_name( getModifiers_name, "getModifiers") \
do_intrinsic(_isInterface, java_lang_Class, isInterface_name, void_boolean_signature, F_RN) \
do_name( isInterface_name, "isInterface") \
do_intrinsic(_isArray, java_lang_Class, isArray_name, void_boolean_signature, F_RN) \
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/jvmci/vmStructs_jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@
nonstatic_field(Klass, _name, Symbol*) \
volatile_nonstatic_field(Klass, _next_sibling, Klass*) \
nonstatic_field(Klass, _java_mirror, OopHandle) \
nonstatic_field(Klass, _modifier_flags, u2) \
nonstatic_field(Klass, _access_flags, AccessFlags) \
nonstatic_field(Klass, _class_loader_data, ClassLoaderData*) \
nonstatic_field(Klass, _secondary_supers_bitmap, uintx) \
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/oops/klass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ jint Klass::array_layout_helper(BasicType etype) {
return lh;
}

int Klass::modifier_flags() const {
int mods = java_lang_Class::modifiers(java_mirror());
assert(mods == compute_modifier_flags(), "should be same");
return mods;
}

bool Klass::can_be_primary_super_slow() const {
if (super() == nullptr)
return true;
Expand Down
9 changes: 1 addition & 8 deletions src/hotspot/share/oops/klass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ class Klass : public Metadata {
AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
// Some flags created by the JVM, not in the class file itself,
// are in _misc_flags below.
// Processed access flags, for use by Class.getModifiers.
u2 _modifier_flags;

KlassFlags _misc_flags;

// The fields _super_check_offset, _secondary_super_cache, _secondary_supers
Expand Down Expand Up @@ -292,10 +289,6 @@ class Klass : public Metadata {
// This leaves the OopHandle in the CLD, but that's ok, you can't release them.
void clear_java_mirror_handle() { _java_mirror = OopHandle(); }

// modifier flags
u2 modifier_flags() const { return _modifier_flags; }
void set_modifier_flags(u2 flags) { _modifier_flags = flags; }

// size helper
int layout_helper() const { return _layout_helper; }
void set_layout_helper(int lh) { _layout_helper = lh; }
Expand Down Expand Up @@ -448,7 +441,6 @@ class Klass : public Metadata {
static ByteSize secondary_supers_offset() { return byte_offset_of(Klass, _secondary_supers); }
static ByteSize java_mirror_offset() { return byte_offset_of(Klass, _java_mirror); }
static ByteSize class_loader_data_offset() { return byte_offset_of(Klass, _class_loader_data); }
static ByteSize modifier_flags_offset() { return byte_offset_of(Klass, _modifier_flags); }
static ByteSize layout_helper_offset() { return byte_offset_of(Klass, _layout_helper); }
static ByteSize access_flags_offset() { return byte_offset_of(Klass, _access_flags); }
#if INCLUDE_JVMCI
Expand Down Expand Up @@ -758,6 +750,7 @@ class Klass : public Metadata {

public:
virtual u2 compute_modifier_flags() const = 0;
int modifier_flags() const;

// JVMTI support
virtual jint jvmti_class_status() const;
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/oops/objArrayKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ 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
3 changes: 0 additions & 3 deletions src/hotspot/share/oops/typeArrayKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ 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: 2 additions & 2 deletions src/hotspot/share/oops/typeArrayKlass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class TypeArrayKlass : public ArrayKlass {
jint max_length() { return _max_length; }
void set_max_length(jint m) { _max_length = m; }

u2 compute_modifier_flags() const;

// testers
DEBUG_ONLY(bool is_typeArray_klass_slow() const { return true; })

Expand All @@ -73,8 +75,6 @@ class TypeArrayKlass : public ArrayKlass {
// Copying
void copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS);

u2 compute_modifier_flags() const;

// Oop iterators. Since there are no oops in TypeArrayKlasses,
// these functions only return the size of the object.

Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/opto/c2compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ bool C2Compiler::is_intrinsic_supported(vmIntrinsics::ID id) {
case vmIntrinsics::_clone:
case vmIntrinsics::_isAssignableFrom:
case vmIntrinsics::_isInstance:
case vmIntrinsics::_getModifiers:
case vmIntrinsics::_isInterface:
case vmIntrinsics::_isArray:
case vmIntrinsics::_isPrimitive:
Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/share/opto/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,8 +1699,6 @@ Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_cr
}
if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
alias_type(idx)->set_rewritable(false);
if (flat->offset() == in_bytes(Klass::modifier_flags_offset()))
alias_type(idx)->set_rewritable(false);
if (flat->offset() == in_bytes(Klass::access_flags_offset()))
alias_type(idx)->set_rewritable(false);
if (flat->offset() == in_bytes(Klass::misc_flags_offset()))
Expand Down
10 changes: 0 additions & 10 deletions src/hotspot/share/opto/library_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ bool LibraryCallKit::try_to_inline(int predicate) {
case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check();

case vmIntrinsics::_isInstance:
case vmIntrinsics::_getModifiers:
case vmIntrinsics::_isInterface:
case vmIntrinsics::_isArray:
case vmIntrinsics::_isPrimitive:
Expand Down Expand Up @@ -3891,10 +3890,6 @@ bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
prim_return_value = intcon(0);
obj = argument(1);
break;
case vmIntrinsics::_getModifiers:
prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
return_type = TypeInt::CHAR;
break;
case vmIntrinsics::_isInterface:
prim_return_value = intcon(0);
break;
Expand Down Expand Up @@ -3974,11 +3969,6 @@ bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
query_value = gen_instanceof(obj, kls, safe_for_replace);
break;

case vmIntrinsics::_getModifiers:
p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset()));
query_value = make_load(nullptr, p, TypeInt::CHAR, T_CHAR, MemNode::unordered);
break;

case vmIntrinsics::_isInterface:
// (To verify this code sequence, check the asserts in JVM_IsInterface.)
if (generate_interface_guard(kls, region) != nullptr)
Expand Down
8 changes: 1 addition & 7 deletions src/hotspot/share/opto/memnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1972,12 +1972,6 @@ LoadNode::load_array_final_field(const TypeKlassPtr *tkls,
ciKlass* klass) const {
assert(!UseCompactObjectHeaders || tkls->offset() != in_bytes(Klass::prototype_header_offset()),
"must not happen");
if (tkls->offset() == in_bytes(Klass::modifier_flags_offset())) {
// The field is Klass::_modifier_flags. Return its (constant) value.
// (Folds up the 2nd indirection in aClassConstant.getModifiers().)
assert(Opcode() == Op_LoadUS, "must load an unsigned short from _modifier_flags");
return TypeInt::make(klass->modifier_flags());
}
if (tkls->offset() == in_bytes(Klass::access_flags_offset())) {
// The field is Klass::_access_flags. Return its (constant) value.
// (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).)
Expand Down Expand Up @@ -2461,7 +2455,7 @@ const Type* LoadNode::klass_value_common(PhaseGVN* phase) const {
// a primitive Class (e.g., int.class) has null for a klass field
return TypePtr::NULL_PTR;
}
// (Folds up the 1st indirection in aClassConstant.getModifiers().)
// Fold up the load of the hidden field
return TypeKlassPtr::make(t->as_klass(), Type::trust_interfaces);
}
// non-constant mirror, so we can't tell what's going on
Expand Down
Loading