src/share/classes/java/lang/instrument/package.html

Print this page




 123 
 124 
 125 
 126 <h3>Starting Agents After VM Startup</h3>
 127 
 128 <p>
 129 An implementation may provide a mechanism to start agents sometime after the
 130 the VM has started. The details as to how this is initiated are implementation 
 131 specific but typically the application has already started and its <code>
 132 main</code> method has already been invoked. In cases where an implementation
 133 supports the starting of agents after the VM has started the following applies:
 134 
 135 <ol>
 136   <li><p>The manifest of the agent JAR must contain the attribute <code>Agent-Class</code>. 
 137       The value of this attribute is the name of the <i>agent class</i>. </p></li> 
 138       
 139   <li><p>The agent class must implement a public static <code>agentmain</code> method. </p></li>
 140 
 141   <li><p>The system class loader (
 142       {@link java.lang.ClassLoader#getSystemClassLoader ClassLoader.getSystemClassLoader}) must
 143       support a mechanism to add an agent JAR file to the system class path. <p></li>
 144 </ol>  
 145 
 146 <P>
 147 The agent JAR is appended to the system class path. This is the class loader that typically loads 
 148 the class containing the application <code>main</code> method. The agent class is loaded and the
 149 JVM attempts to invoke the <code>agentmain</code> method. The JVM first attempts to invoke 
 150 the following method on the agent class:
 151 
 152 <blockquote>
 153 <code>public static void
 154 agentmain(String agentArgs, Instrumentation inst);
 155 </code>
 156 </blockquote>
 157 
 158 <P>
 159 If the agent class does not implement this method then the JVM will attempt to invoke:
 160 
 161 <blockquote>
 162 <code>public static void
 163 agentmain(String agentArgs);




 123 
 124 
 125 
 126 <h3>Starting Agents After VM Startup</h3>
 127 
 128 <p>
 129 An implementation may provide a mechanism to start agents sometime after the
 130 the VM has started. The details as to how this is initiated are implementation 
 131 specific but typically the application has already started and its <code>
 132 main</code> method has already been invoked. In cases where an implementation
 133 supports the starting of agents after the VM has started the following applies:
 134 
 135 <ol>
 136   <li><p>The manifest of the agent JAR must contain the attribute <code>Agent-Class</code>. 
 137       The value of this attribute is the name of the <i>agent class</i>. </p></li> 
 138       
 139   <li><p>The agent class must implement a public static <code>agentmain</code> method. </p></li>
 140 
 141   <li><p>The system class loader (
 142       {@link java.lang.ClassLoader#getSystemClassLoader ClassLoader.getSystemClassLoader}) must
 143       support a mechanism to add an agent JAR file to the system class path.</li>
 144 </ol>  
 145 
 146 <P>
 147 The agent JAR is appended to the system class path. This is the class loader that typically loads 
 148 the class containing the application <code>main</code> method. The agent class is loaded and the
 149 JVM attempts to invoke the <code>agentmain</code> method. The JVM first attempts to invoke 
 150 the following method on the agent class:
 151 
 152 <blockquote>
 153 <code>public static void
 154 agentmain(String agentArgs, Instrumentation inst);
 155 </code>
 156 </blockquote>
 157 
 158 <P>
 159 If the agent class does not implement this method then the JVM will attempt to invoke:
 160 
 161 <blockquote>
 162 <code>public static void
 163 agentmain(String agentArgs);