< prev index next >

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

Print this page

 204             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 205             boolean expected = c.isArray() || !isAbstract(c.getModifiers());
 206             boolean actual = type.isConcrete();
 207             assertEquals(expected, actual);
 208         }
 209     }
 210 
 211     @Test
 212     public void lambdaInternalNameTest() {
 213         // Verify that the last dot in lambda types is properly handled when transitioning from
 214         // internal name to java
 215         // name and vice versa.
 216         Supplier<Runnable> lambda = () -> () -> System.out.println("run");
 217         ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
 218         String typeName = lambdaType.getName();
 219         String javaName = lambda.getClass().getName();
 220         assertEquals(typeName, toInternalName(javaName));
 221         assertEquals(javaName, internalNameToJava(typeName, true, true));
 222     }
 223 
 224     @Test

 225     public void getModifiersTest() {
 226         for (Class<?> c : classes) {
 227             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             }
 241             assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
 242         }
 243     }
 244 

 282     public void getSuperclassTest() {
 283         for (Class<?> c : classes) {
 284             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 285             Class<?> expected = c.getSuperclass();
 286             ResolvedJavaType actual = type.getSuperclass();
 287             if (expected == null) {
 288                 assertTrue(actual == null);
 289             } else {
 290                 assertNotNull(actual);
 291                 assertTrue(actual.equals(metaAccess.lookupJavaType(expected)));
 292             }
 293         }
 294     }
 295 
 296     @Test
 297     public void getInterfacesTest() {
 298         for (Class<?> c : classes) {
 299             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 300             Class<?>[] expected = c.getInterfaces();
 301             ResolvedJavaType[] actual = type.getInterfaces();
 302             assertEquals(expected.length, actual.length);


 303             for (int i = 0; i < expected.length; i++) {
 304                 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i])));
 305             }
 306         }
 307     }
 308 
 309     public Class<?> getSupertype(Class<?> c) {
 310         assert !c.isPrimitive();
 311         if (c.isArray()) {
 312             Class<?> componentType = c.getComponentType();
 313             if (componentType.isPrimitive() || componentType == Object.class) {
 314                 return Object.class;
 315             }
 316             return getArrayClass(getSupertype(componentType));
 317         }
 318         if (c.isInterface()) {
 319             return Object.class;
 320         }
 321         return c.getSuperclass();
 322     }

 204             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 205             boolean expected = c.isArray() || !isAbstract(c.getModifiers());
 206             boolean actual = type.isConcrete();
 207             assertEquals(expected, actual);
 208         }
 209     }
 210 
 211     @Test
 212     public void lambdaInternalNameTest() {
 213         // Verify that the last dot in lambda types is properly handled when transitioning from
 214         // internal name to java
 215         // name and vice versa.
 216         Supplier<Runnable> lambda = () -> () -> System.out.println("run");
 217         ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
 218         String typeName = lambdaType.getName();
 219         String javaName = lambda.getClass().getName();
 220         assertEquals(typeName, toInternalName(javaName));
 221         assertEquals(javaName, internalNameToJava(typeName, true, true));
 222     }
 223 
 224     // TODO 8291719
 225     // @Test
 226     public void getModifiersTest() {
 227         for (Class<?> c : classes) {
 228             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 229             int mask = Modifier.classModifiers() & ~Modifier.STATIC;
 230             int expected = c.getModifiers() & mask;
 231             int actual = type.getModifiers() & mask;
 232             Class<?> elementalType = c;
 233             while (elementalType.isArray()) {
 234                 elementalType = elementalType.getComponentType();
 235             }
 236             if (elementalType.isMemberClass()) {
 237                 // member class get their modifiers from the inner-class attribute in the JVM and
 238                 // from the classfile header in jvmci
 239                 expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 240                 actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 241             }
 242             assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
 243         }
 244     }
 245 

 283     public void getSuperclassTest() {
 284         for (Class<?> c : classes) {
 285             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 286             Class<?> expected = c.getSuperclass();
 287             ResolvedJavaType actual = type.getSuperclass();
 288             if (expected == null) {
 289                 assertTrue(actual == null);
 290             } else {
 291                 assertNotNull(actual);
 292                 assertTrue(actual.equals(metaAccess.lookupJavaType(expected)));
 293             }
 294         }
 295     }
 296 
 297     @Test
 298     public void getInterfacesTest() {
 299         for (Class<?> c : classes) {
 300             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 301             Class<?>[] expected = c.getInterfaces();
 302             ResolvedJavaType[] actual = type.getInterfaces();
 303             // With injection of the IdentityObject interface by the JVM, the number of
 304             // interfaces visible through reflection and through JVMCI could differ by one
 305             assertTrue(expected.length == actual.length || (actual.length - expected.length) == 1);
 306             for (int i = 0; i < expected.length; i++) {
 307                 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i])));
 308             }
 309         }
 310     }
 311 
 312     public Class<?> getSupertype(Class<?> c) {
 313         assert !c.isPrimitive();
 314         if (c.isArray()) {
 315             Class<?> componentType = c.getComponentType();
 316             if (componentType.isPrimitive() || componentType == Object.class) {
 317                 return Object.class;
 318             }
 319             return getArrayClass(getSupertype(componentType));
 320         }
 321         if (c.isInterface()) {
 322             return Object.class;
 323         }
 324         return c.getSuperclass();
 325     }
< prev index next >