Build agent service +javassist byte code operation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.