A VirtualMachine
represents a Java virtual machine to which this
Java virtual machine has attached. The Java virtual machine to which it is
attached is sometimes called the target virtual machine, or target VM.
An application (typically a tool such as a managemet console or profiler) uses a
VirtualMachine to load an agent into the target VM. For example, a profiler tool
written in the Java Language might attach to a running application and load its
profiler agent to profile the running application.
A VirtualMachine is obtained by invoking the attach
method
with an identifier that identifies the target virtual machine. The identifier is
implementation-dependent but is typically the process identifier (or pid) in
environments where each Java virtual machine runs in its own operating system process.
Alternatively, a VirtualMachine
instance is obtained by invoking the
attach
method with a VirtualMachineDescriptor
obtained
from the list of virtual machine descriptors returned by the list
method.
Once a reference to a virtual machine is obtained, the loadAgent
,
loadAgentLibrary
, and loadAgentPath
methods are used to load agents into target virtual machine. The loadAgent
method is used to load agents that are written in the Java
Language and deployed in a JAR file
. (See
java.
for a detailed description on how these agents
are loaded and started). The loadAgentLibrary
and
loadAgentPath
methods are used to load agents that
are deployed either in a dynamic library or statically linked into the VM and
make use of the JVM Tools Interface.
In addition to loading agents a VirtualMachine provides read access to the
system properties
in the target VM.
This can be useful in some environments where properties such as
java.home
, os.name
, or os.arch
are
used to construct the path to agent that will be loaded into the target VM.
The following example demonstrates how VirtualMachine may be used:
// attach to target VM VirtualMachine vm = VirtualMachine.attach("2177"); // start management agent Properties props = new Properties(); props.put("com.sun.management.jmxremote.port", "5000"); vm.startManagementAgent(props); // detach vm.detach();
In this example we attach to a Java virtual machine that is identified by
the process identifier 2177
. Then the JMX management agent is
started in the target process using the supplied arguments. Finally, the
client detaches from the target VM.
A VirtualMachine is safe for use by multiple concurrent threads.
Modifier and Type | Field and Description |
---|---|
private volatile int | |
private String | |
private AttachProvider |
Access | Constructor and Description |
---|---|
protected | VirtualMachine(AttachProvider
The attach provider creating this class. provider, String The abstract identifier that identifies the Java virtual machine. id)Initializes a new instance of this class. |
Modifier and Type | Method and Description |
---|---|
public static VirtualMachine | |
public static VirtualMachine | Returns: A VirtualMachine representing the target VM.The virtual machine descriptor. vmd)Attaches to a Java virtual machine. |
public abstract void | |
public boolean | Returns: true if, and only if, the given object is
a VirtualMachine that is equal to this
VirtualMachine.The object to which this object is to be compared ob)Overrides java. Tests this VirtualMachine for equality with another object. |
public abstract Properties | Returns: The agent propertiesReturns the current agent properties in the target virtual machine. |
public abstract Properties | Returns: The system propertiesReturns the current system properties in the target virtual machine. |
public int | Returns: A hash-code value for this virtual machineOverrides java. Returns a hash-code value for this VirtualMachine. |
public final String | Returns: The identifier for this Java virtual machine.Returns the identifier for this Java virtual machine. |
public static List | |
public abstract void | |
public void | |
public abstract void | loadAgentLibrary(String
The name of the agent library. agentLibrary, String The options to provide to the options)Agent_OnAttach[_L]
function (can be null ).Loads an agent library. |
public void | |
public abstract void | loadAgentPath(String
The full path of the agent library. agentPath, String The options to provide to the options)Agent_OnAttach[_L]
function (can be null ).Load a native agent library by full pathname. |
public void | loadAgentPath(String
The full path to the agent library. agentPath)Load a native agent library by full pathname. |
public final AttachProvider | Returns: The provider that created this virtual machine.Returns the provider that created this virtual machine. |
public abstract String | Returns: The String representation of the local connector's service address. The value can be parsed by thejavax.
constructor.Starts the local JMX management agent in the target virtual machine. |
public abstract void | startManagementAgent(Properties
A Properties object containing the configuration properties
for the agent. agentProperties)Starts the JMX management agent in the target virtual machine. |
public String | toString()
Overrides java. Returns the string representation of the |
hash | back to summary |
---|---|
private volatile int hash |
id | back to summary |
---|---|
private String id |
provider | back to summary |
---|---|
private AttachProvider provider |
VirtualMachine | back to summary |
---|---|
protected VirtualMachine(AttachProvider provider, String id) Initializes a new instance of this class.
|
attach | back to summary |
---|---|
public static VirtualMachine attach(String id) throws AttachNotSupportedException, IOException Attaches to a Java virtual machine. This method obtains the list of attach providers by invoking the
|
attach | back to summary |
---|---|
public static VirtualMachine attach(VirtualMachineDescriptor vmd) throws AttachNotSupportedException, IOException Attaches to a Java virtual machine. This method first invokes the
|
detach | back to summary |
---|---|
public abstract void detach() throws IOException Detach from the virtual machine. After detaching from the virtual machine, any further attempt to invoke
operations on that virtual machine will cause an If already detached from the virtual machine then invoking this method has no effect.
|
equals | back to summary |
---|---|
public boolean equals(Object ob) Overrides java. Tests this VirtualMachine for equality with another object. If the given object is not a VirtualMachine then this
method returns This method satisfies the general contract of the
|
getAgentProperties | back to summary |
---|---|
public abstract Properties getAgentProperties() throws IOException Returns the current agent properties in the target virtual machine. The target virtual machine can maintain a list of properties on behalf of agents. The manner in which this is done, the names of the properties, and the types of values that are allowed, is implementation specific. Agent properties are typically used to store communication end-points and other agent configuration details. For example, a debugger agent might create an agent property for its transport address. This method returns the agent properties whose key and value is a
|
getSystemProperties | back to summary |
---|---|
public abstract Properties getSystemProperties() throws IOException Returns the current system properties in the target virtual machine. This method returns the system properties in the target virtual
machine. Properties whose key or value is not a This method is typically used to decide which agent to load into
the target virtual machine with
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Returns a hash-code value for this VirtualMachine. The hash
code is based upon the VirtualMachine's components, and satisfies
the general contract of the
|
id | back to summary |
---|---|
public final String id() Returns the identifier for this Java virtual machine.
|
list | back to summary |
---|---|
public static List Return a list of Java virtual machines. This method returns a list of Java
|
loadAgent | back to summary |
---|---|
public abstract void loadAgent(String agent, String options) throws AgentLoadException, AgentInitializationException, IOException Loads an agent. The agent provided to this method is a path name to a JAR file on the file
system of the target virtual machine. This path is passed to the target virtual
machine where it is interpreted. The target virtual machine attempts to start
the agent as specified by the
|
loadAgent | back to summary |
---|---|
public void loadAgent(String agent) throws AgentLoadException, AgentInitializationException, IOException Loads an agent. This convenience method works as if by invoking:
|
loadAgentLibrary | back to summary |
---|---|
public abstract void loadAgentLibrary(String agentLibrary, String options) throws AgentLoadException, AgentInitializationException, IOException Loads an agent library. A JVM TI
client is called an agent. It is developed in a native language.
A JVM TI agent is deployed in a platform specific manner but it is typically the
platform equivalent of a dynamic library. Alternatively, it may be statically linked into the VM.
This method causes the given agent library to be loaded into the target
VM (if not already loaded or if not statically linked into the VM).
It then causes the target VM to invoke the The agent library provided is the name of the agent library. It is interpreted
in the target virtual machine in an implementation-dependent manner. Typically an
implementation will expand the library name into an operating system specific file
name. For example, on UNIX systems, the name If the
|
loadAgentLibrary | back to summary |
---|---|
public void loadAgentLibrary(String agentLibrary) throws AgentLoadException, AgentInitializationException, IOException Loads an agent library. This convenience method works as if by invoking:
|
loadAgentPath | back to summary |
---|---|
public abstract void loadAgentPath(String agentPath, String options) throws AgentLoadException, AgentInitializationException, IOException Load a native agent library by full pathname. A JVM TI
client is called an agent. It is developed in a native language.
A JVM TI agent is deployed in a platform specific manner but it is typically the
platform equivalent of a dynamic library. Alternatively, the native
library specified by the agentPath parameter may be statically
linked with the VM. The parsing of the agentPath parameter into
a statically linked library name is done in a platform
specific manner in the VM. For example, in UNIX, an agentPath parameter
of The agent library provided is the absolute path from which to load the
agent library. Unlike If the
|
loadAgentPath | back to summary |
---|---|
public void loadAgentPath(String agentPath) throws AgentLoadException, AgentInitializationException, IOException Load a native agent library by full pathname. This convenience method works as if by invoking:
|
provider | back to summary |
---|---|
public final AttachProvider provider() Returns the provider that created this virtual machine.
|
startLocalManagementAgent | back to summary |
---|---|
public abstract String startLocalManagementAgent() throws IOException Starts the local JMX management agent in the target virtual machine. See the online documentation for Monitoring and Management Using JMX Technology for further details.
|
startManagementAgent | back to summary |
---|---|
public abstract void startManagementAgent(Properties agentProperties) throws IOException Starts the JMX management agent in the target virtual machine. The configuration properties are the same as those specified on
the command line when starting the JMX management agent. In the same
way as on the command line, you need to specify at least the
See the online documentation for Monitoring and Management Using JMX Technology for further details.
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns the string representation of the
|