8169517: WhiteBox should provide concurrent GC phase control

Added WhiteBox API and G1 implementation.

Reviewed-by: shade, dfazunen
diff --git a/test/lib/sun/hotspot/WhiteBox.java b/test/lib/sun/hotspot/WhiteBox.java
index 0198f0a..f72de59 100644
--- a/test/lib/sun/hotspot/WhiteBox.java
+++ b/test/lib/sun/hotspot/WhiteBox.java
@@ -390,6 +390,39 @@
   // Force Full GC
   public native void fullGC();
 
+  // Returns true if the current GC supports control of its concurrent
+  // phase via requestConcurrentGCPhase().  If false, a request will
+  // always fail.
+  public native boolean supportsConcurrentGCPhaseControl();
+
+  // Returns an array of concurrent phase names provided by this
+  // collector.  These are the names recognized by
+  // requestConcurrentGCPhase().
+  public native String[] getConcurrentGCPhases();
+
+  // Attempt to put the collector into the indicated concurrent phase,
+  // and attempt to remain in that state until a new request is made.
+  //
+  // Returns immediately if already in the requested phase.
+  // Otherwise, waits until the phase is reached.
+  //
+  // Throws IllegalStateException if unsupported by the current collector.
+  // Throws NullPointerException if phase is null.
+  // Throws IllegalArgumentException if phase is not valid for the current collector.
+  public void requestConcurrentGCPhase(String phase) {
+    if (!supportsConcurrentGCPhaseControl()) {
+      throw new IllegalStateException("Concurrent GC phase control not supported");
+    } else if (phase == null) {
+      throw new NullPointerException("null phase");
+    } else if (!requestConcurrentGCPhase0(phase)) {
+      throw new IllegalArgumentException("Unknown concurrent GC phase: " + phase);
+    }
+  }
+
+  // Helper for requestConcurrentGCPhase().  Returns true if request
+  // succeeded, false if the phase is invalid.
+  private native boolean requestConcurrentGCPhase0(String phase);
+
   // Method tries to start concurrent mark cycle.
   // It returns false if CM Thread is always in concurrent cycle.
   public native boolean g1StartConcMarkCycle();