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