1 /*
2 * Copyright (c) 2016, 2018, 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.BufferedInputStream;
26 import java.io.FileInputStream;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32 import java.nio.file.StandardOpenOption;
33 import java.util.ArrayList;
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Properties;
38 import java.util.concurrent.Callable;
39 import java.util.concurrent.TimeUnit;
40 import java.util.regex.Matcher;
41 import java.util.regex.Pattern;
42
43 import sun.hotspot.code.Compiler;
44 import sun.hotspot.cpuinfo.CPUInfo;
45 import sun.hotspot.gc.GC;
46 import sun.hotspot.WhiteBox;
47 import jdk.test.lib.Platform;
48
49 /**
50 * The Class to be invoked by jtreg prior Test Suite execution to
51 * collect information about VM.
52 * Do not use any API's that may not be available in all target VMs.
53 * Properties set by this Class will be available in the @requires expressions.
69 map.put("vm.compMode", vmCompMode());
70 map.put("vm.bits", vmBits());
71 map.put("vm.flightRecorder", vmFlightRecorder());
72 map.put("vm.simpleArch", vmArch());
73 map.put("vm.debug", vmDebug());
74 map.put("vm.jvmci", vmJvmci());
75 map.put("vm.emulatedClient", vmEmulatedClient());
76 // vm.hasSA is "true" if the VM contains the serviceability agent
77 // and jhsdb.
78 map.put("vm.hasSA", vmHasSA());
79 // vm.hasSAandCanAttach is "true" if the VM contains the serviceability agent
80 // and jhsdb and it can attach to the VM.
81 map.put("vm.hasSAandCanAttach", vmHasSAandCanAttach());
82 // vm.hasJFR is "true" if JFR is included in the build of the VM and
83 // so tests can be executed.
84 map.put("vm.hasJFR", vmHasJFR());
85 map.put("vm.cpu.features", cpuFeatures());
86 map.put("vm.rtm.cpu", vmRTMCPU());
87 map.put("vm.rtm.compiler", vmRTMCompiler());
88 map.put("vm.aot", vmAOT());
89 // vm.cds is true if the VM is compiled with cds support.
90 map.put("vm.cds", vmCDS());
91 map.put("vm.cds.custom.loaders", vmCDSForCustomLoaders());
92 map.put("vm.cds.archived.java.heap", vmCDSForArchivedJavaHeap());
93 // vm.graal.enabled is true if Graal is used as JIT
94 map.put("vm.graal.enabled", isGraalEnabled());
95 map.put("vm.compiler1.enabled", isCompiler1Enabled());
96 map.put("vm.compiler2.enabled", isCompiler2Enabled());
97 map.put("docker.support", dockerSupport());
98 map.put("release.implementor", implementor());
99 vmGC(map); // vm.gc.X = true/false
100 vmOptFinalFlags(map);
101
102 VMProps.dump(map);
103 return map;
104 }
105
106 /**
107 * Prints a stack trace before returning null.
108 * Used by the various helper functions which parse information from
317 protected String vmRTMCPU() {
318 return "" + CPUInfo.hasFeature("rtm");
319 }
320
321 /**
322 * @return true if VM supports AOT and false otherwise
323 */
324 protected String vmAOT() {
325 // builds with aot have jaotc in <JDK>/bin
326 Path bin = Paths.get(System.getProperty("java.home"))
327 .resolve("bin");
328 Path jaotc;
329 if (Platform.isWindows()) {
330 jaotc = bin.resolve("jaotc.exe");
331 } else {
332 jaotc = bin.resolve("jaotc");
333 }
334 return "" + Files.exists(jaotc);
335 }
336
337 /**
338 * Check for CDS support.
339 *
340 * @return true if CDS is supported by the VM to be tested.
341 */
342 protected String vmCDS() {
343 if (WB.isCDSIncludedInVmBuild()) {
344 return "true";
345 } else {
346 return "false";
347 }
348 }
349
350 /**
351 * Check for CDS support for custom loaders.
352 *
353 * @return true if CDS provides support for customer loader in the VM to be tested.
354 */
355 protected String vmCDSForCustomLoaders() {
356 if (vmCDS().equals("true") && Platform.areCustomLoadersSupportedForCDS()) {
|
1 /*
2 * Copyright (c) 2016, 2019, 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.BufferedInputStream;
26 import java.io.FileInputStream;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32 import java.nio.file.StandardOpenOption;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Properties;
39 import java.util.concurrent.Callable;
40 import java.util.concurrent.TimeUnit;
41 import java.util.regex.Matcher;
42 import java.util.regex.Pattern;
43
44 import sun.hotspot.code.Compiler;
45 import sun.hotspot.cpuinfo.CPUInfo;
46 import sun.hotspot.gc.GC;
47 import sun.hotspot.WhiteBox;
48 import jdk.test.lib.Platform;
49
50 /**
51 * The Class to be invoked by jtreg prior Test Suite execution to
52 * collect information about VM.
53 * Do not use any API's that may not be available in all target VMs.
54 * Properties set by this Class will be available in the @requires expressions.
70 map.put("vm.compMode", vmCompMode());
71 map.put("vm.bits", vmBits());
72 map.put("vm.flightRecorder", vmFlightRecorder());
73 map.put("vm.simpleArch", vmArch());
74 map.put("vm.debug", vmDebug());
75 map.put("vm.jvmci", vmJvmci());
76 map.put("vm.emulatedClient", vmEmulatedClient());
77 // vm.hasSA is "true" if the VM contains the serviceability agent
78 // and jhsdb.
79 map.put("vm.hasSA", vmHasSA());
80 // vm.hasSAandCanAttach is "true" if the VM contains the serviceability agent
81 // and jhsdb and it can attach to the VM.
82 map.put("vm.hasSAandCanAttach", vmHasSAandCanAttach());
83 // vm.hasJFR is "true" if JFR is included in the build of the VM and
84 // so tests can be executed.
85 map.put("vm.hasJFR", vmHasJFR());
86 map.put("vm.cpu.features", cpuFeatures());
87 map.put("vm.rtm.cpu", vmRTMCPU());
88 map.put("vm.rtm.compiler", vmRTMCompiler());
89 map.put("vm.aot", vmAOT());
90 map.put("vm.aot.modules", vmAotModules());
91 // vm.cds is true if the VM is compiled with cds support.
92 map.put("vm.cds", vmCDS());
93 map.put("vm.cds.custom.loaders", vmCDSForCustomLoaders());
94 map.put("vm.cds.archived.java.heap", vmCDSForArchivedJavaHeap());
95 // vm.graal.enabled is true if Graal is used as JIT
96 map.put("vm.graal.enabled", isGraalEnabled());
97 map.put("vm.compiler1.enabled", isCompiler1Enabled());
98 map.put("vm.compiler2.enabled", isCompiler2Enabled());
99 map.put("docker.support", dockerSupport());
100 map.put("release.implementor", implementor());
101 vmGC(map); // vm.gc.X = true/false
102 vmOptFinalFlags(map);
103
104 VMProps.dump(map);
105 return map;
106 }
107
108 /**
109 * Prints a stack trace before returning null.
110 * Used by the various helper functions which parse information from
319 protected String vmRTMCPU() {
320 return "" + CPUInfo.hasFeature("rtm");
321 }
322
323 /**
324 * @return true if VM supports AOT and false otherwise
325 */
326 protected String vmAOT() {
327 // builds with aot have jaotc in <JDK>/bin
328 Path bin = Paths.get(System.getProperty("java.home"))
329 .resolve("bin");
330 Path jaotc;
331 if (Platform.isWindows()) {
332 jaotc = bin.resolve("jaotc.exe");
333 } else {
334 jaotc = bin.resolve("jaotc");
335 }
336 return "" + Files.exists(jaotc);
337 }
338
339 /*
340 * @return a space-separeted list of AOT'ed modules with a space character
341 * at the beginning and end, or an empty string if there are none.
342 */
343 protected String vmAotModules() {
344 String modules = System.getenv().get("TEST_OPTS_AOT_MODULES");
345 if (modules == null || modules.equals("")) {
346 // there is nothing in 'TEST_OPTS_AOT_MODULES', let's try 'JTREG'
347 String e = System.getenv().get("JTREG");
348 if (e == null) {
349 return "";
350 }
351
352 // 'JTREG' is a semicolon-separated list of '<K>=<V>' pairs
353 modules = Arrays.stream(e.split(";"))
354 .filter(s -> "AOT_MODULES".equals(s.substring(0, s.indexOf("="))))
355 .map(s -> s.substring(s.indexOf("=") + 1))
356 .findAny()
357 .orElse(null);
358 }
359
360 if (modules != null && !"".equals(modules)) {
361 return " " + modules.trim() + " ";
362 }
363 return "";
364 }
365
366 /**
367 * Check for CDS support.
368 *
369 * @return true if CDS is supported by the VM to be tested.
370 */
371 protected String vmCDS() {
372 if (WB.isCDSIncludedInVmBuild()) {
373 return "true";
374 } else {
375 return "false";
376 }
377 }
378
379 /**
380 * Check for CDS support for custom loaders.
381 *
382 * @return true if CDS provides support for customer loader in the VM to be tested.
383 */
384 protected String vmCDSForCustomLoaders() {
385 if (vmCDS().equals("true") && Platform.areCustomLoadersSupportedForCDS()) {
|