8073132: Eliminate ProcessTools.getProcessId dependency on sun.management.VMManagement
authorykantser
Fri, 13 Feb 2015 13:17:13 +0100
changeset 29069 938c1c97ad3b
parent 29068 683bef04fb20
child 29070 b0a5fc9c59c8
child 29071 73f45d04ad7a
8073132: Eliminate ProcessTools.getProcessId dependency on sun.management.VMManagement Reviewed-by: jbachorik, dfuchs, mchung
hotspot/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java	Fri Feb 13 06:23:48 2015 -0500
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java	Fri Feb 13 13:17:13 2015 +0100
@@ -33,8 +33,6 @@
 import java.util.Collections;
 import java.util.List;
 
-import sun.management.VMManagement;
-
 public final class ProcessTools {
 
   private ProcessTools() {
@@ -90,19 +88,8 @@
    * @return Process id
    */
   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);
+    int pid = Integer.parseInt(runtime.getName().split("@")[0]);
 
     return pid;
   }