test/compiler/whitebox/BlockingCompilation.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff test/compiler/whitebox

test/compiler/whitebox/BlockingCompilation.java

Print this page
rev 10841 : 8153013: BlockingCompilation test times out
Summary: Task has no invocation count and get stale at once
Reviewed-by: kvn, iveresov, twisti


   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 /*
  25  * @test
  26  * @bug 8150646
  27  * @summary Add support for blocking compiles through whitebox API
  28  * @library /testlibrary /test/lib /
  29  * @build sun.hotspot.WhiteBox
  30  *        compiler.testlibrary.CompilerUtils
  31  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  32  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
  33  *
  34  * @run main/othervm/timeout=60
  35  *        -Xbootclasspath/a:.
  36  *        -Xmixed
  37  *        -XX:+UnlockDiagnosticVMOptions
  38  *        -XX:+WhiteBoxAPI
  39  *        -XX:+PrintCompilation
  40  *        BlockingCompilation
  41  */
  42 

  43 import java.lang.reflect.Method;
  44 import java.util.Random;
  45 
  46 import sun.hotspot.WhiteBox;
  47 import compiler.testlibrary.CompilerUtils;
  48 
  49 public class BlockingCompilation {
  50     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  51     private static final Random RANDOM = new Random();
  52 
  53     public static int foo() {
  54         return RANDOM.nextInt();
  55     }
  56 
  57     public static void main(String[] args) throws Exception {
  58         Method m = BlockingCompilation.class.getMethod("foo");
  59         int[] levels = CompilerUtils.getAvailableCompilationLevels();
  60         int highest_level = levels[levels.length-1];
  61 
  62         // If there are no compilers available these tests don't make any sense.
  63         if (levels.length == 0) return;
  64 
  65         // Make sure no compilations can progress, blocking compiles will hang
  66         WB.lockCompilation();
  67 
  68         // Verify method state before test
  69         if (WB.isMethodCompiled(m)) {
  70             throw new Exception("Should not be compiled after deoptimization");
  71         }
  72         if (WB.isMethodQueuedForCompilation(m)) {
  73             throw new Exception("Should not be enqueued on any level");
  74         }
  75 
  76         // Try compiling on highest available comp level.
  77         // If the compiles are blocking, this call will block until the test time out,
  78         // Progress == success
  79         // (Don't run with -Xcomp since that can cause long timeouts due to many compiles)
  80         WB.enqueueMethodForCompilation(m, highest_level);






  81 
  82         // restore state
  83         WB.unlockCompilation();
  84         while (!WB.isMethodCompiled(m)) {
  85           Thread.sleep(100);
  86         }
  87         WB.deoptimizeMethod(m);
  88         WB.clearMethodState(m);
  89 
  90         // Blocking compilations on all levels, using the default versions of
  91         // WB.enqueueMethodForCompilation() and manually setting compiler directives.
  92         String directive = "[{ match: \"BlockingCompilation.foo\", BackgroundCompilation: false }]";
  93         if (WB.addCompilerDirective(directive) != 1) {
  94             throw new Exception("Failed to add compiler directive");
  95         }
  96 
  97         try {
  98             for (int l : levels) {
  99                 // Make uncompiled
 100                 WB.deoptimizeMethod(m);




   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 /*
  25  * @test
  26  * @bug 8150646 8153013
  27  * @summary Add support for blocking compiles through whitebox API
  28  * @library /testlibrary /test/lib /
  29  * @build sun.hotspot.WhiteBox
  30  *        compiler.testlibrary.CompilerUtils
  31  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  32  *                                sun.hotspot.WhiteBox$WhiteBoxPermission

  33  * @run main/othervm/timeout=60
  34  *        -Xbootclasspath/a:.
  35  *        -Xmixed
  36  *        -XX:+UnlockDiagnosticVMOptions
  37  *        -XX:+WhiteBoxAPI
  38  *        -XX:+PrintCompilation
  39  *        BlockingCompilation
  40  */
  41 
  42 import compiler.testlibrary.CompilerUtils;
  43 import java.lang.reflect.Method;
  44 import java.util.Random;

  45 import sun.hotspot.WhiteBox;

  46 
  47 public class BlockingCompilation {
  48     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  49     private static final Random RANDOM = new Random();
  50 
  51     public static int foo() {
  52         return RANDOM.nextInt();
  53     }
  54 
  55     public static void main(String[] args) throws Exception {
  56         Method m = BlockingCompilation.class.getMethod("foo");
  57         int[] levels = CompilerUtils.getAvailableCompilationLevels();
  58         int highest_level = levels[levels.length-1];
  59 
  60         // If there are no compilers available these tests don't make any sense.
  61         if (levels.length == 0) return;
  62 
  63         // Make sure no compilations can progress, blocking compiles will hang
  64         WB.lockCompilation();
  65 
  66         // Verify method state before test
  67         if (WB.isMethodCompiled(m)) {
  68             throw new Exception("Should not be compiled after deoptimization");
  69         }
  70         if (WB.isMethodQueuedForCompilation(m)) {
  71             throw new Exception("Should not be enqueued on any level");
  72         }
  73 
  74         // Try compiling on highest available comp level.
  75         // If the compiles are blocking, this call will block until the test time out,
  76         // Progress == success
  77         // (Don't run with -Xcomp since that can cause long timeouts due to many compiles)
  78         if (!WB.enqueueMethodForCompilation(m, highest_level)) {
  79             throw new Exception("Failed to enqueue method on level: " + highest_level);
  80         }
  81 
  82         if (!WB.isMethodQueuedForCompilation(m)) {
  83             throw new Exception("Must be enqueued because of locked compilation");
  84         }
  85 
  86         // restore state
  87         WB.unlockCompilation();
  88         while (!WB.isMethodCompiled(m)) {
  89           Thread.sleep(100);
  90         }
  91         WB.deoptimizeMethod(m);
  92         WB.clearMethodState(m);
  93 
  94         // Blocking compilations on all levels, using the default versions of
  95         // WB.enqueueMethodForCompilation() and manually setting compiler directives.
  96         String directive = "[{ match: \"BlockingCompilation.foo\", BackgroundCompilation: false }]";
  97         if (WB.addCompilerDirective(directive) != 1) {
  98             throw new Exception("Failed to add compiler directive");
  99         }
 100 
 101         try {
 102             for (int l : levels) {
 103                 // Make uncompiled
 104                 WB.deoptimizeMethod(m);


test/compiler/whitebox/BlockingCompilation.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File