Skip to content

Commit de0e5a2

Browse files
committedMar 21, 2023
8152432: Implement setting jtreg @requires properties vm.flavor, vm.bits, vm.compMode
Reviewed-by: phh, sgehwolf Backport-of: 24a9e0ac188a37dc57cc4d1bb8d8635abb4c4f89
1 parent ae6405f commit de0e5a2

File tree

5 files changed

+147
-17
lines changed

5 files changed

+147
-17
lines changed
 

‎hotspot/test/TEST.ROOT

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@
3030
keys=cte_test jcmd nmt regression gc stress
3131

3232
groups=TEST.groups [closed/TEST.groups]
33-
requires.properties=sun.arch.data.model
33+
34+
# Source files for classes that will be used at the beginning of each test suite run,
35+
# to determine additional characteristics of the system for use with the @requires tag.
36+
requires.extraPropDefns = ../../test/jtreg-ext/requires/VMProps.java
37+
requires.properties=sun.arch.data.model \
38+
vm.flavor \
39+
vm.bits

‎hotspot/test/runtime/Metaspace/MaxMetaspaceSizeTest.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,17 @@
2323

2424
import com.oracle.java.testlibrary.ProcessTools;
2525
import com.oracle.java.testlibrary.OutputAnalyzer;
26-
import com.oracle.java.testlibrary.Platform;
2726

2827
/*
2928
* @test MaxMetaspaceSizeTest
29+
* @requires vm.bits == "64"
3030
* @bug 8087291
3131
* @library /testlibrary
3232
* @run main/othervm MaxMetaspaceSizeTest
3333
*/
3434

3535
public class MaxMetaspaceSizeTest {
3636
public static void main(String... args) throws Exception {
37-
if (!Platform.is64bit()) {
38-
System.out.println("Test requires 64-bit JVM. Skipping...");
39-
return;
40-
}
4137
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
4238
"-Xmx1g",
4339
"-XX:InitialBootClassLoaderMetaspaceSize=4195328",

‎hotspot/test/runtime/NMT/HugeArenaTracking.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @test
2626
* @key nmt jcmd
2727
* @library /testlibrary /testlibrary/whitebox
28+
* @requires vm.bits == 64
2829
* @build HugeArenaTracking
2930
* @run main ClassFileInstaller sun.hotspot.WhiteBox
3031
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail HugeArenaTracking
@@ -38,10 +39,6 @@ public class HugeArenaTracking {
3839
private static final long GB = 1024 * 1024 * 1024;
3940

4041
public static void main(String args[]) throws Exception {
41-
if (!Platform.is64bit()) {
42-
System.out.println("Test requires 64-bit JVM. Skipping...");
43-
return;
44-
}
4542
OutputAnalyzer output;
4643
final WhiteBox wb = WhiteBox.getWhiteBox();
4744

‎hotspot/test/runtime/SharedArchiveFile/DefaultUseWithClient.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
/*
2525
* @test DefaultUseWithClient
2626
* @summary Test default behavior of sharing with -client
27+
* @requires os.family == "windows" & vm.bits == "32" & vm.flavor == "client"
2728
* @library /testlibrary
28-
* @run main/othervm -client DefaultUseWithClient
29+
* @run main/othervm DefaultUseWithClient
2930
* @bug 8032224
3031
*/
3132

@@ -37,12 +38,6 @@ public static void main(String[] args) throws Exception {
3738
String fileName = "test.jsa";
3839

3940
// On 32-bit windows CDS should be on by default in "-client" config
40-
// Skip this test on any other platform
41-
boolean is32BitWindowsClient = (Platform.isWindows() && Platform.is32bit() && Platform.isClient());
42-
if (!is32BitWindowsClient) {
43-
System.out.println("Test only applicable on 32-bit Windows Client VM. Skipping");
44-
return;
45-
}
4641

4742
// create the archive
4843
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(

‎test/jtreg-ext/requires/VMProps.java

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package requires;
24+
25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Paths;
28+
import java.util.ArrayList;
29+
import java.util.HashMap;
30+
import java.util.List;
31+
import java.util.Map;
32+
import java.util.concurrent.Callable;
33+
import java.util.regex.Matcher;
34+
import java.util.regex.Pattern;
35+
36+
/**
37+
* The Class to be invoked by jtreg prior Test Suite execution to
38+
* collect information about VM.
39+
* Properties set by this Class will be available in the @requires expressions.
40+
*/
41+
public class VMProps implements Callable<Map<String, String>> {
42+
43+
/**
44+
* Collects information about VM properties.
45+
* This method will be invoked by jtreg.
46+
*
47+
* @return Map of property-value pairs.
48+
*/
49+
@Override
50+
public Map<String, String> call() {
51+
Map<String, String> map = new HashMap<>();
52+
map.put("vm.flavor", vmFlavor());
53+
map.put("vm.compMode", vmCompMode());
54+
map.put("vm.bits", vmBits());
55+
dump(map);
56+
return map;
57+
}
58+
59+
/**
60+
* @return VM type value extracted from the "java.vm.name" property.
61+
*/
62+
protected String vmFlavor() {
63+
// E.g. "Java HotSpot(TM) 64-Bit Server VM"
64+
String vmName = System.getProperty("java.vm.name");
65+
if (vmName == null) {
66+
return null;
67+
}
68+
69+
Pattern startP = Pattern.compile(".* (\\S+) VM");
70+
Matcher m = startP.matcher(vmName);
71+
if (m.matches()) {
72+
return m.group(1).toLowerCase();
73+
}
74+
return null;
75+
}
76+
77+
/**
78+
* @return VM compilation mode extracted from the "java.vm.info" property.
79+
*/
80+
protected String vmCompMode() {
81+
// E.g. "mixed mode"
82+
String vmInfo = System.getProperty("java.vm.info");
83+
if (vmInfo == null) {
84+
return null;
85+
}
86+
int k = vmInfo.toLowerCase().indexOf(" mode");
87+
if (k < 0) {
88+
return null;
89+
}
90+
vmInfo = vmInfo.substring(0, k);
91+
switch (vmInfo) {
92+
case "mixed" : return "Xmixed";
93+
case "compiled" : return "Xcomp";
94+
case "interpreted" : return "Xint";
95+
default: return null;
96+
}
97+
}
98+
99+
/**
100+
* @return VM bitness, the value of the "sun.arch.data.model" property.
101+
*/
102+
protected String vmBits() {
103+
return System.getProperty("sun.arch.data.model");
104+
}
105+
106+
/**
107+
* Dumps the map to the file if the file name is given as the property.
108+
* This functionality could be helpful to know context in the real
109+
* execution.
110+
*
111+
* @param map
112+
*/
113+
protected void dump(Map<String, String> map) {
114+
String dumpFileName = System.getProperty("vmprops.dump");
115+
if (dumpFileName == null) {
116+
return;
117+
}
118+
List<String> lines = new ArrayList<>();
119+
map.forEach((k,v) -> lines.add(k + ":" + v));
120+
try {
121+
Files.write(Paths.get(dumpFileName), lines);
122+
} catch (IOException e) {
123+
throw new RuntimeException("Failed to dump properties into '"
124+
+ dumpFileName + "'", e);
125+
}
126+
}
127+
128+
/**
129+
* This method is for the testing purpose only.
130+
* @param args
131+
*/
132+
public static void main(String args[]) {
133+
Map<String, String> map = new VMProps().call();
134+
map.forEach((k,v) -> System.out.println(k + ": '" + v + "'"));
135+
}
136+
}

0 commit comments

Comments
 (0)
Please sign in to comment.