How to use SolarisVirtualMachine class of sun.tools.attach package

Best Powermock code snippet using sun.tools.attach.SolarisVirtualMachine

Source:SolarisVirtualMachine.java Github

copy

Full Screen

...33import java.io.FileNotFoundException;34/*35 * Solaris implementation of HotSpotVirtualMachine.36 */37public class SolarisVirtualMachine extends HotSpotVirtualMachine {38 // "/tmp" is used as a global well-known location for the files39 // .java_pid<pid>. and .attach_pid<pid>. It is important that this40 // location is the same for all processes, otherwise the tools41 // will not be able to find all Hotspot processes.42 // Any changes to this needs to be synchronized with HotSpot.43 private static final String tmpdir = "/tmp";44 // door descriptor;45 private int fd = -1;46 /**47 * Attaches to the target VM48 */49 SolarisVirtualMachine(AttachProvider provider, String vmid)50 throws AttachNotSupportedException, IOException51 {52 super(provider, vmid);53 // This provider only understands process-ids (pids).54 int pid;55 try {56 pid = Integer.parseInt(vmid);57 } catch (NumberFormatException x) {58 throw new AttachNotSupportedException("invalid process identifier");59 }60 // Opens the door file to the target VM. If the file is not61 // found it might mean that the attach mechanism isn't started in the62 // target VM so we attempt to start it and retry.63 try {64 fd = openDoor(pid);65 } catch (FileNotFoundException fnf1) {66 File f = createAttachFile(pid);67 try {68 // kill -QUIT will tickle target VM to check for the69 // attach file.70 sigquit(pid);71 // give the target VM time to start the attach mechanism72 int i = 0;73 long delay = 200;74 int retries = (int)(attachTimeout() / delay);75 do {76 try {77 Thread.sleep(delay);78 } catch (InterruptedException x) { }79 try {80 fd = openDoor(pid);81 } catch (FileNotFoundException fnf2) { }82 i++;83 } while (i <= retries && fd == -1);84 if (fd == -1) {85 throw new AttachNotSupportedException(86 "Unable to open door: target process not responding or " +87 "HotSpot VM not loaded");88 }89 } finally {90 f.delete();91 }92 }93 assert fd >= 0;94 }95 /**96 * Detach from the target VM97 */98 public void detach() throws IOException {99 synchronized (this) {100 if (fd != -1) {101 close(fd);102 fd = -1;103 }104 }105 }106 /**107 * Execute the given command in the target VM.108 */109 InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {110 assert args.length <= 3; // includes null111 // first check that we are still attached112 int door;113 synchronized (this) {114 if (fd == -1) {115 throw new IOException("Detached from target VM");116 }117 door = fd;118 }119 // enqueue the command via a door call120 int s = enqueue(door, cmd, args);121 assert s >= 0; // valid file descriptor122 // The door call returns a file descriptor (one end of a socket pair).123 // Create an input stream around it.124 SocketInputStream sis = new SocketInputStream(s);125 // Read the command completion status126 int completionStatus;127 try {128 completionStatus = readInt(sis);129 } catch (IOException ioe) {130 sis.close();131 throw ioe;132 }133 // If non-0 it means an error but we need to special-case the134 // "load" command to ensure that the right exception is thrown.135 if (completionStatus != 0) {136 // read from the stream and use that as the error message137 String message = readErrorMessage(sis);138 sis.close();139 if (cmd.equals("load")) {140 throw new AgentLoadException("Failed to load agent library");141 } else {142 if (message == null) {143 throw new AttachOperationFailedException("Command failed in target VM");144 } else {145 throw new AttachOperationFailedException(message);146 }147 }148 }149 // Return the input stream so that the command output can be read150 return sis;151 }152 // InputStream over a socket153 private class SocketInputStream extends InputStream {154 int s;155 public SocketInputStream(int s) {156 this.s = s;157 }158 public synchronized int read() throws IOException {159 byte b[] = new byte[1];160 int n = this.read(b, 0, 1);161 if (n == 1) {162 return b[0] & 0xff;163 } else {164 return -1;165 }166 }167 public synchronized int read(byte[] bs, int off, int len) throws IOException {168 if ((off < 0) || (off > bs.length) || (len < 0) ||169 ((off + len) > bs.length) || ((off + len) < 0)) {170 throw new IndexOutOfBoundsException();171 } else if (len == 0)172 return 0;173 return SolarisVirtualMachine.read(s, bs, off, len);174 }175 public void close() throws IOException {176 SolarisVirtualMachine.close(s);177 }178 }179 // The door is attached to .java_pid<pid> in the temporary directory.180 private int openDoor(int pid) throws IOException {181 String path = tmpdir + "/.java_pid" + pid;;182 fd = open(path);183 // Check that the file owner/permission to avoid attaching to184 // bogus process185 try {186 checkPermissions(path);187 } catch (IOException ioe) {188 close(fd);189 throw ioe;190 }...

Full Screen

Full Screen

Source:SolarisAttachProvider.java Github

copy

Full Screen

...23 checkAttachPermission();24 // AttachNotSupportedException will be thrown if the target VM can be determined25 // to be not attachable.26 testAttachable(vmid);27 return new SolarisVirtualMachine(this, vmid);28 }29 public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)30 throws AttachNotSupportedException, IOException31 {32 if (vmd.provider() != this) {33 throw new AttachNotSupportedException("provider mismatch");34 }35 // To avoid re-checking if the VM if attachable, we check if the descriptor36 // is for a hotspot VM - these descriptors are created by the listVirtualMachines37 // implementation which only returns a list of attachable VMs.38 if (vmd instanceof HotSpotVirtualMachineDescriptor) {39 assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();40 checkAttachPermission();41 return new SolarisVirtualMachine(this, vmd.id());42 } else {43 return attachVirtualMachine(vmd.id());44 }45 }46}...

Full Screen

Full Screen

SolarisVirtualMachine

Using AI Code Generation

copy

Full Screen

1import sun.tools.attach.*;2import java.io.*;3import java.util.*;4{5 public static void main(String[] args)6 {7 {8 SolarisVirtualMachine vm = new SolarisVirtualMachine(args[0]);9 vm.loadAgentLibrary("libattach.so", "load");10 vm.detach();11 }12 catch(IOException e)13 {14 System.out.println(e);15 }16 }17}18import sun.tools.attach.*;19import java.io.*;20import java.util.*;21{22 public static void main(String[] args)23 {24 {25 SolarisVirtualMachine vm = new SolarisVirtualMachine(args[0]);26 vm.loadAgentLibrary("libattach.so", "unload");27 vm.detach();28 }29 catch(IOException e)30 {31 System.out.println(e);32 }33 }34}35import sun.tools.attach.*;36import java.io.*;37import java.util.*;38{39 public static void main(String[] args)40 {41 {42 SolarisVirtualMachine vm = new SolarisVirtualMachine(args[0]);43 vm.loadAgentLibrary("libattach.so", "dump");44 vm.detach();45 }46 catch(IOException e)47 {48 System.out.println(e);49 }50 }51}52import sun.tools.attach.*;53import java.io.*;54import java.util.*;55{56 public static void main(String[] args)57 {58 {59 SolarisVirtualMachine vm = new SolarisVirtualMachine(args[0]);60 vm.loadAgentLibrary("libattach.so", "status");61 vm.detach();62 }63 catch(IOException e)64 {65 System.out.println(e);66 }67 }68}69import sun.tools.attach.*;70import java.io.*;71import java.util.*;72{73 public static void main(String[] args)74 {75 {76 SolarisVirtualMachine vm = new SolarisVirtualMachine(args[0]);77 vm.loadAgentLibrary("lib

Full Screen

Full Screen

SolarisVirtualMachine

Using AI Code Generation

copy

Full Screen

1import sun.tools.attach.*;2import com.sun.tools.attach.*;3import java.io.*;4import java.util.*;5import java.lang.management.*;6import java.lang.management.ManagementFactory;7import com.sun.management.*;8import java.util.List;9import java.util.Arrays;10import java.util.ArrayList;11import java.util.Iterator;12import java.lang.reflect.Method;13import java.lang.reflect.InvocationTargetException;14import java.lang.reflect.Field;15import java.lang.reflect.Constructor;16import java.net.URL;17import java.net.URLClassLoader;18import java.net.MalformedURLException;19{20public static void main(String[] args) throws Exception21{22String pid = args[0];23SolarisVirtualMachine vm = new SolarisVirtualMachine(pid);24List classes = vm.getLoadedClasses(true);25System.out.println("List of loaded classes: ");26for (int i = 0; i < classes.size(); i++)27{28System.out.println(classes.get(i));29}30}31}

Full Screen

Full Screen

SolarisVirtualMachine

Using AI Code Generation

copy

Full Screen

1import sun.tools.attach.*;2import java.io.IOException;3public class 4 {4 public static void main(String[] args) {5 try {6 SolarisVirtualMachine vm = new SolarisVirtualMachine(1234);7 System.out.println("PID of the JVM is " + vm.getPid());8 } catch (IOException e) {9 System.out.println("Exception: " + e);10 }11 }12}13import sun.tools.attach.*;14import java.io.IOException;15public class 5 {16 public static void main(String[] args) {17 try {18 HotSpotVirtualMachine vm = new HotSpotVirtualMachine(1234);19 System.out.println("PID of the JVM is " + vm.getPid());20 } catch (IOException e) {21 System.out.println("Exception: " + e);22 }23 }24}25import jdk.tools.attach.*;26import java.io.IOException;27public class 6 {28 public static void main(String[] args) {29 try {30 HotSpotVirtualMachine vm = new HotSpotVirtualMachine(1234);31 System.out.println("PID of the JVM is " + vm.getPid());32 } catch (IOException e) {33 System.out.println("Exception: " + e);34 }35 }36}37import jdk.tools.attach.*;38import java.io.IOException;39public class 7 {40 public static void main(String[] args) {41 try {42 HotSpotVirtualMachine vm = new HotSpotVirtualMachine(1234);43 System.out.println("PID of the JVM is " + vm.getPid());44 } catch (IOException e) {45 System.out.println("Exception: " + e);46 }47 }48}

Full Screen

Full Screen

SolarisVirtualMachine

Using AI Code Generation

copy

Full Screen

1import java.io.*;2import sun.tools.attach.*;3import java.util.*;4{5public static void main(String[] args) throws Exception6{7List<String> l = SolarisVirtualMachine.list();8System.out.println("No of Java processes running on the system: " + l.size());9for(String s : l)10{11System.out.println(s);12}13}14}15import java.io.*;16import com.sun.tools.attach.*;17import java.util.*;18{19public static void main(String[] args) throws Exception20{21List<String> l = WindowsVirtualMachine.list();22System.out.println("No of Java processes running on the system: " + l.size());23for(String s : l)24{25System.out.println(s);26}27}28}

Full Screen

Full Screen

SolarisVirtualMachine

Using AI Code Generation

copy

Full Screen

1import sun.tools.attach.*;2import com.sun.tools.attach.*;3import java.util.*;4import java.io.*;5import java.lang.management.*;6{7public static void main(String args[]) throws Exception8{9VirtualMachine vm = VirtualMachine.attach("pid");10List<ThreadInfo> list = vm.getSystemProperties().getThreadInfo();11for (ThreadInfo info : list)12{13System.out.println("Thread name: " + info.getThreadName());14System.out.println("Thread id: " + info.getThreadId());15System.out.println("Thread state: " + info.getThreadState());16System.out.println("Thread cpu time: " + info.getThreadCpuTime());17System.out.println("Thread user time: " + info.getThreadUserTime());18System.out.println("Thread blocked count: " + info.getBlockedCount());19System.out.println("Thread blocked time: " + info.getBlockedTime());20System.out.println("Thread waited count: " + info.getWaitedCount());21System.out.println("Thread waited time: " + info.getWaitedTime());22System.out.println("Thread lock name: " + info.getLockName());23System.out.println("Thread lock owner name: " + info.getLockOwnerName());24System.out.println("Thread lock owner id: " + info.getLockOwnerId());25System.out.println("Thread in native: " + info.isInNative());26System.out.println("Thread suspended: " + info.isSuspended());27System.out.println("Thread daemon: " + info.isDaemon());28System.out.println("Thread priority: " + info.getPriority());29System.out.println("Thread stack trace: " + info.getStackTrace());30System.out.println("Thread lock info: " + info.getLockInfo());31System.out.println("Thread locked monitors: " + info.getLockedMonitors());32System.out.println("Thread locked synchronizers: " + info.getLockedSynchronizers());33}34}35}

Full Screen

Full Screen

SolarisVirtualMachine

Using AI Code Generation

copy

Full Screen

1import java.io.IOException;2import java.util.List;3import java.util.ArrayList;4import java.util.Properties;5import com.sun.tools.attach.*;6import com.sun.tools.attach.spi.AttachProvider;7public class 4 {8 public static void main(String[] args) throws IOException {9 List<VirtualMachineDescriptor> vmList = VirtualMachine.list();10 for (VirtualMachineDescriptor vmd : vmList) {11 System.out.println("PID: " + vmd.id());12 System.out.println("Display Name: " + vmd.displayName());13 System.out.println("Provider: " + vmd.provider());14 System.out.println("Virtual Machine: " + vmd);15 System.out.println("");16 }17 }18}

Full Screen

Full Screen

SolarisVirtualMachine

Using AI Code Generation

copy

Full Screen

1import com.sun.tools.attach.*;2import java.io.*;3import java.util.*;4public class 4 {5 public static void main(String[] args) {6 if (args.length != 1) {7 System.out.println("Usage: java 4 <pid>");8 System.out.println("where pid is the process id of the java process");9 System.out.println("for example: java 4 1234");10 System.exit(1);11 }12 String pid = args[0];13 String cmd = "jstack " + pid;14 String line;15 Process p;16 try {17 p = Runtime.getRuntime().exec(cmd);18 BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));19 while ((line = input.readLine()) != null) {20 System.out.println(line);21 }22 input.close();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Powermock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful