Skip to content

Commit 666e489

Browse files
author
Andrew Lu
committedJul 26, 2024
8317228: GC: Make TestXXXHeapSizeFlags use createTestJvm
Reviewed-by: mbaesken Backport-of: 7ca0ae94159ac0fd2df23ee1a1e8cf626ce31048
1 parent c18ddd8 commit 666e489

File tree

6 files changed

+54
-15
lines changed

6 files changed

+54
-15
lines changed
 

‎test/hotspot/jtreg/TEST.ROOT

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
# randomness: test uses randomness, test cases differ from run to run
3434
# cgroups: test uses cgroups
3535
# external-dep: test requires external dependencies to work
36-
keys=stress headful intermittent randomness cgroups external-dep
36+
# flag-sensitive: test is sensitive to certain flags and might fail when flags are passed using -vmoptions and -javaoptions
37+
keys=stress headful intermittent randomness cgroups external-dep flag-sensitive
3738

3839
groups=TEST.groups TEST.quick-groups
3940

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

+3-2
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

+6-6
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

+3-2
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

+3-1
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

+37-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import java.util.function.Supplier;
4747
import java.util.regex.Matcher;
4848
import java.util.regex.Pattern;
49+
import java.util.stream.Collectors;
50+
import java.util.stream.Stream;
4951

5052
import jdk.test.whitebox.code.Compiler;
5153
import jdk.test.whitebox.cpuinfo.CPUInfo;
@@ -80,6 +82,10 @@ public void put(String key, Supplier<String> s) {
8082
}
8183
map.put(key, value);
8284
}
85+
86+
public void putAll(Map<String, String> map) {
87+
map.entrySet().forEach(e -> put(e.getKey(), () -> e.getValue()));
88+
}
8389
}
8490

8591
/**
@@ -126,6 +132,7 @@ public Map<String, String> call() {
126132
map.put("release.implementor", this::implementor);
127133
map.put("jdk.containerized", this::jdkContainerized);
128134
map.put("vm.flagless", this::isFlagless);
135+
map.putAll(xOptFlags()); // -Xmx4g -> @requires vm.opt.x.Xmx == "4g" )
129136
vmGC(map); // vm.gc.X = true/false
130137
vmOptFinalFlags(map);
131138

@@ -583,9 +590,7 @@ private String isFlagless() {
583590
return "" + "true".equalsIgnoreCase(flagless);
584591
}
585592

586-
List<String> allFlags = new ArrayList<String>();
587-
Collections.addAll(allFlags, System.getProperty("test.vm.opts", "").trim().split("\\s+"));
588-
Collections.addAll(allFlags, System.getProperty("test.java.opts", "").trim().split("\\s+"));
593+
List<String> allFlags = allFlags().toList();
589594

590595
// check -XX flags
591596
var ignoredXXFlags = Set.of(
@@ -632,6 +637,35 @@ private String isFlagless() {
632637
return "" + result;
633638
}
634639

640+
private Stream<String> allFlags() {
641+
return Stream.of((System.getProperty("test.vm.opts", "") + " " + System.getProperty("test.java.opts", "")).trim().split("\\s+"));
642+
}
643+
644+
/**
645+
* Parses extra options, options that start with -X excluding the
646+
* bare -X option (as it is not considered an extra option).
647+
* Ignores extra options not starting with -X
648+
*
649+
* This could be improved to handle extra options not starting
650+
* with -X as well as "standard" options.
651+
*/
652+
private Map<String, String> xOptFlags() {
653+
return allFlags()
654+
.filter(s -> s.startsWith("-X") && !s.startsWith("-XX:") && !s.equals("-X"))
655+
.map(s -> s.replaceFirst("-", ""))
656+
.map(flag -> {
657+
String[] split = flag.split("[:0123456789]", 2);
658+
return split.length == 2 ? new String[] {split[0], flag.substring(split[0].length(), flag.length() - split[1].length()), split[1]}
659+
: split;
660+
})
661+
.collect(Collectors.toMap(a -> "vm.opt.x." + a[0],
662+
a -> (a.length == 1)
663+
? "true" // -Xnoclassgc
664+
: (a[1].equals(":")
665+
? a[2] // ["-XshowSettings", ":", "system"]
666+
: a[1] + a[2]))); // ["-Xmx", "4", "g"]
667+
}
668+
635669
/**
636670
* Dumps the map to the file if the file name is given as the property.
637671
* This functionality could be helpful to know context in the real

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jul 26, 2024

@openjdk-notifier[bot]
Please sign in to comment.