Wed, 14 Aug 2013 23:50:23 +0400
8022832: Add WB APIs for OSR compilation
Reviewed-by: kvn
iignatyev@4592 | 1 | /* |
iignatyev@4592 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
iignatyev@4592 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
iignatyev@4592 | 4 | * |
iignatyev@4592 | 5 | * This code is free software; you can redistribute it and/or modify it |
iignatyev@4592 | 6 | * under the terms of the GNU General Public License version 2 only, as |
iignatyev@4592 | 7 | * published by the Free Software Foundation. |
iignatyev@4592 | 8 | * |
iignatyev@4592 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
iignatyev@4592 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
iignatyev@4592 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
iignatyev@4592 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
iignatyev@4592 | 13 | * accompanied this code). |
iignatyev@4592 | 14 | * |
iignatyev@4592 | 15 | * You should have received a copy of the GNU General Public License version |
iignatyev@4592 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
iignatyev@4592 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
iignatyev@4592 | 18 | * |
iignatyev@4592 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
iignatyev@4592 | 20 | * or visit www.oracle.com if you need additional information or have any |
iignatyev@4592 | 21 | * questions. |
iignatyev@4592 | 22 | */ |
iignatyev@4592 | 23 | |
iignatyev@4592 | 24 | /* |
iignatyev@4592 | 25 | * @test MakeMethodNotCompilableTest |
iignatyev@5541 | 26 | * @bug 8012322 8006683 8007288 8022832 |
mgerdin@4637 | 27 | * @library /testlibrary /testlibrary/whitebox |
mgerdin@4637 | 28 | * @build MakeMethodNotCompilableTest |
mgerdin@4637 | 29 | * @run main ClassFileInstaller sun.hotspot.WhiteBox |
iignatyev@5541 | 30 | * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,TestCase$Helper::* MakeMethodNotCompilableTest |
iignatyev@4951 | 31 | * @summary testing of WB::makeMethodNotCompilable() |
iignatyev@4592 | 32 | * @author igor.ignatyev@oracle.com |
iignatyev@4592 | 33 | */ |
iignatyev@4592 | 34 | public class MakeMethodNotCompilableTest extends CompilerWhiteBoxTest { |
iignatyev@5541 | 35 | private int bci; |
iignatyev@4592 | 36 | public static void main(String[] args) throws Exception { |
iignatyev@4951 | 37 | if (args.length == 0) { |
iignatyev@4951 | 38 | for (TestCase test : TestCase.values()) { |
iignatyev@4951 | 39 | new MakeMethodNotCompilableTest(test).runTest(); |
iignatyev@4951 | 40 | } |
iignatyev@4951 | 41 | } else { |
iignatyev@4951 | 42 | for (String name : args) { |
iignatyev@4951 | 43 | new MakeMethodNotCompilableTest( |
iignatyev@4951 | 44 | TestCase.valueOf(name)).runTest(); |
iignatyev@4951 | 45 | } |
iignatyev@4951 | 46 | } |
iignatyev@4592 | 47 | } |
iignatyev@4592 | 48 | |
iignatyev@4951 | 49 | public MakeMethodNotCompilableTest(TestCase testCase) { |
iignatyev@4951 | 50 | super(testCase); |
iignatyev@4951 | 51 | // to prevent inlining of #method |
iignatyev@4951 | 52 | WHITE_BOX.testSetDontInlineMethod(method, true); |
iignatyev@4951 | 53 | } |
iignatyev@4951 | 54 | |
iignatyev@4951 | 55 | /** |
iignatyev@4951 | 56 | * Tests {@code WB::makeMethodNotCompilable()} by calling it before |
iignatyev@4951 | 57 | * compilation and checking that method isn't compiled. Also |
iignatyev@4951 | 58 | * checks that WB::clearMethodState() clears no-compilable flags. For |
iignatyev@4951 | 59 | * tiered, additional checks for all available levels are conducted. |
iignatyev@4951 | 60 | * |
iignatyev@4951 | 61 | * @throws Exception if one of the checks fails. |
iignatyev@4951 | 62 | */ |
iignatyev@4951 | 63 | @Override |
iignatyev@4951 | 64 | protected void test() throws Exception { |
iignatyev@4951 | 65 | checkNotCompiled(); |
iignatyev@5541 | 66 | if (!isCompilable()) { |
iignatyev@4951 | 67 | throw new RuntimeException(method + " must be compilable"); |
iignatyev@4592 | 68 | } |
iignatyev@4951 | 69 | |
iignatyev@5541 | 70 | bci = getBci(); |
iignatyev@5541 | 71 | |
iignatyev@4951 | 72 | if (TIERED_COMPILATION) { |
iignatyev@5032 | 73 | final int tierLimit = TIERED_STOP_AT_LEVEL + 1; |
iignatyev@5032 | 74 | for (int testedTier = 1; testedTier < tierLimit; ++testedTier) { |
iignatyev@5032 | 75 | testTier(testedTier); |
iignatyev@5032 | 76 | } |
iignatyev@5032 | 77 | for (int testedTier = 1; testedTier < tierLimit; ++testedTier) { |
iignatyev@5541 | 78 | makeNotCompilable(testedTier); |
iignatyev@5541 | 79 | if (isCompilable(testedTier)) { |
iignatyev@4951 | 80 | throw new RuntimeException(method |
iignatyev@5032 | 81 | + " must be not compilable at level" + testedTier); |
iignatyev@4951 | 82 | } |
iignatyev@5541 | 83 | WHITE_BOX.enqueueMethodForCompilation(method, testedTier, bci); |
iignatyev@4951 | 84 | checkNotCompiled(); |
iignatyev@4951 | 85 | |
iignatyev@5541 | 86 | if (!isCompilable()) { |
iignatyev@4951 | 87 | System.out.println(method |
iignatyev@5032 | 88 | + " is not compilable after level " + testedTier); |
iignatyev@4951 | 89 | } |
iignatyev@4951 | 90 | } |
iignatyev@5032 | 91 | } else { |
iignatyev@5032 | 92 | compile(); |
iignatyev@5032 | 93 | checkCompiled(); |
iignatyev@5541 | 94 | int compLevel = getCompLevel(); |
iignatyev@5541 | 95 | deoptimize(); |
iignatyev@5541 | 96 | makeNotCompilable(compLevel); |
iignatyev@5541 | 97 | if (isCompilable(COMP_LEVEL_ANY)) { |
iignatyev@5032 | 98 | throw new RuntimeException(method |
iignatyev@5032 | 99 | + " must be not compilable at CompLevel::CompLevel_any," |
iignatyev@5032 | 100 | + " after it is not compilable at " + compLevel); |
iignatyev@5032 | 101 | } |
iignatyev@5541 | 102 | |
iignatyev@5032 | 103 | WHITE_BOX.clearMethodState(method); |
iignatyev@5541 | 104 | if (!isCompilable()) { |
iignatyev@5541 | 105 | throw new RuntimeException(method |
iignatyev@5541 | 106 | + " is not compilable after clearMethodState()"); |
iignatyev@5541 | 107 | } |
iignatyev@4951 | 108 | |
iignatyev@5032 | 109 | // nocompilable at opposite level must make no sense |
iignatyev@5032 | 110 | int oppositeLevel; |
iignatyev@5032 | 111 | if (isC1Compile(compLevel)) { |
iignatyev@5032 | 112 | oppositeLevel = COMP_LEVEL_FULL_OPTIMIZATION; |
iignatyev@5032 | 113 | } else { |
iignatyev@5032 | 114 | oppositeLevel = COMP_LEVEL_SIMPLE; |
iignatyev@5032 | 115 | } |
iignatyev@5541 | 116 | makeNotCompilable(oppositeLevel); |
iignatyev@5032 | 117 | |
iignatyev@5541 | 118 | if (!isCompilable(COMP_LEVEL_ANY)) { |
iignatyev@5032 | 119 | throw new RuntimeException(method |
iignatyev@5032 | 120 | + " must be compilable at CompLevel::CompLevel_any," |
iignatyev@5032 | 121 | + " even it is not compilable at opposite level [" |
iignatyev@5032 | 122 | + compLevel + "]"); |
iignatyev@5032 | 123 | } |
iignatyev@5032 | 124 | |
iignatyev@5541 | 125 | if (!isCompilable(compLevel)) { |
iignatyev@5032 | 126 | throw new RuntimeException(method |
iignatyev@5032 | 127 | + " must be compilable at level " + compLevel |
iignatyev@5032 | 128 | + ", even it is not compilable at opposite level [" |
iignatyev@5032 | 129 | + compLevel + "]"); |
iignatyev@4951 | 130 | } |
iignatyev@4951 | 131 | } |
iignatyev@5032 | 132 | |
iignatyev@5032 | 133 | // clearing after tiered/non-tiered tests |
iignatyev@5032 | 134 | // WB.clearMethodState() must reset no-compilable flags |
iignatyev@5032 | 135 | WHITE_BOX.clearMethodState(method); |
iignatyev@5541 | 136 | if (!isCompilable()) { |
iignatyev@5032 | 137 | throw new RuntimeException(method |
iignatyev@5032 | 138 | + " is not compilable after clearMethodState()"); |
iignatyev@5032 | 139 | } |
iignatyev@5032 | 140 | |
iignatyev@5541 | 141 | makeNotCompilable(); |
iignatyev@5541 | 142 | if (isCompilable()) { |
iignatyev@4951 | 143 | throw new RuntimeException(method + " must be not compilable"); |
iignatyev@4951 | 144 | } |
iignatyev@4951 | 145 | |
iignatyev@4951 | 146 | compile(); |
iignatyev@4951 | 147 | checkNotCompiled(); |
iignatyev@5541 | 148 | if (isCompilable()) { |
iignatyev@4951 | 149 | throw new RuntimeException(method + " must be not compilable"); |
iignatyev@4951 | 150 | } |
iignatyev@4951 | 151 | // WB.clearMethodState() must reset no-compilable flags |
iignatyev@4951 | 152 | WHITE_BOX.clearMethodState(method); |
iignatyev@5541 | 153 | if (!isCompilable()) { |
iignatyev@4951 | 154 | throw new RuntimeException(method |
iignatyev@4951 | 155 | + " is not compilable after clearMethodState()"); |
iignatyev@4592 | 156 | } |
iignatyev@4592 | 157 | compile(); |
iignatyev@4951 | 158 | checkCompiled(); |
iignatyev@4592 | 159 | } |
iignatyev@5032 | 160 | |
iignatyev@5032 | 161 | // separately tests each tier |
iignatyev@5032 | 162 | private void testTier(int testedTier) { |
iignatyev@5541 | 163 | if (!isCompilable(testedTier)) { |
iignatyev@5032 | 164 | throw new RuntimeException(method |
iignatyev@5032 | 165 | + " is not compilable on start"); |
iignatyev@5032 | 166 | } |
iignatyev@5541 | 167 | makeNotCompilable(testedTier); |
iignatyev@5032 | 168 | |
iignatyev@5032 | 169 | // tests for all other tiers |
iignatyev@5032 | 170 | for (int anotherTier = 1, tierLimit = TIERED_STOP_AT_LEVEL + 1; |
iignatyev@5032 | 171 | anotherTier < tierLimit; ++anotherTier) { |
iignatyev@5541 | 172 | boolean isCompilable = isCompilable(anotherTier); |
iignatyev@5032 | 173 | if (sameCompile(testedTier, anotherTier)) { |
iignatyev@5032 | 174 | if (isCompilable) { |
iignatyev@5032 | 175 | throw new RuntimeException(method |
iignatyev@5032 | 176 | + " must be not compilable at level " + anotherTier |
iignatyev@5032 | 177 | + ", if it is not compilable at " + testedTier); |
iignatyev@5032 | 178 | } |
iignatyev@5541 | 179 | WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci); |
iignatyev@5032 | 180 | checkNotCompiled(); |
iignatyev@5032 | 181 | } else { |
iignatyev@5032 | 182 | if (!isCompilable) { |
iignatyev@5032 | 183 | throw new RuntimeException(method |
iignatyev@5032 | 184 | + " must be compilable at level " + anotherTier |
iignatyev@5032 | 185 | + ", even if it is not compilable at " |
iignatyev@5032 | 186 | + testedTier); |
iignatyev@5032 | 187 | } |
iignatyev@5541 | 188 | WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci); |
iignatyev@5032 | 189 | checkCompiled(); |
iignatyev@5541 | 190 | deoptimize(); |
iignatyev@5032 | 191 | } |
iignatyev@5032 | 192 | |
iignatyev@5541 | 193 | if (!isCompilable(COMP_LEVEL_ANY)) { |
iignatyev@5032 | 194 | throw new RuntimeException(method |
iignatyev@5032 | 195 | + " must be compilable at 'CompLevel::CompLevel_any'" |
iignatyev@5032 | 196 | + ", if it is not compilable only at " + testedTier); |
iignatyev@5032 | 197 | } |
iignatyev@5032 | 198 | } |
iignatyev@5032 | 199 | |
iignatyev@5032 | 200 | // clear state after test |
iignatyev@5032 | 201 | WHITE_BOX.clearMethodState(method); |
iignatyev@5541 | 202 | if (!isCompilable(testedTier)) { |
iignatyev@5032 | 203 | throw new RuntimeException(method |
iignatyev@5032 | 204 | + " is not compilable after clearMethodState()"); |
iignatyev@5032 | 205 | } |
iignatyev@5032 | 206 | } |
iignatyev@5032 | 207 | |
iignatyev@5032 | 208 | private boolean sameCompile(int level1, int level2) { |
iignatyev@5032 | 209 | if (level1 == level2) { |
iignatyev@5032 | 210 | return true; |
iignatyev@5032 | 211 | } |
iignatyev@5032 | 212 | if (isC1Compile(level1) && isC1Compile(level2)) { |
iignatyev@5032 | 213 | return true; |
iignatyev@5032 | 214 | } |
iignatyev@5032 | 215 | if (isC2Compile(level1) && isC2Compile(level2)) { |
iignatyev@5032 | 216 | return true; |
iignatyev@5032 | 217 | } |
iignatyev@5032 | 218 | return false; |
iignatyev@5032 | 219 | } |
iignatyev@5541 | 220 | |
iignatyev@5541 | 221 | private int getBci() { |
iignatyev@5541 | 222 | compile(); |
iignatyev@5541 | 223 | checkCompiled(); |
iignatyev@5541 | 224 | int result = WHITE_BOX.getMethodEntryBci(method); |
iignatyev@5541 | 225 | deoptimize(); |
iignatyev@5541 | 226 | WHITE_BOX.clearMethodState(method); |
iignatyev@5541 | 227 | return result; |
iignatyev@5541 | 228 | } |
iignatyev@4592 | 229 | } |