changeset 7852:b14b199c0eaa

8073132: Eliminate ProcessTools.getProcessId dependency on sun.management.VMManagement Reviewed-by: jbachorik, dfuchs, mchung
author ykantser
date Fri, 13 Feb 2015 13:17:13 +0100
parents b00d819e1fcc
children 30137e7eef47 034eb71ab7fd
files test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java
diffstat 1 files changed, 1 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/test/testlibrary/com/oracle/java/testlibrary/ProcessTools.java	Fri Feb 13 06:23:48 2015 -0500
+++ b/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;
   }