hotspot/test/compiler/aot/RecompilationTest.java
author kvn
Sun, 11 Dec 2016 19:07:04 -0800
changeset 42650 1f304d0c888b
child 42657 9e1850986b28
permissions -rw-r--r--
8171008: Integrate AOT compiler into JDK Reviewed-by: erikj, mchung, psandoz, coleenp, iklam, stefank, simonis Contributed-by: Bharadwaj Yadavalli <bharadwaj.yadavalli@oracle.com>, Christian Thalinger <cthalinger@twitter.com>, Dean Long <dean.long@oracle.com>, Dmitrij Pochepko <dmitrij.pochepko@oracle.com>, Dmitry Chuyko <dmitry.chuyko@oracle.com>, Doug Simon <doug.simon@oracle.com>, Eric Caspole <eric.caspole@oracle.com>, Igor Ignatyev <igor.ignatyev@oracle.com>, Igor Veresov <igor.veresov@oracle.com>, John Rose <john.r.rose@oracle.com>, Morris Meyer <morris.meyer@oracle.com>, Niclas Adlertz <niclas.adlertz@oracle.com>, Rickard Backman <rickard.backman@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     1
/*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     4
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     8
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    13
 * accompanied this code).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    14
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    18
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    21
 * questions.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    22
 */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    23
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    24
/*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    25
 * @test
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    26
 * @library /test/lib /testlibrary /
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    27
 * @requires vm.bits == "64" & os.arch == "amd64" & os.family == "linux"
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    29
 * @build compiler.aot.RecompilationTest
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    30
 *        compiler.aot.AotCompiler
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    31
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    32
 *     sun.hotspot.WhiteBox$WhiteBoxPermission
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    33
 * @run main compiler.aot.AotCompiler -libname libRecompilationTest.so
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    34
 *     -class compiler.whitebox.SimpleTestCaseHelper
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    35
 *     -extraopt -Dgraal.TieredAOT=true -extraopt -Dgraal.ProfileSimpleMethods=true
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    36
 *     -extraopt -XX:+UnlockDiagnosticVMOptions -extraopt -XX:+WhiteBoxAPI -extraopt -Xbootclasspath/a:.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    37
 * @run main/othervm -Xmixed -Xbatch -XX:+UseAOT -XX:+TieredCompilation -XX:-UseCounterDecay
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    38
 *     -XX:CompileCommand=dontinline,*.*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    39
 *     -XX:AOTLibrary=./libRecompilationTest.so -Xbootclasspath/a:.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    40
 *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    41
 *     -Dcompiler.aot.RecompilationTest.check_level=1
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    42
 *     compiler.aot.RecompilationTest
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    43
 * @run main compiler.aot.AotCompiler -libname libRecompilationTest.so
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    44
 *     -class compiler.whitebox.SimpleTestCaseHelper
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    45
 *     -extraopt -Dgraal.TieredAOT=false
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    46
 *     -extraopt -XX:+UnlockDiagnosticVMOptions -extraopt -XX:+WhiteBoxAPI -extraopt -Xbootclasspath/a:.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    47
 * @run main/othervm -Xmixed -Xbatch -XX:+UseAOT -XX:+TieredCompilation -XX:-UseCounterDecay
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    48
 *     -XX:CompileCommand=dontinline,*.*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    49
 *     -XX:AOTLibrary=./libRecompilationTest.so -Xbootclasspath/a:.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    50
 *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    51
 *     -Dcompiler.aot.RecompilationTest.check_level=-1
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    52
 *     compiler.aot.RecompilationTest
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    53
 * @run main/othervm -Xmixed -Xbatch -XX:+UseAOT -XX:-TieredCompilation -XX:-UseCounterDecay
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    54
 *     -XX:CompileCommand=dontinline,*.*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    55
 *     -XX:AOTLibrary=./libRecompilationTest.so -Xbootclasspath/a:.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    56
 *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    57
 *     -Dcompiler.aot.RecompilationTest.check_level=-1
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    58
 *     compiler.aot.RecompilationTest
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    59
 * @summary check if recompilation after aot goes fine
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    60
 */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    61
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    62
 /* having whitebox-related options for aot compiler is a temporary solution,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    63
    because of JDK-8146201
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    64
 */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    65
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    66
package compiler.aot;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    67
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    68
import compiler.whitebox.CompilerWhiteBoxTest;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    69
import java.lang.reflect.Executable;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    70
import jdk.test.lib.Asserts;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    71
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    72
public final class RecompilationTest extends CompilerWhiteBoxTest {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    73
    private static final int CHECK_LEVEL = Integer.getInteger(
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    74
                "compiler.aot.RecompilationTest.check_level");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    75
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    76
    public static void main(String args[]) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    77
        CompilerWhiteBoxTest.main(RecompilationTest::new, args);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    78
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    79
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    80
    private RecompilationTest(TestCase testCase) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    81
        super(testCase);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    82
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    83
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    84
    @Override
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    85
    protected void test() throws Exception {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    86
        if (testCase.isOsr()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    87
            /* aot compiler is not using osr compilation */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    88
            System.out.println("Skipping OSR case");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    89
            return;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    90
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    91
        Executable e = testCase.getExecutable();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    92
        Asserts.assertTrue(WHITE_BOX.isMethodCompiled(e),
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    93
                testCase.name() +  ": an executable expected to be compiled");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    94
        Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(e),
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    95
                COMP_LEVEL_AOT,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    96
                String.format("%s: unexpected compilation level at start",
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    97
                        testCase.name()));
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    98
        compile();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    99
        Asserts.assertTrue(WHITE_BOX.isMethodCompiled(e), testCase.name()
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   100
                + ": method expected to be compiled");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   101
        /* a case with AOT'ed code checks exact compilation level equality
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   102
           while another case checks minimum level and if method compiled
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   103
           because there might be different compilation level transitions */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   104
        if (CHECK_LEVEL != COMP_LEVEL_AOT) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   105
            Asserts.assertGTE(WHITE_BOX.getMethodCompilationLevel(e),
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   106
                CHECK_LEVEL,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   107
                String.format("%s: expected compilation level"
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   108
                        + " after compilation to be no less than %d for %s",
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   109
                        testCase.name(), CHECK_LEVEL, testCase.name()));
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   110
        } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   111
            Asserts.assertEQ(WHITE_BOX.getMethodCompilationLevel(e),
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   112
                COMP_LEVEL_AOT, String.format("%s: expected compilation"
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   113
                        + " level after compilation to be equal to %d for %s",
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   114
                        testCase.name(), COMP_LEVEL_AOT, testCase.name()));
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   115
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   116
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   117
}