< prev index next >

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

Print this page

 224             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 225             boolean expected = c.isArray() || !isAbstract(c.getModifiers());
 226             boolean actual = type.isConcrete();
 227             assertEquals(expected, actual);
 228         }
 229     }
 230 
 231     @Test
 232     public void lambdaInternalNameTest() {
 233         // Verify that the last dot in lambda types is properly handled when transitioning from
 234         // internal name to java
 235         // name and vice versa.
 236         Supplier<Runnable> lambda = () -> () -> System.out.println("run");
 237         ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
 238         String typeName = lambdaType.getName();
 239         String javaName = lambda.getClass().getName();
 240         assertEquals(typeName, toInternalName(javaName));
 241         assertEquals(javaName, internalNameToJava(typeName, true, true));
 242     }
 243 
 244     @Test

 245     public void getModifiersTest() {
 246         for (Class<?> c : classes) {
 247             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 248             int mask = Modifier.classModifiers() & ~Modifier.STATIC;
 249             int expected = c.getModifiers() & mask;
 250             int actual = type.getModifiers() & mask;
 251             Class<?> elementalType = c;
 252             while (elementalType.isArray()) {
 253                 elementalType = elementalType.getComponentType();
 254             }
 255             if (elementalType.isMemberClass()) {
 256                 // member class get their modifiers from the inner-class attribute in the JVM and
 257                 // from the classfile header in jvmci
 258                 expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 259                 actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 260             }
 261             assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
 262         }
 263     }
 264 

 302     public void getSuperclassTest() {
 303         for (Class<?> c : classes) {
 304             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 305             Class<?> expected = c.getSuperclass();
 306             ResolvedJavaType actual = type.getSuperclass();
 307             if (expected == null) {
 308                 assertTrue(actual == null);
 309             } else {
 310                 assertNotNull(actual);
 311                 assertTrue(actual.equals(metaAccess.lookupJavaType(expected)));
 312             }
 313         }
 314     }
 315 
 316     @Test
 317     public void getInterfacesTest() {
 318         for (Class<?> c : classes) {
 319             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 320             Class<?>[] expected = c.getInterfaces();
 321             ResolvedJavaType[] actual = type.getInterfaces();
 322             assertEquals(expected.length, actual.length);


 323             for (int i = 0; i < expected.length; i++) {
 324                 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i])));
 325             }
 326         }
 327     }
 328 
 329     public Class<?> getSupertype(Class<?> c) {
 330         assert !c.isPrimitive();
 331         if (c.isArray()) {
 332             Class<?> componentType = c.getComponentType();
 333             if (componentType.isPrimitive() || componentType == Object.class) {
 334                 return Object.class;
 335             }
 336             return getArrayClass(getSupertype(componentType));
 337         }
 338         if (c.isInterface()) {
 339             return Object.class;
 340         }
 341         return c.getSuperclass();
 342     }

 224             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 225             boolean expected = c.isArray() || !isAbstract(c.getModifiers());
 226             boolean actual = type.isConcrete();
 227             assertEquals(expected, actual);
 228         }
 229     }
 230 
 231     @Test
 232     public void lambdaInternalNameTest() {
 233         // Verify that the last dot in lambda types is properly handled when transitioning from
 234         // internal name to java
 235         // name and vice versa.
 236         Supplier<Runnable> lambda = () -> () -> System.out.println("run");
 237         ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
 238         String typeName = lambdaType.getName();
 239         String javaName = lambda.getClass().getName();
 240         assertEquals(typeName, toInternalName(javaName));
 241         assertEquals(javaName, internalNameToJava(typeName, true, true));
 242     }
 243 
 244     // TODO 8291719
 245     // @Test
 246     public void getModifiersTest() {
 247         for (Class<?> c : classes) {
 248             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 249             int mask = Modifier.classModifiers() & ~Modifier.STATIC;
 250             int expected = c.getModifiers() & mask;
 251             int actual = type.getModifiers() & mask;
 252             Class<?> elementalType = c;
 253             while (elementalType.isArray()) {
 254                 elementalType = elementalType.getComponentType();
 255             }
 256             if (elementalType.isMemberClass()) {
 257                 // member class get their modifiers from the inner-class attribute in the JVM and
 258                 // from the classfile header in jvmci
 259                 expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 260                 actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
 261             }
 262             assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
 263         }
 264     }
 265 

 303     public void getSuperclassTest() {
 304         for (Class<?> c : classes) {
 305             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 306             Class<?> expected = c.getSuperclass();
 307             ResolvedJavaType actual = type.getSuperclass();
 308             if (expected == null) {
 309                 assertTrue(actual == null);
 310             } else {
 311                 assertNotNull(actual);
 312                 assertTrue(actual.equals(metaAccess.lookupJavaType(expected)));
 313             }
 314         }
 315     }
 316 
 317     @Test
 318     public void getInterfacesTest() {
 319         for (Class<?> c : classes) {
 320             ResolvedJavaType type = metaAccess.lookupJavaType(c);
 321             Class<?>[] expected = c.getInterfaces();
 322             ResolvedJavaType[] actual = type.getInterfaces();
 323             // With injection of the IdentityObject interface by the JVM, the number of
 324             // interfaces visible through reflection and through JVMCI could differ by one
 325             assertTrue(expected.length == actual.length || (actual.length - expected.length) == 1);
 326             for (int i = 0; i < expected.length; i++) {
 327                 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i])));
 328             }
 329         }
 330     }
 331 
 332     public Class<?> getSupertype(Class<?> c) {
 333         assert !c.isPrimitive();
 334         if (c.isArray()) {
 335             Class<?> componentType = c.getComponentType();
 336             if (componentType.isPrimitive() || componentType == Object.class) {
 337                 return Object.class;
 338             }
 339             return getArrayClass(getSupertype(componentType));
 340         }
 341         if (c.isInterface()) {
 342             return Object.class;
 343         }
 344         return c.getSuperclass();
 345     }
< prev index next >