8334772: Change Class::signers to an explicit field

Reviewed-by: dholmes, alanb, rriggs, coleenp
This commit is contained in:
Chen Liang 2024-07-18 22:22:59 +00:00
parent 902c2afb67
commit 39f4476813
6 changed files with 19 additions and 66 deletions

View File

@ -1220,10 +1220,6 @@ objArrayOop java_lang_Class::signers(oop java_class) {
assert(_signers_offset != 0, "must be set");
return (objArrayOop)java_class->obj_field(_signers_offset);
}
void java_lang_Class::set_signers(oop java_class, objArrayOop signers) {
assert(_signers_offset != 0, "must be set");
java_class->obj_field_put(_signers_offset, signers);
}
oop java_lang_Class::class_data(oop java_class) {
assert(_classData_offset != 0, "must be set");
@ -1418,12 +1414,13 @@ oop java_lang_Class::primitive_mirror(BasicType t) {
}
#define CLASS_FIELDS_DO(macro) \
macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
macro(_component_mirror_offset, k, "componentType", class_signature, false); \
macro(_module_offset, k, "module", module_signature, false); \
macro(_name_offset, k, "name", string_signature, false); \
macro(_classData_offset, k, "classData", object_signature, false);
macro(_classRedefinedCount_offset, k, "classRedefinedCount", int_signature, false); \
macro(_class_loader_offset, k, "classLoader", classloader_signature, false); \
macro(_component_mirror_offset, k, "componentType", class_signature, false); \
macro(_module_offset, k, "module", module_signature, false); \
macro(_name_offset, k, "name", string_signature, false); \
macro(_classData_offset, k, "classData", object_signature, false); \
macro(_signers_offset, k, "signers", object_array_signature, false);
void java_lang_Class::compute_offsets() {
if (_offsets_computed) {

View File

@ -208,7 +208,6 @@ class java_lang_String : AllStatic {
macro(java_lang_Class, oop_size, int_signature, false) \
macro(java_lang_Class, static_oop_field_count, int_signature, false) \
macro(java_lang_Class, protection_domain, object_signature, false) \
macro(java_lang_Class, signers, object_signature, false) \
macro(java_lang_Class, source_file, object_signature, false) \
class java_lang_Class : AllStatic {
@ -299,8 +298,7 @@ class java_lang_Class : AllStatic {
set_init_lock(java_class, nullptr);
}
static oop component_mirror(oop java_class);
static objArrayOop signers(oop java_class);
static void set_signers(oop java_class, objArrayOop signers);
static objArrayOop signers(oop java_class);
static oop class_data(oop java_class);
static void set_class_data(oop java_class, oop classData);

View File

@ -552,12 +552,6 @@ JVM_GetClassInterfaces(JNIEnv *env, jclass cls);
JNIEXPORT jboolean JNICALL
JVM_IsInterface(JNIEnv *env, jclass cls);
JNIEXPORT jobjectArray JNICALL
JVM_GetClassSigners(JNIEnv *env, jclass cls);
JNIEXPORT void JNICALL
JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers);
JNIEXPORT jobject JNICALL
JVM_GetProtectionDomain(JNIEnv *env, jclass cls);

View File

@ -1252,45 +1252,6 @@ JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
return k->is_hidden();
JVM_END
JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
JvmtiVMObjectAllocEventCollector oam;
oop mirror = JNIHandles::resolve_non_null(cls);
if (java_lang_Class::is_primitive(mirror)) {
// There are no signers for primitive types
return nullptr;
}
objArrayHandle signers(THREAD, java_lang_Class::signers(mirror));
// If there are no signers set in the class, or if the class
// is an array, return null.
if (signers == nullptr) return nullptr;
// copy of the signers array
Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass();
objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
for (int index = 0; index < signers->length(); index++) {
signers_copy->obj_at_put(index, signers->obj_at(index));
}
// return the copy
return (jobjectArray) JNIHandles::make_local(THREAD, signers_copy);
JVM_END
JVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers))
oop mirror = JNIHandles::resolve_non_null(cls);
if (!java_lang_Class::is_primitive(mirror)) {
// This call is ignored for primitive types and arrays.
// Signers are only set once, ClassLoader.java, and thus shouldn't
// be called with an array. Only the bootstrap loader creates arrays.
Klass* k = java_lang_Class::as_Klass(mirror);
if (k->is_instance_klass()) {
java_lang_Class::set_signers(k->java_mirror(), objArrayOop(JNIHandles::resolve(signers)));
}
}
JVM_END
JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls))
oop mirror = JNIHandles::resolve_non_null(cls);

View File

@ -1110,8 +1110,8 @@ public final class Class<T> implements java.io.Serializable,
// will throw NoSuchFieldException
private final ClassLoader classLoader;
// Set by VM
private transient Object classData;
private transient Object classData; // Set by VM
private transient Object[] signers; // Read by VM, mutable
// package-private
Object getClassData() {
@ -1510,14 +1510,19 @@ public final class Class<T> implements java.io.Serializable,
* a primitive type or void.
* @since 1.1
*/
public native Object[] getSigners();
public Object[] getSigners() {
var signers = this.signers;
return signers == null ? null : signers.clone();
}
/**
* Set the signers of this class.
*/
native void setSigners(Object[] signers);
void setSigners(Object[] signers) {
if (!isPrimitive() && !isArray()) {
this.signers = signers;
}
}
/**
* If this {@code Class} object represents a local or anonymous

View File

@ -58,8 +58,6 @@ static JNINativeMethod methods[] = {
{"getSuperclass", "()" CLS, NULL},
{"getInterfaces0", "()[" CLS, (void *)&JVM_GetClassInterfaces},
{"isInterface", "()Z", (void *)&JVM_IsInterface},
{"getSigners", "()[" OBJ, (void *)&JVM_GetClassSigners},
{"setSigners", "([" OBJ ")V", (void *)&JVM_SetClassSigners},
{"isArray", "()Z", (void *)&JVM_IsArrayClass},
{"isHidden", "()Z", (void *)&JVM_IsHiddenClass},
{"isPrimitive", "()Z", (void *)&JVM_IsPrimitiveClass},