java agent

-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
Agent (agent) is in front of your main method of an interceptor (interceptor), that is, before the main method of execution, execution agent code.
The agent with your main code running in the same JVM method, and loaded with a system classloader, by the same security policy (security policy) and context (context) managed.
For example: java -javaagent: myagent.jar = mode =  test Test specify jar path we've written agent of (./myagent.jar), as well as arguments to the agent (mode = test), when the start of this agent on we hope that you can do some things:
You can do to intercept before loading class files, make changes to the bytecode
You can make changes to the loaded class bytecode at runtime
Get all the classes have been loaded
Get all the classes already initialized (performed clinit method, is a subset of the above)
Gets the size of an object
The jar was added to a bootstrap classpath in as a high priority is loaded bootstrapClassloader
A jar will be added to the classpath for AppClassloard to load
Set some native method prefix, the main job of matching rules in the native method to find the time.

In a java application, -javaagent number is not limited to this parameter, you can specify multiple javaagent, all javaagent be executed sequentially, each performed after completing Agent, then execute the main method, in the method after the main premain method will not be executed. such as
set JAVA_OPTS=%JAVA_OPTS% -javaagent:D:/tools/myagent1.jar -javaagent:D:/tools/myagent2.jar -javaagent:D:/tools/myagent3.jar Test
The execution order is: myagent1.premain -> myagent2.premain -> myagent.premain -> Test.main

Guess you like

Origin www.cnblogs.com/doit8791/p/11993184.html