Skip to content

Commit c9cadbd

Browse files
committed
8346567: Make Class.getModifiers() non-native
Reviewed-by: alanb, vlivanov, yzheng, dlong
1 parent 5589892 commit c9cadbd

File tree

31 files changed

+90
-146
lines changed

31 files changed

+90
-146
lines changed

src/hotspot/share/c1/c1_Canonicalizer.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -547,22 +547,6 @@ void Canonicalizer::do_Intrinsic (Intrinsic* x) {
547547
}
548548
break;
549549
}
550-
case vmIntrinsics::_getModifiers: {
551-
assert(x->number_of_arguments() == 1, "wrong type");
552-
553-
// Optimize for Foo.class.getModifier()
554-
InstanceConstant* c = x->argument_at(0)->type()->as_InstanceConstant();
555-
if (c != nullptr && !c->value()->is_null_object()) {
556-
ciType* t = c->value()->java_mirror_type();
557-
if (t->is_klass()) {
558-
set_constant(t->as_klass()->modifier_flags());
559-
} else {
560-
assert(t->is_primitive_type(), "should be a primitive type");
561-
set_constant(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
562-
}
563-
}
564-
break;
565-
}
566550
default:
567551
break;
568552
}

src/hotspot/share/c1/c1_Compiler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ bool Compiler::is_intrinsic_supported(vmIntrinsics::ID id) {
156156
case vmIntrinsics::_getClass:
157157
case vmIntrinsics::_isInstance:
158158
case vmIntrinsics::_isPrimitive:
159-
case vmIntrinsics::_getModifiers:
160159
case vmIntrinsics::_currentCarrierThread:
161160
case vmIntrinsics::_currentThread:
162161
case vmIntrinsics::_scopedValueCache:

src/hotspot/share/c1/c1_LIRGenerator.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,42 +1297,6 @@ void LIRGenerator::do_isPrimitive(Intrinsic* x) {
12971297
__ cmove(lir_cond_notEqual, LIR_OprFact::intConst(0), LIR_OprFact::intConst(1), result, T_BOOLEAN);
12981298
}
12991299

1300-
// Example: Foo.class.getModifiers()
1301-
void LIRGenerator::do_getModifiers(Intrinsic* x) {
1302-
assert(x->number_of_arguments() == 1, "wrong type");
1303-
1304-
LIRItem receiver(x->argument_at(0), this);
1305-
receiver.load_item();
1306-
LIR_Opr result = rlock_result(x);
1307-
1308-
CodeEmitInfo* info = nullptr;
1309-
if (x->needs_null_check()) {
1310-
info = state_for(x);
1311-
}
1312-
1313-
// While reading off the universal constant mirror is less efficient than doing
1314-
// another branch and returning the constant answer, this branchless code runs into
1315-
// much less risk of confusion for C1 register allocator. The choice of the universe
1316-
// object here is correct as long as it returns the same modifiers we would expect
1317-
// from the primitive class itself. See spec for Class.getModifiers that provides
1318-
// the typed array klasses with similar modifiers as their component types.
1319-
1320-
Klass* univ_klass = Universe::byteArrayKlass();
1321-
assert(univ_klass->modifier_flags() == (JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC), "Sanity");
1322-
LIR_Opr prim_klass = LIR_OprFact::metadataConst(univ_klass);
1323-
1324-
LIR_Opr recv_klass = new_register(T_METADATA);
1325-
__ move(new LIR_Address(receiver.result(), java_lang_Class::klass_offset(), T_ADDRESS), recv_klass, info);
1326-
1327-
// Check if this is a Java mirror of primitive type, and select the appropriate klass.
1328-
LIR_Opr klass = new_register(T_METADATA);
1329-
__ cmp(lir_cond_equal, recv_klass, LIR_OprFact::metadataConst(nullptr));
1330-
__ cmove(lir_cond_equal, prim_klass, recv_klass, klass, T_ADDRESS);
1331-
1332-
// Get the answer.
1333-
__ move(new LIR_Address(klass, in_bytes(Klass::modifier_flags_offset()), T_CHAR), result);
1334-
}
1335-
13361300
void LIRGenerator::do_getObjectSize(Intrinsic* x) {
13371301
assert(x->number_of_arguments() == 3, "wrong type");
13381302
LIR_Opr result_reg = rlock_result(x);
@@ -2951,7 +2915,6 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
29512915
case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break;
29522916
case vmIntrinsics::_isInstance: do_isInstance(x); break;
29532917
case vmIntrinsics::_isPrimitive: do_isPrimitive(x); break;
2954-
case vmIntrinsics::_getModifiers: do_getModifiers(x); break;
29552918
case vmIntrinsics::_getClass: do_getClass(x); break;
29562919
case vmIntrinsics::_getObjectSize: do_getObjectSize(x); break;
29572920
case vmIntrinsics::_currentCarrierThread: do_currentCarrierThread(x); break;

src/hotspot/share/c1/c1_LIRGenerator.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -255,7 +255,6 @@ class LIRGenerator: public InstructionVisitor, public BlockClosure {
255255
void do_RegisterFinalizer(Intrinsic* x);
256256
void do_isInstance(Intrinsic* x);
257257
void do_isPrimitive(Intrinsic* x);
258-
void do_getModifiers(Intrinsic* x);
259258
void do_getClass(Intrinsic* x);
260259
void do_getObjectSize(Intrinsic* x);
261260
void do_currentCarrierThread(Intrinsic* x);

src/hotspot/share/ci/ciKlass.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ciKlass : public ciType {
119119
// Get the instance of java.lang.Class corresponding to this klass.
120120
ciInstance* java_mirror();
121121

122-
// Fetch Klass::modifier_flags.
122+
// Fetch modifier flags.
123123
jint modifier_flags();
124124

125125
// Fetch Klass::access_flags.

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,11 +3747,6 @@ void ClassFileParser::apply_parsed_class_metadata(
37473747
this_klass->set_permitted_subclasses(_permitted_subclasses);
37483748
this_klass->set_record_components(_record_components);
37493749

3750-
// Initialize cached modifier_flags to support Class.getModifiers().
3751-
// This must follow setting inner_class attributes.
3752-
u2 computed_modifiers = this_klass->compute_modifier_flags();
3753-
this_klass->set_modifier_flags(computed_modifiers);
3754-
37553750
// Delay the setting of _local_interfaces and _transitive_interfaces until after
37563751
// initialize_supers() in fill_instance_klass(). It is because the _local_interfaces could
37573752
// be shared with _transitive_interfaces and _transitive_interfaces may be shared with

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ int java_lang_Class::_source_file_offset;
867867
int java_lang_Class::_classData_offset;
868868
int java_lang_Class::_classRedefinedCount_offset;
869869
int java_lang_Class::_reflectionData_offset;
870+
int java_lang_Class::_modifiers_offset;
870871

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

1064+
// Set the modifiers flag.
1065+
int computed_modifiers = k->compute_modifier_flags();
1066+
set_modifiers(mirror(), computed_modifiers);
1067+
10631068
InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
10641069
assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
10651070

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

@@ -1493,7 +1499,8 @@ oop java_lang_Class::primitive_mirror(BasicType t) {
14931499
macro(_name_offset, k, "name", string_signature, false); \
14941500
macro(_classData_offset, k, "classData", object_signature, false); \
14951501
macro(_reflectionData_offset, k, "reflectionData", java_lang_ref_SoftReference_signature, false); \
1496-
macro(_signers_offset, k, "signers", object_array_signature, false);
1502+
macro(_signers_offset, k, "signers", object_array_signature, false); \
1503+
macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false);
14971504

14981505
void java_lang_Class::compute_offsets() {
14991506
if (_offsets_computed) {
@@ -1527,6 +1534,16 @@ void java_lang_Class::set_classRedefinedCount(oop the_class_mirror, int value) {
15271534
the_class_mirror->int_field_put(_classRedefinedCount_offset, value);
15281535
}
15291536

1537+
int java_lang_Class::modifiers(oop the_class_mirror) {
1538+
assert(_modifiers_offset != 0, "offsets should have been initialized");
1539+
return the_class_mirror->int_field(_modifiers_offset);
1540+
}
1541+
1542+
void java_lang_Class::set_modifiers(oop the_class_mirror, int value) {
1543+
assert(_modifiers_offset != 0, "offsets should have been initialized");
1544+
the_class_mirror->int_field_put(_modifiers_offset, value);
1545+
}
1546+
15301547

15311548
// Note: JDK1.1 and before had a privateInfo_offset field which was used for the
15321549
// platform thread structure, and a eetop offset which was used for thread

src/hotspot/share/classfile/javaClasses.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class java_lang_Class : AllStatic {
257257
static int _classData_offset;
258258
static int _classRedefinedCount_offset;
259259
static int _reflectionData_offset;
260+
static int _modifiers_offset;
260261

261262
static bool _offsets_computed;
262263

@@ -337,6 +338,9 @@ class java_lang_Class : AllStatic {
337338
static oop source_file(oop java_class);
338339
static void set_source_file(oop java_class, oop source_file);
339340

341+
static int modifiers(oop java_class);
342+
static void set_modifiers(oop java_class, int value);
343+
340344
static size_t oop_size(oop java_class);
341345
static void set_oop_size(HeapWord* java_class, size_t size);
342346
static int static_oop_field_count(oop java_class);

src/hotspot/share/classfile/vmIntrinsics.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ bool vmIntrinsics::disabled_by_jvm_flags(vmIntrinsics::ID id) {
256256
switch (id) {
257257
case vmIntrinsics::_isInstance:
258258
case vmIntrinsics::_isAssignableFrom:
259-
case vmIntrinsics::_getModifiers:
260259
case vmIntrinsics::_isInterface:
261260
case vmIntrinsics::_isArray:
262261
case vmIntrinsics::_isPrimitive:

src/hotspot/share/classfile/vmIntrinsics.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ class methodHandle;
304304
do_name( isAssignableFrom_name, "isAssignableFrom") \
305305
do_intrinsic(_isInstance, java_lang_Class, isInstance_name, object_boolean_signature, F_RN) \
306306
do_name( isInstance_name, "isInstance") \
307-
do_intrinsic(_getModifiers, java_lang_Class, getModifiers_name, void_int_signature, F_RN) \
308-
do_name( getModifiers_name, "getModifiers") \
309307
do_intrinsic(_isInterface, java_lang_Class, isInterface_name, void_boolean_signature, F_RN) \
310308
do_name( isInterface_name, "isInterface") \
311309
do_intrinsic(_isArray, java_lang_Class, isArray_name, void_boolean_signature, F_RN) \

0 commit comments

Comments
 (0)