< prev index next >

test/compiler/jvmci/compilerToVM/ReprofileTest.java

Print this page




  29  * @library /testlibrary /../../test/lib /
  30  * @compile ../common/CompilerToVMHelper.java
  31  * @build sun.hotspot.WhiteBox
  32  * @run main ClassFileInstaller
  33  *      sun.hotspot.WhiteBox
  34  *      sun.hotspot.WhiteBox$WhiteBoxPermission
  35  *      jdk.vm.ci.hotspot.CompilerToVMHelper
  36  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  37  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
  38  *      -Xmixed
  39  *      compiler.jvmci.compilerToVM.ReprofileTest
  40  */
  41 
  42 package compiler.jvmci.compilerToVM;
  43 
  44 import compiler.jvmci.common.CTVMUtilities;
  45 import java.lang.reflect.Method;
  46 import java.util.ArrayList;
  47 import java.util.List;
  48 import java.util.Random;
  49 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
  50 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  51 import jdk.vm.ci.meta.ProfilingInfo;
  52 import jdk.test.lib.Asserts;
  53 import jdk.test.lib.Utils;
  54 import sun.hotspot.WhiteBox;
  55 
  56 public class ReprofileTest {
  57 
  58     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  59 
  60     public static void main(String[] args) {
  61         List<Method> testCases = createTestCases();
  62         testCases.forEach(ReprofileTest::runSanityTest);
  63     }
  64 
  65     private static List<Method> createTestCases() {
  66         List<Method> testCases = new ArrayList<>();
  67         try {
  68 
  69             Class<?> aClass = DummyClass.class;
  70             testCases.add(aClass.getMethod("withLoop"));
  71 
  72             aClass = DummyClass.class;
  73             testCases.add(aClass.getDeclaredMethod("dummyFunction"));
  74         } catch (NoSuchMethodException e) {
  75             throw new Error("TEST BUG " + e.getMessage(), e);
  76         }
  77         return testCases;
  78     }
  79 
  80     private static void runSanityTest(Method aMethod) {
  81         HotSpotResolvedJavaMethodImpl method = CTVMUtilities
  82                 .getResolvedMethod(aMethod);
  83         ProfilingInfo startProfile = method.getProfilingInfo();
  84         Asserts.assertFalse(startProfile.isMature(), aMethod
  85                 + " : profiling info is mature in the begging");
  86 
  87         long compileThreshold = (Long) WB.getVMFlag("CompileThreshold");
  88         // make interpreter to profile this method
  89         try {
  90             Object obj = aMethod.getDeclaringClass().newInstance();
  91             for (long i = 0; i < compileThreshold; i++) {
  92                 aMethod.invoke(obj);
  93             }
  94         } catch (ReflectiveOperationException e) {
  95             throw new Error("TEST BUG : " + e.getMessage(), e);
  96         }
  97         ProfilingInfo compProfile = method.getProfilingInfo();
  98 
  99         Asserts.assertNE(startProfile.toString(), compProfile.toString(),
 100                 String.format("%s : profiling info wasn't changed after "
 101                                 + "%d invocations",


  29  * @library /testlibrary /../../test/lib /
  30  * @compile ../common/CompilerToVMHelper.java
  31  * @build sun.hotspot.WhiteBox
  32  * @run main ClassFileInstaller
  33  *      sun.hotspot.WhiteBox
  34  *      sun.hotspot.WhiteBox$WhiteBoxPermission
  35  *      jdk.vm.ci.hotspot.CompilerToVMHelper
  36  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
  37  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
  38  *      -Xmixed
  39  *      compiler.jvmci.compilerToVM.ReprofileTest
  40  */
  41 
  42 package compiler.jvmci.compilerToVM;
  43 
  44 import compiler.jvmci.common.CTVMUtilities;
  45 import java.lang.reflect.Method;
  46 import java.util.ArrayList;
  47 import java.util.List;
  48 import java.util.Random;
  49 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  50 import jdk.vm.ci.hotspot.CompilerToVMHelper;
  51 import jdk.vm.ci.meta.ProfilingInfo;
  52 import jdk.test.lib.Asserts;
  53 import jdk.test.lib.Utils;
  54 import sun.hotspot.WhiteBox;
  55 
  56 public class ReprofileTest {
  57 
  58     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  59 
  60     public static void main(String[] args) {
  61         List<Method> testCases = createTestCases();
  62         testCases.forEach(ReprofileTest::runSanityTest);
  63     }
  64 
  65     private static List<Method> createTestCases() {
  66         List<Method> testCases = new ArrayList<>();
  67         try {
  68 
  69             Class<?> aClass = DummyClass.class;
  70             testCases.add(aClass.getMethod("withLoop"));
  71 
  72             aClass = DummyClass.class;
  73             testCases.add(aClass.getDeclaredMethod("dummyFunction"));
  74         } catch (NoSuchMethodException e) {
  75             throw new Error("TEST BUG " + e.getMessage(), e);
  76         }
  77         return testCases;
  78     }
  79 
  80     private static void runSanityTest(Method aMethod) {
  81         HotSpotResolvedJavaMethod method = CTVMUtilities
  82                 .getResolvedMethod(aMethod);
  83         ProfilingInfo startProfile = method.getProfilingInfo();
  84         Asserts.assertFalse(startProfile.isMature(), aMethod
  85                 + " : profiling info is mature in the begging");
  86 
  87         long compileThreshold = (Long) WB.getVMFlag("CompileThreshold");
  88         // make interpreter to profile this method
  89         try {
  90             Object obj = aMethod.getDeclaringClass().newInstance();
  91             for (long i = 0; i < compileThreshold; i++) {
  92                 aMethod.invoke(obj);
  93             }
  94         } catch (ReflectiveOperationException e) {
  95             throw new Error("TEST BUG : " + e.getMessage(), e);
  96         }
  97         ProfilingInfo compProfile = method.getProfilingInfo();
  98 
  99         Asserts.assertNE(startProfile.toString(), compProfile.toString(),
 100                 String.format("%s : profiling info wasn't changed after "
 101                                 + "%d invocations",
< prev index next >