# HG changeset patch # User coleenp # Date 1482505743 0 # Node ID 9f1561ed8b7be98ba743b1dbc36be6301476538e # Parent 6e7a0f24778bfeadd111447b4f8ab7d444a307a3# Parent f6dc40ed6ce9a3c8e2eca168c649262c82244ba2 Merge diff -r f6dc40ed6ce9 -r 9f1561ed8b7b hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java --- a/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java Thu Dec 22 16:51:25 2016 +0100 +++ b/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapProc.java Fri Dec 23 15:09:03 2016 +0000 @@ -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; - } - } diff -r f6dc40ed6ce9 -r 9f1561ed8b7b hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java --- a/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java Thu Dec 22 16:51:25 2016 +0100 +++ b/hotspot/test/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java Fri Dec 23 15:09:03 2016 +0000 @@ -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); }