Brief introduction
for Agents, it is the service proxy that modifies the bytecode before the VM starts and executes the method.
for Javassist, a specific implementation of the bytecode is modified.
What's the use of these two combinations? writing a test framework is not limited to this.
for byte codes:
BYTE-code processing tool, BCEL,ASM with virtual machine directives. Javassist uses a Java-encoded method to process bytecode, which is relatively low-performance, but convenient.
Official: http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/
Example:
Create a class http://blog.csdn.net/sadfishsc/article/details/9999169
Interception Method AOP http://yonglin4605.iteye.com/blog/1396494
Tutorial: http://www.ibm.com/developerworks/cn/java/j-dyn0916/
Api:http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/html/index.html
API documentation: 045Javassist Getting Started manual
Use
The use of combination with Agent
1. Create a project, introduce a jar package
2. Writing the MANIFEST.MF file
Content:
manifest-version:1.0
Premain-class:com.agent.perfmonagent//Start Agent Mode implementation class
Can-redefine-classes:true
3. Write the Perfmonagent class, that is, after the JVM starts the agent mode, the class that is called before executing the method
4. Write the transform method of Perfmonxformer class to implement Classfiletransformer interface, that is, the implementation of conversion class format
The specific methods is the specific processing of the bytecode, which needs to be modified by the method provided in the Javassist package.
5. Package The agent service jar, using a custom. MF File
1) Project Right-click->export->java->jar file
2) Select item
3) Select the path to the jar
4) Next,next
5) Use MF file
6) Finish
6. Project configuration, add Agent service
1) Project Right-click, or Java file Right-click->run configurations
2) (x) =arguments tab, fill in the boot VM parameters
3) Run
7. Start the project or run a Java class, start the agent and modify the byte code
Download
Source: http://download.csdn.net/detail/supermarss/8716783
Build agent service +javassist byte code operation