< prev index next >

test/jtreg-ext/requires/VMProps.java

Print this page

        

*** 21,30 **** --- 21,32 ---- * 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,59 **** --- 52,62 ---- 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,111 **** --- 105,135 ---- 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,124 **** 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); } catch (IOException e) { throw new RuntimeException("Failed to dump properties into '" + dumpFileName + "'", e); --- 138,148 ---- 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); } catch (IOException e) { throw new RuntimeException("Failed to dump properties into '" + dumpFileName + "'", e);
*** 129,136 **** * 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 + "'")); } } --- 153,160 ---- * 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 + "'")); } }
< prev index next >