8072856: Eliminate ProcessTools.getProcessId dependency on sun.management.VMManagement
authorykantser
Thu, 12 Feb 2015 10:28:14 +0100
changeset 28870 cc64f71a38ec
parent 28869 9725237b107d
child 28871 d04fa3bde1d0
8072856: Eliminate ProcessTools.getProcessId dependency on sun.management.VMManagement Reviewed-by: jbachorik, dfuchs, mchung
jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java	Wed Feb 11 17:20:39 2015 -0800
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java	Thu Feb 12 10:28:14 2015 +0100
@@ -218,19 +218,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;
     }