< prev index next >
test/jtreg-ext/requires/VMProps.java
Print this page
@@ -21,10 +21,12 @@
* questions.
*/
package requires;
import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -50,10 +52,11 @@
public Map<String, String> call() {
Map<String, String> map = new HashMap<>();
map.put("vm.flavor", vmFlavor());
map.put("vm.compMode", vmCompMode());
map.put("vm.bits", vmBits());
+ map.put("vm.flightRecorder", vmFlightRecorder());
dump(map);
return map;
}
/**
@@ -102,10 +105,31 @@
protected String vmBits() {
return System.getProperty("sun.arch.data.model");
}
/**
+ * @return "true" if Flight Recorder is enabled, "false" if is disabled.
+ */
+ protected String vmFlightRecorder() {
+ RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
+ List<String> arguments = runtimeMxBean.getInputArguments();
+ if (arguments.contains("-XX:+UnlockCommercialFeatures")) {
+ if (arguments.contains("-XX:+FlightRecorder")) {
+ return "true";
+ }
+ if (arguments.contains("-XX:-FlightRecorder")) {
+ return "false";
+ }
+ if (arguments.stream()
+ .anyMatch(option -> option.startsWith("-XX:StartFlightRecording"))) {
+ return "true";
+ }
+ }
+ return "false";
+ }
+
+ /**
* 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
@@ -114,11 +138,11 @@
String dumpFileName = System.getProperty("vmprops.dump");
if (dumpFileName == null) {
return;
}
List<String> lines = new ArrayList<>();
- map.forEach((k,v) -> lines.add(k + ":" + v));
+ map.forEach((k, v) -> lines.add(k + ":" + v));
try {
Files.write(Paths.get(dumpFileName), lines);
} catch (IOException e) {
throw new RuntimeException("Failed to dump properties into '"
+ dumpFileName + "'", e);
@@ -129,8 +153,8 @@
* This method is for the testing purpose only.
* @param args
*/
public static void main(String args[]) {
Map<String, String> map = new VMProps().call();
- map.forEach((k,v) -> System.out.println(k + ": '" + v + "'"));
+ map.forEach((k, v) -> System.out.println(k + ": '" + v + "'"));
}
}
< prev index next >