private VirtualMachine createVirtualMachine ( ) throws VirtualMachineException { ClassLoader toolsClassLoader ; File toolsJar = getToolsJar ( ) ; if ( toolsJar == null ) { // The attach classes are on the boot classpath on Mac. toolsClassLoader = HotSpotJavaDumperImpl . class . getClassLoader ( ) ; } else { try { toolsClassLoader = new URLClassLoader ( new URL [ ] { toolsJar . getAbsoluteFile ( ) . toURI ( ) . toURL ( ) } ) ; } catch ( MalformedURLException e ) { throw new RuntimeException ( e ) ; } } try { Class < ? > vmClass = toolsClassLoader . loadClass ( "com.sun.tools.attach.VirtualMachine" ) ; Method attachMethod = vmClass . getMethod ( "attach" , new Class < ? > [ ] { String . class } ) ; Object toolsVM = attachMethod . invoke ( null , new Object [ ] { PID } ) ; Method remoteDataDumpMethod = toolsVM . getClass ( ) . getMethod ( "remoteDataDump" , new Class < ? > [ ] { Object [ ] . class } ) ; return new VirtualMachine ( toolsVM , remoteDataDumpMethod ) ; } catch ( ClassNotFoundException e ) { // The class isn't found, so we won't be able to create dumps. } catch ( InvocationTargetException e ) { throw new VirtualMachineException ( e ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return new VirtualMachine ( null , null ) ; }
Create a VirtualMachine wrapper .