< prev index next >

test/compiler/jvmci/compilerToVM/HasCompiledCodeForOSRTest.java

Print this page




  33  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  34  *                              jdk.vm.ci.hotspot.CompilerToVMHelper
  35  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  36  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
  37  *      -XX:-BackgroundCompilation
  38  *      compiler.jvmci.compilerToVM.HasCompiledCodeForOSRTest
  39  */
  40 
  41 package compiler.jvmci.compilerToVM;
  42 
  43 import compiler.jvmci.common.CTVMUtilities;
  44 
  45 import java.lang.reflect.Executable;
  46 import java.lang.reflect.Method;
  47 import java.util.ArrayList;
  48 import java.util.HashMap;
  49 import java.util.List;
  50 import java.util.Map;
  51 
  52 import compiler.testlibrary.CompilerUtils;
  53 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
  54 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  55 import jdk.test.lib.Asserts;

  56 import sun.hotspot.WhiteBox;
  57 import sun.hotspot.code.NMethod;
  58 
  59 public class HasCompiledCodeForOSRTest {
  60     public static void main(String[] args) {
  61         List<CompileCodeTestCase>testCases = createTestCases();
  62         testCases.forEach(HasCompiledCodeForOSRTest::runSanityTest);
  63     }
  64 
  65     public static List<CompileCodeTestCase> createTestCases() {
  66         List<CompileCodeTestCase> testCases = new ArrayList<>();
  67 
  68         try {
  69             Class<?> aClass = DummyClass.class;
  70             testCases.add(new CompileCodeTestCase(

  71                     aClass.getMethod("withLoop"), 17));
  72         } catch (NoSuchMethodException e) {
  73             throw new Error("TEST BUG : " + e.getMessage(), e);
  74         }
  75         return testCases;
  76     }
  77 
  78     private static void runSanityTest(CompileCodeTestCase testCase) {
  79         System.out.println(testCase);
  80         Executable aMethod = testCase.executable;
  81         HotSpotResolvedJavaMethodImpl method = CTVMUtilities
  82                 .getResolvedMethod(aMethod);

  83         testCase.deoptimize();
  84         int[] levels = CompilerUtils.getAvailableCompilationLevels();
  85         // not compiled
  86         for (int level : levels) {
  87             boolean isCompiled = CompilerToVMHelper.hasCompiledCodeForOSR(
  88                     method, testCase.bci, level);
  89             Asserts.assertFalse(isCompiled, String.format(
  90                     "%s : unexpected return value for non-compiled method at "
  91                             + "level %d", testCase, level));
  92         }
  93         NMethod nm = testCase.compile();
  94         if (nm == null) {
  95             throw new Error(String.format(
  96                     "TEST BUG : %s : cannot compile method", testCase));
  97         }
  98 
  99         boolean isCompiled;
 100         int level = nm.comp_level;
 101         for (int i : levels) {
 102             isCompiled = CompilerToVMHelper.hasCompiledCodeForOSR(


  33  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  34  *                              jdk.vm.ci.hotspot.CompilerToVMHelper
  35  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  36  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
  37  *      -XX:-BackgroundCompilation
  38  *      compiler.jvmci.compilerToVM.HasCompiledCodeForOSRTest
  39  */
  40 
  41 package compiler.jvmci.compilerToVM;
  42 
  43 import compiler.jvmci.common.CTVMUtilities;
  44 
  45 import java.lang.reflect.Executable;
  46 import java.lang.reflect.Method;
  47 import java.util.ArrayList;
  48 import java.util.HashMap;
  49 import java.util.List;
  50 import java.util.Map;
  51 
  52 import compiler.testlibrary.CompilerUtils;
  53 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  54 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  55 import jdk.test.lib.Asserts;
  56 import jdk.test.lib.Utils;
  57 import sun.hotspot.WhiteBox;
  58 import sun.hotspot.code.NMethod;
  59 
  60 public class HasCompiledCodeForOSRTest {
  61     public static void main(String[] args) {
  62         List<CompileCodeTestCase>testCases = createTestCases();
  63         testCases.forEach(HasCompiledCodeForOSRTest::runSanityTest);
  64     }
  65 
  66     public static List<CompileCodeTestCase> createTestCases() {
  67         List<CompileCodeTestCase> testCases = new ArrayList<>();
  68 
  69         try {
  70             Class<?> aClass = DummyClass.class;
  71             Object receiver = new DummyClass();
  72             testCases.add(new CompileCodeTestCase(receiver,
  73                     aClass.getMethod("withLoop"), 17));
  74         } catch (NoSuchMethodException e) {
  75             throw new Error("TEST BUG : " + e.getMessage(), e);
  76         }
  77         return testCases;
  78     }
  79 
  80     private static void runSanityTest(CompileCodeTestCase testCase) {
  81         System.out.println(testCase);
  82         Executable aMethod = testCase.executable;
  83         HotSpotResolvedJavaMethod method = CTVMUtilities
  84                 .getResolvedMethod(aMethod);
  85         testCase.invoke(Utils.getNullValues(aMethod.getParameterTypes()));
  86         testCase.deoptimize();
  87         int[] levels = CompilerUtils.getAvailableCompilationLevels();
  88         // not compiled
  89         for (int level : levels) {
  90             boolean isCompiled = CompilerToVMHelper.hasCompiledCodeForOSR(
  91                     method, testCase.bci, level);
  92             Asserts.assertFalse(isCompiled, String.format(
  93                     "%s : unexpected return value for non-compiled method at "
  94                             + "level %d", testCase, level));
  95         }
  96         NMethod nm = testCase.compile();
  97         if (nm == null) {
  98             throw new Error(String.format(
  99                     "TEST BUG : %s : cannot compile method", testCase));
 100         }
 101 
 102         boolean isCompiled;
 103         int level = nm.comp_level;
 104         for (int i : levels) {
 105             isCompiled = CompilerToVMHelper.hasCompiledCodeForOSR(
< prev index next >