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.function.Supplier;
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 import jdk.test.lib.Container;
50
51 /**
52 * The Class to be invoked by jtreg prior Test Suite execution to
53 * collect information about VM.
54 * Do not use any APIs that may not be available in all target VMs.
55 * Properties set by this Class will be available in the @requires expressions.
56 */
57 public class VMProps implements Callable<Map<String, String>> {
98 map.put("vm.hasSA", this::vmHasSA);
99 // vm.hasJFR is "true" if JFR is included in the build of the VM and
100 // so tests can be executed.
101 map.put("vm.hasJFR", this::vmHasJFR);
102 map.put("vm.cpu.features", this::cpuFeatures);
103 map.put("vm.rtm.cpu", this::vmRTMCPU);
104 map.put("vm.rtm.compiler", this::vmRTMCompiler);
105 map.put("vm.aot", this::vmAOT);
106 map.put("vm.aot.enabled", this::vmAotEnabled);
107 // vm.cds is true if the VM is compiled with cds support.
108 map.put("vm.cds", this::vmCDS);
109 map.put("vm.cds.custom.loaders", this::vmCDSForCustomLoaders);
110 map.put("vm.cds.archived.java.heap", this::vmCDSForArchivedJavaHeap);
111 // vm.graal.enabled is true if Graal is used as JIT
112 map.put("vm.graal.enabled", this::isGraalEnabled);
113 map.put("vm.compiler1.enabled", this::isCompiler1Enabled);
114 map.put("vm.compiler2.enabled", this::isCompiler2Enabled);
115 map.put("docker.support", this::dockerSupport);
116 map.put("release.implementor", this::implementor);
117 map.put("test.vm.gc.nvdimm", this::isNvdimmTestEnabled);
118 vmGC(map); // vm.gc.X = true/false
119 vmOptFinalFlags(map);
120
121 dump(map.map);
122 return map.map;
123 }
124
125 /**
126 * Print a stack trace before returning error state;
127 * Used by the various helper functions which parse information from
128 * VM properties in the case where they don't find an expected property
129 * or a property doesn't conform to an expected format.
130 *
131 * @return {@link #ERROR_STATE}
132 */
133 private String errorWithMessage(String message) {
134 new Exception(message).printStackTrace();
135 return ERROR_STATE + message;
136 }
137
485 System.getProperty("java.home") + "/release"))) {
486 Properties properties = new Properties();
487 properties.load(in);
488 String implementorProperty = properties.getProperty("IMPLEMENTOR");
489 if (implementorProperty != null) {
490 return implementorProperty.replace("\"", "");
491 }
492 return errorWithMessage("Can't get 'IMPLEMENTOR' property from 'release' file");
493 } catch (IOException e) {
494 e.printStackTrace();
495 return errorWithMessage("Failed to read 'release' file " + e);
496 }
497 }
498
499 private String isNvdimmTestEnabled() {
500 String isEnabled = System.getenv("TEST_VM_GC_NVDIMM");
501 return "" + "true".equalsIgnoreCase(isEnabled);
502 }
503
504 /**
505 * Dumps the map to the file if the file name is given as the property.
506 * This functionality could be helpful to know context in the real
507 * execution.
508 *
509 * @param map
510 */
511 protected static void dump(Map<String, String> map) {
512 String dumpFileName = System.getProperty("vmprops.dump");
513 if (dumpFileName == null) {
514 return;
515 }
516 List<String> lines = new ArrayList<>();
517 map.forEach((k, v) -> lines.add(k + ":" + v));
518 try {
519 Files.write(Paths.get(dumpFileName), lines,
520 StandardOpenOption.APPEND, StandardOpenOption.CREATE);
521 } catch (IOException e) {
522 throw new RuntimeException("Failed to dump properties into '"
523 + dumpFileName + "'", e);
524 }
|
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.Collections;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Properties;
39 import java.util.Set;
40 import java.util.concurrent.Callable;
41 import java.util.concurrent.TimeUnit;
42 import java.util.function.Supplier;
43 import java.util.regex.Matcher;
44 import java.util.regex.Pattern;
45
46 import sun.hotspot.code.Compiler;
47 import sun.hotspot.cpuinfo.CPUInfo;
48 import sun.hotspot.gc.GC;
49 import sun.hotspot.WhiteBox;
50 import jdk.test.lib.Platform;
51 import jdk.test.lib.Container;
52
53 /**
54 * The Class to be invoked by jtreg prior Test Suite execution to
55 * collect information about VM.
56 * Do not use any APIs that may not be available in all target VMs.
57 * Properties set by this Class will be available in the @requires expressions.
58 */
59 public class VMProps implements Callable<Map<String, String>> {
100 map.put("vm.hasSA", this::vmHasSA);
101 // vm.hasJFR is "true" if JFR is included in the build of the VM and
102 // so tests can be executed.
103 map.put("vm.hasJFR", this::vmHasJFR);
104 map.put("vm.cpu.features", this::cpuFeatures);
105 map.put("vm.rtm.cpu", this::vmRTMCPU);
106 map.put("vm.rtm.compiler", this::vmRTMCompiler);
107 map.put("vm.aot", this::vmAOT);
108 map.put("vm.aot.enabled", this::vmAotEnabled);
109 // vm.cds is true if the VM is compiled with cds support.
110 map.put("vm.cds", this::vmCDS);
111 map.put("vm.cds.custom.loaders", this::vmCDSForCustomLoaders);
112 map.put("vm.cds.archived.java.heap", this::vmCDSForArchivedJavaHeap);
113 // vm.graal.enabled is true if Graal is used as JIT
114 map.put("vm.graal.enabled", this::isGraalEnabled);
115 map.put("vm.compiler1.enabled", this::isCompiler1Enabled);
116 map.put("vm.compiler2.enabled", this::isCompiler2Enabled);
117 map.put("docker.support", this::dockerSupport);
118 map.put("release.implementor", this::implementor);
119 map.put("test.vm.gc.nvdimm", this::isNvdimmTestEnabled);
120 map.put("vm.flagless", this::isFlagless);
121 vmGC(map); // vm.gc.X = true/false
122 vmOptFinalFlags(map);
123
124 dump(map.map);
125 return map.map;
126 }
127
128 /**
129 * Print a stack trace before returning error state;
130 * Used by the various helper functions which parse information from
131 * VM properties in the case where they don't find an expected property
132 * or a property doesn't conform to an expected format.
133 *
134 * @return {@link #ERROR_STATE}
135 */
136 private String errorWithMessage(String message) {
137 new Exception(message).printStackTrace();
138 return ERROR_STATE + message;
139 }
140
488 System.getProperty("java.home") + "/release"))) {
489 Properties properties = new Properties();
490 properties.load(in);
491 String implementorProperty = properties.getProperty("IMPLEMENTOR");
492 if (implementorProperty != null) {
493 return implementorProperty.replace("\"", "");
494 }
495 return errorWithMessage("Can't get 'IMPLEMENTOR' property from 'release' file");
496 } catch (IOException e) {
497 e.printStackTrace();
498 return errorWithMessage("Failed to read 'release' file " + e);
499 }
500 }
501
502 private String isNvdimmTestEnabled() {
503 String isEnabled = System.getenv("TEST_VM_GC_NVDIMM");
504 return "" + "true".equalsIgnoreCase(isEnabled);
505 }
506
507 /**
508 * Checks if we are in <i>almost</i> out-of-box configuration, i.e. the flags
509 * which JVM is started with don't affect its behavior "significantly".
510 * {@code TEST_VM_FLAGLESS} enviroment variable can be used to force this
511 * method to return true and allow any flags.
512 *
513 * @return true if there are no JVM flags
514 */
515 private String isFlagless() {
516 boolean result = true;
517 if (System.getenv("TEST_VM_FLAGLESS") != null) {
518 return "" + result;
519 }
520
521 List<String> allFlags = new ArrayList<String>();
522 Collections.addAll(allFlags, System.getProperty("test.vm.opts", "").trim().split("\\s+"));
523 Collections.addAll(allFlags, System.getProperty("test.java.opts", "").trim().split("\\s+"));
524
525 // check -XX flags
526 var ignoredXXFlags = Set.of(
527 // added by run-test framework
528 "MaxRAMPercentage",
529 // added by test environment
530 "CreateCoredumpOnCrash"
531 );
532 result &= allFlags.stream()
533 .filter(s -> s.startsWith("-XX:"))
534 // map to names:
535 // remove -XX:
536 .map(s -> s.substring(4))
537 // remove +/- from bool flags
538 .map(s -> s.charAt(0) == '+' || s.charAt(0) == '-' ? s.substring(1) : s)
539 // remove =.* from others
540 .map(s -> s.contains("=") ? s.substring(0, s.indexOf('=')) : s)
541 // skip known-to-be-there flags
542 .filter(s -> !ignoredXXFlags.contains(s))
543 .findAny()
544 .isEmpty();
545
546 // check -X flags
547 var ignoredXFlags = Set.of(
548 // default, yet still seen to be explicitly set
549 "mixed"
550 );
551 result &= allFlags.stream()
552 .filter(s -> s.startsWith("-X") && !s.startsWith("-XX:"))
553 // map to names:
554 // remove -X
555 .map(s -> s.substring(2))
556 // remove :.* from flags with values
557 .map(s -> s.contains(":") ? s.substring(0, s.indexOf(':')) : s)
558 // skip known-to-be-there flags
559 .filter(s -> !ignoredXFlags.contains(s))
560 .findAny()
561 .isEmpty();
562
563 return "" + result;
564 }
565
566 /**
567 * Dumps the map to the file if the file name is given as the property.
568 * This functionality could be helpful to know context in the real
569 * execution.
570 *
571 * @param map
572 */
573 protected static void dump(Map<String, String> map) {
574 String dumpFileName = System.getProperty("vmprops.dump");
575 if (dumpFileName == null) {
576 return;
577 }
578 List<String> lines = new ArrayList<>();
579 map.forEach((k, v) -> lines.add(k + ":" + v));
580 try {
581 Files.write(Paths.get(dumpFileName), lines,
582 StandardOpenOption.APPEND, StandardOpenOption.CREATE);
583 } catch (IOException e) {
584 throw new RuntimeException("Failed to dump properties into '"
585 + dumpFileName + "'", e);
586 }
|