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; 136,149c135,136 < try { < // 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; < } catch(Exception ex) { < return null; < } --- > // Get the current process id > return (int)ProcessHandle.current().getPid(); I'd appreciate any feedback please, and help obtaining a suitable 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 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