hotspot/test/compiler/8009761/Test8009761.java
changeset 25377 73d03d578d8e
parent 24919 080f9a6da70a
child 25958 8dc85547d6d6
equal deleted inserted replaced
25365:6db782823853 25377:73d03d578d8e
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import com.sun.management.HotSpotDiagnosticMXBean;
       
    25 import com.sun.management.VMOption;
       
    26 import sun.hotspot.WhiteBox;
    24 import sun.hotspot.WhiteBox;
    27 import sun.management.ManagementFactoryHelper;
       
    28 
       
    29 import java.lang.reflect.Method;
    25 import java.lang.reflect.Method;
    30 
    26 
    31 /*
    27 /*
    32  * @test
    28  * @test
    33  * @bug 8009761
    29  * @bug 8009761
    38  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=exclude,Test8009761::m2 -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -Xss256K Test8009761
    34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=exclude,Test8009761::m2 -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -Xss256K Test8009761
    39  */
    35  */
    40 public class Test8009761 {
    36 public class Test8009761 {
    41 
    37 
    42     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
    38     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
       
    39     private static int COMP_LEVEL_SIMPLE = 1;
    43     private static int COMP_LEVEL_FULL_OPTIMIZATION = 4;
    40     private static int COMP_LEVEL_FULL_OPTIMIZATION = 4;
    44     private static Method m3 = null;
    41     private static Method m3 = null;
    45 
    42 
    46     static Object m1(boolean deopt) {
    43     static Object m1(boolean deopt) {
    47         // When running interpreted, on sparc, the caller's stack is
    44         // When running interpreted, on sparc, the caller's stack is
   234         return o;
   231         return o;
   235     }
   232     }
   236 
   233 
   237     static public void main(String[] args) {
   234     static public void main(String[] args) {
   238         // Make sure background compilation is disabled
   235         // Make sure background compilation is disabled
   239         if (backgroundCompilationEnabled()) {
   236         if (WHITE_BOX.getBooleanVMFlag("BackgroundCompilation")) {
   240             throw new RuntimeException("Background compilation enabled");
   237             throw new RuntimeException("Background compilation enabled");
   241         }
   238         }
   242 
   239 
   243         try {
   240         try {
   244             // Get Method object for m3
   241             // Get Method object for m3
   254         } catch(StackOverflowError soe) {
   251         } catch(StackOverflowError soe) {
   255         }
   252         }
   256         c1 = count;
   253         c1 = count;
   257 
   254 
   258         // Force the compilation of m3() that will inline m1()
   255         // Force the compilation of m3() that will inline m1()
   259         WHITE_BOX.enqueueMethodForCompilation(m3, COMP_LEVEL_FULL_OPTIMIZATION);
   256         if(!WHITE_BOX.enqueueMethodForCompilation(m3, COMP_LEVEL_FULL_OPTIMIZATION)) {
       
   257             // C2 compiler not available, compile with C1
       
   258             WHITE_BOX.enqueueMethodForCompilation(m3, COMP_LEVEL_SIMPLE);
       
   259         }
       
   260 
   260         // Because background compilation is disabled, method should now be compiled
   261         // Because background compilation is disabled, method should now be compiled
   261         if(!WHITE_BOX.isMethodCompiled(m3)) {
   262         if(!WHITE_BOX.isMethodCompiled(m3)) {
   262             throw new RuntimeException(m3 + " not compiled");
   263             throw new RuntimeException(m3 + " not compiled");
   263         }
   264         }
   264 
   265 
   276             throw new RuntimeException("Failed: init recursive calls: " + c1 + ". After deopt " + count);
   277             throw new RuntimeException("Failed: init recursive calls: " + c1 + ". After deopt " + count);
   277         } else {
   278         } else {
   278             System.out.println("PASSED " + c1);
   279             System.out.println("PASSED " + c1);
   279         }
   280         }
   280     }
   281     }
   281 
       
   282     /**
       
   283      * Checks if background compilation (-XX:+BackgroundCompilation) is enabled.
       
   284      * @return True if background compilation is enabled, false otherwise
       
   285      */
       
   286     private static boolean backgroundCompilationEnabled() {
       
   287       HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();
       
   288       VMOption backgroundCompilation;
       
   289       try {
       
   290           backgroundCompilation = diagnostic.getVMOption("BackgroundCompilation");
       
   291       } catch (IllegalArgumentException e) {
       
   292           return false;
       
   293       }
       
   294       return Boolean.valueOf(backgroundCompilation.getValue());
       
   295     }
       
   296 }
   282 }