This seems a good clean-up, esp. as java.management doesn't open sun.management to jdk.management.agent so I'll bet this wasn't working any. I assume the exception swallowing can be removed too.

Can you bring this to serviceability-dev as this is where this code is maintained?

On 22/06/2017 14:34, Andrew Leonard wrote:
Hello,
I would like to propose the change below to the
JdpController.getProcessId() method which currently uses a reflection hack
and the VMManagement interface. Instead for JDK9+ we can use the
ProcessHandle.current().getPid() method, which will also allow better
compatibility with other pluggable VMs.

jdk/src/jdk.management.agent/share/classes/sun/management/jdp/JdpController.java
36d35
< import sun.management.VMManagement;
137,146c136,137
<             // 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);
<             Integer pid = (Integer) pid_method.invoke(mgmt);
<             return pid;
---
             // Get the current process id
             return (int)ProcessHandle.current().getPid();
I'd appreciate any feedback please, and how I would go about obtaining a
sponsor and contributor?

Thanks
Andrew

Andrew Leonard
Java Runtimes Development
IBM Hursley
IBM United Kingdom Ltd
Phone internal: 245913, external: 01962 815913
internet email: andrew_m_leon...@uk.ibm.com

Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number
741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU

Reply via email to