Skip to content
Permalink
Browse files
8243565: some gc tests use 'test.java.opts' and not 'test.vm.opts'
Reviewed-by: clanger
Backport-of: d84e4f1
  • Loading branch information
GoeLin committed Oct 10, 2022
1 parent 9c29d00 commit 3ce188ba7de1348309d9b7bc3a8ccdbb6d18e5e5
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 165 deletions.
@@ -29,7 +29,7 @@
* @requires vm.gc != "Z" & os.family != "aix"
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @run main gc.TestAllocateHeapAt
* @run driver gc.TestAllocateHeapAt
*/

import jdk.test.lib.JDKToolFinder;
@@ -40,28 +40,15 @@

public class TestAllocateHeapAt {
public static void main(String args[]) throws Exception {
ArrayList<String> vmOpts = new ArrayList<>();

String testVmOptsStr = System.getProperty("test.java.opts");
if (!testVmOptsStr.isEmpty()) {
String[] testVmOpts = testVmOptsStr.split(" ");
Collections.addAll(vmOpts, testVmOpts);
}
String test_dir = System.getProperty("test.dir", ".");
Collections.addAll(vmOpts, new String[] {"-XX:AllocateHeapAt=" + test_dir,
"-Xlog:gc+heap=info",
"-Xmx32m",
"-Xms32m",
"-version"});

System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));
for (int i = 0; i < vmOpts.size(); i += 1) {
System.out.print(" " + vmOpts.get(i));
}
System.out.println();

ProcessBuilder pb =
ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
String[] flags = {
"-XX:AllocateHeapAt=" + test_dir,
"-Xlog:gc+heap=info",
"-Xmx32m",
"-Xms32m",
"-version"};

ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, flags);
OutputAnalyzer output = new OutputAnalyzer(pb.start());

System.out.println("Output:\n" + output.getOutput());
@@ -29,47 +29,31 @@
* @requires vm.gc != "Z" & os.family != "aix"
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @run main gc.TestAllocateHeapAtError
* @run driver gc.TestAllocateHeapAtError
*/

import java.io.File;
import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;

public class TestAllocateHeapAtError {
public static void main(String args[]) throws Exception {
ArrayList<String> vmOpts = new ArrayList<>();

String testVmOptsStr = System.getProperty("test.java.opts");
if (!testVmOptsStr.isEmpty()) {
String[] testVmOpts = testVmOptsStr.split(" ");
Collections.addAll(vmOpts, testVmOpts);
}
String test_dir = System.getProperty("test.dir", ".");

File f = null;
do {
f = new File(test_dir, UUID.randomUUID().toString());
} while(f.exists());

Collections.addAll(vmOpts, new String[] {"-XX:AllocateHeapAt=" + f.getName(),
"-Xlog:gc+heap=info",
"-Xmx32m",
"-Xms32m",
"-version"});

System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));
for (int i = 0; i < vmOpts.size(); i += 1) {
System.out.print(" " + vmOpts.get(i));
}
System.out.println();
String[] flags = {
"-XX:AllocateHeapAt=" + f.getName(),
"-Xlog:gc+heap=info",
"-Xmx32m",
"-Xms32m",
"-version"};

ProcessBuilder pb =
ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, flags);
OutputAnalyzer output = new OutputAnalyzer(pb.start());

System.out.println("Output:\n" + output.getOutput());
@@ -29,7 +29,7 @@
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @requires vm.bits == "64" & vm.gc != "Z" & os.family != "aix"
* @run main/timeout=360 gc.TestAllocateHeapAtMultiple
* @run driver/timeout=360 gc.TestAllocateHeapAtMultiple
*/

import jdk.test.lib.JDKToolFinder;
@@ -40,48 +40,30 @@

