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.nio.file.StandardOpenOption;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.concurrent.Callable;
34 import java.util.regex.Matcher;
35 import java.util.regex.Pattern;
36
37 import sun.hotspot.cpuinfo.CPUInfo;
38 import sun.hotspot.gc.GC;
39 import sun.hotspot.WhiteBox;
40 import jdk.test.lib.Platform;
41
42 /**
43 * The Class to be invoked by jtreg prior Test Suite execution to
44 * collect information about VM.
45 * Do not use any API's that may not be available in all target VMs.
46 * Properties set by this Class will be available in the @requires expressions.
52 /**
53 * Collects information about VM properties.
54 * This method will be invoked by jtreg.
55 *
56 * @return Map of property-value pairs.
57 */
58 @Override
59 public Map<String, String> call() {
60 Map<String, String> map = new HashMap<>();
61 map.put("vm.flavor", vmFlavor());
62 map.put("vm.compMode", vmCompMode());
63 map.put("vm.bits", vmBits());
64 map.put("vm.flightRecorder", vmFlightRecorder());
65 map.put("vm.simpleArch", vmArch());
66 map.put("vm.debug", vmDebug());
67 map.put("vm.jvmci", vmJvmci());
68 map.put("vm.emulatedClient", vmEmulatedClient());
69 map.put("vm.cpu.features", cpuFeatures());
70 map.put("vm.rtm.cpu", vmRTMCPU());
71 map.put("vm.rtm.os", vmRTMOS());
72 vmGC(map); // vm.gc.X = true/false
73
74 VMProps.dump(map);
75 return map;
76 }
77
78 /**
79 * @return vm.simpleArch value of "os.simpleArch" property of tested JDK.
80 */
81 protected String vmArch() {
82 String arch = System.getProperty("os.arch");
83 if (arch.equals("x86_64") || arch.equals("amd64")) {
84 return "x64";
85 }
86 else if (arch.contains("86")) {
87 return "x86";
88 } else {
89 return arch;
90 }
91 }
222
223 } else if (Platform.isLinux()) {
224 if (Platform.isPPC()) {
225 isRTMOS = (Platform.getOsVersionMajor() > 4) ||
226 (Platform.getOsVersionMajor() == 4 && Platform.getOsVersionMinor() > 1);
227 }
228 }
229 return "" + isRTMOS;
230 }
231
232 /**
233 * @return true if VM runs RTM supported CPU and false otherwise.
234 */
235 protected String vmRTMCPU() {
236 boolean vmRTMCPU = (Platform.isPPC() ? CPUInfo.hasFeature("tcheck") : CPUInfo.hasFeature("rtm"));
237
238 return "" + vmRTMCPU;
239 }
240
241 /**
242 * Dumps the map to the file if the file name is given as the property.
243 * This functionality could be helpful to know context in the real
244 * execution.
245 *
246 * @param map
247 */
248 protected static void dump(Map<String, String> map) {
249 String dumpFileName = System.getProperty("vmprops.dump");
250 if (dumpFileName == null) {
251 return;
252 }
253 List<String> lines = new ArrayList<>();
254 map.forEach((k, v) -> lines.add(k + ":" + v));
255 try {
256 Files.write(Paths.get(dumpFileName), lines, StandardOpenOption.APPEND);
257 } catch (IOException e) {
258 throw new RuntimeException("Failed to dump properties into '"
259 + dumpFileName + "'", e);
260 }
261 }
|
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.Path;
28 import java.nio.file.Paths;
29 import java.nio.file.StandardOpenOption;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.concurrent.Callable;
35 import java.util.regex.Matcher;
36 import java.util.regex.Pattern;
37
38 import sun.hotspot.cpuinfo.CPUInfo;
39 import sun.hotspot.gc.GC;
40 import sun.hotspot.WhiteBox;
41 import jdk.test.lib.Platform;
42
43 /**
44 * The Class to be invoked by jtreg prior Test Suite execution to
45 * collect information about VM.
46 * Do not use any API's that may not be available in all target VMs.
47 * Properties set by this Class will be available in the @requires expressions.
53 /**
54 * Collects information about VM properties.
55 * This method will be invoked by jtreg.
56 *
57 * @return Map of property-value pairs.
58 */
59 @Override
60 public Map<String, String> call() {
61 Map<String, String> map = new HashMap<>();
62 map.put("vm.flavor", vmFlavor());
63 map.put("vm.compMode", vmCompMode());
64 map.put("vm.bits", vmBits());
65 map.put("vm.flightRecorder", vmFlightRecorder());
66 map.put("vm.simpleArch", vmArch());
67 map.put("vm.debug", vmDebug());
68 map.put("vm.jvmci", vmJvmci());
69 map.put("vm.emulatedClient", vmEmulatedClient());
70 map.put("vm.cpu.features", cpuFeatures());
71 map.put("vm.rtm.cpu", vmRTMCPU());
72 map.put("vm.rtm.os", vmRTMOS());
73 map.put("vm.aot", vmAot());
74 vmGC(map); // vm.gc.X = true/false
75
76 VMProps.dump(map);
77 return map;
78 }
79
80 /**
81 * @return vm.simpleArch value of "os.simpleArch" property of tested JDK.
82 */
83 protected String vmArch() {
84 String arch = System.getProperty("os.arch");
85 if (arch.equals("x86_64") || arch.equals("amd64")) {
86 return "x64";
87 }
88 else if (arch.contains("86")) {
89 return "x86";
90 } else {
91 return arch;
92 }
93 }
224
225 } else if (Platform.isLinux()) {
226 if (Platform.isPPC()) {
227 isRTMOS = (Platform.getOsVersionMajor() > 4) ||
228 (Platform.getOsVersionMajor() == 4 && Platform.getOsVersionMinor() > 1);
229 }
230 }
231 return "" + isRTMOS;
232 }
233
234 /**
235 * @return true if VM runs RTM supported CPU and false otherwise.
236 */
237 protected String vmRTMCPU() {
238 boolean vmRTMCPU = (Platform.isPPC() ? CPUInfo.hasFeature("tcheck") : CPUInfo.hasFeature("rtm"));
239
240 return "" + vmRTMCPU;
241 }
242
243 /**
244 * @return true if VM supports AOT and false otherwise
245 */
246 protected String vmAot() {
247 // builds with aot have jaotc in <JDK>/bin
248 Path bin = Paths.get(System.getProperty("java.home"))
249 .resolve("bin");
250 Path jaotc;
251 if (Platform.isWindows()) {
252 jaotc = bin.resolve("jaotc.exe");
253 } else {
254 jaotc = bin.resolve("jaotc");
255 }
256 return "" + Files.exists(jaotc);
257 }
258
259 /**
260 * Dumps the map to the file if the file name is given as the property.
261 * This functionality could be helpful to know context in the real
262 * execution.
263 *
264 * @param map
265 */
266 protected static void dump(Map<String, String> map) {
267 String dumpFileName = System.getProperty("vmprops.dump");
268 if (dumpFileName == null) {
269 return;
270 }
271 List<String> lines = new ArrayList<>();
272 map.forEach((k, v) -> lines.add(k + ":" + v));
273 try {
274 Files.write(Paths.get(dumpFileName), lines, StandardOpenOption.APPEND);
275 } catch (IOException e) {
276 throw new RuntimeException("Failed to dump properties into '"
277 + dumpFileName + "'", e);
278 }
279 }
|