Skip to content

Commit 8311805

Browse files
lkorinthpull[bot]
authored andcommitted
8317228: GC: Make TestXXXHeapSizeFlags use createTestJvm
Reviewed-by: sjohanss, ayang
1 parent 144eed7 commit 8311805

File tree

6 files changed

+50
-16
lines changed

6 files changed

+50
-16
lines changed

test/hotspot/jtreg/TEST.ROOT

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
# intermittent: flaky test, known to fail intermittently
3333
# randomness: test uses randomness, test cases differ from run to run
3434
# cgroups: test uses cgroups
35-
keys=stress headful intermittent randomness cgroups
35+
# flag-sensitive: test is sensitive to certain flags and might fail when flags are passed using -vmoptions and -javaoptions
36+
keys=stress headful intermittent randomness cgroups flag-sensitive
3637

3738
groups=TEST.groups TEST.quick-groups
3839

test/hotspot/jtreg/gc/arguments/TestG1HeapSizeFlags.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,9 @@
2626
/*
2727
* @test TestG1HeapSizeFlags
2828
* @bug 8006088
29-
* @requires vm.gc.G1
3029
* @summary Tests argument processing for initial and maximum heap size for the G1 collector
30+
* @key flag-sensitive
31+
* @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
3132
* @library /test/lib
3233
* @library /
3334
* @modules java.base/jdk.internal.misc

test/hotspot/jtreg/gc/arguments/TestMaxHeapSizeTools.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,10 +23,10 @@
2323

2424
package gc.arguments;
2525

26-
import java.util.regex.Matcher;
27-
import java.util.regex.Pattern;
2826
import java.util.ArrayList;
2927
import java.util.Arrays;
28+
import java.util.regex.Matcher;
29+
import java.util.regex.Pattern;
3030

3131
import jdk.test.lib.process.OutputAnalyzer;
3232
import jdk.test.whitebox.WhiteBox;
@@ -115,7 +115,7 @@ private static long align_up(long value, long alignment) {
115115
}
116116

117117
private static void getNewOldSize(String gcflag, long[] values) throws Exception {
118-
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(gcflag,
118+
ProcessBuilder pb = GCArguments.createTestJvm(gcflag,
119119
"-XX:+PrintFlagsFinal", "-version");
120120
OutputAnalyzer output = new OutputAnalyzer(pb.start());
121121
output.shouldHaveExitValue(0);
@@ -208,7 +208,7 @@ public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname,
208208
finalargs.add(classname);
209209
finalargs.addAll(Arrays.asList(arguments));
210210

211-
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(finalargs.toArray(String[]::new));
211+
ProcessBuilder pb = GCArguments.createTestJvm(finalargs.toArray(String[]::new));
212212
OutputAnalyzer output = new OutputAnalyzer(pb.start());
213213
output.shouldHaveExitValue(0);
214214

@@ -308,7 +308,7 @@ private static void shouldContainOrNot(OutputAnalyzer output, boolean contains,
308308
}
309309

310310
private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception {
311-
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(flags);
311+
ProcessBuilder pb = GCArguments.createTestJvm(flags);
312312
OutputAnalyzer output = new OutputAnalyzer(pb.start());
313313
shouldContainOrNot(output, hasWarning, "Warning");
314314
shouldContainOrNot(output, hasError, "Error");

test/hotspot/jtreg/gc/arguments/TestParallelHeapSizeFlags.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,8 @@
2828
* @bug 8006088
2929
* @summary Tests argument processing for initial and maximum heap size for the
3030
* parallel collectors.
31-
* @requires vm.gc.Parallel
31+
* @key flag-sensitive
32+
* @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
3233
* @library /test/lib
3334
* @library /
3435
* @modules java.base/jdk.internal.misc

test/hotspot/jtreg/gc/arguments/TestSerialHeapSizeFlags.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,8 @@
2727
* @test TestSerialHeapSizeFlags
2828
* @bug 8006088
2929
* @summary Tests argument processing for initial and maximum heap size for the Serial collector
30+
* @key flag-sensitive
31+
* @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
3032
* @library /test/lib
3133
* @library /
3234
* @modules java.base/jdk.internal.misc

test/jtreg-ext/requires/VMProps.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@
4747
import java.util.function.Supplier;
4848
import java.util.regex.Matcher;
4949
import java.util.regex.Pattern;
50+
import java.util.stream.Collectors;
51+
import java.util.stream.Stream;
5052

5153
import jdk.internal.foreign.CABI;
52-
5354
import jdk.test.whitebox.code.Compiler;
5455
import jdk.test.whitebox.cpuinfo.CPUInfo;
5556
import jdk.test.whitebox.gc.GC;
@@ -83,6 +84,10 @@ public void put(String key, Supplier<String> s) {
8384
}
8485
map.put(key, value);
8586
}
87+
88+
public void putAll(Map<String, String> map) {
89+
map.entrySet().forEach(e -> put(e.getKey(), () -> e.getValue()));
90+
}
8691
}
8792

8893
/**
@@ -135,6 +140,7 @@ public Map<String, String> call() {
135140
map.put("jdk.containerized", this::jdkContainerized);
136141
map.put("vm.flagless", this::isFlagless);
137142
map.put("jdk.foreign.linker", this::jdkForeignLinker);
143+
map.putAll(xOptFlags()); // -Xmx4g -> @requires vm.opt.x.Xmx == "4g" )
138144
vmGC(map); // vm.gc.X = true/false
139145
vmGCforCDS(map); // may set vm.gc
140146
vmOptFinalFlags(map);
@@ -662,9 +668,7 @@ private String isFlagless() {
662668
return "" + result;
663669
}
664670

665-
List<String> allFlags = new ArrayList<String>();
666-
Collections.addAll(allFlags, System.getProperty("test.vm.opts", "").trim().split("\\s+"));
667-
Collections.addAll(allFlags, System.getProperty("test.java.opts", "").trim().split("\\s+"));
671+
List<String> allFlags = allFlags().toList();
668672

669673
// check -XX flags
670674
var ignoredXXFlags = Set.of(
@@ -711,6 +715,31 @@ private String isFlagless() {
711715
return "" + result;
712716
}
713717

718+
private Stream<String> allFlags() {
719+
return Stream.of((System.getProperty("test.vm.opts", "") + " " + System.getProperty("test.java.opts", "")).trim().split("\\s+"));
720+
}
721+
722+
/**
723+
* Parses extra options, options that start with -X excluding the
724+
* bare -X option (as it is not considered an extra option).
725+
* Ignores extra options not starting with -X
726+
*
727+
* This could be improved to handle extra options not starting
728+
* with -X as well as "standard" options.
729+
*/
730+
private Map<String, String> xOptFlags() {
731+
return allFlags()
732+
.filter(s -> s.startsWith("-X") && !s.startsWith("-XX:") && !s.equals("-X"))
733+
.map(s -> s.replaceFirst("-", ""))
734+
.map(flag -> flag.splitWithDelimiters("[:0123456789]", 2))
735+
.collect(Collectors.toMap(a -> "vm.opt.x." + a[0],
736+
a -> (a.length == 1)
737+
? "true" // -Xnoclassgc
738+
: (a[1].equals(":")
739+
? a[2] // ["-XshowSettings", ":", "system"]
740+
: a[1] + a[2]))); // ["-Xmx", "4", "g"]
741+
}
742+
714743
/*
715744
* A string indicating the foreign linker that is currently being used. See jdk.internal.foreign.CABI
716745
* for valid values.

0 commit comments

Comments
 (0)