< prev index next >

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

Print this page

 170         for (Class<?> c : classes) {
 171             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 172             boolean expected = c.isArray();
 173             boolean actual = type.isArray();
 174             assertEquals(expected, actual);
 175         }
 176     }
 177 
 178     @Test
 179     public void lambdaInternalNameTest() {
 180         // Verify that the last dot in lambda types is properly handled when transitioning from internal name to java
 181         // name and vice versa.
 182         Supplier<Runnable> lambda = () -> () -> System.out.println("run");
 183         ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
 184         String typeName = lambdaType.getName();
 185         String javaName = lambda.getClass().getName();
 186         assertEquals(typeName, toInternalName(javaName));
 187         assertEquals(javaName, internalNameToJava(typeName, true, true));
 188     }
 189 
 190     @Test

 191     public void getModifiersTest() {
 192         for (Class<?> c : classes) {
 193             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 194             int mask = Modifier.classModifiers() & ~Modifier.STATIC;
 195             int expected = c.getModifiers() & mask;
 196             int actual = type.getModifiers() & mask;
 197             Class<?> elementalType = c;
 198             while (elementalType.isArray()) {
 199                 elementalType = elementalType.getComponentType();
 200             }
 201             if (elementalType.isMemberClass()) {
 202                 // member class get their modifiers from the inner-class attribute in the JVM and
 203                 // from the classfile header in jvmci
 204                 expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 205                 actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 206             }
 207             assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
 208         }
 209     }
 210 

 248     public void getSuperclassTest() {
 249         for (Class<?> c : classes) {
 250             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 251             Class<?> expected = c.getSuperclass();
 252             ResolvedJavaType actual = type.getSuperclass();
 253             if (expected == null) {
 254                 assertTrue(actual == null);
 255             } else {
 256                 assertNotNull(actual);
 257                 assertTrue(actual.equals(metaAccess.lookupJavaType(expected)));
 258             }
 259         }
 260     }
 261 
 262     @Test
 263     public void getInterfacesTest() {
 264         for (Class<?> c : classes) {
 265             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 266             Class<?>[] expected = c.getInterfaces();
 267             ResolvedJavaType[] actual = type.getInterfaces();
 268             assertEquals(expected.length, actual.length);


 269             for (int i = 0; i < expected.length; i++) {
 270                 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i])));
 271             }
 272         }
 273     }
 274 
 275     public Class<?> getSupertype(Class<?> c) {
 276         assert !c.isPrimitive();
 277         if (c.isArray()) {
 278             Class<?> componentType = c.getComponentType();
 279             if (componentType.isPrimitive() || componentType == Object.class) {
 280                 return Object.class;
 281             }
 282             return getArrayClass(getSupertype(componentType));
 283         }
 284         if (c.isInterface()) {
 285             return Object.class;
 286         }
 287         return c.getSuperclass();
 288     }

 170         for (Class<?> c : classes) {
 171             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 172             boolean expected = c.isArray();
 173             boolean actual = type.isArray();
 174             assertEquals(expected, actual);
 175         }
 176     }
 177 
 178     @Test
 179     public void lambdaInternalNameTest() {
 180         // Verify that the last dot in lambda types is properly handled when transitioning from internal name to java
 181         // name and vice versa.
 182         Supplier<Runnable> lambda = () -> () -> System.out.println("run");
 183         ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
 184         String typeName = lambdaType.getName();
 185         String javaName = lambda.getClass().getName();
 186         assertEquals(typeName, toInternalName(javaName));
 187         assertEquals(javaName, internalNameToJava(typeName, true, true));
 188     }
 189 
 190     // TODO 8291719
 191     // @Test
 192     public void getModifiersTest() {
 193         for (Class<?> c : classes) {
 194             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 195             int mask = Modifier.classModifiers() & ~Modifier.STATIC;
 196             int expected = c.getModifiers() & mask;
 197             int actual = type.getModifiers() & mask;
 198             Class<?> elementalType = c;
 199             while (elementalType.isArray()) {
 200                 elementalType = elementalType.getComponentType();
 201             }
 202             if (elementalType.isMemberClass()) {
 203                 // member class get their modifiers from the inner-class attribute in the JVM and
 204                 // from the classfile header in jvmci
 205                 expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 206                 actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 207             }
 208             assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
 209         }
 210     }
 211 

 249     public void getSuperclassTest() {
 250         for (Class<?> c : classes) {
 251             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 252             Class<?> expected = c.getSuperclass();
 253             ResolvedJavaType actual = type.getSuperclass();
 254             if (expected == null) {
 255                 assertTrue(actual == null);
 256             } else {
 257                 assertNotNull(actual);
 258                 assertTrue(actual.equals(metaAccess.lookupJavaType(expected)));
 259             }
 260         }
 261     }
 262 
 263     @Test
 264     public void getInterfacesTest() {
 265         for (Class<?> c : classes) {
 266             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 267             Class<?>[] expected = c.getInterfaces();
 268             ResolvedJavaType[] actual = type.getInterfaces();
 269             // With injection of the IdentityObject interface by the JVM, the number of
 270             // interfaces visible through reflection and through JVMCI could differ by one
 271             assertTrue(expected.length == actual.length || (actual.length - expected.length) == 1);
 272             for (int i = 0; i < expected.length; i++) {
 273                 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i])));
 274             }
 275         }
 276     }
 277 
 278     public Class<?> getSupertype(Class<?> c) {
 279         assert !c.isPrimitive();
 280         if (c.isArray()) {
 281             Class<?> componentType = c.getComponentType();
 282             if (componentType.isPrimitive() || componentType == Object.class) {
 283                 return Object.class;
 284             }
 285             return getArrayClass(getSupertype(componentType));
 286         }
 287         if (c.isInterface()) {
 288             return Object.class;
 289         }
 290         return c.getSuperclass();
 291     }
< prev index next >