changeset 2194:4fe0143c0a15

8161208: Unable to run jtreg tests with MinimalVM Reviewed-by: dholmes, dfazunen
author mchernov
date Thu, 21 Jul 2016 16:07:41 +0300
parents 905adc9acd30
children e1c38bf34755
files test/jtreg-ext/requires/VMProps.java
diffstat 1 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/test/jtreg-ext/requires/VMProps.java	Wed Jul 20 12:52:45 2016 -0700
+++ b/test/jtreg-ext/requires/VMProps.java	Thu Jul 21 16:07:41 2016 +0300
@@ -23,8 +23,6 @@
 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;
@@ -35,14 +33,18 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import sun.hotspot.gc.GC;
+import sun.hotspot.WhiteBox;
 
 /**
  * The Class to be invoked by jtreg prior Test Suite execution to
  * collect information about VM.
+ * Do not use any API's that may not be available in all target VMs.
  * Properties set by this Class will be available in the @requires expressions.
  */
 public class VMProps implements Callable<Map<String, String>> {
 
+    private static final WhiteBox WB = WhiteBox.getWhiteBox();
+
     /**
      * Collects information about VM properties.
      * This method will be invoked by jtreg.
@@ -131,17 +133,14 @@
      * @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")) {
+        Boolean isUnlockedCommercialFatures = WB.getBooleanVMFlag("UnlockCommercialFeatures");
+        Boolean isFlightRecorder = WB.getBooleanVMFlag("FlightRecorder");
+        String startFROptions = WB.getStringVMFlag("StartFlightRecording");
+        if (isUnlockedCommercialFatures != null && isUnlockedCommercialFatures) {
+            if (isFlightRecorder != null && isFlightRecorder) {
                 return "true";
             }
-            if (arguments.contains("-XX:-FlightRecorder")) {
-                return "false";
-            }
-            if (arguments.stream()
-                    .anyMatch(option -> option.startsWith("-XX:StartFlightRecording"))) {
+            if (startFROptions != null && !startFROptions.isEmpty()) {
                 return "true";
             }
         }