192 ResolvedJavaType type = metaAccess.lookupJavaType(c);
193 boolean expected = c.isArray();
194 boolean actual = type.isArray();
195 assertEquals(expected, actual);
196 }
197 }
198
199 @Test
200 public void lambdaInternalNameTest() {
201 // Verify that the last dot in lambda types is properly handled when transitioning from
202 // internal name to java
203 // name and vice versa.
204 Supplier<Runnable> lambda = () -> () -> System.out.println("run");
205 ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
206 String typeName = lambdaType.getName();
207 String javaName = lambda.getClass().getName();
208 assertEquals(typeName, toInternalName(javaName));
209 assertEquals(javaName, internalNameToJava(typeName, true, true));
210 }
211
212 @Test
213 public void getModifiersTest() {
214 for (Class<?> c : classes) {
215 ResolvedJavaType type = metaAccess.lookupJavaType(c);
216 int mask = Modifier.classModifiers() & ~Modifier.STATIC;
217 int expected = c.getModifiers() & mask;
218 int actual = type.getModifiers() & mask;
219 Class<?> elementalType = c;
220 while (elementalType.isArray()) {
221 elementalType = elementalType.getComponentType();
222 }
223 if (elementalType.isMemberClass()) {
224 // member class get their modifiers from the inner-class attribute in the JVM and
225 // from the classfile header in jvmci
226 expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
227 actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
228 }
229 assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
230 }
231 }
232
270 public void getSuperclassTest() {
271 for (Class<?> c : classes) {
272 ResolvedJavaType type = metaAccess.lookupJavaType(c);
273 Class<?> expected = c.getSuperclass();
274 ResolvedJavaType actual = type.getSuperclass();
275 if (expected == null) {
276 assertTrue(actual == null);
277 } else {
278 assertNotNull(actual);
279 assertTrue(actual.equals(metaAccess.lookupJavaType(expected)));
280 }
281 }
282 }
283
284 @Test
285 public void getInterfacesTest() {
286 for (Class<?> c : classes) {
287 ResolvedJavaType type = metaAccess.lookupJavaType(c);
288 Class<?>[] expected = c.getInterfaces();
289 ResolvedJavaType[] actual = type.getInterfaces();
290 assertEquals(expected.length, actual.length);
291 for (int i = 0; i < expected.length; i++) {
292 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i])));
293 }
294 }
295 }
296
297 public Class<?> getSupertype(Class<?> c) {
298 assert !c.isPrimitive();
299 if (c.isArray()) {
300 Class<?> componentType = c.getComponentType();
301 if (componentType.isPrimitive() || componentType == Object.class) {
302 return Object.class;
303 }
304 return getArrayClass(getSupertype(componentType));
305 }
306 if (c.isInterface()) {
307 return Object.class;
308 }
309 return c.getSuperclass();
310 }
|
192 ResolvedJavaType type = metaAccess.lookupJavaType(c);
193 boolean expected = c.isArray();
194 boolean actual = type.isArray();
195 assertEquals(expected, actual);
196 }
197 }
198
199 @Test
200 public void lambdaInternalNameTest() {
201 // Verify that the last dot in lambda types is properly handled when transitioning from
202 // internal name to java
203 // name and vice versa.
204 Supplier<Runnable> lambda = () -> () -> System.out.println("run");
205 ResolvedJavaType lambdaType = metaAccess.lookupJavaType(lambda.getClass());
206 String typeName = lambdaType.getName();
207 String javaName = lambda.getClass().getName();
208 assertEquals(typeName, toInternalName(javaName));
209 assertEquals(javaName, internalNameToJava(typeName, true, true));
210 }
211
212 // TODO 8291719
213 // @Test
214 public void getModifiersTest() {
215 for (Class<?> c : classes) {
216 ResolvedJavaType type = metaAccess.lookupJavaType(c);
217 int mask = Modifier.classModifiers() & ~Modifier.STATIC;
218 int expected = c.getModifiers() & mask;
219 int actual = type.getModifiers() & mask;
220 Class<?> elementalType = c;
221 while (elementalType.isArray()) {
222 elementalType = elementalType.getComponentType();
223 }
224 if (elementalType.isMemberClass()) {
225 // member class get their modifiers from the inner-class attribute in the JVM and
226 // from the classfile header in jvmci
227 expected &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
228 actual &= ~(Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED);
229 }
230 assertEquals(String.format("%s: 0x%x != 0x%x", type, expected, actual), expected, actual);
231 }
232 }
233
271 public void getSuperclassTest() {
272 for (Class<?> c : classes) {
273 ResolvedJavaType type = metaAccess.lookupJavaType(c);
274 Class<?> expected = c.getSuperclass();
275 ResolvedJavaType actual = type.getSuperclass();
276 if (expected == null) {
277 assertTrue(actual == null);
278 } else {
279 assertNotNull(actual);
280 assertTrue(actual.equals(metaAccess.lookupJavaType(expected)));
281 }
282 }
283 }
284
285 @Test
286 public void getInterfacesTest() {
287 for (Class<?> c : classes) {
288 ResolvedJavaType type = metaAccess.lookupJavaType(c);
289 Class<?>[] expected = c.getInterfaces();
290 ResolvedJavaType[] actual = type.getInterfaces();
291 // With injection of the IdentityObject interface by the JVM, the number of
292 // interfaces visible through reflection and through JVMCI could differ by one
293 assertTrue(expected.length == actual.length || (actual.length - expected.length) == 1);
294 for (int i = 0; i < expected.length; i++) {
295 assertTrue(actual[i].equals(metaAccess.lookupJavaType(expected[i])));
296 }
297 }
298 }
299
300 public Class<?> getSupertype(Class<?> c) {
301 assert !c.isPrimitive();
302 if (c.isArray()) {
303 Class<?> componentType = c.getComponentType();
304 if (componentType.isPrimitive() || componentType == Object.class) {
305 return Object.class;
306 }
307 return getArrayClass(getSupertype(componentType));
308 }
309 if (c.isInterface()) {
310 return Object.class;
311 }
312 return c.getSuperclass();
313 }
|