< prev index next >

test/compiler/jvmci/compilerToVM/GetVtableIndexForInterfaceTest.java

Print this page




  36 
  37 package compiler.jvmci.compilerToVM;
  38 
  39 import compiler.jvmci.common.testcases.AbstractClass;
  40 import compiler.jvmci.common.testcases.DoNotExtendClass;
  41 import compiler.jvmci.common.testcases.MultipleAbstractImplementer;
  42 import compiler.jvmci.common.testcases.MultipleImplementersInterface;
  43 import compiler.jvmci.common.testcases.MultipleImplementersInterfaceExtender;
  44 import compiler.jvmci.common.testcases.SingleImplementer;
  45 import compiler.jvmci.common.testcases.SingleImplementerInterface;
  46 import compiler.jvmci.common.testcases.SingleSubclass;
  47 import compiler.jvmci.common.testcases.SingleSubclassedClass;
  48 import compiler.jvmci.common.CTVMUtilities;
  49 import compiler.jvmci.common.testcases.AnotherSingleImplementer;
  50 import compiler.jvmci.common.testcases.AnotherSingleImplementerInterface;
  51 import java.lang.reflect.Method;
  52 import java.util.HashSet;
  53 import java.util.Set;
  54 import java.util.stream.Stream;
  55 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  56 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
  57 import jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl;
  58 import jdk.test.lib.Asserts;
  59 import jdk.test.lib.Utils;
  60 
  61 public class GetVtableIndexForInterfaceTest {
  62     private static final int INVALID_VTABLE_INDEX = -4; // see method.hpp: VtableIndexFlag
  63 
  64     public static void main(String args[]) {
  65         GetVtableIndexForInterfaceTest test
  66                 = new GetVtableIndexForInterfaceTest();
  67         try {
  68             for (TestCase tcase : createTestCases()) {
  69                 test.runTest(tcase);
  70             }
  71         } catch (NoSuchMethodException e) {
  72             throw new Error("TEST BUG: can't find requested method", e);
  73         }
  74     }
  75 
  76     private static Set<TestCase> createTestCases() {
  77         Set<TestCase> result = new HashSet<>();


 108                 InternalError.class));
 109         // class not implementing iface
 110         result.add(new TestCase(DoNotExtendClass.class,
 111                 SingleImplementerInterface.class, "defaultMethod", false));
 112         // abstract class which doesn't implement iface
 113         result.add(new TestCase(AbstractClass.class,
 114                 SingleImplementerInterface.class, "defaultMethod", false));
 115         // abstract class which implements iface
 116         result.add(new TestCase(MultipleAbstractImplementer.class,
 117                 MultipleImplementersInterface.class, "defaultMethod", true));
 118         // class not initialized
 119         result.add(new TestCase(AnotherSingleImplementer.class,
 120                 AnotherSingleImplementerInterface.class, "defaultMethod",
 121                 false, InternalError.class));
 122         return result;
 123     }
 124 
 125     private void runTest(TestCase tcase) throws NoSuchMethodException {
 126         System.out.println(tcase);
 127         Method method = tcase.holder.getDeclaredMethod(tcase.methodName);
 128         HotSpotResolvedObjectTypeImpl metaspaceKlass = CompilerToVMHelper
 129                 .lookupType(Utils.toJVMTypeSignature(tcase.receiver),
 130                         getClass(), /* resolve = */ true);
 131         HotSpotResolvedJavaMethodImpl metaspaceMethod = CTVMUtilities
 132                 .getResolvedMethod(tcase.holder, method);
 133         int index = 0;
 134         try {
 135             index = CompilerToVMHelper
 136                     .getVtableIndexForInterfaceMethod(metaspaceKlass,
 137                             metaspaceMethod);
 138         } catch (Throwable t) {
 139             if (tcase.isPositive || tcase.expectedException == null) {
 140                 throw new Error("Caught unexpected exception " + t);
 141             }
 142             if (!tcase.expectedException.equals(t.getClass())) {
 143                 throw new Error(String.format("Caught %s while expected %s",
 144                         t.getClass().getName(),
 145                         tcase.expectedException.getName()));
 146             }
 147             return;
 148         }
 149         if (tcase.expectedException != null) {
 150             throw new AssertionError("Expected exception wasn't caught: "
 151                     + tcase.expectedException.getName());




  36 
  37 package compiler.jvmci.compilerToVM;
  38 
  39 import compiler.jvmci.common.testcases.AbstractClass;
  40 import compiler.jvmci.common.testcases.DoNotExtendClass;
  41 import compiler.jvmci.common.testcases.MultipleAbstractImplementer;
  42 import compiler.jvmci.common.testcases.MultipleImplementersInterface;
  43 import compiler.jvmci.common.testcases.MultipleImplementersInterfaceExtender;
  44 import compiler.jvmci.common.testcases.SingleImplementer;
  45 import compiler.jvmci.common.testcases.SingleImplementerInterface;
  46 import compiler.jvmci.common.testcases.SingleSubclass;
  47 import compiler.jvmci.common.testcases.SingleSubclassedClass;
  48 import compiler.jvmci.common.CTVMUtilities;
  49 import compiler.jvmci.common.testcases.AnotherSingleImplementer;
  50 import compiler.jvmci.common.testcases.AnotherSingleImplementerInterface;
  51 import java.lang.reflect.Method;
  52 import java.util.HashSet;
  53 import java.util.Set;
  54 import java.util.stream.Stream;
  55 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  56 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  57 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
  58 import jdk.test.lib.Asserts;
  59 import jdk.test.lib.Utils;
  60 
  61 public class GetVtableIndexForInterfaceTest {
  62     private static final int INVALID_VTABLE_INDEX = -4; // see method.hpp: VtableIndexFlag
  63 
  64     public static void main(String args[]) {
  65         GetVtableIndexForInterfaceTest test
  66                 = new GetVtableIndexForInterfaceTest();
  67         try {
  68             for (TestCase tcase : createTestCases()) {
  69                 test.runTest(tcase);
  70             }
  71         } catch (NoSuchMethodException e) {
  72             throw new Error("TEST BUG: can't find requested method", e);
  73         }
  74     }
  75 
  76     private static Set<TestCase> createTestCases() {
  77         Set<TestCase> result = new HashSet<>();


 108                 InternalError.class));
 109         // class not implementing iface
 110         result.add(new TestCase(DoNotExtendClass.class,
 111                 SingleImplementerInterface.class, "defaultMethod", false));
 112         // abstract class which doesn't implement iface
 113         result.add(new TestCase(AbstractClass.class,
 114                 SingleImplementerInterface.class, "defaultMethod", false));
 115         // abstract class which implements iface
 116         result.add(new TestCase(MultipleAbstractImplementer.class,
 117                 MultipleImplementersInterface.class, "defaultMethod", true));
 118         // class not initialized
 119         result.add(new TestCase(AnotherSingleImplementer.class,
 120                 AnotherSingleImplementerInterface.class, "defaultMethod",
 121                 false, InternalError.class));
 122         return result;
 123     }
 124 
 125     private void runTest(TestCase tcase) throws NoSuchMethodException {
 126         System.out.println(tcase);
 127         Method method = tcase.holder.getDeclaredMethod(tcase.methodName);
 128         HotSpotResolvedObjectType metaspaceKlass = CompilerToVMHelper
 129                 .lookupType(Utils.toJVMTypeSignature(tcase.receiver),
 130                         getClass(), /* resolve = */ true);
 131         HotSpotResolvedJavaMethod metaspaceMethod = CTVMUtilities
 132                 .getResolvedMethod(tcase.holder, method);
 133         int index = 0;
 134         try {
 135             index = CompilerToVMHelper
 136                     .getVtableIndexForInterfaceMethod(metaspaceKlass,
 137                             metaspaceMethod);
 138         } catch (Throwable t) {
 139             if (tcase.isPositive || tcase.expectedException == null) {
 140                 throw new Error("Caught unexpected exception " + t);
 141             }
 142             if (!tcase.expectedException.equals(t.getClass())) {
 143                 throw new Error(String.format("Caught %s while expected %s",
 144                         t.getClass().getName(),
 145                         tcase.expectedException.getName()));
 146             }
 147             return;
 148         }
 149         if (tcase.expectedException != null) {
 150             throw new AssertionError("Expected exception wasn't caught: "
 151                     + tcase.expectedException.getName());


< prev index next >