test/hotspot/jtreg/compiler/aot/cli/jaotc/JaotcTestHelper.java
author rraghavan
Thu, 08 Aug 2019 14:13:16 +0530
changeset 57681 41f2f2829a09
parent 47216 71c04702a3d5
permissions -rw-r--r--
8227439: Turn off AOT by default Summary: Made UseAOT, AOTLibrary experimental and UseAOT false by default Reviewed-by: iignatyev, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     1
/*
57681
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
42650
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
package compiler.aot.cli.jaotc;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    25
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    26
import compiler.aot.AotCompiler;
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    27
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    28
import java.io.File;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    29
import java.io.IOException;
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    30
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    31
import jdk.test.lib.process.ExitCode;
46804
db2cd95b294c 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 46289
diff changeset
    32
import jdk.test.lib.Platform;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    33
import jdk.test.lib.JDKToolLauncher;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    34
import jdk.test.lib.Utils;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    35
import jdk.test.lib.cli.CommandLineOptionTest;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    37
import jdk.test.lib.process.ProcessTools;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    38
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    39
public class JaotcTestHelper {
46804
db2cd95b294c 8174202: jtreg AOT tests should not assume library extension of .so
iignatyev
parents: 46289
diff changeset
    40
    public static final String DEFAULT_LIB_PATH = "./unnamed." + Platform.sharedLibraryExt();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    41
    public static final String DEFAULT_LIBRARY_LOAD_MESSAGE = "loaded    " + DEFAULT_LIB_PATH
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    42
            + "  aot library";
57681
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 47216
diff changeset
    43
    private static final String UNLOCK_EXPERIMENTAL_VM_OPTIONS = "-XX:+UnlockExperimentalVMOptions";
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    44
    private static final String ENABLE_AOT = "-XX:+UseAOT";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    45
    private static final String AOT_LIBRARY = "-XX:AOTLibrary=" + DEFAULT_LIB_PATH;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    46
    private static final String PRINT_AOT = "-XX:+PrintAOT";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    47
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    48
    public static OutputAnalyzer compileLibrary(String... args) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    49
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jaotc");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    50
        for (String vmOpt : Utils.getTestJavaOpts()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    51
            launcher.addVMArg(vmOpt);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    52
        }
43425
c5dc48e6d9e6 8172054: Aot tests should include Java assertions into AOT compiled code
kvn
parents: 42650
diff changeset
    53
        launcher.addToolArg("--compile-with-assertions");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    54
        for (String arg : args) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    55
            launcher.addToolArg(arg);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    56
        }
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    57
        String linker = AotCompiler.resolveLinker();
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    58
        if (linker != null) {
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    59
            launcher.addToolArg("--linker-path");
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    60
            launcher.addToolArg(linker);
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    61
        }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    62
        String[] cmd = launcher.getCommand();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    63
        try {
46826
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    64
            return ProcessTools.executeCommand(cmd);
dae7992b1615 8183337: hotspot/compiler/aot tests fail due to missed tools
iignatyev
parents: 46804
diff changeset
    65
        } catch (Throwable e) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    66
            throw new Error("Can't start test process: " + e, e);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    67
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    68
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    69
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    70
    public static void checkLibraryUsage(String classToRun) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    71
        checkLibraryUsage(classToRun, new String[]{DEFAULT_LIBRARY_LOAD_MESSAGE}, null);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    72
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    73
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    74
    public static void checkLibraryUsage(String classToRun, String[] expectedOutput,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    75
            String[] unexpectedOutput) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    76
        try {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    77
            CommandLineOptionTest.verifyJVMStartup(expectedOutput, unexpectedOutput,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    78
                    "Unexpected exit code", "Unexpected output", ExitCode.OK,
57681
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 47216
diff changeset
    79
                    /* addTestVMOpts */ true, UNLOCK_EXPERIMENTAL_VM_OPTIONS,
41f2f2829a09 8227439: Turn off AOT by default
rraghavan
parents: 47216
diff changeset
    80
                    ENABLE_AOT, AOT_LIBRARY, PRINT_AOT, classToRun);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    81
        } catch (Throwable t) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    82
            throw new Error("Library usage verification failed: " + t, t);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    83
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    84
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    85
43464
f38fde4a6b52 8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents: 43425
diff changeset
    86
    public static String getClassAotCompilationFilename(Class<?> classToCompile) {
46289
bobv
parents: 43464 46260
diff changeset
    87
        return classToCompile.getName().replaceAll("\\.","/") + ".class";
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    88
    }
43464
f38fde4a6b52 8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents: 43425
diff changeset
    89
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    90
    public static String getClassAotCompilationName(Class<?> classToCompile) {
43464
f38fde4a6b52 8169588: [AOT] jaotc --classpath option is confusing
rbackman
parents: 43425
diff changeset
    91
        return classToCompile.getName();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    92
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    93
}