iignatyev@4592: /* iignatyev@6353: * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. iignatyev@4592: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. iignatyev@4592: * iignatyev@4592: * This code is free software; you can redistribute it and/or modify it iignatyev@4592: * under the terms of the GNU General Public License version 2 only, as iignatyev@4592: * published by the Free Software Foundation. iignatyev@4592: * iignatyev@4592: * This code is distributed in the hope that it will be useful, but WITHOUT iignatyev@4592: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or iignatyev@4592: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License iignatyev@4592: * version 2 for more details (a copy is included in the LICENSE file that iignatyev@4592: * accompanied this code). iignatyev@4592: * iignatyev@4592: * You should have received a copy of the GNU General Public License version iignatyev@4592: * 2 along with this work; if not, write to the Free Software Foundation, iignatyev@4592: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. iignatyev@4592: * iignatyev@4592: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA iignatyev@4592: * or visit www.oracle.com if you need additional information or have any iignatyev@4592: * questions. iignatyev@4592: */ iignatyev@4592: iignatyev@4592: /* iignatyev@4592: * @test MakeMethodNotCompilableTest iignatyev@5541: * @bug 8012322 8006683 8007288 8022832 mgerdin@4637: * @library /testlibrary /testlibrary/whitebox mgerdin@4637: * @build MakeMethodNotCompilableTest mgerdin@4637: * @run main ClassFileInstaller sun.hotspot.WhiteBox iignatyev@6211: * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* MakeMethodNotCompilableTest iignatyev@4951: * @summary testing of WB::makeMethodNotCompilable() iignatyev@4592: * @author igor.ignatyev@oracle.com iignatyev@4592: */ iignatyev@4592: public class MakeMethodNotCompilableTest extends CompilerWhiteBoxTest { iignatyev@5541: private int bci; iignatyev@4592: public static void main(String[] args) throws Exception { iignatyev@6211: CompilerWhiteBoxTest.main(MakeMethodNotCompilableTest::new, args); iignatyev@4592: } iignatyev@4592: iignatyev@6211: private MakeMethodNotCompilableTest(TestCase testCase) { iignatyev@4951: super(testCase); iignatyev@4951: // to prevent inlining of #method iignatyev@4951: WHITE_BOX.testSetDontInlineMethod(method, true); iignatyev@4951: } iignatyev@4951: iignatyev@4951: /** iignatyev@4951: * Tests {@code WB::makeMethodNotCompilable()} by calling it before iignatyev@4951: * compilation and checking that method isn't compiled. Also iignatyev@4951: * checks that WB::clearMethodState() clears no-compilable flags. For iignatyev@4951: * tiered, additional checks for all available levels are conducted. iignatyev@4951: * iignatyev@4951: * @throws Exception if one of the checks fails. iignatyev@4951: */ iignatyev@4951: @Override iignatyev@4951: protected void test() throws Exception { iignatyev@6353: if (skipXcompOSR()) { iignatyev@6353: return; iignatyev@5796: } iignatyev@4951: checkNotCompiled(); iignatyev@5541: if (!isCompilable()) { iignatyev@4951: throw new RuntimeException(method + " must be compilable"); iignatyev@4592: } iignatyev@4951: iignatyev@5541: bci = getBci(); iignatyev@5541: iignatyev@4951: if (TIERED_COMPILATION) { iignatyev@5032: final int tierLimit = TIERED_STOP_AT_LEVEL + 1; iignatyev@5032: for (int testedTier = 1; testedTier < tierLimit; ++testedTier) { iignatyev@5032: testTier(testedTier); iignatyev@5032: } iignatyev@5032: for (int testedTier = 1; testedTier < tierLimit; ++testedTier) { iignatyev@5541: makeNotCompilable(testedTier); iignatyev@5541: if (isCompilable(testedTier)) { iignatyev@4951: throw new RuntimeException(method iignatyev@5032: + " must be not compilable at level" + testedTier); iignatyev@4951: } iignatyev@5541: WHITE_BOX.enqueueMethodForCompilation(method, testedTier, bci); iignatyev@4951: checkNotCompiled(); iignatyev@4951: iignatyev@5541: if (!isCompilable()) { iignatyev@4951: System.out.println(method iignatyev@5032: + " is not compilable after level " + testedTier); iignatyev@4951: } iignatyev@4951: } iignatyev@5032: } else { iignatyev@5032: compile(); iignatyev@5032: checkCompiled(); iignatyev@5541: int compLevel = getCompLevel(); iignatyev@5541: deoptimize(); iignatyev@5541: makeNotCompilable(compLevel); iignatyev@5541: if (isCompilable(COMP_LEVEL_ANY)) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " must be not compilable at CompLevel::CompLevel_any," iignatyev@5032: + " after it is not compilable at " + compLevel); iignatyev@5032: } iignatyev@5541: iignatyev@5032: WHITE_BOX.clearMethodState(method); iignatyev@5541: if (!isCompilable()) { iignatyev@5541: throw new RuntimeException(method iignatyev@5541: + " is not compilable after clearMethodState()"); iignatyev@5541: } iignatyev@4951: iignatyev@5032: // nocompilable at opposite level must make no sense iignatyev@5032: int oppositeLevel; iignatyev@5032: if (isC1Compile(compLevel)) { iignatyev@5032: oppositeLevel = COMP_LEVEL_FULL_OPTIMIZATION; iignatyev@5032: } else { iignatyev@5032: oppositeLevel = COMP_LEVEL_SIMPLE; iignatyev@5032: } iignatyev@5541: makeNotCompilable(oppositeLevel); iignatyev@5032: iignatyev@5541: if (!isCompilable(COMP_LEVEL_ANY)) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " must be compilable at CompLevel::CompLevel_any," iignatyev@5032: + " even it is not compilable at opposite level [" iignatyev@5032: + compLevel + "]"); iignatyev@5032: } iignatyev@5032: iignatyev@5541: if (!isCompilable(compLevel)) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " must be compilable at level " + compLevel iignatyev@5032: + ", even it is not compilable at opposite level [" iignatyev@5032: + compLevel + "]"); iignatyev@4951: } iignatyev@4951: } iignatyev@5032: iignatyev@5032: // clearing after tiered/non-tiered tests iignatyev@5032: // WB.clearMethodState() must reset no-compilable flags iignatyev@5032: WHITE_BOX.clearMethodState(method); iignatyev@5541: if (!isCompilable()) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " is not compilable after clearMethodState()"); iignatyev@5032: } iignatyev@5032: iignatyev@5541: makeNotCompilable(); iignatyev@5541: if (isCompilable()) { iignatyev@4951: throw new RuntimeException(method + " must be not compilable"); iignatyev@4951: } iignatyev@4951: iignatyev@4951: compile(); iignatyev@4951: checkNotCompiled(); iignatyev@5541: if (isCompilable()) { iignatyev@4951: throw new RuntimeException(method + " must be not compilable"); iignatyev@4951: } iignatyev@4951: // WB.clearMethodState() must reset no-compilable flags iignatyev@4951: WHITE_BOX.clearMethodState(method); iignatyev@5541: if (!isCompilable()) { iignatyev@4951: throw new RuntimeException(method iignatyev@4951: + " is not compilable after clearMethodState()"); iignatyev@4592: } iignatyev@4592: compile(); iignatyev@4951: checkCompiled(); iignatyev@4592: } iignatyev@5032: iignatyev@5032: // separately tests each tier iignatyev@5032: private void testTier(int testedTier) { iignatyev@5541: if (!isCompilable(testedTier)) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " is not compilable on start"); iignatyev@5032: } iignatyev@5541: makeNotCompilable(testedTier); iignatyev@5032: iignatyev@5032: // tests for all other tiers iignatyev@5032: for (int anotherTier = 1, tierLimit = TIERED_STOP_AT_LEVEL + 1; iignatyev@5032: anotherTier < tierLimit; ++anotherTier) { iignatyev@5541: boolean isCompilable = isCompilable(anotherTier); iignatyev@5032: if (sameCompile(testedTier, anotherTier)) { iignatyev@5032: if (isCompilable) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " must be not compilable at level " + anotherTier iignatyev@5032: + ", if it is not compilable at " + testedTier); iignatyev@5032: } iignatyev@5541: WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci); iignatyev@5032: checkNotCompiled(); iignatyev@5032: } else { iignatyev@5032: if (!isCompilable) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " must be compilable at level " + anotherTier iignatyev@5032: + ", even if it is not compilable at " iignatyev@5032: + testedTier); iignatyev@5032: } iignatyev@5541: WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci); iignatyev@5032: checkCompiled(); iignatyev@5541: deoptimize(); iignatyev@5032: } iignatyev@5032: iignatyev@5541: if (!isCompilable(COMP_LEVEL_ANY)) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " must be compilable at 'CompLevel::CompLevel_any'" iignatyev@5032: + ", if it is not compilable only at " + testedTier); iignatyev@5032: } iignatyev@5032: } iignatyev@5032: iignatyev@5032: // clear state after test iignatyev@5032: WHITE_BOX.clearMethodState(method); iignatyev@5541: if (!isCompilable(testedTier)) { iignatyev@5032: throw new RuntimeException(method iignatyev@5032: + " is not compilable after clearMethodState()"); iignatyev@5032: } iignatyev@5032: } iignatyev@5032: iignatyev@5032: private boolean sameCompile(int level1, int level2) { iignatyev@5032: if (level1 == level2) { iignatyev@5032: return true; iignatyev@5032: } iignatyev@5032: if (isC1Compile(level1) && isC1Compile(level2)) { iignatyev@5032: return true; iignatyev@5032: } iignatyev@5032: if (isC2Compile(level1) && isC2Compile(level2)) { iignatyev@5032: return true; iignatyev@5032: } iignatyev@5032: return false; iignatyev@5032: } iignatyev@5541: iignatyev@5541: private int getBci() { iignatyev@5541: compile(); iignatyev@5541: checkCompiled(); iignatyev@5541: int result = WHITE_BOX.getMethodEntryBci(method); iignatyev@5541: deoptimize(); iignatyev@5541: WHITE_BOX.clearMethodState(method); iignatyev@5541: return result; iignatyev@5541: } iignatyev@4592: }