Skip to content

Commit

Permalink
8321812: Update GC tests to use execute[Limited]TestJava
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken
Backport-of: 1d1cd32bc355a33448d8f15555e142570bb49c21
  • Loading branch information
TheRealMDoerr committed May 23, 2024
1 parent a4d2a5a commit 9035981
Show file tree
Hide file tree
Showing 129 changed files with 439 additions and 627 deletions.
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestAgeOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void checkPattern(String pattern, String what) throws Exception {
}

public static void runTest(String gcArg) throws Exception {
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
OutputAnalyzer output = ProcessTools.executeLimitedTestJava(
"-Xbootclasspath/a:.",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UnlockDiagnosticVMOptions",
Expand All @@ -75,7 +75,6 @@ public static void runTest(String gcArg) throws Exception {
"-Xmx10M",
"-Xlog:gc+age=trace",
GCTest.class.getName());
OutputAnalyzer output = new OutputAnalyzer(pb.start());

output.shouldHaveExitValue(0);

Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestAllocateHeapAt.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@

public class TestAllocateHeapAt {
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
OutputAnalyzer output = ProcessTools.executeTestJava(
"-XX:AllocateHeapAt=" + System.getProperty("test.dir", "."),
"-Xlog:gc+heap=info",
"-Xmx32m",
"-Xms32m",
"-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());

System.out.println("Output:\n" + output.getOutput());

Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestAllocateHeapAtError.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ public static void main(String args[]) throws Exception {
f = new File(test_dir, UUID.randomUUID().toString());
} while(f.exists());

ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
OutputAnalyzer output = ProcessTools.executeTestJava(
"-XX:AllocateHeapAt=" + f.getName(),
"-Xlog:gc+heap=info",
"-Xmx32m",
"-Xms32m",
"-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());

System.out.println("Output:\n" + output.getOutput());

Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestAllocateHeapAtMultiple.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public static void main(String args[]) throws Exception {
"-Xlog:gc+heap=info",
"-version"});

ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(flags);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = ProcessTools.executeTestJava(flags);

System.out.println("Output:\n" + output.getOutput());

Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestCardTablePageCommits.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ public static void main(String args[]) throws Exception {
// because of 8kB pages, assume 4 KB pages for all other CPUs.
String Xmx = "-Xmx4m";

ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
OutputAnalyzer output = ProcessTools.executeLimitedTestJava(
Xmx,
"-XX:NativeMemoryTracking=detail",
"-XX:+UseParallelGC",
"-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
}
}
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestNumWorkerOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void checkPatternOnce(String pattern, String what) throws Exceptio
}

public static void runTest(String gcArg) throws Exception {
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
OutputAnalyzer output = ProcessTools.executeLimitedTestJava(
"-Xbootclasspath/a:.",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UnlockDiagnosticVMOptions",
Expand All @@ -67,7 +67,6 @@ public static void runTest(String gcArg) throws Exception {
"-Xmx10M",
"-XX:+PrintGCDetails",
GCTest.class.getName());
OutputAnalyzer output = new OutputAnalyzer(pb.start());

output.shouldHaveExitValue(0);

Expand Down
4 changes: 1 addition & 3 deletions test/hotspot/jtreg/gc/TestPLABAdaptToMinTLABSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ private static void runTest(boolean shouldSucceed, String... extraArgs) throws E
Collections.addAll(testArguments, extraArgs);
testArguments.add("-version");

ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(testArguments);

OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = ProcessTools.executeTestJava(testArguments);

System.out.println(output.getStderr());

Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestSmallHeap.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ public static void main(String[] args) throws Exception {

private static void verifySmallHeapSize(String gc, long expectedMaxHeap) throws Exception {
long minMaxHeap = 4 * 1024 * 1024;
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
OutputAnalyzer analyzer = ProcessTools.executeLimitedTestJava(
gc,
"-Xmx" + minMaxHeap,
"-XX:+PrintFlagsFinal",
VerifyHeapSize.class.getName());
OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
analyzer.shouldHaveExitValue(0);

expectedMaxHeap = Math.max(expectedMaxHeap, minMaxHeap);
Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestVerifyDuringStartup.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@

public class TestVerifyDuringStartup {
public static void main(String args[]) throws Exception {
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
OutputAnalyzer output = ProcessTools.executeTestJava(
"-XX:-UseTLAB",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+VerifyDuringStartup",
"-Xlog:gc+verify=debug",
"-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());

System.out.println("Output:\n" + output.getOutput());

Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestVerifySilently.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ private static OutputAnalyzer runTest(boolean verifySilently) throws Exception {
"-XX:+VerifyAfterGC",
(verifySilently ? "-Xlog:gc":"-Xlog:gc+verify=debug"),
TestVerifySilentlyRunSystemGC.class.getName()});
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(vmOpts);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = ProcessTools.executeLimitedTestJava(vmOpts);

System.out.println("Output:\n" + output.getOutput());
return output;
Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/TestVerifySubSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ private static OutputAnalyzer runTest(String subset) throws Exception {
"-Xlog:gc+verify=debug",
"-XX:VerifySubSet="+subset,
TestVerifySubSetRunSystemGC.class.getName()});
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(vmOpts);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = ProcessTools.executeLimitedTestJava(vmOpts);

System.out.println("Output:\n" + output.getOutput());
return output;
Expand Down
17 changes: 17 additions & 0 deletions test/hotspot/jtreg/gc/arguments/GCArguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.List;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

/**
Expand Down Expand Up @@ -81,4 +82,20 @@ static public ProcessBuilder createTestJavaProcessBuilder(List<String> arguments
static public ProcessBuilder createTestJavaProcessBuilder(String... arguments) {
return ProcessTools.createTestJavaProcessBuilder(withDefaults(arguments));
}

static public OutputAnalyzer executeLimitedTestJava(List<String> arguments) throws Exception {
return executeLimitedTestJava(arguments.toArray(String[]::new));
}

static public OutputAnalyzer executeLimitedTestJava(String... arguments) throws Exception {
return ProcessTools.executeLimitedTestJava(withDefaults(arguments));
}

static public OutputAnalyzer executeTestJava(List<String> arguments) throws Exception {
return executeTestJava(arguments.toArray(String[]::new));
}

static public OutputAnalyzer executeTestJava(String... arguments) throws Exception {
return ProcessTools.executeTestJava(withDefaults(arguments));
}
}
4 changes: 1 addition & 3 deletions test/hotspot/jtreg/gc/arguments/TestAggressiveHeap.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ public static void main(String args[]) throws Exception {
" *bool +UseParallelGC *= *true +\\{product\\} *\\{command line\\}";

private static void testFlag() throws Exception {
ProcessBuilder pb = GCArguments.createTestJavaProcessBuilder(
OutputAnalyzer output = GCArguments.executeTestJava(
option, heapSizeOption, "-XX:+PrintFlagsFinal", "-version");

OutputAnalyzer output = new OutputAnalyzer(pb.start());

output.shouldHaveExitValue(0);

String value = output.firstMatch(parallelGCPattern);
Expand Down
12 changes: 4 additions & 8 deletions test/hotspot/jtreg/gc/arguments/TestCompressedClassFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,13 @@
public class TestCompressedClassFlags {
public static void main(String[] args) throws Exception {
if (Platform.is64bit()) {
OutputAnalyzer output = runJava("-XX:CompressedClassSpaceSize=1g",
"-XX:-UseCompressedClassPointers",
"-version");
OutputAnalyzer output = GCArguments.executeTestJava(
"-XX:CompressedClassSpaceSize=1g",
"-XX:-UseCompressedClassPointers",
"-version");
output.shouldContain("warning");
output.shouldNotContain("error");
output.shouldHaveExitValue(0);
}
}

private static OutputAnalyzer runJava(String ... args) throws Exception {
ProcessBuilder pb = GCArguments.createTestJavaProcessBuilder(args);
return new OutputAnalyzer(pb.start());
}
}
15 changes: 7 additions & 8 deletions test/hotspot/jtreg/gc/arguments/TestDisableDefaultGC.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@
public class TestDisableDefaultGC {
public static void main(String[] args) throws Exception {
// Start VM, disabling all possible default GCs
ProcessBuilder pb = GCArguments.createTestJavaProcessBuilder("-XX:-UseSerialGC",
"-XX:-UseParallelGC",
"-XX:-UseG1GC",
"-XX:-UseZGC",
"-XX:+UnlockExperimentalVMOptions",
"-XX:-UseShenandoahGC",
"-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = GCArguments.executeTestJava("-XX:-UseSerialGC",
"-XX:-UseParallelGC",
"-XX:-UseG1GC",
"-XX:-UseZGC",
"-XX:+UnlockExperimentalVMOptions",
"-XX:-UseShenandoahGC",
"-version");
output.shouldMatch("Garbage collector not selected");
output.shouldHaveExitValue(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ private static void runG1ConcMarkStepDurationMillisTest(String expectedValue, in

Collections.addAll(vmOpts, "-XX:+UseG1GC", "-XX:G1ConcMarkStepDurationMillis="+expectedValue, "-XX:+PrintFlagsFinal", "-version");

ProcessBuilder pb = GCArguments.createTestJavaProcessBuilder(vmOpts);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = GCArguments.executeTestJava(vmOpts);

output.shouldHaveExitValue(expectedResult == PASS ? 0 : 1);
String stdout = output.getStdout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ private static void runG1ConcRefinementThreadsTest(String[] passedOpts,
}
Collections.addAll(vmOpts, "-XX:+UseG1GC", "-XX:+PrintFlagsFinal", "-version");

ProcessBuilder pb = GCArguments.createTestJavaProcessBuilder(vmOpts);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = GCArguments.executeTestJava(vmOpts);

output.shouldHaveExitValue(0);
String stdout = output.getStdout();
Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/arguments/TestG1HeapRegionSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ private static void checkG1HeapRegionSize(String[] flags, int expectedValue, int
flagList.add("-XX:+PrintFlagsFinal");
flagList.add("-version");

ProcessBuilder pb = GCArguments.createTestJavaProcessBuilder(flagList);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = GCArguments.executeTestJava(flagList);
output.shouldHaveExitValue(exitValue);

if (exitValue == 0) {
Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/arguments/TestG1PercentageOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ private static final class OptionDescription {
};

private static void check(String flag, boolean is_valid) throws Exception {
ProcessBuilder pb = GCArguments.createTestJavaProcessBuilder("-XX:+UseG1GC", flag, "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = GCArguments.executeTestJava("-XX:+UseG1GC", flag, "-version");
if (is_valid) {
output.shouldHaveExitValue(0);
} else {
Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/arguments/TestG1RemSetFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ private static void checkG1RemSetFlags(String[] flags, int exitValue) throws Exc
flagList.add("-XX:+PrintFlagsFinal");
flagList.add("-version");

ProcessBuilder pb = GCArguments.createTestJavaProcessBuilder(flagList);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
OutputAnalyzer output = GCArguments.executeTestJava(flagList);
output.shouldHaveExitValue(exitValue);
}

Expand Down
3 changes: 1 addition & 2 deletions test/hotspot/jtreg/gc/arguments/TestHeapFreeRatio.java