8072856: Eliminate ProcessTools.getProcessId dependency on sun.management.VMManagement
Reviewed-by: jbachorik, dfuchs, mchung
--- 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;
}