8346567: Make Class.getModifiers() non-native

Reviewed-by: alanb, vlivanov, yzheng, dlong
This commit is contained in:
Coleen Phillimore 2025-02-10 12:44:30 +00:00
parent 5589892262
commit c9cadbd23f
31 changed files with 90 additions and 146 deletions

View file

@ -236,11 +236,12 @@ public final class Class<T> implements java.io.Serializable,
* This constructor is not used and prevents the default constructor being
* generated.
*/
private Class(ClassLoader loader, Class<?> arrayComponentType) {
private Class(ClassLoader loader, Class<?> arrayComponentType, int mods) {
// 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;
}
/**
@ -1000,6 +1001,7 @@ public final class Class<T> implements java.io.Serializable,
private transient Object classData; // Set by VM
private transient Object[] signers; // Read by VM, mutable
private final transient int modifiers; // Set by the VM
// package-private
Object getClassData() {
@ -1344,8 +1346,7 @@ public final class Class<T> implements java.io.Serializable,
* @jls 9.1.1 Interface Modifiers
* @jvms 4.1 The {@code ClassFile} Structure
*/
@IntrinsicCandidate
public native int getModifiers();
public int getModifiers() { return modifiers; }
/**
* {@return an unmodifiable set of the {@linkplain AccessFlag access

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -56,7 +56,7 @@ public class Reflection {
fieldFilterMap = Map.of(
Reflection.class, ALL_MEMBERS,
AccessibleObject.class, ALL_MEMBERS,
Class.class, Set.of("classLoader", "classData"),
Class.class, Set.of("classLoader", "classData", "modifiers"),
ClassLoader.class, ALL_MEMBERS,
Constructor.class, ALL_MEMBERS,
Field.class, ALL_MEMBERS,