changeset 12533:5e3570b00a30

8171318: serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java fails latest Jigsaw integration Reviewed-by: sspitsyn, dholmes
author gtriantafill
date Thu, 22 Dec 2016 11:37:49 -0500
parents 5fa1aab53b6c
children 9cd4389354c0
files test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java
diffstat 2 files changed, 5 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java	Thu Dec 22 17:26:02 2016 -0800
+++ b/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/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java	Thu Dec 22 17:26:02 2016 -0800
+++ b/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);
             }