/* * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * The Class to be invoked by jtreg prior Test Suite execution to * collect information about VM. * Do not use any APIs that may not be available in all target VMs. * Properties set by this Class will be available in the @requires expressions.
*/ publicclass VMProps implements Callable<Map<String, String>> { // value known to jtreg as an indicator of error state privatestaticfinal String ERROR_STATE = "__ERROR__";
privatestaticclass SafeMap { privatefinal Map<String, String> map = new HashMap<>();
publicvoid put(String key, Supplier<String> s) {
String value; try {
value = s.get();
} catch (Throwable t) {
System.err.println("failed to get value for " + key);
t.printStackTrace(System.err);
value = ERROR_STATE + t;
}
map.put(key, value);
}
}
/** * Collects information about VM properties. * This method will be invoked by jtreg. * * @return Map of property-value pairs.
*/
@Override public Map<String, String> call() {
SafeMap map = new SafeMap();
map.put("vm.flavor", this::vmFlavor);
map.put("vm.compMode", this::vmCompMode);
map.put("vm.bits", this::vmBits);
map.put("vm.flightRecorder", this::vmFlightRecorder);
map.put("vm.simpleArch", this::vmArch);
map.put("vm.debug", this::vmDebug);
map.put("vm.jvmci", this::vmJvmci);
map.put("vm.emulatedClient", this::vmEmulatedClient); // vm.hasSA is "true" if the VM contains the serviceability agent // and jhsdb.
map.put("vm.hasSA", this::vmHasSA); // vm.hasJFR is "true" if JFR is included in the build of the VM and // so tests can be executed.
map.put("vm.hasJFR", this::vmHasJFR);
map.put("vm.hasDTrace", this::vmHasDTrace);
map.put("vm.jvmti", this::vmHasJVMTI);
map.put("vm.cpu.features", this::cpuFeatures);
map.put("vm.pageSize", this::vmPageSize);
map.put("vm.rtm.cpu", this::vmRTMCPU);
map.put("vm.rtm.compiler", this::vmRTMCompiler); // vm.cds is true if the VM is compiled with cds support.
map.put("vm.cds", this::vmCDS);
map.put("vm.cds.custom.loaders", this::vmCDSForCustomLoaders);
map.put("vm.cds.write.archived.java.heap", this::vmCDSCanWriteArchivedJavaHeap);
map.put("vm.continuations", this::vmContinuations); // vm.graal.enabled is true if Graal is used as JIT
map.put("vm.graal.enabled", this::isGraalEnabled);
map.put("vm.compiler1.enabled", this::isCompiler1Enabled);
map.put("vm.compiler2.enabled", this::isCompiler2Enabled);
map.put("docker.support", this::dockerSupport);
map.put("vm.musl", this::isMusl);
map.put("release.implementor", this::implementor);
map.put("jdk.containerized", this::jdkContainerized);
map.put("vm.flagless", this::isFlagless);
vmGC(map); // vm.gc.X = true/false
vmGCforCDS(map); // may set vm.gc
vmOptFinalFlags(map);
dump(map.map); return map.map;
}
/** * Print a stack trace before returning error state; * Used by the various helper functions which parse information from * VM properties in the case where they don't find an expected property * or a property doesn't conform to an expected format. * * @return {@link #ERROR_STATE}
*/ private String errorWithMessage(String message) { new Exception(message).printStackTrace(); return ERROR_STATE + message;
}
/** * @return vm.simpleArch value of "os.simpleArch" property of tested JDK.
*/ protected String vmArch() {
String arch = System.getProperty("os.arch"); if (arch.equals("x86_64") || arch.equals("amd64")) { return"x64";
} elseif (arch.contains("86")) { return"x86";
} else { return arch;
}
}
/** * @return VM type value extracted from the "java.vm.name" property.
*/ protected String vmFlavor() { // E.g. "Java HotSpot(TM) 64-Bit Server VM"
String vmName = System.getProperty("java.vm.name"); if (vmName == null) { return errorWithMessage("Can't get 'java.vm.name' property");
}
Pattern startP = Pattern.compile(".* (\\S+) VM");
Matcher m = startP.matcher(vmName); if (m.matches()) { return m.group(1).toLowerCase();
} return errorWithMessage("Can't get VM flavor from 'java.vm.name'");
}
/** * @return VM compilation mode extracted from the "java.vm.info" property.
*/ protected String vmCompMode() { // E.g. "mixed mode"
String vmInfo = System.getProperty("java.vm.info"); if (vmInfo == null) { return errorWithMessage("Can't get 'java.vm.info' property");
}
vmInfo = vmInfo.toLowerCase(); if (vmInfo.contains("mixed mode")) { return"Xmixed";
} elseif (vmInfo.contains("compiled mode")) { return"Xcomp";
} elseif (vmInfo.contains("interpreted mode")) { return"Xint";
} else { return errorWithMessage("Can't get compilation mode from 'java.vm.info'");
}
}
/** * @return VM bitness, the value of the "sun.arch.data.model" property.
*/ protected String vmBits() {
String dataModel = System.getProperty("sun.arch.data.model"); if (dataModel != null) { return dataModel;
} else { return errorWithMessage("Can't get 'sun.arch.data.model' property");
}
}
/** * @return "true" if Flight Recorder is enabled, "false" if is disabled.
*/ protected String vmFlightRecorder() { Boolean isFlightRecorder = WB.getBooleanVMFlag("FlightRecorder");
String startFROptions = WB.getStringVMFlag("StartFlightRecording"); if (isFlightRecorder != null && isFlightRecorder) { return"true";
} if (startFROptions != null && !startFROptions.isEmpty()) { return"true";
} return"false";
}
/** * @return debug level value extracted from the "jdk.debug" property.
*/ protected String vmDebug() {
String debug = System.getProperty("jdk.debug"); if (debug != null) { return"" + debug.contains("debug");
} else { return errorWithMessage("Can't get 'jdk.debug' property");
}
}
/** * @return true if VM supports JVMCI and false otherwise
*/ protected String vmJvmci() { // builds with jvmci have this flag if (WB.getBooleanVMFlag("EnableJVMCI") == null) { return"false";
}
// Not all GCs have full JVMCI support if (!WB.isJVMCISupportedByGC()) { return"false";
}
/** * @return true if VM runs in emulated-client mode and false otherwise.
*/ protected String vmEmulatedClient() {
String vmInfo = System.getProperty("java.vm.info"); if (vmInfo == null) { return errorWithMessage("Can't get 'java.vm.info' property");
} return"" + vmInfo.contains(" emulated-client");
}
/** * @return supported CPU features
*/ protected String cpuFeatures() { return CPUInfo.getFeatures().toString();
}
/** * For all existing GC sets vm.gc.X property. * Example vm.gc.G1=true means: * VM supports G1 * User either set G1 explicitely (-XX:+UseG1GC) or did not set any GC * G1 can be selected, i.e. it doesn't conflict with other VM flags * * @param map - property-value pairs
*/ protectedvoid vmGC(SafeMap map) { var isJVMCIEnabled = Compiler.isJVMCIEnabled(); for (GC gc: GC.values()) {
map.put("vm.gc." + gc.name(),
() -> "" + (gc.isSupported()
&& (!isJVMCIEnabled || gc.isSupportedByJVMCICompiler())
&& (gc.isSelected() || GC.isSelectedErgonomically())));
}
}
/** * "jtreg -vmoptions:-Dtest.cds.runtime.options=..." can be used to specify * the GC type to be used when running with a CDS archive. Set "vm.gc" accordingly, * so that tests that need to explicitly choose the GC type can be excluded * with "@requires vm.gc == null". * * @param map - property-value pairs
*/ protectedvoid vmGCforCDS(SafeMap map) { if (!GC.isSelectedErgonomically()) { // The GC has been explicitly specified on the command line, so // jtreg will set the "vm.gc" property. Let's not interfere with it. return;
}
/** * @return "true" if VM has a serviceability agent.
*/ protected String vmHasSA() { return"" + Platform.hasSA();
}
/** * @return "true" if the VM is compiled with Java Flight Recorder (JFR) * support.
*/ protected String vmHasJFR() { return"" + WB.isJFRIncluded();
}
/** * @return "true" if the VM is compiled with JVMTI
*/ protected String vmHasJVMTI() { return"" + WB.isJVMTIIncluded();
}
/** * @return "true" if the VM is compiled with DTrace
*/ protected String vmHasDTrace() { return"" + WB.isDTraceIncluded();
}
/** * @return true if compiler in use supports RTM and false otherwise.
*/ protected String vmRTMCompiler() { boolean isRTMCompiler = false;
/** * @return true if VM runs RTM supported CPU and false otherwise.
*/ protected String vmRTMCPU() { return"" + CPUInfo.hasFeature("rtm");
}
/** * Check for CDS support. * * @return true if CDS is supported by the VM to be tested.
*/ protected String vmCDS() { return"" + WB.isCDSIncluded();
}
/** * Check for CDS support for custom loaders. * * @return true if CDS provides support for customer loader in the VM to be tested.
*/ protected String vmCDSForCustomLoaders() { return"" + ("true".equals(vmCDS()) && Platform.areCustomLoadersSupportedForCDS());
}
/** * @return true if this VM can write Java heap objects into the CDS archive
*/ protected String vmCDSCanWriteArchivedJavaHeap() { return"" + ("true".equals(vmCDS()) && WB.canWriteJavaHeapArchive());
}
/** * @return "true" if this VM supports continuations.
*/ protected String vmContinuations() { if (WB.getBooleanVMFlag("VMContinuations")) { return"true";
} else { return"false";
}
}
/** * @return System page size in bytes.
*/ protected String vmPageSize() { return"" + WB.getVMPageSize();
}
/** * Check if Graal is used as JIT compiler. * * @return true if Graal is used as JIT compiler.
*/ protected String isGraalEnabled() { return"" + Compiler.isGraalEnabled();
}
/** * Check if Compiler1 is present. * * @return true if Compiler1 is used as JIT compiler, either alone or as part of the tiered system.
*/ protected String isCompiler1Enabled() { return"" + Compiler.isC1Enabled();
}
/** * Check if Compiler2 is present. * * @return true if Compiler2 is used as JIT compiler, either alone or as part of the tiered system.
*/ protected String isCompiler2Enabled() { return"" + Compiler.isC2Enabled();
}
/** * A simple check for docker support * * @return true if docker is supported in a given environment
*/ protected String dockerSupport() { boolean isSupported = false; if (Platform.isLinux()) { // currently docker testing is only supported for Linux, // on certain platforms
/** * Checks if we are in <i>almost</i> out-of-box configuration, i.e. the flags * which JVM is started with don't affect its behavior "significantly". * {@code TEST_VM_FLAGLESS} enviroment variable can be used to force this * method to return true and allow any flags. * * @return true if there are no JVM flags
*/ private String isFlagless() { boolean result = true; if (System.getenv("TEST_VM_FLAGLESS") != null) { return"" + result;
}
// check -XX flags var ignoredXXFlags = Set.of( // added by run-test framework "MaxRAMPercentage", // added by test environment "CreateCoredumpOnCrash"
);
result &= allFlags.stream()
.filter(s -> s.startsWith("-XX:")) // map to names: // remove -XX:
.map(s -> s.substring(4)) // remove +/- from bool flags
.map(s -> s.charAt(0) == '+' || s.charAt(0) == '-' ? s.substring(1) : s) // remove =.* from others
.map(s -> s.contains("=") ? s.substring(0, s.indexOf('=')) : s) // skip known-to-be-there flags
.filter(s -> !ignoredXXFlags.contains(s))
.findAny()
.isEmpty();
// check -X flags var ignoredXFlags = Set.of( // default, yet still seen to be explicitly set "mixed"
);
result &= allFlags.stream()
.filter(s -> s.startsWith("-X") && !s.startsWith("-XX:")) // map to names: // remove -X
.map(s -> s.substring(2)) // remove :.* from flags with values
.map(s -> s.contains(":") ? s.substring(0, s.indexOf(':')) : s) // skip known-to-be-there flags
.filter(s -> !ignoredXFlags.contains(s))
.findAny()
.isEmpty();
return"" + result;
}
/** * Dumps the map to the file if the file name is given as the property. * This functionality could be helpful to know context in the real * execution. * * @param map
*/ protectedstaticvoid dump(Map<String, String> map) {
String dumpFileName = System.getProperty("vmprops.dump"); if (dumpFileName == null) { return;
}
List<String> lines = new ArrayList<>();
map.forEach((k, v) -> lines.add(k + ":" + v)); try {
Files.write(Paths.get(dumpFileName), lines,
StandardOpenOption.APPEND, StandardOpenOption.CREATE);
} catch (IOException e) { thrownew RuntimeException("Failed to dump properties into '"
+ dumpFileName + "'", e);
}
}
/** * This method is for the testing purpose only. * * @param args
*/ publicstaticvoid main(String args[]) {
Map<String, String> map = new VMProps().call();
map.forEach((k, v) -> System.out.println(k + ": '" + v + "'"));
}
}
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.