public class TestAllocateHeapAtMultiple {
public static void main(String args[]) throws Exception {
ArrayList<String> vmOpts = new ArrayList<>();
String[] testVmOpts = null;
ArrayList<String> flags = new ArrayList<>();

String test_dir = System.getProperty("test.dir", ".");

String testVmOptsStr = System.getProperty("test.java.opts");
if (!testVmOptsStr.isEmpty()) {
testVmOpts = testVmOptsStr.split(" ");
}

// Extra options for each of the sub-tests
String[] extraOptsList = new String[] {
"-Xmx32m -Xms32m -XX:+UseCompressedOops", // 1. With compressedoops enabled.
"-Xmx32m -Xms32m -XX:-UseCompressedOops", // 2. With compressedoops disabled.
"-Xmx32m -Xms32m -XX:HeapBaseMinAddress=3g", // 3. With user specified HeapBaseMinAddress.
"-Xmx32m -Xms32m -XX:+UseLargePages", // 4. Set UseLargePages.
"-Xmx32m -Xms32m -XX:+UseNUMA" // 5. Set UseNUMA.
// Extra flags for each of the sub-tests
String[][] extraFlagsList = new String[][] {
{"-Xmx32m", "-Xms32m", "-XX:+UseCompressedOops"}, // 1. With compressedoops enabled.
{"-Xmx32m", "-Xms32m", "-XX:-UseCompressedOops"}, // 2. With compressedoops disabled.
{"-Xmx32m", "-Xms32m", "-XX:HeapBaseMinAddress=3g"}, // 3. With user specified HeapBaseMinAddress.
{"-Xmx32m", "-Xms32m", "-XX:+UseLargePages"}, // 4. Set UseLargePages.
{"-Xmx32m", "-Xms32m", "-XX:+UseNUMA"} // 5. Set UseNUMA.
};

for(String extraOpts : extraOptsList) {
vmOpts.clear();
if(testVmOpts != null) {
Collections.addAll(vmOpts, testVmOpts);
}
// Add extra options specific to the sub-test.
String[] extraOptsArray = extraOpts.split(" ");
if(extraOptsArray != null) {
Collections.addAll(vmOpts, extraOptsArray);
}
// Add common options
Collections.addAll(vmOpts, new String[] {"-XX:AllocateHeapAt=" + test_dir,
"-Xlog:gc+heap=info",
"-version"});

System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));
for (int i = 0; i < vmOpts.size(); i += 1) {
System.out.print(" " + vmOpts.get(i));
}
System.out.println();
for (String[] extraFlags : extraFlagsList) {
flags.clear();
// Add extra flags specific to the sub-test.
Collections.addAll(flags, extraFlags);
// Add common flags
Collections.addAll(flags, new String[] {"-XX:AllocateHeapAt=" + test_dir,
"-Xlog:gc+heap=info",
"-version"});

ProcessBuilder pb =
ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
ProcessTools.createJavaProcessBuilder(true, flags.toArray(String[]::new));
OutputAnalyzer output = new OutputAnalyzer(pb.start());

System.out.println("Output:\n" + output.getOutput());
@@ -30,38 +30,22 @@
* @requires vm.gc != "Z"
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @run main gc.TestVerifyDuringStartup
* @run driver gc.TestVerifyDuringStartup
*/

import jdk.test.lib.JDKToolFinder;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import java.util.ArrayList;
import java.util.Collections;

public class TestVerifyDuringStartup {
public static void main(String args[]) throws Exception {
ArrayList<String> vmOpts = new ArrayList<>();

String testVmOptsStr = System.getProperty("test.java.opts");
if (!testVmOptsStr.isEmpty()) {
String[] testVmOpts = testVmOptsStr.split(" ");
Collections.addAll(vmOpts, testVmOpts);
}
Collections.addAll(vmOpts, new String[] {"-XX:-UseTLAB",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+VerifyDuringStartup",
"-Xlog:gc+verify=debug",
"-version"});

System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));
for (int i = 0; i < vmOpts.size(); i += 1) {
System.out.print(" " + vmOpts.get(i));
}
System.out.println();

ProcessBuilder pb =
ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
String[] flags = {
"-XX:-UseTLAB",
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+VerifyDuringStartup",
"-Xlog:gc+verify=debug",
"-version"};

ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, flags);
OutputAnalyzer output = new OutputAnalyzer(pb.start());

System.out.println("Output:\n" + output.getOutput());
@@ -152,10 +152,9 @@ private static long valueAfter(String source, String match) {
* @param vmargs Arguments to the VM to run
* @param classname Name of the class to run
* @param arguments Arguments to the class
* @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string
* @return The OutputAnalyzer with the results for the invocation.
*/
public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {
public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments) throws Exception {
ArrayList<String> finalargs = new ArrayList<String>();

String[] whiteboxOpts = new String[] {
@@ -164,30 +163,20 @@ public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname,
"-cp", System.getProperty("java.class.path"),
};

if (useTestDotJavaDotOpts) {
// System.getProperty("test.java.opts") is '' if no options is set,
// we need to skip such a result
String[] externalVMOpts = new String[0];
if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) {
externalVMOpts = System.getProperty("test.java.opts").split(" ");
}
finalargs.addAll(Arrays.asList(externalVMOpts));
}

finalargs.addAll(Arrays.asList(vmargs));
finalargs.addAll(Arrays.asList(whiteboxOpts));
finalargs.add(classname);
finalargs.addAll(Arrays.asList(arguments));

ProcessBuilder pb = GCArguments.createJavaProcessBuilder(finalargs.toArray(new String[0]));
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(finalargs.toArray(String[]::new));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);

return output;
}

private static void getMinInitialMaxHeap(String[] args, MinInitialMaxValues val) throws Exception {
OutputAnalyzer output = runWhiteBoxTest(args, ErgoArgsPrinter.class.getName(), new String[] {}, false);
OutputAnalyzer output = runWhiteBoxTest(args, ErgoArgsPrinter.class.getName(), new String[] {});

// the output we watch for has the following format:
//
@@ -35,8 +35,8 @@
* java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm gc.arguments.TestUseCompressedOopsErgo -XX:+UseSerialGC
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run driver gc.arguments.TestUseCompressedOopsErgo -XX:+UseSerialGC
*/

/*
@@ -51,9 +51,9 @@
* java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm gc.arguments.TestUseCompressedOopsErgo -XX:+UseParallelGC
* @run main/othervm gc.arguments.TestUseCompressedOopsErgo -XX:+UseParallelGC -XX:-UseParallelOldGC
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run driver gc.arguments.TestUseCompressedOopsErgo -XX:+UseParallelGC
* @run driver gc.arguments.TestUseCompressedOopsErgo -XX:+UseParallelGC -XX:-UseParallelOldGC
*/

/*
@@ -68,8 +68,8 @@
* java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm gc.arguments.TestUseCompressedOopsErgo -XX:+UseG1GC
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run driver gc.arguments.TestUseCompressedOopsErgo -XX:+UseG1GC
*/

/*
@@ -84,8 +84,8 @@
* java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm gc.arguments.TestUseCompressedOopsErgo -XX:+UseConcMarkSweepGC
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run driver gc.arguments.TestUseCompressedOopsErgo -XX:+UseConcMarkSweepGC
*/

/*
@@ -100,8 +100,8 @@
* java.management/sun.management
* @build sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm gc.arguments.TestUseCompressedOopsErgo -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run driver gc.arguments.TestUseCompressedOopsErgo -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC
*/

public class TestUseCompressedOopsErgo {
@@ -56,7 +56,7 @@ private static long getCompressedClassSpaceSize() {


public static long getMaxHeapForCompressedOops(String[] vmargs) throws Exception {
OutputAnalyzer output = runWhiteBoxTest(vmargs, DetermineMaxHeapForCompressedOops.class.getName(), new String[] {}, false);
OutputAnalyzer output = runWhiteBoxTest(vmargs, DetermineMaxHeapForCompressedOops.class.getName(), new String[] {});
return Long.parseLong(output.getStdout());
}

@@ -78,10 +78,9 @@ public static boolean is64bitVM() {
* @param vmargs Arguments to the VM to run
* @param classname Name of the class to run
* @param arguments Arguments to the class
* @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string
* @return The OutputAnalyzer with the results for the invocation.
*/
public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {
public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments) throws Exception {
ArrayList<String> finalargs = new ArrayList<String>();

String[] whiteboxOpts = new String[] {
@@ -90,22 +89,12 @@ public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname,
"-cp", System.getProperty("java.class.path"),
};

if (useTestDotJavaDotOpts) {
// System.getProperty("test.java.opts") is '' if no options is set,
// we need to skip such a result
String[] externalVMOpts = new String[0];
if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) {
externalVMOpts = System.getProperty("test.java.opts").split(" ");
}
finalargs.addAll(Arrays.asList(externalVMOpts));
}

finalargs.addAll(Arrays.asList(vmargs));
finalargs.addAll(Arrays.asList(whiteboxOpts));
finalargs.add(classname);
finalargs.addAll(Arrays.asList(arguments));

ProcessBuilder pb = GCArguments.createJavaProcessBuilder(finalargs.toArray(new String[0]));
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(finalargs.toArray(String[]::new));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
return output;
@@ -115,7 +104,7 @@ private static String[] join(String[] part1, String part2) {
ArrayList<String> result = new ArrayList<String>();
result.addAll(Arrays.asList(part1));
result.add(part2);
return result.toArray(new String[0]);
return result.toArray(String[]::new);
}

public static void checkCompressedOopsErgo(String[] gcflags) throws Exception {

1 comment on commit 3ce188b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.