HotSpot Dynamic Attach Mechanism

http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#battach

HotSpot Dynamic Attach Mechanism

This is a Sun extension that allows a tool to ‘attach’ to another process running Java code and launch a JVM TI agent or a java.lang.instrument agent in that process. This also allows the system properties to be obtained from the target JVM.

The Sun implementation of this API also includes some HotSpot specific methods that allow additional information to be obtained from HotSpot:

  • The ctrl-break output from the local JVM
  • The ctrl-break output from the remote JVM
  • A dump of the heap
  • A histogram showing the number of instances of the classes loaded in the target JVM. Either all instances or just ‘live’ instances can be counted.
  • The value of a manageable command line flag. Such flags can also be set.

Dynamic attach has an attach listener thread in the target JVM. This is a thread that is started when the first attach request occurs. On Linux and Solaris, the client creates a file named .attach_pid(pid) and sends a SIGQUIT to the target JVM process. The existence of this file causes the SIGQUIT handler in HotSpot to start the attach listener thread. On Windows, the client uses the Win32 CreateRemoteThread function to create a new thread in the target process. The attach listener thread then communicates with the source JVM in an OS dependent manner:

  • On Solaris, the Doors IPC mechanism is used. The door is attached to a file in the file system so that clients can access it.
  • On Linux, a Unix domain socket is used. This socket is bound to a file in the filesystem so that clients can access it.
  • On Windows, the created thread is given the name of a pipe which is served by the client. The result of the operations are written to this pipe by the target JVM.
This entry was posted in Software. Bookmark the permalink.

Leave a comment