Skip to content

Commit 36ec24f

Browse files
committed
fix getModifiers() for inner classes
1 parent 1ca008f commit 36ec24f

File tree

7 files changed

+51
-35
lines changed

7 files changed

+51
-35
lines changed

src/hotspot/share/jvmci/jvmciEnv.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,13 +1365,15 @@ JVMCIObject JVMCIEnv::get_jvmci_type(const JVMCIKlassHandle& klass, JVMCI_TRAPS)
13651365
guarantee(klass->is_loader_alive(), "klass must be alive");
13661366

13671367
jlong pointer = (jlong) klass();
1368+
int modifiers = klass()->modifier_flags();
13681369
JavaThread* THREAD = JVMCI::compilation_tick(JavaThread::current()); // For exception macros.
13691370
jboolean exception = false;
13701371
if (is_hotspot()) {
13711372
CompilerThreadCanCallJava ccj(THREAD, true);
13721373
JavaValue result(T_OBJECT);
13731374
JavaCallArguments args;
13741375
args.push_long(pointer);
1376+
args.push_int(modifiers);
13751377
JavaCalls::call_static(&result,
13761378
HotSpotJVMCI::HotSpotResolvedObjectTypeImpl::klass(),
13771379
vmSymbols::fromMetaspace_name(),
@@ -1388,7 +1390,7 @@ JVMCIObject JVMCIEnv::get_jvmci_type(const JVMCIKlassHandle& klass, JVMCI_TRAPS)
13881390
HandleMark hm(THREAD);
13891391
type = JNIJVMCI::wrap(jni()->CallStaticObjectMethod(JNIJVMCI::HotSpotResolvedObjectTypeImpl::clazz(),
13901392
JNIJVMCI::HotSpotResolvedObjectTypeImpl_fromMetaspace_method(),
1391-
pointer));
1393+
pointer, modifiers));
13921394
exception = jni()->ExceptionCheck();
13931395
}
13941396
if (exception) {

src/hotspot/share/jvmci/vmSymbols_jvmci.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
template(fromMetaspace_name, "fromMetaspace") \
8686
template(method_fromMetaspace_signature, "(JLjdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;)Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethod;") \
8787
template(constantPool_fromMetaspace_signature, "(J)Ljdk/vm/ci/hotspot/HotSpotConstantPool;") \
88-
template(klass_fromMetaspace_signature, "(J)Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;") \
88+
template(klass_fromMetaspace_signature, "(JI)Ljdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;") \
8989
template(primitive_fromMetaspace_signature, "(Ljdk/vm/ci/hotspot/HotSpotObjectConstantImpl;C)Ljdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType;") \
9090
template(getRuntime_name, "getRuntime") \
9191
template(getRuntime_signature, "()Ljdk/vm/ci/runtime/JVMCIRuntime;") \

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ HotSpotResolvedJavaType fromClass(Class<?> javaClass) {
687687
return fromClass0(javaClass);
688688
}
689689

690-
synchronized HotSpotResolvedObjectTypeImpl fromMetaspace(Long klassPointer) {
690+
synchronized HotSpotResolvedObjectTypeImpl fromMetaspace(Long klassPointer, int modifiers) {
691691
if (resolvedJavaTypes == null) {
692692
resolvedJavaTypes = new HashMap<>();
693693
resolvedJavaTypesQueue = new ReferenceQueue<>();
@@ -700,7 +700,11 @@ synchronized HotSpotResolvedObjectTypeImpl fromMetaspace(Long klassPointer) {
700700
}
701701
if (javaType == null) {
702702
String name = compilerToVm.getSignatureName(klassPointer);
703-
javaType = new HotSpotResolvedObjectTypeImpl(klassPointer, name);
703+
char charModifiers = (char) modifiers;
704+
if (charModifiers != modifiers) {
705+
throw new IllegalArgumentException(String.format("%x != %x", modifiers, charModifiers));
706+
}
707+
javaType = new HotSpotResolvedObjectTypeImpl(klassPointer, name, charModifiers);
704708
resolvedJavaTypes.put(klassPointer, new KlassWeakReference(klassPointer, javaType, resolvedJavaTypesQueue));
705709
}
706710
expungeStaleKlassEntries();

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ final class HotSpotResolvedObjectTypeImpl extends HotSpotResolvedJavaType implem
9292
*/
9393
private FieldInfo[] fieldInfo;
9494

95+
/**
96+
* The JVM defined modifiers. This is different from {@code Klass::_access_flags}
97+
* in the case of inner classes where the modifiers are provided by an
98+
* InnerClasses attribute.
99+
*/
100+
private final char modifiers;
101+
95102
/**
96103
* Managed exclusively by {@link HotSpotJDKReflection#getField}.
97104
*/
@@ -107,12 +114,13 @@ static HotSpotResolvedObjectTypeImpl getJavaLangObject() {
107114
* Called from the VM.
108115
*
109116
* @param klassPointer a native pointer to the Klass*
117+
* @param modifiers the {@linkplain Class#getModifiers() class modifiers}
110118
* @return the {@link ResolvedJavaType} corresponding to {@code javaClass}
111119
*/
112120
@SuppressWarnings("unused")
113121
@VMEntryPoint
114-
private static HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer) {
115-
return runtime().fromMetaspace(klassPointer);
122+
private static HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer, int modifiers) {
123+
return runtime().fromMetaspace(klassPointer, modifiers);
116124
}
117125

118126
/**
@@ -123,12 +131,14 @@ private static HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer) {
123131
* </p>
124132
*
125133
* @param klass the {@code Klass*} for the type
134+
* @param modifiers the {@linkplain Class#getModifiers() class modifiers}
126135
*/
127136
@SuppressWarnings("try")
128-
HotSpotResolvedObjectTypeImpl(long klass, String name) {
137+
HotSpotResolvedObjectTypeImpl(long klass, String name, char modifiers) {
129138
super(name);
130139
assert klass != 0;
131140
this.klassPointer = klass;
141+
this.modifiers = modifiers;
132142

133143
// The mirror object must be in the global scope since
134144
// this object will be cached in HotSpotJVMCIRuntime.resolvedJavaTypes
@@ -157,16 +167,7 @@ public long getMetaspacePointer() {
157167

158168
@Override
159169
public int getModifiers() {
160-
if (isArray()) {
161-
return (getElementalType().getModifiers() & (Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED)) | Modifier.FINAL | Modifier.ABSTRACT;
162-
} else {
163-
return getAccessFlags() & jvmClassModifiers();
164-
}
165-
}
166-
167-
public int getAccessFlags() {
168-
HotSpotVMConfig config = config();
169-
return UNSAFE.getInt(getKlassPointer() + config.klassAccessFlagsOffset);
170+
return modifiers;
170171
}
171172

172173
public int getMiscFlags() {
@@ -461,7 +462,7 @@ public boolean isInstanceClass() {
461462

462463
@Override
463464
public boolean isInterface() {
464-
return (getAccessFlags() & config().jvmAccInterface) != 0;
465+
return (modifiers & config().jvmAccInterface) != 0;
465466
}
466467

467468
@Override

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ModifiersProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package jdk.vm.ci.meta;
2424

25+
import java.lang.reflect.Member;
2526
import java.lang.reflect.Modifier;
2627

2728
import static java.lang.reflect.Modifier.PRIVATE;
@@ -35,7 +36,10 @@
3536
public interface ModifiersProvider {
3637

3738
/**
38-
* Returns the modifiers for this element.
39+
* Returns the Java language modifiers for this element.
40+
*
41+
* @see Class#getModifiers
42+
* @see Member#getModifiers
3943
*/
4044
int getModifiers();
4145

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,8 @@ public void lambdaInternalNameTest() {
225225
public void getModifiersTest() {
226226
for (Class<?> c : classes) {
227227
ResolvedJavaType type = metaAccess.lookupJavaType(c);
228-
int mask = Modifier.classModifiers() & ~Modifier.STATIC;
229-
int expected = c.getModifiers() & mask;
230-
int actual = type.getModifiers() & mask;
231-
Class<?> elementalType = c;
232-
while (elementalType.isArray()) {
233-
elementalType = elementalType.getComponentType();
234-
}
235-
if (elementalType.isMemberClass()) {
236-
// member class get their modifiers from the inner-class attribute in the JVM and
237-
// from the classfile header in jvmci
238-
expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
239-
actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
240-
}
228+
int expected = c.getModifiers();
229+
int actual = type.getModifiers();
241230
assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
242231
}
243232
}

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TypeUniverse.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.HashSet;
4040
import java.util.IdentityHashMap;
4141
import java.util.LinkedHashMap;
42+
import java.util.LinkedHashSet;
4243
import java.util.LinkedList;
4344
import java.util.List;
4445
import java.util.Map;
@@ -69,10 +70,10 @@ public class TypeUniverse {
6970

7071
public static final MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
7172
public static final ConstantReflectionProvider constantReflection = JVMCI.getRuntime().getHostJVMCIBackend().getConstantReflection();
72-
public static final Collection<Class<?>> classes = new HashSet<>();
73+
public static final Collection<Class<?>> classes = new LinkedHashSet<>();
7374
public static final Set<ResolvedJavaType> javaTypes;
7475
public static final ResolvedJavaType predicateType;
75-
public static final Map<Class<?>, Class<?>> arrayClasses = new HashMap<>();
76+
public static final Map<Class<?>, Class<?>> arrayClasses = new LinkedHashMap<>();
7677

7778
private static List<ConstantValue> constants;
7879

@@ -92,10 +93,25 @@ private class PrivateInnerClass {
9293

9394
}
9495

96+
private static class PrivateStaticInnerClass {
97+
98+
}
9599
protected class ProtectedInnerClass {
96100

97101
}
98102

103+
protected static class ProtectedStaticInnerClass {
104+
105+
}
106+
107+
protected interface ProtectedInnerInterface {
108+
109+
}
110+
111+
protected static interface ProtectedStaticInnerInterface {
112+
113+
}
114+
99115
static {
100116
Unsafe theUnsafe = null;
101117
try {
@@ -116,7 +132,7 @@ protected class ProtectedInnerClass {
116132
byte[][].class, short[][].class, char[][].class, int[][].class, float[][].class, long[][].class, double[][].class, Object[][].class, Class[][].class, List[][].class,
117133
ClassLoader.class, String.class, Serializable.class, Cloneable.class, Test.class, TestMetaAccessProvider.class, List.class, Collection.class, Map.class, Queue.class,
118134
HashMap.class, LinkedHashMap.class, IdentityHashMap.class, AbstractCollection.class, AbstractList.class, ArrayList.class, InnerClass.class, InnerStaticClass.class,
119-
InnerStaticFinalClass.class, PrivateInnerClass.class, ProtectedInnerClass.class, ScopedMemoryAccess.class};
135+
ScopedMemoryAccess.class, TypeUniverse.class};
120136
for (Class<?> c : initialClasses) {
121137
addClass(c);
122138
}

0 commit comments

Comments
 (0)