8329750: Change Universe functions to return more specific Klass* types

Reviewed-by: coleenp
This commit is contained in:
Stefan Karlsson 2024-04-09 12:31:13 +00:00
parent 87131fb2f7
commit 492b954f81
6 changed files with 36 additions and 41 deletions

View File

@ -368,7 +368,7 @@ Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
} }
} else { } else {
k = Universe::typeArrayKlass(t); k = Universe::typeArrayKlass(t);
k = TypeArrayKlass::cast(k)->array_klass(ndims, CHECK_NULL); k = k->array_klass(ndims, CHECK_NULL);
} }
return k; return k;
} }

View File

@ -636,7 +636,7 @@ C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, ARGU
resolved_klass = resolved_klass->array_klass(ndim, CHECK_NULL); resolved_klass = resolved_klass->array_klass(ndim, CHECK_NULL);
} }
} else { } else {
resolved_klass = TypeArrayKlass::cast(Universe::typeArrayKlass(ss.type()))->array_klass(ndim, CHECK_NULL); resolved_klass = Universe::typeArrayKlass(ss.type())->array_klass(ndim, CHECK_NULL);
} }
} else { } else {
resolved_klass = SystemDictionary::find_instance_klass(THREAD, class_name, resolved_klass = SystemDictionary::find_instance_klass(THREAD, class_name,

View File

@ -41,41 +41,41 @@
#include "utilities/utf8.hpp" #include "utilities/utf8.hpp"
typeArrayOop oopFactory::new_boolArray(int length, TRAPS) { typeArrayOop oopFactory::new_boolArray(int length, TRAPS) {
return TypeArrayKlass::cast(Universe::boolArrayKlass())->allocate(length, THREAD); return Universe::boolArrayKlass()->allocate(length, THREAD);
} }
typeArrayOop oopFactory::new_charArray(int length, TRAPS) { typeArrayOop oopFactory::new_charArray(int length, TRAPS) {
return TypeArrayKlass::cast(Universe::charArrayKlass())->allocate(length, THREAD); return Universe::charArrayKlass()->allocate(length, THREAD);
} }
typeArrayOop oopFactory::new_floatArray(int length, TRAPS) { typeArrayOop oopFactory::new_floatArray(int length, TRAPS) {
return TypeArrayKlass::cast(Universe::floatArrayKlass())->allocate(length, THREAD); return Universe::floatArrayKlass()->allocate(length, THREAD);
} }
typeArrayOop oopFactory::new_doubleArray(int length, TRAPS) { typeArrayOop oopFactory::new_doubleArray(int length, TRAPS) {
return TypeArrayKlass::cast(Universe::doubleArrayKlass())->allocate(length, THREAD); return Universe::doubleArrayKlass()->allocate(length, THREAD);
} }
typeArrayOop oopFactory::new_byteArray(int length, TRAPS) { typeArrayOop oopFactory::new_byteArray(int length, TRAPS) {
return TypeArrayKlass::cast(Universe::byteArrayKlass())->allocate(length, THREAD); return Universe::byteArrayKlass()->allocate(length, THREAD);
} }
typeArrayOop oopFactory::new_shortArray(int length, TRAPS) { typeArrayOop oopFactory::new_shortArray(int length, TRAPS) {
return TypeArrayKlass::cast(Universe::shortArrayKlass())->allocate(length, THREAD); return Universe::shortArrayKlass()->allocate(length, THREAD);
} }
typeArrayOop oopFactory::new_intArray(int length, TRAPS) { typeArrayOop oopFactory::new_intArray(int length, TRAPS) {
return TypeArrayKlass::cast(Universe::intArrayKlass())->allocate(length, THREAD); return Universe::intArrayKlass()->allocate(length, THREAD);
} }
typeArrayOop oopFactory::new_longArray(int length, TRAPS) { typeArrayOop oopFactory::new_longArray(int length, TRAPS) {
return TypeArrayKlass::cast(Universe::longArrayKlass())->allocate(length, THREAD); return Universe::longArrayKlass()->allocate(length, THREAD);
} }
// create java.lang.Object[] // create java.lang.Object[]
objArrayOop oopFactory::new_objectArray(int length, TRAPS) { objArrayOop oopFactory::new_objectArray(int length, TRAPS) {
assert(Universe::objectArrayKlass() != nullptr, "Too early?"); assert(Universe::objectArrayKlass() != nullptr, "Too early?");
return ObjArrayKlass::cast(Universe::objectArrayKlass())->allocate(length, THREAD); return Universe::objectArrayKlass()->allocate(length, THREAD);
} }
typeArrayOop oopFactory::new_charArray(const char* utf8_str, TRAPS) { typeArrayOop oopFactory::new_charArray(const char* utf8_str, TRAPS) {
@ -88,10 +88,8 @@ typeArrayOop oopFactory::new_charArray(const char* utf8_str, TRAPS) {
} }
typeArrayOop oopFactory::new_typeArray(BasicType type, int length, TRAPS) { typeArrayOop oopFactory::new_typeArray(BasicType type, int length, TRAPS) {
Klass* klass = Universe::typeArrayKlass(type); TypeArrayKlass* klass = Universe::typeArrayKlass(type);
TypeArrayKlass* typeArrayKlass = TypeArrayKlass::cast(klass); return klass->allocate(length, THREAD);
typeArrayOop result = typeArrayKlass->allocate(length, THREAD);
return result;
} }
// Create a Java array that points to Symbol. // Create a Java array that points to Symbol.
@ -100,17 +98,12 @@ typeArrayOop oopFactory::new_typeArray(BasicType type, int length, TRAPS) {
// this. They cast Symbol* into this type. // this. They cast Symbol* into this type.
typeArrayOop oopFactory::new_symbolArray(int length, TRAPS) { typeArrayOop oopFactory::new_symbolArray(int length, TRAPS) {
BasicType type = LP64_ONLY(T_LONG) NOT_LP64(T_INT); BasicType type = LP64_ONLY(T_LONG) NOT_LP64(T_INT);
Klass* klass = Universe::typeArrayKlass(type); return new_typeArray(type, length, THREAD);
TypeArrayKlass* typeArrayKlass = TypeArrayKlass::cast(klass);
typeArrayOop result = typeArrayKlass->allocate(length, THREAD);
return result;
} }
typeArrayOop oopFactory::new_typeArray_nozero(BasicType type, int length, TRAPS) { typeArrayOop oopFactory::new_typeArray_nozero(BasicType type, int length, TRAPS) {
Klass* klass = Universe::typeArrayKlass(type); TypeArrayKlass* klass = Universe::typeArrayKlass(type);
TypeArrayKlass* typeArrayKlass = TypeArrayKlass::cast(klass); return klass->allocate_common(length, false, THREAD);
typeArrayOop result = typeArrayKlass->allocate_common(length, false, THREAD);
return result;
} }

View File

@ -111,9 +111,9 @@ static LatestMethodCache _throw_no_such_method_error_cache; // Unsafe.throwNoSuc
static LatestMethodCache _do_stack_walk_cache; // AbstractStackWalker.doStackWalk() static LatestMethodCache _do_stack_walk_cache; // AbstractStackWalker.doStackWalk()
// Known objects // Known objects
Klass* Universe::_typeArrayKlasses[T_LONG+1] = { nullptr /*, nullptr...*/ }; TypeArrayKlass* Universe::_typeArrayKlasses[T_LONG+1] = { nullptr /*, nullptr...*/ };
Klass* Universe::_objectArrayKlass = nullptr; ObjArrayKlass* Universe::_objectArrayKlass = nullptr;
Klass* Universe::_fillerArrayKlass = nullptr; Klass* Universe::_fillerArrayKlass = nullptr;
OopHandle Universe::_basic_type_mirrors[T_VOID+1]; OopHandle Universe::_basic_type_mirrors[T_VOID+1];
#if INCLUDE_CDS_JAVA_HEAP #if INCLUDE_CDS_JAVA_HEAP
int Universe::_archived_basic_type_mirror_indices[T_VOID+1]; int Universe::_archived_basic_type_mirror_indices[T_VOID+1];
@ -472,8 +472,10 @@ void Universe::genesis(TRAPS) {
// ordinary object arrays, _objectArrayKlass will be loaded when // ordinary object arrays, _objectArrayKlass will be loaded when
// SystemDictionary::initialize(CHECK); is run. See the extra check // SystemDictionary::initialize(CHECK); is run. See the extra check
// for Object_klass_loaded in objArrayKlassKlass::allocate_objArray_klass_impl. // for Object_klass_loaded in objArrayKlassKlass::allocate_objArray_klass_impl.
_objectArrayKlass = InstanceKlass:: {
cast(vmClasses::Object_klass())->array_klass(1, CHECK); Klass* oak = vmClasses::Object_klass()->array_klass(CHECK);
_objectArrayKlass = ObjArrayKlass::cast(oak);
}
// OLD // OLD
// Add the class to the class hierarchy manually to make sure that // Add the class to the class hierarchy manually to make sure that
// its vtable is initialized after core bootstrapping is completed. // its vtable is initialized after core bootstrapping is completed.

View File

@ -65,8 +65,8 @@ class Universe: AllStatic {
private: private:
// Known classes in the VM // Known classes in the VM
static Klass* _typeArrayKlasses[T_LONG+1]; static TypeArrayKlass* _typeArrayKlasses[T_LONG+1];
static Klass* _objectArrayKlass; static ObjArrayKlass* _objectArrayKlass;
// Special int-Array that represents filler objects that are used by GC to overwrite // Special int-Array that represents filler objects that are used by GC to overwrite
// dead objects. References to them are generally an error. // dead objects. References to them are generally an error.
static Klass* _fillerArrayKlass; static Klass* _fillerArrayKlass;
@ -174,20 +174,20 @@ class Universe: AllStatic {
static void set_verify_data(uintptr_t mask, uintptr_t bits) PRODUCT_RETURN; static void set_verify_data(uintptr_t mask, uintptr_t bits) PRODUCT_RETURN;
// Known classes in the VM // Known classes in the VM
static Klass* boolArrayKlass() { return typeArrayKlass(T_BOOLEAN); } static TypeArrayKlass* boolArrayKlass() { return typeArrayKlass(T_BOOLEAN); }
static Klass* byteArrayKlass() { return typeArrayKlass(T_BYTE); } static TypeArrayKlass* byteArrayKlass() { return typeArrayKlass(T_BYTE); }
static Klass* charArrayKlass() { return typeArrayKlass(T_CHAR); } static TypeArrayKlass* charArrayKlass() { return typeArrayKlass(T_CHAR); }
static Klass* intArrayKlass() { return typeArrayKlass(T_INT); } static TypeArrayKlass* intArrayKlass() { return typeArrayKlass(T_INT); }
static Klass* shortArrayKlass() { return typeArrayKlass(T_SHORT); } static TypeArrayKlass* shortArrayKlass() { return typeArrayKlass(T_SHORT); }
static Klass* longArrayKlass() { return typeArrayKlass(T_LONG); } static TypeArrayKlass* longArrayKlass() { return typeArrayKlass(T_LONG); }
static Klass* floatArrayKlass() { return typeArrayKlass(T_FLOAT); } static TypeArrayKlass* floatArrayKlass() { return typeArrayKlass(T_FLOAT); }
static Klass* doubleArrayKlass() { return typeArrayKlass(T_DOUBLE); } static TypeArrayKlass* doubleArrayKlass() { return typeArrayKlass(T_DOUBLE); }
static Klass* objectArrayKlass() { return _objectArrayKlass; } static ObjArrayKlass* objectArrayKlass() { return _objectArrayKlass; }
static Klass* fillerArrayKlass() { return _fillerArrayKlass; } static Klass* fillerArrayKlass() { return _fillerArrayKlass; }
static Klass* typeArrayKlass(BasicType t) { static TypeArrayKlass* typeArrayKlass(BasicType t) {
assert((uint)t >= T_BOOLEAN, "range check for type: %s", type2name(t)); assert((uint)t >= T_BOOLEAN, "range check for type: %s", type2name(t));
assert((uint)t < T_LONG+1, "range check for type: %s", type2name(t)); assert((uint)t < T_LONG+1, "range check for type: %s", type2name(t));
assert(_typeArrayKlasses[t] != nullptr, "domain check"); assert(_typeArrayKlasses[t] != nullptr, "domain check");

View File

@ -138,7 +138,7 @@ Handle VectorSupport::allocate_vector_payload_helper(InstanceKlass* ik, frame* f
int elem_size = type2aelembytes(elem_bt); int elem_size = type2aelembytes(elem_bt);
// On-heap vector values are represented as primitive arrays. // On-heap vector values are represented as primitive arrays.
TypeArrayKlass* tak = TypeArrayKlass::cast(Universe::typeArrayKlass(elem_bt)); TypeArrayKlass* tak = Universe::typeArrayKlass(elem_bt);
typeArrayOop arr = tak->allocate(num_elem, CHECK_NH); // safepoint typeArrayOop arr = tak->allocate(num_elem, CHECK_NH); // safepoint