test/compiler/whitebox/IsMethodCompilableTest.java

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 */
aoqi@0 23
aoqi@0 24 /*
aoqi@0 25 * @test IsMethodCompilableTest
aoqi@0 26 * @bug 8007270 8006683 8007288 8022832
aoqi@0 27 * @library /testlibrary /testlibrary/whitebox /testlibrary/com/oracle/java/testlibrary
aoqi@0 28 * @build IsMethodCompilableTest
aoqi@0 29 * @run main ClassFileInstaller sun.hotspot.WhiteBox
aoqi@0 30 * @run main ClassFileInstaller com.oracle.java.testlibrary.Platform
aoqi@0 31 * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -Xmixed -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:PerMethodRecompilationCutoff=3 -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* IsMethodCompilableTest
aoqi@0 32 * @summary testing of WB::isMethodCompilable()
aoqi@0 33 * @author igor.ignatyev@oracle.com
aoqi@0 34 */
aoqi@0 35
aoqi@0 36 import com.oracle.java.testlibrary.Platform;
aoqi@0 37
aoqi@0 38 public class IsMethodCompilableTest extends CompilerWhiteBoxTest {
aoqi@0 39 /**
aoqi@0 40 * Value of {@code -XX:PerMethodRecompilationCutoff}
aoqi@0 41 */
aoqi@0 42 protected static final long PER_METHOD_RECOMPILATION_CUTOFF;
aoqi@0 43
aoqi@0 44 static {
aoqi@0 45 long tmp = Long.parseLong(
aoqi@0 46 getVMOption("PerMethodRecompilationCutoff", "400"));
aoqi@0 47 if (tmp == -1) {
aoqi@0 48 PER_METHOD_RECOMPILATION_CUTOFF = -1 /* Inf */;
aoqi@0 49 } else {
aoqi@0 50 PER_METHOD_RECOMPILATION_CUTOFF = (0xFFFFFFFFL & tmp);
aoqi@0 51 }
aoqi@0 52 }
aoqi@0 53
aoqi@0 54 public static void main(String[] args) throws Exception {
aoqi@0 55 CompilerWhiteBoxTest.main(IsMethodCompilableTest::new, args);
aoqi@0 56 }
aoqi@0 57
aoqi@0 58 private IsMethodCompilableTest(TestCase testCase) {
aoqi@0 59 super(testCase);
aoqi@0 60 // to prevent inlining of #method
aoqi@0 61 WHITE_BOX.testSetDontInlineMethod(method, true);
aoqi@0 62 }
aoqi@0 63
aoqi@0 64 /**
aoqi@0 65 * Tests {@code WB::isMethodCompilable()} by recompilation of tested method
aoqi@0 66 * 'PerMethodRecompilationCutoff' times and checks compilation status. Also
aoqi@0 67 * checks that WB::clearMethodState() clears no-compilable flags. Only
aoqi@0 68 * applicable to c2 compiled methods.
aoqi@0 69 *
aoqi@0 70 * @throws Exception if one of the checks fails.
aoqi@0 71 */
aoqi@0 72 @Override
aoqi@0 73 protected void test() throws Exception {
aoqi@0 74 // Only c2 compilations can be disabled through PerMethodRecompilationCutoff
aoqi@0 75 if (!Platform.isServer()) {
aoqi@0 76 return;
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 if (skipXcompOSR()) {
aoqi@0 80 return;
aoqi@0 81 }
aoqi@0 82 if (!isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
aoqi@0 83 throw new RuntimeException(method + " must be compilable");
aoqi@0 84 }
aoqi@0 85 System.out.println("PerMethodRecompilationCutoff = "
aoqi@0 86 + PER_METHOD_RECOMPILATION_CUTOFF);
aoqi@0 87 if (PER_METHOD_RECOMPILATION_CUTOFF == -1) {
aoqi@0 88 System.err.println(
aoqi@0 89 "Warning: test is not applicable if PerMethodRecompilationCutoff == Inf");
aoqi@0 90 return;
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 // deoptimize 'PerMethodRecompilationCutoff' times
aoqi@0 94 for (long attempts = 0, successes = 0;
aoqi@0 95 (successes < PER_METHOD_RECOMPILATION_CUTOFF) &&
aoqi@0 96 (attempts < PER_METHOD_RECOMPILATION_CUTOFF*2) &&
aoqi@0 97 isCompilable(COMP_LEVEL_FULL_OPTIMIZATION); attempts++) {
aoqi@0 98 if (compileAndDeoptimize() == COMP_LEVEL_FULL_OPTIMIZATION) {
aoqi@0 99 successes++;
aoqi@0 100 }
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 if (!testCase.isOsr() && !isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
aoqi@0 104 // in osr test case count of deopt maybe more than iterations
aoqi@0 105 throw new RuntimeException(method + " is not compilable after "
aoqi@0 106 + PER_METHOD_RECOMPILATION_CUTOFF + " iterations");
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 // Now compile once more
aoqi@0 110 compileAndDeoptimize();
aoqi@0 111
aoqi@0 112 if (isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
aoqi@0 113 throw new RuntimeException(method + " is still compilable after "
aoqi@0 114 + PER_METHOD_RECOMPILATION_CUTOFF + " iterations");
aoqi@0 115 }
aoqi@0 116 checkNotCompiled();
aoqi@0 117 compile();
aoqi@0 118 waitBackgroundCompilation();
aoqi@0 119 checkNotCompiled(COMP_LEVEL_FULL_OPTIMIZATION);
aoqi@0 120
aoqi@0 121 // WB.clearMethodState() must reset no-compilable flags
aoqi@0 122 WHITE_BOX.clearMethodState(method);
aoqi@0 123 if (!isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
aoqi@0 124 throw new RuntimeException(method
aoqi@0 125 + " is not compilable after clearMethodState()");
aoqi@0 126 }
aoqi@0 127 compile();
aoqi@0 128 checkCompiled();
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 private int compileAndDeoptimize() throws Exception {
aoqi@0 132 compile();
aoqi@0 133 waitBackgroundCompilation();
aoqi@0 134 int compLevel = getCompLevel();
aoqi@0 135 deoptimize();
aoqi@0 136 return compLevel;
aoqi@0 137 }
aoqi@0 138 }

mercurial