test/compiler/whitebox/MakeMethodNotCompilableTest.java

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/whitebox/MakeMethodNotCompilableTest.java	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,223 @@
     1.4 +/*
     1.5 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test MakeMethodNotCompilableTest
    1.29 + * @bug 8012322 8006683 8007288 8022832
    1.30 + * @library /testlibrary /testlibrary/whitebox
    1.31 + * @build MakeMethodNotCompilableTest
    1.32 + * @run main ClassFileInstaller sun.hotspot.WhiteBox
    1.33 + * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* MakeMethodNotCompilableTest
    1.34 + * @summary testing of WB::makeMethodNotCompilable()
    1.35 + * @author igor.ignatyev@oracle.com
    1.36 + */
    1.37 +public class MakeMethodNotCompilableTest extends CompilerWhiteBoxTest {
    1.38 +    private int bci;
    1.39 +    public static void main(String[] args) throws Exception {
    1.40 +        CompilerWhiteBoxTest.main(MakeMethodNotCompilableTest::new, args);
    1.41 +    }
    1.42 +
    1.43 +    private MakeMethodNotCompilableTest(TestCase testCase) {
    1.44 +        super(testCase);
    1.45 +        // to prevent inlining of #method
    1.46 +        WHITE_BOX.testSetDontInlineMethod(method, true);
    1.47 +    }
    1.48 +
    1.49 +    /**
    1.50 +     * Tests {@code WB::makeMethodNotCompilable()} by calling it before
    1.51 +     * compilation and checking that method isn't compiled. Also
    1.52 +     * checks that WB::clearMethodState() clears no-compilable flags. For
    1.53 +     * tiered, additional checks for all available levels are conducted.
    1.54 +     *
    1.55 +     * @throws Exception if one of the checks fails.
    1.56 +     */
    1.57 +    @Override
    1.58 +    protected void test() throws Exception {
    1.59 +        if (skipXcompOSR()) {
    1.60 +            return;
    1.61 +        }
    1.62 +        checkNotCompiled();
    1.63 +        if (!isCompilable()) {
    1.64 +            throw new RuntimeException(method + " must be compilable");
    1.65 +        }
    1.66 +
    1.67 +        bci = getBci();
    1.68 +
    1.69 +        if (TIERED_COMPILATION) {
    1.70 +            final int tierLimit = TIERED_STOP_AT_LEVEL + 1;
    1.71 +            for (int testedTier = 1; testedTier < tierLimit; ++testedTier) {
    1.72 +                testTier(testedTier);
    1.73 +            }
    1.74 +            for (int testedTier = 1; testedTier < tierLimit; ++testedTier) {
    1.75 +                makeNotCompilable(testedTier);
    1.76 +                if (isCompilable(testedTier)) {
    1.77 +                    throw new RuntimeException(method
    1.78 +                            + " must be not compilable at level" + testedTier);
    1.79 +                }
    1.80 +                WHITE_BOX.enqueueMethodForCompilation(method, testedTier, bci);
    1.81 +                checkNotCompiled();
    1.82 +
    1.83 +                if (!isCompilable()) {
    1.84 +                    System.out.println(method
    1.85 +                            + " is not compilable after level " + testedTier);
    1.86 +                }
    1.87 +            }
    1.88 +        } else {
    1.89 +            compile();
    1.90 +            checkCompiled();
    1.91 +            int compLevel = getCompLevel();
    1.92 +            deoptimize();
    1.93 +            makeNotCompilable(compLevel);
    1.94 +            if (isCompilable(COMP_LEVEL_ANY)) {
    1.95 +                throw new RuntimeException(method
    1.96 +                        + " must be not compilable at CompLevel::CompLevel_any,"
    1.97 +                        + " after it is not compilable at " + compLevel);
    1.98 +            }
    1.99 +
   1.100 +            WHITE_BOX.clearMethodState(method);
   1.101 +            if (!isCompilable()) {
   1.102 +                throw new RuntimeException(method
   1.103 +                        + " is not compilable after clearMethodState()");
   1.104 +            }
   1.105 +
   1.106 +            // nocompilable at opposite level must make no sense
   1.107 +            int oppositeLevel;
   1.108 +            if (isC1Compile(compLevel)) {
   1.109 +              oppositeLevel = COMP_LEVEL_FULL_OPTIMIZATION;
   1.110 +            } else {
   1.111 +              oppositeLevel = COMP_LEVEL_SIMPLE;
   1.112 +            }
   1.113 +            makeNotCompilable(oppositeLevel);
   1.114 +
   1.115 +            if (!isCompilable(COMP_LEVEL_ANY)) {
   1.116 +                  throw new RuntimeException(method
   1.117 +                        + " must be compilable at CompLevel::CompLevel_any,"
   1.118 +                        + " even it is not compilable at opposite level ["
   1.119 +                        + compLevel + "]");
   1.120 +            }
   1.121 +
   1.122 +            if (!isCompilable(compLevel)) {
   1.123 +                  throw new RuntimeException(method
   1.124 +                        + " must be compilable at level " + compLevel
   1.125 +                        + ", even it is not compilable at opposite level ["
   1.126 +                        + compLevel + "]");
   1.127 +            }
   1.128 +        }
   1.129 +
   1.130 +        // clearing after tiered/non-tiered tests
   1.131 +        // WB.clearMethodState() must reset no-compilable flags
   1.132 +        WHITE_BOX.clearMethodState(method);
   1.133 +        if (!isCompilable()) {
   1.134 +            throw new RuntimeException(method
   1.135 +                    + " is not compilable after clearMethodState()");
   1.136 +        }
   1.137 +
   1.138 +        makeNotCompilable();
   1.139 +        if (isCompilable()) {
   1.140 +            throw new RuntimeException(method + " must be not compilable");
   1.141 +        }
   1.142 +
   1.143 +        compile();
   1.144 +        checkNotCompiled();
   1.145 +        if (isCompilable()) {
   1.146 +            throw new RuntimeException(method + " must be not compilable");
   1.147 +        }
   1.148 +        // WB.clearMethodState() must reset no-compilable flags
   1.149 +        WHITE_BOX.clearMethodState(method);
   1.150 +        if (!isCompilable()) {
   1.151 +            throw new RuntimeException(method
   1.152 +                    + " is not compilable after clearMethodState()");
   1.153 +        }
   1.154 +        compile();
   1.155 +        checkCompiled();
   1.156 +    }
   1.157 +
   1.158 +    // separately tests each tier
   1.159 +    private void testTier(int testedTier) {
   1.160 +        if (!isCompilable(testedTier)) {
   1.161 +            throw new RuntimeException(method
   1.162 +                    + " is not compilable on start");
   1.163 +        }
   1.164 +        makeNotCompilable(testedTier);
   1.165 +
   1.166 +        // tests for all other tiers
   1.167 +        for (int anotherTier = 1, tierLimit = TIERED_STOP_AT_LEVEL + 1;
   1.168 +                    anotherTier < tierLimit; ++anotherTier) {
   1.169 +            boolean isCompilable = isCompilable(anotherTier);
   1.170 +            if (sameCompile(testedTier, anotherTier)) {
   1.171 +                if (isCompilable) {
   1.172 +                    throw new RuntimeException(method
   1.173 +                            + " must be not compilable at level " + anotherTier
   1.174 +                            + ", if it is not compilable at " + testedTier);
   1.175 +                }
   1.176 +                WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci);
   1.177 +                checkNotCompiled();
   1.178 +            } else {
   1.179 +                if (!isCompilable) {
   1.180 +                    throw new RuntimeException(method
   1.181 +                            + " must be compilable at level " + anotherTier
   1.182 +                            + ", even if it is not compilable at "
   1.183 +                            + testedTier);
   1.184 +                }
   1.185 +                WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci);
   1.186 +                checkCompiled();
   1.187 +                deoptimize();
   1.188 +            }
   1.189 +
   1.190 +            if (!isCompilable(COMP_LEVEL_ANY)) {
   1.191 +                throw new RuntimeException(method
   1.192 +                        + " must be compilable at 'CompLevel::CompLevel_any'"
   1.193 +                        + ", if it is not compilable only at " + testedTier);
   1.194 +            }
   1.195 +        }
   1.196 +
   1.197 +        // clear state after test
   1.198 +        WHITE_BOX.clearMethodState(method);
   1.199 +        if (!isCompilable(testedTier)) {
   1.200 +            throw new RuntimeException(method
   1.201 +                    + " is not compilable after clearMethodState()");
   1.202 +        }
   1.203 +    }
   1.204 +
   1.205 +    private boolean sameCompile(int level1, int level2) {
   1.206 +        if (level1 == level2) {
   1.207 +            return true;
   1.208 +        }
   1.209 +        if (isC1Compile(level1) && isC1Compile(level2)) {
   1.210 +            return true;
   1.211 +        }
   1.212 +        if (isC2Compile(level1) && isC2Compile(level2)) {
   1.213 +            return true;
   1.214 +        }
   1.215 +        return false;
   1.216 +    }
   1.217 +
   1.218 +    private int getBci() {
   1.219 +        compile();
   1.220 +        checkCompiled();
   1.221 +        int result = WHITE_BOX.getMethodEntryBci(method);
   1.222 +        deoptimize();
   1.223 +        WHITE_BOX.clearMethodState(method);
   1.224 +        return result;
   1.225 +    }
   1.226 +}

mercurial