< prev index next >

test/compiler/jvmci/compilerToVM/GetExceptionTableTest.java

Print this page




  25 /**
  26  * @test
  27  * @bug 8136421
  28  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
  29  * @library /testlibrary /../../test/lib /
  30  * @compile ../common/CompilerToVMHelper.java
  31  * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper
  32  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  33  *      -Xbootclasspath/a:.
  34  *      compiler.jvmci.compilerToVM.GetExceptionTableTest
  35  */
  36 
  37 package compiler.jvmci.compilerToVM;
  38 
  39 import compiler.jvmci.common.CTVMUtilities;
  40 import java.io.IOException;
  41 import java.lang.reflect.Executable;
  42 import java.net.Socket;
  43 import java.util.HashMap;
  44 import java.util.Map;
  45 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
  46 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  47 import jdk.test.lib.Asserts;
  48 
  49 public class GetExceptionTableTest {
  50 
  51     public static final int TRY_CATCH_COUNT = 3;
  52     public static final int TRY_CATCH_FINALLY_COUNT = 8;
  53     public static final int TRY_WITH_RESOURCES_COUNT = 6;
  54     public static final int EMPTY_COUNT = 0;
  55 
  56     public static void main(String[] args) {
  57         Map<Executable, Integer> testCases = createTestCases();
  58         testCases.forEach(GetExceptionTableTest::runSanityTest);
  59     }
  60 
  61     private static Map<Executable, Integer> createTestCases() {
  62         HashMap<Executable, Integer> methods = new HashMap<>();
  63         try {
  64             Class<?> aClass = GetExceptionTableTest.DummyClass.class;
  65             methods.put(aClass.getMethod("tryCatchDummy"), TRY_CATCH_COUNT);
  66             methods.put(aClass.getMethod("tryCatchFinallyDummy"),
  67                     TRY_CATCH_FINALLY_COUNT);
  68             methods.put(aClass.getMethod("tryWithResourcesDummy"),
  69                     TRY_WITH_RESOURCES_COUNT);
  70             methods.put(aClass.getMethod("emptyFunction"), EMPTY_COUNT);
  71         } catch (NoSuchMethodException e) {
  72             throw new Error("TEST BUG", e);
  73         }
  74         return methods;
  75     }
  76 
  77     private static void runSanityTest(Executable aMethod,
  78                                       Integer expectedTableLength) {
  79         HotSpotResolvedJavaMethodImpl method = CTVMUtilities
  80                 .getResolvedMethod(aMethod);
  81         int tableLength = CompilerToVMHelper.getExceptionTableLength(method);
  82         Asserts.assertEQ(tableLength, expectedTableLength, aMethod
  83                 + " incorrect exception table length.");
  84 
  85         long tableStart = CompilerToVMHelper.getExceptionTableStart(method);
  86         if (tableLength > 0) {
  87             Asserts.assertNE(tableStart, 0L, aMethod + " exception table starts "
  88                     + "at 0.");
  89         }
  90     }
  91 
  92     private static class DummyClass {
  93         public static void emptyFunction() {}
  94         public static void tryCatchDummy() throws Throwable {
  95             try {
  96                 throw new Exception("Dummy exception");
  97             } catch (ArithmeticException ex) {
  98                 throw new IOException(ex.getMessage());
  99             } catch (IOException ex) {




  25 /**
  26  * @test
  27  * @bug 8136421
  28  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
  29  * @library /testlibrary /../../test/lib /
  30  * @compile ../common/CompilerToVMHelper.java
  31  * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper
  32  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  33  *      -Xbootclasspath/a:.
  34  *      compiler.jvmci.compilerToVM.GetExceptionTableTest
  35  */
  36 
  37 package compiler.jvmci.compilerToVM;
  38 
  39 import compiler.jvmci.common.CTVMUtilities;
  40 import java.io.IOException;
  41 import java.lang.reflect.Executable;
  42 import java.net.Socket;
  43 import java.util.HashMap;
  44 import java.util.Map;
  45 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  46 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  47 import jdk.test.lib.Asserts;
  48 
  49 public class GetExceptionTableTest {
  50 
  51     public static final int TRY_CATCH_COUNT = 3;
  52     public static final int TRY_CATCH_FINALLY_COUNT = 8;
  53     public static final int TRY_WITH_RESOURCES_COUNT = 6;
  54     public static final int EMPTY_COUNT = 0;
  55 
  56     public static void main(String[] args) {
  57         Map<Executable, Integer> testCases = createTestCases();
  58         testCases.forEach(GetExceptionTableTest::runSanityTest);
  59     }
  60 
  61     private static Map<Executable, Integer> createTestCases() {
  62         HashMap<Executable, Integer> methods = new HashMap<>();
  63         try {
  64             Class<?> aClass = GetExceptionTableTest.DummyClass.class;
  65             methods.put(aClass.getMethod("tryCatchDummy"), TRY_CATCH_COUNT);
  66             methods.put(aClass.getMethod("tryCatchFinallyDummy"),
  67                     TRY_CATCH_FINALLY_COUNT);
  68             methods.put(aClass.getMethod("tryWithResourcesDummy"),
  69                     TRY_WITH_RESOURCES_COUNT);
  70             methods.put(aClass.getMethod("emptyFunction"), EMPTY_COUNT);
  71         } catch (NoSuchMethodException e) {
  72             throw new Error("TEST BUG", e);
  73         }
  74         return methods;
  75     }
  76 
  77     private static void runSanityTest(Executable aMethod,
  78                                       Integer expectedTableLength) {
  79         HotSpotResolvedJavaMethod method = CTVMUtilities
  80                 .getResolvedMethod(aMethod);
  81         int tableLength = CompilerToVMHelper.getExceptionTableLength(method);
  82         Asserts.assertEQ(tableLength, expectedTableLength, aMethod
  83                 + " incorrect exception table length.");
  84 
  85         long tableStart = CompilerToVMHelper.getExceptionTableStart(method);
  86         if (tableLength > 0) {
  87             Asserts.assertNE(tableStart, 0L, aMethod + " exception table starts "
  88                     + "at 0.");
  89         }
  90     }
  91 
  92     private static class DummyClass {
  93         public static void emptyFunction() {}
  94         public static void tryCatchDummy() throws Throwable {
  95             try {
  96                 throw new Exception("Dummy exception");
  97             } catch (ArithmeticException ex) {
  98                 throw new IOException(ex.getMessage());
  99             } catch (IOException ex) {


< prev index next >