8171318: serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java fails latest Jigsaw integration
authorgtriantafill
Thu, 22 Dec 2016 11:37:49 -0500
changeset 43406 6e7a0f24778b
parent 43405 1fab8e6866d7
child 43408 9f1561ed8b7b
8171318: serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java fails latest Jigsaw integration Reviewed-by: sspitsyn, dholmes
hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java
hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java
--- a/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java	Thu Dec 22 17:26:02 2016 -0800
+++ b/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java	Thu Dec 22 11:37:49 2016 -0500
@@ -21,12 +21,9 @@
  * questions.
  */
 
-import java.lang.management.ManagementFactory;
-import java.lang.management.RuntimeMXBean;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
+import jdk.test.lib.process.ProcessTools;
 
 import sun.management.VMManagement;
 
@@ -38,7 +35,7 @@
         buildLargeHeap(args);
 
         // Print our pid on stdout
-        System.out.println("PID[" + getProcessId() + "]");
+        System.out.println("PID[" + ProcessTools.getProcessId() + "]");
 
         // Wait for input before termination
         System.in.read();
@@ -50,22 +47,4 @@
         }
     }
 
-    public static int getProcessId() throws Exception {
-
-        // Get the current process id using a reflection hack
-        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
-        Field jvm = runtime.getClass().getDeclaredField("jvm");
-
-        jvm.setAccessible(true);
-        VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);
-
-        Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
-
-        pid_method.setAccessible(true);
-
-        int pid = (Integer) pid_method.invoke(mgmt);
-
-        return pid;
-    }
-
 }
--- a/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java	Thu Dec 22 17:26:02 2016 -0800
+++ b/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java	Thu Dec 22 11:37:49 2016 -0500
@@ -90,6 +90,9 @@
         try (Scanner largeHeapScanner = new Scanner(
                 largeHeapProc.getInputStream());) {
             String pidstring = null;
+            if (!largeHeapScanner.hasNext()) {
+                throw new RuntimeException ("Test failed: could not open largeHeapScanner.");
+            }
             while ((pidstring = largeHeapScanner.findInLine("PID\\[[0-9].*\\]")) == null) {
                 Thread.sleep(500);
             }