From b66265312cc95cd5e736466bb8975c3bee54de43 Mon Sep 17 00:00:00 2001
From: Dmitry Fazunenko <dfazunen@openjdk.org>
Date: Tue, 21 Jun 2016 18:36:37 +0400
Subject: [PATCH] 8151283: Implement setting jtreg @requires property
 vm.isG1Supported

Reviewed-by: tschatzl, iignatyev, mchernov
---
 test/jtreg-ext/requires/VMProps.java | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/test/jtreg-ext/requires/VMProps.java b/test/jtreg-ext/requires/VMProps.java
index 7bb67f32828..945d754199e 100644
--- a/test/jtreg-ext/requires/VMProps.java
+++ b/test/jtreg-ext/requires/VMProps.java
@@ -34,6 +34,7 @@ import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import sun.hotspot.gc.GC;
 
 /**
  * The Class to be invoked by jtreg prior Test Suite execution to
@@ -56,11 +57,12 @@ public class VMProps implements Callable<Map<String, String>> {
         map.put("vm.bits", vmBits());
         map.put("vm.flightRecorder", vmFlightRecorder());
         map.put("vm.simpleArch", vmArch());
+        vmGC(map); // vm.gc.X = true/false
+
         dump(map);
         return map;
     }
 
-
     /**
      * @return vm.simpleArch value of "os.simpleArch" property of tested JDK.
      */
@@ -146,6 +148,24 @@ public class VMProps implements Callable<Map<String, String>> {
         return "false";
     }
 
+    /**
+     * 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
+     * @param map - property-value pairs
+     */
+    protected void vmGC(Map<String, String> map){
+        GC currentGC = GC.current();
+        boolean isByErgo = GC.currentSetByErgo();
+        List<GC> supportedGC = GC.allSupported();
+        for (GC gc: GC.values()) {
+            boolean isSupported = supportedGC.contains(gc);
+            boolean isAcceptable = isSupported && (gc == currentGC || isByErgo);
+            map.put("vm.gc." + gc.name(), "" + isAcceptable);
+        }
+    }
+
     /**
      * 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