Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8349860: Make Class.isArray(), Class.isInterface() and Class.isPrimitive() non-native #23572

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
@@ -1512,7 +1512,7 @@ oop java_lang_Class::primitive_mirror(BasicType t) {
macro(_signers_offset, k, "signers", object_array_signature, false); \
macro(_modifiers_offset, k, vmSymbols::modifiers_name(), char_signature, false); \
macro(_protection_domain_offset, k, "protectionDomain", java_security_ProtectionDomain_signature, false); \
macro(_is_primitive_offset, k, "isPrimitiveType", bool_signature, false);
macro(_is_primitive_offset, k, "primitive", bool_signature, false);

void java_lang_Class::compute_offsets() {
if (_offsets_computed) {
12 changes: 7 additions & 5 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
@@ -236,14 +236,14 @@ private static void runtimeSetup() {
* This constructor is not used and prevents the default constructor being
* generated.
*/
private Class(ClassLoader loader, Class<?> arrayComponentType, char mods, ProtectionDomain pd, boolean primitive) {
private Class(ClassLoader loader, Class<?> arrayComponentType, char mods, ProtectionDomain pd, boolean isPrim) {
// Initialize final field for classLoader. The initialization value of non-null
// prevents future JIT optimizations from assuming this final field is null.
classLoader = loader;
componentType = arrayComponentType;
modifiers = mods;
protectionDomain = pd;
isPrimitiveType = primitive;
primitive = isPrim;
}

/**
@@ -847,7 +847,7 @@ public boolean isArray() {
* @jls 15.8.2 Class Literals
*/
public boolean isPrimitive() {
return isPrimitiveType;
return primitive;
}

/**
@@ -1007,7 +1007,7 @@ public Module getModule() {
private transient Object classData; // Set by VM
private transient Object[] signers; // Read by VM, mutable
private final transient char modifiers; // Set by the VM
private final transient boolean isPrimitiveType; // Set by the VM
private final transient boolean primitive; // Set by the VM if the Class is a primitive type.

// package-private
Object getClassData() {
@@ -1292,7 +1292,9 @@ public Class<?> getComponentType() {
return componentType;
}

private final Class<?> componentType;
// The componentType field's null value is the sole indication that the class is an array,
// see isArray().
private transient final Class<?> componentType;

/*
* Returns the {@code Class} representing the element type of an array class.
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ public class Reflection {
fieldFilterMap = Map.of(
Reflection.class, ALL_MEMBERS,
AccessibleObject.class, ALL_MEMBERS,
Class.class, Set.of("classLoader", "classData", "modifiers", "protectionDomain", "isPrimitiveType"),
Class.class, Set.of("classLoader", "classData", "modifiers", "protectionDomain", "primitive"),
ClassLoader.class, ALL_MEMBERS,
Constructor.class, ALL_MEMBERS,
Field.class, ALL_MEMBERS,
Original file line number Diff line number Diff line change
@@ -934,7 +934,7 @@ private static boolean isHiddenFromReflection(ResolvedJavaField f) {
name.equals("classData") ||
name.equals("modifiers") ||
name.equals("protectionDomain") ||
name.equals("isPrimitiveType");
name.equals("primitive");
}
if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Lookup.class))) {
return f.getName().equals("allowedModes") || f.getName().equals("lookupClass");
2 changes: 1 addition & 1 deletion test/jdk/jdk/internal/reflect/Reflection/Filtering.java
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ private Object[][] sensitiveFields() {
{ Class.class, "classData" },
{ Class.class, "modifiers" },
{ Class.class, "protectionDomain" },
{ Class.class, "isPrimitiveType" },
{ Class.class, "primitive" },
{ ClassLoader.class, "parent" },
{ Field.class, "clazz" },
{ Field.class, "modifiers" },