< prev index next >

test/compiler/jvmci/compilerToVM/FindUniqueConcreteMethodTest.java

Print this page




  28  * @library / /testlibrary /../../test/lib
  29  * @compile ../common/CompilerToVMHelper.java
  30  * @build compiler.jvmci.compilerToVM.FindUniqueConcreteMethodTest
  31  * @run main ClassFileInstaller
  32  *     jdk.vm.ci.hotspot.CompilerToVMHelper
  33  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockExperimentalVMOptions
  34  *     -XX:+EnableJVMCI compiler.jvmci.compilerToVM.FindUniqueConcreteMethodTest
  35  */
  36 
  37 package compiler.jvmci.compilerToVM;
  38 
  39 import compiler.jvmci.common.testcases.MultipleImplementer1;
  40 import compiler.jvmci.common.testcases.SingleImplementer;
  41 import compiler.jvmci.common.testcases.SingleSubclass;
  42 import compiler.jvmci.common.CTVMUtilities;
  43 import compiler.jvmci.common.testcases.SingleImplementerInterface;
  44 import java.lang.reflect.Method;
  45 import java.util.HashSet;
  46 import java.util.Set;
  47 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  48 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
  49 import jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl;
  50 import jdk.test.lib.Asserts;
  51 import jdk.test.lib.Utils;
  52 
  53 public class FindUniqueConcreteMethodTest {
  54     public static void main(String args[]) {
  55         FindUniqueConcreteMethodTest test = new FindUniqueConcreteMethodTest();
  56         try {
  57             for (TestCase tcase : createTestCases()) {
  58                 test.runTest(tcase);
  59             }
  60         } catch (NoSuchMethodException e) {
  61             throw new Error("TEST BUG: can't find method", e);
  62         }
  63     }
  64 
  65     private static Set<TestCase> createTestCases() {
  66         Set<TestCase> result = new HashSet<>();
  67         // a public method
  68         result.add(new TestCase(true, SingleSubclass.class,
  69                 SingleSubclass.class, "usualMethod"));


  80         result.add(new TestCase(true, SingleSubclass.class,
  81                 SingleSubclass.class, "defaultAccessMethod"));
  82         // default interface method redefined in implementer
  83         result.add(new TestCase(true, MultipleImplementer1.class,
  84                 MultipleImplementer1.class, "defaultMethod"));
  85         // interface method
  86         result.add(new TestCase(true, MultipleImplementer1.class,
  87                 MultipleImplementer1.class, "testMethod"));
  88         // default interface method not redefined in implementer
  89         result.add(new TestCase(true, SingleImplementer.class,
  90                 SingleImplementerInterface.class, "defaultMethod"));
  91         // static method
  92         result.add(new TestCase(false, SingleSubclass.class,
  93                 SingleSubclass.class, "staticMethod"));
  94         return result;
  95     }
  96 
  97     private void runTest(TestCase tcase) throws NoSuchMethodException {
  98         System.out.println(tcase);
  99         Method method = tcase.holder.getDeclaredMethod(tcase.methodName);
 100         HotSpotResolvedJavaMethodImpl testMethod = CTVMUtilities
 101                 .getResolvedMethod(tcase.reciever, method);
 102         HotSpotResolvedObjectTypeImpl resolvedType = CompilerToVMHelper
 103                 .lookupType(Utils.toJVMTypeSignature(tcase.reciever), getClass(),
 104                 /* resolve = */ true);
 105         HotSpotResolvedJavaMethodImpl concreteMethod = CompilerToVMHelper
 106                 .findUniqueConcreteMethod(resolvedType, testMethod);
 107         Asserts.assertEQ(concreteMethod, tcase.isPositive ? testMethod : null,
 108                 "Unexpected concrete method for " + tcase.methodName);
 109     }
 110 
 111     private static class TestCase {
 112         public final Class<?> reciever;
 113         public final Class<?> holder;
 114         public final String methodName;
 115         public final boolean isPositive;
 116 
 117         public TestCase(boolean isPositive, Class<?> clazz, Class<?> holder,
 118                 String methodName) {
 119             this.reciever = clazz;
 120             this.methodName = methodName;
 121             this.isPositive = isPositive;
 122             this.holder = holder;
 123         }
 124 
 125         @Override
 126         public String toString() {
 127             return String.format("CASE: reciever=%s, holder=%s, method=%s,"
 128                     + " isPositive=%s", reciever.getName(),
 129                     holder.getName(), methodName, isPositive);
 130         }
 131     }
 132 }


  28  * @library / /testlibrary /../../test/lib
  29  * @compile ../common/CompilerToVMHelper.java
  30  * @build compiler.jvmci.compilerToVM.FindUniqueConcreteMethodTest
  31  * @run main ClassFileInstaller
  32  *     jdk.vm.ci.hotspot.CompilerToVMHelper
  33  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockExperimentalVMOptions
  34  *     -XX:+EnableJVMCI compiler.jvmci.compilerToVM.FindUniqueConcreteMethodTest
  35  */
  36 
  37 package compiler.jvmci.compilerToVM;
  38 
  39 import compiler.jvmci.common.testcases.MultipleImplementer1;
  40 import compiler.jvmci.common.testcases.SingleImplementer;
  41 import compiler.jvmci.common.testcases.SingleSubclass;
  42 import compiler.jvmci.common.CTVMUtilities;
  43 import compiler.jvmci.common.testcases.SingleImplementerInterface;
  44 import java.lang.reflect.Method;
  45 import java.util.HashSet;
  46 import java.util.Set;
  47 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  48 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  49 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
  50 import jdk.test.lib.Asserts;
  51 import jdk.test.lib.Utils;
  52 
  53 public class FindUniqueConcreteMethodTest {
  54     public static void main(String args[]) {
  55         FindUniqueConcreteMethodTest test = new FindUniqueConcreteMethodTest();
  56         try {
  57             for (TestCase tcase : createTestCases()) {
  58                 test.runTest(tcase);
  59             }
  60         } catch (NoSuchMethodException e) {
  61             throw new Error("TEST BUG: can't find method", e);
  62         }
  63     }
  64 
  65     private static Set<TestCase> createTestCases() {
  66         Set<TestCase> result = new HashSet<>();
  67         // a public method
  68         result.add(new TestCase(true, SingleSubclass.class,
  69                 SingleSubclass.class, "usualMethod"));


  80         result.add(new TestCase(true, SingleSubclass.class,
  81                 SingleSubclass.class, "defaultAccessMethod"));
  82         // default interface method redefined in implementer
  83         result.add(new TestCase(true, MultipleImplementer1.class,
  84                 MultipleImplementer1.class, "defaultMethod"));
  85         // interface method
  86         result.add(new TestCase(true, MultipleImplementer1.class,
  87                 MultipleImplementer1.class, "testMethod"));
  88         // default interface method not redefined in implementer
  89         result.add(new TestCase(true, SingleImplementer.class,
  90                 SingleImplementerInterface.class, "defaultMethod"));
  91         // static method
  92         result.add(new TestCase(false, SingleSubclass.class,
  93                 SingleSubclass.class, "staticMethod"));
  94         return result;
  95     }
  96 
  97     private void runTest(TestCase tcase) throws NoSuchMethodException {
  98         System.out.println(tcase);
  99         Method method = tcase.holder.getDeclaredMethod(tcase.methodName);
 100         HotSpotResolvedJavaMethod testMethod = CTVMUtilities
 101                 .getResolvedMethod(tcase.receiver, method);
 102         HotSpotResolvedObjectType resolvedType = CompilerToVMHelper
 103                 .lookupType(Utils.toJVMTypeSignature(tcase.receiver), getClass(),
 104                 /* resolve = */ true);
 105         HotSpotResolvedJavaMethod concreteMethod = CompilerToVMHelper
 106                 .findUniqueConcreteMethod(resolvedType, testMethod);
 107         Asserts.assertEQ(concreteMethod, tcase.isPositive ? testMethod : null,
 108                 "Unexpected concrete method for " + tcase.methodName);
 109     }
 110 
 111     private static class TestCase {
 112         public final Class<?> receiver;
 113         public final Class<?> holder;
 114         public final String methodName;
 115         public final boolean isPositive;
 116 
 117         public TestCase(boolean isPositive, Class<?> clazz, Class<?> holder,
 118                 String methodName) {
 119             this.receiver = clazz;
 120             this.methodName = methodName;
 121             this.isPositive = isPositive;
 122             this.holder = holder;
 123         }
 124 
 125         @Override
 126         public String toString() {
 127             return String.format("CASE: receiver=%s, holder=%s, method=%s,"
 128                     + " isPositive=%s", receiver.getName(),
 129                     holder.getName(), methodName, isPositive);
 130         }
 131     }
 132 }
< prev index next >