test/compiler/whitebox/IsMethodCompilableTest.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/IsMethodCompilableTest.java	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,138 @@
     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 IsMethodCompilableTest
    1.29 + * @bug 8007270 8006683 8007288 8022832
    1.30 + * @library /testlibrary /testlibrary/whitebox /testlibrary/com/oracle/java/testlibrary
    1.31 + * @build IsMethodCompilableTest
    1.32 + * @run main ClassFileInstaller sun.hotspot.WhiteBox
    1.33 + * @run main ClassFileInstaller com.oracle.java.testlibrary.Platform
    1.34 + * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -Xmixed -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:PerMethodRecompilationCutoff=3 -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* IsMethodCompilableTest
    1.35 + * @summary testing of WB::isMethodCompilable()
    1.36 + * @author igor.ignatyev@oracle.com
    1.37 + */
    1.38 +
    1.39 +import com.oracle.java.testlibrary.Platform;
    1.40 +
    1.41 +public class IsMethodCompilableTest extends CompilerWhiteBoxTest {
    1.42 +    /**
    1.43 +     * Value of {@code -XX:PerMethodRecompilationCutoff}
    1.44 +     */
    1.45 +    protected static final long PER_METHOD_RECOMPILATION_CUTOFF;
    1.46 +
    1.47 +    static {
    1.48 +        long tmp = Long.parseLong(
    1.49 +                getVMOption("PerMethodRecompilationCutoff", "400"));
    1.50 +        if (tmp == -1) {
    1.51 +            PER_METHOD_RECOMPILATION_CUTOFF = -1 /* Inf */;
    1.52 +        } else {
    1.53 +            PER_METHOD_RECOMPILATION_CUTOFF = (0xFFFFFFFFL & tmp);
    1.54 +        }
    1.55 +    }
    1.56 +
    1.57 +    public static void main(String[] args) throws Exception {
    1.58 +        CompilerWhiteBoxTest.main(IsMethodCompilableTest::new, args);
    1.59 +    }
    1.60 +
    1.61 +    private IsMethodCompilableTest(TestCase testCase) {
    1.62 +        super(testCase);
    1.63 +        // to prevent inlining of #method
    1.64 +        WHITE_BOX.testSetDontInlineMethod(method, true);
    1.65 +    }
    1.66 +
    1.67 +    /**
    1.68 +     * Tests {@code WB::isMethodCompilable()} by recompilation of tested method
    1.69 +     * 'PerMethodRecompilationCutoff' times and checks compilation status. Also
    1.70 +     * checks that WB::clearMethodState() clears no-compilable flags. Only
    1.71 +     * applicable to c2 compiled methods.
    1.72 +     *
    1.73 +     * @throws Exception if one of the checks fails.
    1.74 +     */
    1.75 +    @Override
    1.76 +    protected void test() throws Exception {
    1.77 +        // Only c2 compilations can be disabled through PerMethodRecompilationCutoff
    1.78 +        if (!Platform.isServer()) {
    1.79 +            return;
    1.80 +        }
    1.81 +
    1.82 +        if (skipXcompOSR()) {
    1.83 +          return;
    1.84 +        }
    1.85 +        if (!isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
    1.86 +            throw new RuntimeException(method + " must be compilable");
    1.87 +        }
    1.88 +        System.out.println("PerMethodRecompilationCutoff = "
    1.89 +                + PER_METHOD_RECOMPILATION_CUTOFF);
    1.90 +        if (PER_METHOD_RECOMPILATION_CUTOFF == -1) {
    1.91 +            System.err.println(
    1.92 +                    "Warning: test is not applicable if PerMethodRecompilationCutoff == Inf");
    1.93 +            return;
    1.94 +        }
    1.95 +
    1.96 +        // deoptimize 'PerMethodRecompilationCutoff' times
    1.97 +        for (long attempts = 0, successes = 0;
    1.98 +               (successes < PER_METHOD_RECOMPILATION_CUTOFF)  &&
    1.99 +               (attempts < PER_METHOD_RECOMPILATION_CUTOFF*2) &&
   1.100 +               isCompilable(COMP_LEVEL_FULL_OPTIMIZATION); attempts++) {
   1.101 +            if (compileAndDeoptimize() == COMP_LEVEL_FULL_OPTIMIZATION) {
   1.102 +                successes++;
   1.103 +            }
   1.104 +        }
   1.105 +
   1.106 +        if (!testCase.isOsr() && !isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
   1.107 +            // in osr test case count of deopt maybe more than iterations
   1.108 +            throw new RuntimeException(method + " is not compilable after "
   1.109 +                    + PER_METHOD_RECOMPILATION_CUTOFF + " iterations");
   1.110 +        }
   1.111 +
   1.112 +        // Now compile once more
   1.113 +        compileAndDeoptimize();
   1.114 +
   1.115 +        if (isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
   1.116 +            throw new RuntimeException(method + " is still compilable after "
   1.117 +                    + PER_METHOD_RECOMPILATION_CUTOFF + " iterations");
   1.118 +        }
   1.119 +        checkNotCompiled();
   1.120 +        compile();
   1.121 +        waitBackgroundCompilation();
   1.122 +        checkNotCompiled(COMP_LEVEL_FULL_OPTIMIZATION);
   1.123 +
   1.124 +        // WB.clearMethodState() must reset no-compilable flags
   1.125 +        WHITE_BOX.clearMethodState(method);
   1.126 +        if (!isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
   1.127 +            throw new RuntimeException(method
   1.128 +                    + " is not compilable after clearMethodState()");
   1.129 +        }
   1.130 +        compile();
   1.131 +        checkCompiled();
   1.132 +    }
   1.133 +
   1.134 +    private int compileAndDeoptimize() throws Exception {
   1.135 +        compile();
   1.136 +        waitBackgroundCompilation();
   1.137 +        int compLevel = getCompLevel();
   1.138 +        deoptimize();
   1.139 +        return compLevel;
   1.140 +    }
   1.141 +}

mercurial