Skip to content

Commit

Permalink
[GR-19829] Make unit tests work on JDK 11 on Windows.
Browse files Browse the repository at this point in the history
PullRequest: graal/4991
  • Loading branch information
dougxc committed Dec 11, 2019
2 parents 412d076 + a53d3f0 commit abbbfb3
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 40 deletions.
4 changes: 3 additions & 1 deletion compiler/ci_common/gate_tasks.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ builds += [
# ${gateTestBenchmark} ${oraclejdk8} ${gateDarwinAMD64} {name: "weekly-test-compiler-benchmarktest-8-darwin-amd64"} ${graalWeekly}

# Windows AMD64
${gateTest} ${oraclejdk8} ${gateWindowsAMD64} {name: "gate-compiler-test-8-windows-amd64", timelimit: "50:00", packages: {msvc: "==10.0" }}
${gateTest} ${oraclejdk8} ${gateWindowsAMD64} {name: "gate-compiler-test-8-windows-amd64", timelimit: "50:00", packages: {msvc: "==10.0" }}
# GR-20001
# ${gateTest} ${labsjdk-ee-11} ${gateWindowsAMD64} {name: "gate-compiler-test-labsjdk-ee-11-windows-amd64", timelimit: "50:00"} ${windows-devkit-jdk11}

# Linux AMD64
${gateTest} ${oraclejdk8} ${gateLinuxAMD64} {name: "gate-compiler-test-8-linux-amd64"}
Expand Down
4 changes: 2 additions & 2 deletions compiler/mx.compiler/mx_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def compiler_gate_runner(suites, unit_test_runs, bootstrap_tests, tasks, extraVM
try:
makegraaljdk_cli(['-a', join(ws, 'graaljdk-' + str(jdk.javaCompliance) + '.tar'), '-b', graaljdk])
finally:
shutil.rmtree(ws)
mx.rmtree(ws)

# Run ctw against rt.jar on hosted
with Task('CTW:hosted', tasks, tags=GraalTags.ctw) as t:
Expand Down Expand Up @@ -1198,7 +1198,7 @@ def _update_graaljdk(src_jdk, dst_jdk_dir=None, root_module_names=None, export_t
# may have changed and we want to pick up these changes.
source_jdk_timestamps_file = dst_jdk_dir + '.source_jdk_timestamps'
timestamps = []
nl = os.linesep
nl = '\n'
for root, _, filenames in os.walk(jdk.home):
for name in filenames:
ts = mx.TimeStampFile(join(root, name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void launchSubprocess(Runnable runnable) throws InterruptedException, IOE
runnable.run();
} else {
List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
vmArgs.add(SubprocessUtil.PACKAGE_OPENING_OPTIONS);
vmArgs.add("-D" + recursionPropName + "=true");
configSubprocess(vmArgs);
SubprocessUtil.Subprocess proc = java(vmArgs, "com.oracle.mxtool.junit.MxJUnitWrapper", getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void spawnSubprocess() throws IOException, InterruptedException {
List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
vmArgs.add("-XX:JVMCICounterSize=1");
vmArgs.add("-Dgraal." + BenchmarkCounters.Options.AbortOnBenchmarkCounterOverflow.getName() + "=true");
vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
vmArgs.add(SubprocessUtil.PACKAGE_OPENING_OPTIONS);
vmArgs.add("-D" + SUBPROCESS_PROPERTY + "=true");

// Disable increment range checks (e.g. HotSpotCounterOp.checkIncrements())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package org.graalvm.compiler.hotspot.test;

import static org.graalvm.compiler.test.SubprocessUtil.getPackageOpeningOptions;
import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;

Expand All @@ -51,13 +50,6 @@
*/
public class CompilationWrapperTest extends GraalCompilerTest {

private static List<String> join(List<String> l1, List<String> l2) {
ArrayList<String> result = new ArrayList<>(l1.size() + l2.size());
result.addAll(l1);
result.addAll(l2);
return result;
}

/**
* Tests compilation requested by the VM.
*/
Expand Down Expand Up @@ -167,11 +159,11 @@ String test() {
public void testTruffleCompilation1() throws IOException, InterruptedException {
assumeManagementLibraryIsLoadable();
testHelper(Collections.emptyList(),
join(getPackageOpeningOptions(),
Arrays.asList(
"-Dgraal.CompilationFailureAction=ExitVM",
"-Dgraal.TrufflePerformanceWarningsAreFatal=true",
"-Dgraal.CrashAt=root test1")),
Arrays.asList(
SubprocessUtil.PACKAGE_OPENING_OPTIONS,
"-Dgraal.CompilationFailureAction=ExitVM",
"-Dgraal.TrufflePerformanceWarningsAreFatal=true",
"-Dgraal.CrashAt=root test1"),
"org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
}

Expand All @@ -184,11 +176,11 @@ public void testTruffleCompilation2() throws IOException, InterruptedException {
new Probe("Exiting VM due to TruffleCompilationExceptionsAreFatal=true", 1),
};
testHelper(Arrays.asList(probes),
join(getPackageOpeningOptions(),
Arrays.asList(
"-Dgraal.CompilationFailureAction=Silent",
"-Dgraal.TruffleCompilationExceptionsAreFatal=true",
"-Dgraal.CrashAt=root test1")),
Arrays.asList(
SubprocessUtil.PACKAGE_OPENING_OPTIONS,
"-Dgraal.CompilationFailureAction=Silent",
"-Dgraal.TruffleCompilationExceptionsAreFatal=true",
"-Dgraal.CrashAt=root test1"),
"org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
}

Expand All @@ -202,11 +194,11 @@ public void testTruffleCompilation3() throws IOException, InterruptedException {
new Probe("Exiting VM due to TrufflePerformanceWarningsAreFatal=true", 1),
};
testHelper(Arrays.asList(probes),
join(getPackageOpeningOptions(),
Arrays.asList(
"-Dgraal.CompilationFailureAction=Silent",
"-Dgraal.TrufflePerformanceWarningsAreFatal=true",
"-Dgraal.CrashAt=root test1:PermanentBailout")),
Arrays.asList(
SubprocessUtil.PACKAGE_OPENING_OPTIONS,
"-Dgraal.CompilationFailureAction=Silent",
"-Dgraal.TrufflePerformanceWarningsAreFatal=true",
"-Dgraal.CrashAt=root test1:PermanentBailout"),
"org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ public static void main(String[] args) {

@Test
public void run() throws IOException, InterruptedException {
Assume.assumeFalse("GR-19833", runtime().getVMConfig().osName.equals("windows"));
Assume.assumeTrue(runtime().getVMConfig().enableStackReservedZoneAddress != 0);
List<String> vmArgs = SubprocessUtil.withoutDebuggerArguments(SubprocessUtil.getVMCommandLine());
vmArgs.add("-XX:+UseJVMCICompiler");
vmArgs.add("-Dgraal.Inline=false");
vmArgs.add("-XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread");
vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
vmArgs.add(SubprocessUtil.PACKAGE_OPENING_OPTIONS);

// Avoid SOE in HotSpotJVMCIRuntime.adjustCompilationLevel
vmArgs.add("-Dgraal.CompileGraalWithC1Only=false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void test() throws Throwable {
} else {
List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
vmArgs.add("-D" + recursionPropName + "=true");
vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
vmArgs.add(SubprocessUtil.PACKAGE_OPENING_OPTIONS);
vmArgs.add("-Djdk.attach.allowAttachSelf=true");
Subprocess proc = java(vmArgs, "com.oracle.mxtool.junit.MxJUnitWrapper", getClass().getName());
if (proc.exitCode != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Formatter;
Expand All @@ -47,6 +49,14 @@
*/
public final class SubprocessUtil {

/**
* The name of the boolean system property that can be set to preserve temporary files created
* as arguments files passed to the java launcher.
*
* @see "https://docs.oracle.com/javase/9/tools/java.htm#JSWOR-GUID-4856361B-8BFD-4964-AE84-121F5F6CF111"
*/
public static final String KEEP_TEMPORARY_ARGUMENT_FILES_PROPERTY_NAME = "test." + SubprocessUtil.class.getSimpleName() + ".keepTempArgumentFiles";

private SubprocessUtil() {
}

Expand Down Expand Up @@ -184,8 +194,14 @@ public static class Subprocess {
*/
public final List<String> output;

public Subprocess(List<String> command, int exitCode, List<String> output) {
/**
* Explicit environment variables.
*/
private Map<String, String> env;

public Subprocess(List<String> command, Map<String, String> env, int exitCode, List<String> output) {
this.command = command;
this.env = env;
this.exitCode = exitCode;
this.output = output;
}
Expand All @@ -202,6 +218,13 @@ public String toString(String delimiter) {
if (delimiter != null) {
msg.format("%s%n", delimiter);
}
if (env != null && !env.isEmpty()) {
msg.format("env");
for (Map.Entry<String, String> e : env.entrySet()) {
msg.format(" %s=%s", e.getKey(), quoteShellArg(e.getValue()));
}
msg.format("\\%n");
}
msg.format("%s%n", CollectionsUtil.mapAndJoin(command, e -> quoteShellArg(String.valueOf(e)), " "));
for (String line : output) {
msg.format("%s%n", line);
Expand All @@ -222,6 +245,14 @@ public String toString() {
}
}

/**
* A sentinel value which when present in the {@code vmArgs} parameter for any of the
* {@code java(...)} methods in this class is replaced with a temporary argument file containing
* the contents of {@link #getPackageOpeningOptions}. The argument file is preserved if the
* {@link #KEEP_TEMPORARY_ARGUMENT_FILES_PROPERTY_NAME} system property is true.
*/
public static final String PACKAGE_OPENING_OPTIONS = ";:PACKAGE_OPENING_OPTIONS_IN_TEMPORARY_ARGUMENTS_FILE:;";

/**
* Executes a Java subprocess.
*
Expand Down Expand Up @@ -272,22 +303,45 @@ public static Subprocess java(List<String> vmArgs, Map<String, String> env, List
* @param mainClassAndArgs the main class and its arguments
*/
private static Subprocess javaHelper(List<String> vmArgs, Map<String, String> env, List<String> mainClassAndArgs) throws IOException, InterruptedException {
List<String> command = new ArrayList<>(vmArgs);
List<String> command = new ArrayList<>(vmArgs.size());
Path packageOpeningOptionsArgumentsFile = null;
for (String vmArg : vmArgs) {
if (vmArg == PACKAGE_OPENING_OPTIONS) {
if (packageOpeningOptionsArgumentsFile == null) {
List<String> packageOpeningOptions = getPackageOpeningOptions();
if (!packageOpeningOptions.isEmpty()) {
packageOpeningOptionsArgumentsFile = Files.createTempFile(Paths.get("."), "package-opening-options-arguments-file", ".txt").toAbsolutePath();
Files.write(packageOpeningOptionsArgumentsFile, packageOpeningOptions);
command.add("@" + packageOpeningOptionsArgumentsFile);
}
}
} else {
command.add(vmArg);
}
}
command.addAll(mainClassAndArgs);
ProcessBuilder processBuilder = new ProcessBuilder(command);
if (env != null) {
Map<String, String> processBuilderEnv = processBuilder.environment();
processBuilderEnv.putAll(env);
}
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
List<String> output = new ArrayList<>();
while ((line = stdout.readLine()) != null) {
output.add(line);
try {
Process process = processBuilder.start();
BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
List<String> output = new ArrayList<>();
while ((line = stdout.readLine()) != null) {
output.add(line);
}
return new Subprocess(command, env, process.waitFor(), output);
} finally {
if (packageOpeningOptionsArgumentsFile != null) {
if (!Boolean.getBoolean(KEEP_TEMPORARY_ARGUMENT_FILES_PROPERTY_NAME)) {
Files.delete(packageOpeningOptionsArgumentsFile);
}
}
}
return new Subprocess(command, process.waitFor(), output);
}

private static final boolean isJava8OrEarlier = JavaVersionUtil.JAVA_SPEC <= 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void runTest(Class<?> testClass, boolean expectGraalClassesLoaded) throw
vmArgs.add("-XX:+TraceClassLoading");
} else {
vmArgs.add("-Xlog:class+init=info");
vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
vmArgs.add(SubprocessUtil.PACKAGE_OPENING_OPTIONS);
}
vmArgs.add("-dsa");
vmArgs.add("-da");
Expand Down

0 comments on commit abbbfb3

Please sign in to comment.