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

Chen Liang liach at openjdk.org
Tue Feb 18 23:49:54 UTC 2025


On Tue, 11 Feb 2025 20:56:39 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

> Class.isInterface() can check modifier flags, Class.isArray() can check whether component mirror is non-null and Class.isPrimitive() needs a new final transient boolean in java.lang.Class that the JVM code initializes.
> Tested with tier1-4 and performance tests.

We often need to determine what primitive type a `class` is. Currently we do it through `Wrapper.forPrimitiveType`. Do you see potential value in encoding the primitive status in a byte, so primitive info also knows what primitive type this class is instead of doing identity comparisons?

@cl4es Can you offer some insight here?

src/java.base/share/classes/jdk/internal/reflect/Reflection.java line 59:

> 57:             Reflection.class, ALL_MEMBERS,
> 58:             AccessibleObject.class, ALL_MEMBERS,
> 59:             Class.class, Set.of("classLoader", "classData", "modifiers", "isPrimitive"),

I think the field is named `isPrimitive`, right?

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java line 933:

> 931:         if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Class.class))) {
> 932:             String name = f.getName();
> 933:             return name.equals("classLoader") || name.equals("classData") || name.equals("modifiers") || name.equals("isPrimitive");

Same field name remark.

test/jdk/jdk/internal/reflect/Reflection/Filtering.java line 59:

> 57:             { Class.class, "classData" },
> 58:             { Class.class, "modifiers" },
> 59:             { Class.class, "isPrimitive" },

Same field name remark.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23572#issuecomment-2654120983
PR Comment: https://git.openjdk.org/jdk/pull/23572#issuecomment-2659605250
PR Review Comment: https://git.openjdk.org/jdk/pull/23572#discussion_r1951773863
PR Review Comment: https://git.openjdk.org/jdk/pull/23572#discussion_r1951774073
PR Review Comment: https://git.openjdk.org/jdk/pull/23572#discussion_r1951774214


More information about the core-libs-dev mailing list