1 /* 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. 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 /* 25 * @test MakeMethodNotCompilableTest 26 * @bug 8012322 8006683 8007288 8022832 27 * @library /testlibrary /testlibrary/whitebox 28 * @ignore 8046268 29 * @build MakeMethodNotCompilableTest 30 * @run main ClassFileInstaller sun.hotspot.WhiteBox 31 * sun.hotspot.WhiteBox$WhiteBoxPermission 32 * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* MakeMethodNotCompilableTest 33 * @summary testing of WB::makeMethodNotCompilable() 34 * @author igor.ignatyev@oracle.com 35 */ 36 public class MakeMethodNotCompilableTest extends CompilerWhiteBoxTest { 37 private int bci; 38 public static void main(String[] args) throws Exception { 39 CompilerWhiteBoxTest.main(MakeMethodNotCompilableTest::new, args); 40 } 41 42 private MakeMethodNotCompilableTest(TestCase testCase) { 43 super(testCase); 44 // to prevent inlining of #method 45 WHITE_BOX.testSetDontInlineMethod(method, true); 46 } 47 48 /** 49 * Tests {@code WB::makeMethodNotCompilable()} by calling it before 50 * compilation and checking that method isn't compiled. Also 51 * checks that WB::clearMethodState() clears no-compilable flags. For 52 * tiered, additional checks for all available levels are conducted. 53 * 54 * @throws Exception if one of the checks fails. 55 */ 56 @Override 57 protected void test() throws Exception { 58 if (skipXcompOSR()) { 59 return; 60 } 61 checkNotCompiled(); 62 if (!isCompilable()) { 63 throw new RuntimeException(method + " must be compilable"); 64 } 65 66 bci = getBci(); 67 68 if (TIERED_COMPILATION) { 69 final int tierLimit = TIERED_STOP_AT_LEVEL + 1; 70 for (int testedTier = 1; testedTier < tierLimit; ++testedTier) { 71 testTier(testedTier); 72 } 73 for (int testedTier = 1; testedTier < tierLimit; ++testedTier) { 74 makeNotCompilable(testedTier); 75 if (isCompilable(testedTier)) { 76 throw new RuntimeException(method 77 + " must be not compilable at level" + testedTier); 78 } 79 WHITE_BOX.enqueueMethodForCompilation(method, testedTier, bci); 80 checkNotCompiled(); 81 82 if (!isCompilable()) { 83 System.out.println(method 84 + " is not compilable after level " + testedTier); 85 } 86 } 87 } else { 88 compile(); 89 checkCompiled(); 90 int compLevel = getCompLevel(); 91 deoptimize(); 92 makeNotCompilable(compLevel); 93 if (isCompilable(COMP_LEVEL_ANY)) { 94 throw new RuntimeException(method 95 + " must be not compilable at CompLevel::CompLevel_any," 96 + " after it is not compilable at " + compLevel); 97 } 98 99 WHITE_BOX.clearMethodState(method); 100 if (!isCompilable()) { 101 throw new RuntimeException(method 102 + " is not compilable after clearMethodState()"); 103 } 104 105 // nocompilable at opposite level must make no sense 106 int oppositeLevel; 107 if (isC1Compile(compLevel)) { 108 oppositeLevel = COMP_LEVEL_FULL_OPTIMIZATION; 109 } else { 110 oppositeLevel = COMP_LEVEL_SIMPLE; 111 } 112 makeNotCompilable(oppositeLevel); 113 114 if (!isCompilable(COMP_LEVEL_ANY)) { 115 throw new RuntimeException(method 116 + " must be compilable at CompLevel::CompLevel_any," 117 + " even it is not compilable at opposite level [" 118 + compLevel + "]"); 119 } 120 121 if (!isCompilable(compLevel)) { 122 throw new RuntimeException(method 123 + " must be compilable at level " + compLevel 124 + ", even it is not compilable at opposite level [" 125 + compLevel + "]"); 126 } 127 } 128 129 // clearing after tiered/non-tiered tests 130 // WB.clearMethodState() must reset no-compilable flags 131 WHITE_BOX.clearMethodState(method); 132 if (!isCompilable()) { 133 throw new RuntimeException(method 134 + " is not compilable after clearMethodState()"); 135 } 136 137 makeNotCompilable(); 138 if (isCompilable()) { 139 throw new RuntimeException(method + " must be not compilable"); 140 } 141 142 compile(); 143 checkNotCompiled(); 144 if (isCompilable()) { 145 throw new RuntimeException(method + " must be not compilable"); 146 } 147 // WB.clearMethodState() must reset no-compilable flags 148 WHITE_BOX.clearMethodState(method); 149 if (!isCompilable()) { 150 throw new RuntimeException(method 151 + " is not compilable after clearMethodState()"); 152 } 153 compile(); 154 checkCompiled(); 155 } 156 157 // separately tests each tier 158 private void testTier(int testedTier) { 159 if (!isCompilable(testedTier)) { 160 throw new RuntimeException(method 161 + " is not compilable on start"); 162 } 163 makeNotCompilable(testedTier); 164 165 // tests for all other tiers 166 for (int anotherTier = 1, tierLimit = TIERED_STOP_AT_LEVEL + 1; 167 anotherTier < tierLimit; ++anotherTier) { 168 boolean isCompilable = isCompilable(anotherTier); 169 if (sameCompile(testedTier, anotherTier)) { 170 if (isCompilable) { 171 throw new RuntimeException(method 172 + " must be not compilable at level " + anotherTier 173 + ", if it is not compilable at " + testedTier); 174 } 175 WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci); 176 checkNotCompiled(); 177 } else { 178 if (!isCompilable) { 179 throw new RuntimeException(method 180 + " must be compilable at level " + anotherTier 181 + ", even if it is not compilable at " 182 + testedTier); 183 } 184 WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci); 185 checkCompiled(); 186 deoptimize(); 187 } 188 189 if (!isCompilable(COMP_LEVEL_ANY)) { 190 throw new RuntimeException(method 191 + " must be compilable at 'CompLevel::CompLevel_any'" 192 + ", if it is not compilable only at " + testedTier); 193 } 194 } 195 196 // clear state after test 197 WHITE_BOX.clearMethodState(method); 198 if (!isCompilable(testedTier)) { 199 throw new RuntimeException(method 200 + " is not compilable after clearMethodState()"); 201 } 202 } 203 204 private boolean sameCompile(int level1, int level2) { 205 if (level1 == level2) { 206 return true; 207 } 208 if (isC1Compile(level1) && isC1Compile(level2)) { 209 return true; 210 } 211 if (isC2Compile(level1) && isC2Compile(level2)) { 212 return true; 213 } 214 return false; 215 } 216 217 private int getBci() { 218 compile(); 219 checkCompiled(); 220 int result = WHITE_BOX.getMethodEntryBci(method); 221 deoptimize(); 222 WHITE_BOX.clearMethodState(method); 223 return result; 224 } 225 }