Skip to content

Commit

Permalink
8317228: GC: Make TestXXXHeapSizeFlags use createTestJvm
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken
Backport-of: 7ca0ae94159ac0fd2df23ee1a1e8cf626ce31048
  • Loading branch information
Andrew Lu committed Jul 30, 2024
1 parent a09c615 commit 22fa6b8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 18 deletions.
3 changes: 2 additions & 1 deletion test/hotspot/jtreg/TEST.ROOT
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
# randomness: test uses randomness, test cases differ from run to run
# cgroups: test uses cgroups
# external-dep: test requires external dependencies to work
keys=cte_test jcmd nmt regression gc stress metaspace headful intermittent randomness cgroups external-dep
# flag-sensitive: test is sensitive to certain flags and might fail when flags are passed using -vmoptions and -javaoptions
keys=cte_test jcmd nmt regression gc stress metaspace headful intermittent randomness cgroups external-dep flag-sensitive

groups=TEST.groups TEST.quick-groups

Expand Down
6 changes: 3 additions & 3 deletions test/hotspot/jtreg/gc/arguments/TestG1HeapSizeFlags.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,10 +25,10 @@

/*
* @test TestG1HeapSizeFlags
* @key gc
* @bug 8006088
* @requires vm.gc.G1
* @summary Tests argument processing for initial and maximum heap size for the G1 collector
* @key gc flag-sensitive
* @requires vm.gc.G1 & vm.opt.x.Xmx == null & vm.opt.x.Xms == null & vm.opt.MinHeapSize == null & vm.opt.MaxHeapSize == null & vm.opt.InitialHeapSize == null
* @library /test/lib
* @library /
* @modules java.base/jdk.internal.misc
Expand Down
12 changes: 6 additions & 6 deletions test/hotspot/jtreg/gc/arguments/TestMaxHeapSizeTools.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,10 +23,10 @@

package gc.arguments;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
Expand Down Expand Up @@ -98,7 +98,7 @@ private static long align_up(long value, long alignment) {
}

private static void getNewOldSize(String gcflag, long[] values) throws Exception {
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(gcflag,
ProcessBuilder pb = GCArguments.createTestJvm(gcflag,
"-XX:+PrintFlagsFinal", "-version");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
output.shouldHaveExitValue(0);
Expand Down Expand Up @@ -168,7 +168,7 @@ public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname,
finalargs.add(classname);
finalargs.addAll(Arrays.asList(arguments));

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

Expand Down Expand Up @@ -268,7 +268,7 @@ private static void shouldContainOrNot(OutputAnalyzer output, boolean contains,
}

private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception {
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(flags);
ProcessBuilder pb = GCArguments.createTestJvm(flags);
OutputAnalyzer output = new OutputAnalyzer(pb.start());
shouldContainOrNot(output, hasWarning, "Warning");
shouldContainOrNot(output, hasError, "Error");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,11 +25,11 @@

/*
* @test TestParallelHeapSizeFlags
* @key gc
* @bug 8006088
* @summary Tests argument processing for initial and maximum heap size for the
* parallel collectors.
* @requires vm.gc.Parallel
* @key gc flag-sensitive
* @requires vm.gc.Parallel & vm.opt.x.Xmx == null & vm.opt.x.Xms == null & vm.opt.MinHeapSize == null & vm.opt.MaxHeapSize == null & vm.opt.InitialHeapSize == null
* @library /test/lib
* @library /
* @modules java.base/jdk.internal.misc
Expand Down
5 changes: 3 additions & 2 deletions test/hotspot/jtreg/gc/arguments/TestSerialHeapSizeFlags.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,9 +25,10 @@

/*
* @test TestSerialHeapSizeFlags
* @key gc
* @bug 8006088
* @summary Tests argument processing for initial and maximum heap size for the Serial collector
* @key gc flag-sensitive
* @requires vm.gc.Serial & vm.opt.x.Xmx == null & vm.opt.x.Xms == null & vm.opt.MinHeapSize == null & vm.opt.MaxHeapSize == null & vm.opt.InitialHeapSize == null
* @library /test/lib
* @library /
* @modules java.base/jdk.internal.misc
Expand Down
40 changes: 37 additions & 3 deletions test/jtreg-ext/requires/VMProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import sun.hotspot.code.Compiler;
import sun.hotspot.cpuinfo.CPUInfo;
Expand Down Expand Up @@ -80,6 +82,10 @@ public void put(String key, Supplier<String> s) {
}
map.put(key, value);
}

public void putAll(Map<String, String> map) {
map.entrySet().forEach(e -> put(e.getKey(), () -> e.getValue()));
}
}

/**
Expand Down Expand Up @@ -123,6 +129,7 @@ public Map<String, String> call() {
map.put("vm.musl", this::isMusl);
map.put("release.implementor", this::implementor);
map.put("vm.flagless", this::isFlagless);
map.putAll(xOptFlags()); // -Xmx4g -> @requires vm.opt.x.Xmx == "4g" )
vmGC(map); // vm.gc.X = true/false
vmOptFinalFlags(map);

Expand Down Expand Up @@ -582,9 +589,7 @@ private String isFlagless() {
return "" + "true".equalsIgnoreCase(flagless);
}

List<String> allFlags = new ArrayList<String>();
Collections.addAll(allFlags, System.getProperty("test.vm.opts", "").trim().split("\\s+"));
Collections.addAll(allFlags, System.getProperty("test.java.opts", "").trim().split("\\s+"));
List<String> allFlags = allFlags().collect(Collectors.toList());

// check -XX flags
var ignoredXXFlags = Set.of(
Expand Down Expand Up @@ -627,6 +632,35 @@ private String isFlagless() {
return "" + result;
}

private Stream<String> allFlags() {
return Stream.of((System.getProperty("test.vm.opts", "") + " " + System.getProperty("test.java.opts", "")).trim().split("\\s+"));
}

/**
* Parses extra options, options that start with -X excluding the
* bare -X option (as it is not considered an extra option).
* Ignores extra options not starting with -X
*
* This could be improved to handle extra options not starting
* with -X as well as "standard" options.
*/
private Map<String, String> xOptFlags() {
return allFlags()
.filter(s -> s.startsWith("-X") && !s.startsWith("-XX:") && !s.equals("-X"))
.map(s -> s.replaceFirst("-", ""))
.map(flag -> {
String[] split = flag.split("[:0123456789]", 2);
return split.length == 2 ? new String[] {split[0], flag.substring(split[0].length(), flag.length() - split[1].length()), split[1]}
: split;
})
.collect(Collectors.toMap(a -> "vm.opt.x." + a[0],
a -> (a.length == 1)
? "true" // -Xnoclassgc
: (a[1].equals(":")
? a[2] // ["-XshowSettings", ":", "system"]
: a[1] + a[2]))); // ["-Xmx", "4", "g"]
}

/**
* Dumps the map to the file if the file name is given as the property.
* This functionality could be helpful to know context in the real
Expand Down

0 comments on commit 22fa6b8

Please sign in to comment.