< prev index next >

test/compiler/whitebox/CompilerWhiteBoxTest.java

Print this page




   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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
  21  * questions.
  22  */

  23 
  24 import sun.hotspot.WhiteBox;
  25 import sun.hotspot.code.NMethod;
  26 
  27 import java.lang.reflect.Constructor;
  28 import java.lang.reflect.Executable;
  29 import java.lang.reflect.Method;
  30 import java.util.Objects;
  31 import java.util.concurrent.Callable;
  32 import java.util.function.Function;
  33 
  34 /**
  35  * Abstract class for WhiteBox testing of JIT.
  36  *
  37  * @author igor.ignatyev@oracle.com
  38  */
  39 public abstract class CompilerWhiteBoxTest {
  40     /** {@code CompLevel::CompLevel_none} -- Interpreter */
  41     protected static final int COMP_LEVEL_NONE = 0;
  42     /** {@code CompLevel::CompLevel_any}, {@code CompLevel::CompLevel_all} */
  43     protected static final int COMP_LEVEL_ANY = -1;
  44     /** {@code CompLevel::CompLevel_simple} -- C1 */
  45     protected static final int COMP_LEVEL_SIMPLE = 1;
  46     /** {@code CompLevel::CompLevel_limited_profile} -- C1, invocation &amp; backedge counters */
  47     protected static final int COMP_LEVEL_LIMITED_PROFILE = 2;
  48     /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation &amp; backedge counters + mdo */
  49     protected static final int COMP_LEVEL_FULL_PROFILE = 3;
  50     /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */
  51     protected static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
  52     /** Maximal value for CompLevel */
  53     protected static final int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION;
  54 
  55     /** Instance of WhiteBox */
  56     protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
  57     /** Value of {@code -XX:CompileThreshold} */
  58     protected static final int COMPILE_THRESHOLD
  59             = Integer.parseInt(getVMOption("CompileThreshold", "10000"));
  60     /** Value of {@code -XX:BackgroundCompilation} */
  61     protected static final boolean BACKGROUND_COMPILATION
  62             = Boolean.valueOf(getVMOption("BackgroundCompilation", "true"));
  63     /** Value of {@code -XX:TieredCompilation} */
  64     protected static final boolean TIERED_COMPILATION
  65             = Boolean.valueOf(getVMOption("TieredCompilation", "false"));
  66     /** Value of {@code -XX:TieredStopAtLevel} */
  67     protected static final int TIERED_STOP_AT_LEVEL
  68             = Integer.parseInt(getVMOption("TieredStopAtLevel", "0"));
  69     /** Flag for verbose output, true if {@code -Dverbose} specified */
  70     protected static final boolean IS_VERBOSE
  71             = System.getProperty("verbose") != null;
  72     /** invocation count to trigger compilation */
  73     protected static final int THRESHOLD;


 295         WHITE_BOX.makeMethodNotCompilable(method, COMP_LEVEL_ANY,
 296                 testCase.isOsr());
 297     }
 298 
 299     protected final void makeNotCompilable(int compLevel) {
 300         WHITE_BOX.makeMethodNotCompilable(method, compLevel, testCase.isOsr());
 301     }
 302 
 303     /**
 304      * Waits for completion of background compilation of {@linkplain #method}.
 305      */
 306     protected final void waitBackgroundCompilation() {
 307         waitBackgroundCompilation(method);
 308     }
 309 
 310     /**
 311      * Waits for completion of background compilation of the given executable.
 312      *
 313      * @param executable Executable
 314      */
 315     protected static final void waitBackgroundCompilation(Executable executable) {
 316         if (!BACKGROUND_COMPILATION) {
 317             return;
 318         }
 319         final Object obj = new Object();
 320         for (int i = 0; i < 10
 321                 && WHITE_BOX.isMethodQueuedForCompilation(executable); ++i) {
 322             synchronized (obj) {
 323                 try {
 324                     obj.wait(1000);
 325                 } catch (InterruptedException e) {
 326                     Thread.currentThread().interrupt();
 327                 }
 328             }
 329         }
 330     }
 331 
 332     /**
 333      * Prints information about {@linkplain #method}.
 334      */
 335     protected final void printInfo() {


 424     /**
 425      * @return {@code true} if the current test case is OSR and the mode is
 426      *          Xcomp, otherwise {@code false}
 427      */
 428     protected boolean skipXcompOSR() {
 429         boolean result =  testCase.isOsr()
 430                 && CompilerWhiteBoxTest.MODE.startsWith("compiled ");
 431         if (result && IS_VERBOSE) {
 432             System.err.printf("Warning: %s is not applicable in %s%n",
 433                     testCase.name(), CompilerWhiteBoxTest.MODE);
 434         }
 435         return result;
 436     }
 437 
 438     /**
 439      * Skip the test for the specified value of Tiered Compilation
 440      * @param value of TieredCompilation the test should not run with
 441      * @return {@code true} if the test should be skipped,
 442      *         {@code false} otherwise
 443      */
 444     protected static boolean skipOnTieredCompilation(boolean value) {
 445         if (value == CompilerWhiteBoxTest.TIERED_COMPILATION) {
 446             System.err.println("Test isn't applicable w/ "
 447                     + (value ? "enabled" : "disabled")
 448                     + "TieredCompilation. Skip test.");
 449             return true;
 450         }
 451         return false;
 452     }
 453 }
 454 
 455 enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase {
 456     /** constructor test case */
 457     CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false),
 458     /** method test case */
 459     METHOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false),
 460     /** static method test case */
 461     STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false),
 462     /** OSR constructor test case */
 463     OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR,
 464             Helper.OSR_CONSTRUCTOR_CALLABLE, true),




   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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
  21  * questions.
  22  */
  23 package compiler.whitebox;
  24 
  25 import sun.hotspot.WhiteBox;
  26 import sun.hotspot.code.NMethod;
  27 
  28 import java.lang.reflect.Constructor;
  29 import java.lang.reflect.Executable;
  30 import java.lang.reflect.Method;
  31 import java.util.Objects;
  32 import java.util.concurrent.Callable;
  33 import java.util.function.Function;
  34 
  35 /**
  36  * Abstract class for WhiteBox testing of JIT.
  37  *
  38  * @author igor.ignatyev@oracle.com
  39  */
  40 public abstract class CompilerWhiteBoxTest {
  41     /** {@code CompLevel::CompLevel_none} -- Interpreter */
  42     public static final int COMP_LEVEL_NONE = 0;
  43     /** {@code CompLevel::CompLevel_any}, {@code CompLevel::CompLevel_all} */
  44     public static final int COMP_LEVEL_ANY = -1;
  45     /** {@code CompLevel::CompLevel_simple} -- C1 */
  46     public static final int COMP_LEVEL_SIMPLE = 1;
  47     /** {@code CompLevel::CompLevel_limited_profile} -- C1, invocation &amp; backedge counters */
  48     public static final int COMP_LEVEL_LIMITED_PROFILE = 2;
  49     /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation &amp; backedge counters + mdo */
  50     public static final int COMP_LEVEL_FULL_PROFILE = 3;
  51     /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */
  52     public static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
  53     /** Maximal value for CompLevel */
  54     public static final int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION;
  55 
  56     /** Instance of WhiteBox */
  57     protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
  58     /** Value of {@code -XX:CompileThreshold} */
  59     protected static final int COMPILE_THRESHOLD
  60             = Integer.parseInt(getVMOption("CompileThreshold", "10000"));
  61     /** Value of {@code -XX:BackgroundCompilation} */
  62     protected static final boolean BACKGROUND_COMPILATION
  63             = Boolean.valueOf(getVMOption("BackgroundCompilation", "true"));
  64     /** Value of {@code -XX:TieredCompilation} */
  65     protected static final boolean TIERED_COMPILATION
  66             = Boolean.valueOf(getVMOption("TieredCompilation", "false"));
  67     /** Value of {@code -XX:TieredStopAtLevel} */
  68     protected static final int TIERED_STOP_AT_LEVEL
  69             = Integer.parseInt(getVMOption("TieredStopAtLevel", "0"));
  70     /** Flag for verbose output, true if {@code -Dverbose} specified */
  71     protected static final boolean IS_VERBOSE
  72             = System.getProperty("verbose") != null;
  73     /** invocation count to trigger compilation */
  74     protected static final int THRESHOLD;


 296         WHITE_BOX.makeMethodNotCompilable(method, COMP_LEVEL_ANY,
 297                 testCase.isOsr());
 298     }
 299 
 300     protected final void makeNotCompilable(int compLevel) {
 301         WHITE_BOX.makeMethodNotCompilable(method, compLevel, testCase.isOsr());
 302     }
 303 
 304     /**
 305      * Waits for completion of background compilation of {@linkplain #method}.
 306      */
 307     protected final void waitBackgroundCompilation() {
 308         waitBackgroundCompilation(method);
 309     }
 310 
 311     /**
 312      * Waits for completion of background compilation of the given executable.
 313      *
 314      * @param executable Executable
 315      */
 316     public static final void waitBackgroundCompilation(Executable executable) {
 317         if (!BACKGROUND_COMPILATION) {
 318             return;
 319         }
 320         final Object obj = new Object();
 321         for (int i = 0; i < 10
 322                 && WHITE_BOX.isMethodQueuedForCompilation(executable); ++i) {
 323             synchronized (obj) {
 324                 try {
 325                     obj.wait(1000);
 326                 } catch (InterruptedException e) {
 327                     Thread.currentThread().interrupt();
 328                 }
 329             }
 330         }
 331     }
 332 
 333     /**
 334      * Prints information about {@linkplain #method}.
 335      */
 336     protected final void printInfo() {


 425     /**
 426      * @return {@code true} if the current test case is OSR and the mode is
 427      *          Xcomp, otherwise {@code false}
 428      */
 429     protected boolean skipXcompOSR() {
 430         boolean result =  testCase.isOsr()
 431                 && CompilerWhiteBoxTest.MODE.startsWith("compiled ");
 432         if (result && IS_VERBOSE) {
 433             System.err.printf("Warning: %s is not applicable in %s%n",
 434                     testCase.name(), CompilerWhiteBoxTest.MODE);
 435         }
 436         return result;
 437     }
 438 
 439     /**
 440      * Skip the test for the specified value of Tiered Compilation
 441      * @param value of TieredCompilation the test should not run with
 442      * @return {@code true} if the test should be skipped,
 443      *         {@code false} otherwise
 444      */
 445     public static boolean skipOnTieredCompilation(boolean value) {
 446         if (value == CompilerWhiteBoxTest.TIERED_COMPILATION) {
 447             System.err.println("Test isn't applicable w/ "
 448                     + (value ? "enabled" : "disabled")
 449                     + "TieredCompilation. Skip test.");
 450             return true;
 451         }
 452         return false;
 453     }
 454 }
 455 
 456 enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase {
 457     /** constructor test case */
 458     CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false),
 459     /** method test case */
 460     METHOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false),
 461     /** static method test case */
 462     STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false),
 463     /** OSR constructor test case */
 464     OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR,
 465             Helper.OSR_CONSTRUCTOR_CALLABLE, true),


< prev index next >