comparison jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java @ 24100:839dcc4f2cf6 jvmci-0.24

handle signature polymorphic methods correctly (JDK-8161550)
author Doug Simon <doug.simon@oracle.com>
date Wed, 08 Feb 2017 23:49:32 +0100
parents d6bd0b9cd0b6
children 6d70d9c43369
comparison
equal deleted inserted replaced
24099:955ebad35cba 24100:839dcc4f2cf6
66 66
67 /** 67 /**
68 * Tests for {@link ResolvedJavaType}. 68 * Tests for {@link ResolvedJavaType}.
69 */ 69 */
70 public class TestResolvedJavaType extends TypeUniverse { 70 public class TestResolvedJavaType extends TypeUniverse {
71 private static final Class<? extends Annotation> SIGNATURE_POLYMORPHIC_CLASS = findPolymorphicSignatureClass();
71 72
72 public TestResolvedJavaType() { 73 public TestResolvedJavaType() {
74 }
75
76 @SuppressWarnings("unchecked")
77 private static Class<? extends Annotation> findPolymorphicSignatureClass() {
78 Class<? extends Annotation> signaturePolyAnnotation = null;
79 try {
80 for (Class<?> clazz : TestResolvedJavaType.class.getClassLoader().loadClass("java.lang.invoke.MethodHandle").getDeclaredClasses()) {
81 if (clazz.getName().endsWith("PolymorphicSignature") && Annotation.class.isAssignableFrom(clazz)) {
82 signaturePolyAnnotation = (Class<? extends Annotation>) clazz;
83 break;
84 }
85 }
86 } catch (Throwable e) {
87 throw new AssertionError("Could not find annotation PolymorphicSignature in java.lang.invoke.MethodHandle", e);
88 }
89 assertNotNull(signaturePolyAnnotation);
90 return signaturePolyAnnotation;
73 } 91 }
74 92
75 @Test 93 @Test
76 public void findInstanceFieldWithOffsetTest() { 94 public void findInstanceFieldWithOffsetTest() {
77 for (Class<?> c : classes) { 95 for (Class<?> c : classes) {
569 for (Method impl : vtable.methods.values()) { 587 for (Method impl : vtable.methods.values()) {
570 Set<Method> decls = findDeclarations(impl, c); 588 Set<Method> decls = findDeclarations(impl, c);
571 for (Method decl : decls) { 589 for (Method decl : decls) {
572 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); 590 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl);
573 if (m.isPublic()) { 591 if (m.isPublic()) {
574 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); 592 ResolvedJavaMethod resolvedMethod = type.resolveMethod(m, context);
575 assertEquals(m.toString(), i, type.resolveMethod(m, context)); 593 if (isSignaturePolymorphic(m)) {
594 // Signature polymorphic methods must not be resolved
595 assertNull(resolvedMethod);
596 } else {
597 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl);
598 assertEquals(m.toString(), i, resolvedMethod);
599 }
576 } 600 }
577 } 601 }
578 } 602 }
579 } 603 }
580 } 604 }
598 for (Method impl : vtable.methods.values()) { 622 for (Method impl : vtable.methods.values()) {
599 Set<Method> decls = findDeclarations(impl, c); 623 Set<Method> decls = findDeclarations(impl, c);
600 for (Method decl : decls) { 624 for (Method decl : decls) {
601 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl); 625 ResolvedJavaMethod m = metaAccess.lookupJavaMethod(decl);
602 if (m.isPublic()) { 626 if (m.isPublic()) {
603 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl); 627 ResolvedJavaMethod resolvedMethod = type.resolveConcreteMethod(m, context);
604 assertEquals(i, type.resolveConcreteMethod(m, context)); 628 if (isSignaturePolymorphic(m)) {
629 // Signature polymorphic methods must not be resolved
630 assertNull(String.format("Got: %s", resolvedMethod), resolvedMethod);
631 } else {
632 ResolvedJavaMethod i = metaAccess.lookupJavaMethod(impl);
633 assertEquals(i, resolvedMethod);
634 }
605 } 635 }
606 } 636 }
607 } 637 }
608 for (Method m : c.getDeclaredMethods()) { 638 for (Method m : c.getDeclaredMethods()) {
609 ResolvedJavaMethod impl = type.resolveConcreteMethod(metaAccess.lookupJavaMethod(m), context); 639 ResolvedJavaMethod impl = type.resolveConcreteMethod(metaAccess.lookupJavaMethod(m), context);
917 } else { 947 } else {
918 assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName())); 948 assertFalse("test should be removed from untestedApiMethods" + m, known.contains(m.getName()));
919 } 949 }
920 } 950 }
921 } 951 }
952
953 private static boolean isSignaturePolymorphic(ResolvedJavaMethod method) {
954 return method.getAnnotation(SIGNATURE_POLYMORPHIC_CLASS) != null;
955 }
922 } 956 }