2121 * questions.
2222 */
2323
24- import com .sun .management .HotSpotDiagnosticMXBean ;
25- import com .sun .management .VMOption ;
2624import sun .hotspot .WhiteBox ;
27- import sun .management .ManagementFactoryHelper ;
28-
2925import java .lang .reflect .Method ;
3026
3127/*
4137public class Test8009761 {
4238
4339 private static final WhiteBox WHITE_BOX = WhiteBox .getWhiteBox ();
40+ private static int COMP_LEVEL_SIMPLE = 1 ;
4441 private static int COMP_LEVEL_FULL_OPTIMIZATION = 4 ;
4542 private static Method m3 = null ;
4643
@@ -237,7 +234,7 @@ static Object m3(boolean overflow_stack, boolean deopt) {
237234
238235 static public void main (String [] args ) {
239236 // Make sure background compilation is disabled
240- if (backgroundCompilationEnabled ( )) {
237+ if (WHITE_BOX . getBooleanVMFlag ( "BackgroundCompilation" )) {
241238 throw new RuntimeException ("Background compilation enabled" );
242239 }
243240
@@ -257,7 +254,11 @@ static public void main(String[] args) {
257254 c1 = count ;
258255
259256 // Force the compilation of m3() that will inline m1()
260- WHITE_BOX .enqueueMethodForCompilation (m3 , COMP_LEVEL_FULL_OPTIMIZATION );
257+ if (!WHITE_BOX .enqueueMethodForCompilation (m3 , COMP_LEVEL_FULL_OPTIMIZATION )) {
258+ // C2 compiler not available, compile with C1
259+ WHITE_BOX .enqueueMethodForCompilation (m3 , COMP_LEVEL_SIMPLE );
260+ }
261+
261262 // Because background compilation is disabled, method should now be compiled
262263 if (!WHITE_BOX .isMethodCompiled (m3 )) {
263264 throw new RuntimeException (m3 + " not compiled" );
@@ -279,19 +280,4 @@ static public void main(String[] args) {
279280 System .out .println ("PASSED " + c1 );
280281 }
281282 }
282-
283- /**
284- * Checks if background compilation (-XX:+BackgroundCompilation) is enabled.
285- * @return True if background compilation is enabled, false otherwise
286- */
287- private static boolean backgroundCompilationEnabled () {
288- HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper .getDiagnosticMXBean ();
289- VMOption backgroundCompilation ;
290- try {
291- backgroundCompilation = diagnostic .getVMOption ("BackgroundCompilation" );
292- } catch (IllegalArgumentException e ) {
293- return false ;
294- }
295- return Boolean .valueOf (backgroundCompilation .getValue ());
296- }
297283}
0 commit comments