`
月迷津渡
  • 浏览: 100504 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

javassist和asm比较

    博客分类:
  • Java
阅读更多
Javassist:

• Javassist (Java Programming Assistant) makes Java bytecode manipulation simple. It is a class library for editing bytecodes in Java; it enables Java programs to define a new class at runtime and to modify a class file when the JVM loads it. Unlike other similar bytecode editors
• Javassist provides two levels of API: source level and bytecode level. If the users use the source-level API, they can edit a class file without knowledge of the specifications of the Java bytecode. The whole API is designed with only the vocabulary of the Java language. You can even specify inserted bytecode in the form of source text; Javassist compiles it on the fly. On the other hand, the bytecode-level API allows the users to directly edit a class file as other editors.
• Javassist lets you inspect, edit, and create Java binary classes.
• Javassist isn’t the only library for working with bytecode, but it does have one feature in particular that makes it a great starting point for experimenting with classworking: you can use Javassist to alter the bytecode of a Java class without actually needing to learn anything about bytecode or the Java virtual machine (JVM) architecture.
• Aspect Oriented Programming: Javassist can be a good tool for adding new methods into a class and for inserting before/after/around advice at the both caller and callee sides.
• Reflection: One of applications of Javassist is runtime reflection; Javassist enables Java programs to use a metaobject that controls method calls on base-level objects. No specialized compiler or virtual machine are needed.
• Javassist also provides lower-level API for directly editing a class file. To use this level of API, you need detailed knowledge of the Java bytecode and the class file format while this level of API allows you any kind of modification of class files.

ASM:

• ASM is an all purpose Java bytecode manipulation and analysis framework. It can be used to modify existing classes or dynamically generate classes, directly in binary form. Provided common transformations and analysis algorithms allow to easily assembling custom complex transformations and code analysis tools.
• ASM offer similar functionality as other bytecode frameworks, but it is focused on simplicity of use and performance. Because it was designed and implemented to be as small and as fast as possible, it makes it very attractive for using in dynamic systems*.
• ASM is a Java class manipulation tool designed to dynamically generate and manipulate Java classes, which are useful techniques to implement adaptable systems. ASM is based on a new approach, compared to equivalent existing tools, which consists in using the “visitor” design pattern without explicitly representing the visited tree with objects. This new approach gives much better performances than those of existing tools, for most of practical needs.

Comparison between Javassist & ASM:

• Javassist source level API is much easier to use than the actual bytecode manipulation in ASM
• Javassist provides a higher level abstraction layer over complex bytecode level operations. Javassist source level API requires very less or no knowledge of actual bytecodes, so much easier & faster to implement.
• Javassist uses reflection mechanism which makes it slower compared to ASM which uses Classworking techniques at runtime.
• Overall ASM is much faster & gives better performance than Javassist. Javassist uses a simplified version of Java source code, which it then compiles into bytecode. That makes Javassist very easy to use, but it also limits the use of bytecode to what can be expressed within the limits of the Javassist source code.
• In conclusion, if someone needs easier way of dynamically manipulating or creating Java classes Javassist API should be used & where the performance is the key issue ASM library should be used.

Table 1. Class construction times

Framework        First time       Later times
Javassist             257                  5.2
BCEL                     473                  5.5
ASM                      62.4                 1.1
The Table 1 results show that ASM does live up to its billing as faster than the other frameworks, and this advantage applies both to startup time and to repeated uses.
分享到:
评论

相关推荐

    Java动态代理机制详解(JDK 和CGLIB,Javassist,ASM)

    NULL 博文链接:https://bijian1013.iteye.com/blog/2382393

    JavaAgent:Javassist 与 Asm JavaAgent 字节码动态编程项目

    JavaAgent Javassist 与 Asm JavaAgent 字节码动态编程项目

    javassist-3.14.0-GA

    Javassist是一个开源的分析、编辑和创建Java字节码的类库。是由东京工业大学的数学和计算机科学系的 Shigeru Chiba (千叶 滋)所创建的。它已加入了开放源代码JBoss 应用服务器项目,通过使用Javassist对字节码操作...

    Javassistjar包

    关于java字节码的处理,目前有很多工具,如bcel,asm。不过这些都需要直接跟虚拟机指令打交道。如果你不想了解虚拟机指令,可以采用javassist。javassist是jboss的一个子项目,其主要的优点,在于简单,而且快速。...

    javassist反射工具

    Javassist是一个开源的分析、编辑和创建Java字节码的类库。是由东京工业大学的数学和计算机科学系的 Shigeru Chiba (千叶 滋)所创建的。它已加入了开放源代码JBoss 应用服务器项目,通过使用Javassist对字节码操作...

    手写组件化框架路由跳转功能

    使用Apt、Javassist、ASM技术分别实现组件化路由跳转功能

    javassist使用手册

    javassist一款日本开源的字节码工具类,相比asm等工具来说,更加利于让人理解,方便使用。该集合包中,详尽的介绍了javassist的使用

    Android代码-jaop

    jaop 是一个基于javassist和asm的gradle aop插件,可以在特定的方法调用处或方法体内 编程 javassist做简单的代码插入,asm做操作数栈分析和字节码的转录 不会新增任何方法,秒杀aspectj 兼容性更好 不支持instant ...

    Javassist 修改class字节码

    Javassist 提供了java类库,...与其他同类工具(asm等)不同的是,Javassist提供了两个层面的API: 1.java代码层 2.字节码层 通过java代码层,开发者即时对字节码不是很熟悉,也可以非常方便快速的完成字节码的修改。

    java6string源码-dynamic-proxy:利用ASM、CGLIB、ByteBuddy、Javassist和JDKDynamicP

    java6string源码Java 动态代理 动态代理是 Java 开发人员生成代理对象的有用...ASM、Javassist、ByteBuddy、CGLIB 和传统 JDK 动态代理的特定代码生成创建者。 ObjectInvoker是定义方法行为的地方。 createInvokerProx

    Struts2实现文件的上传和下载

    用到的jar包有:asm-3.3.jar,asm-commons-3.3.jar,asm-tree-3.3.jar,commons-fileupload-1.2.2.jar,commons-io-2.0.1.jar,commons-lang-2.5.jar,freemarker-2.3.18.jar,javassist-3.11.0.GA.jar,ognl-3.0.4....

    小傅哥的字节码编程(公众号:bugstack虫洞栈).pdf

    ASM、Javassist、Byte-buddy以及JavaAgent,没有很大的市场也就没有很多的资料。但大家其实已经从其他的框架或者中间件中使用到,就像你用到的;Cglib、混沌工程、非入侵的全链路监控以及你是否使用过jetbrains-...

    struts2中json依赖包

    asm-3.3.jar/asm-commons-3.3.jar/asm-tree-3.3.jar/commons-beanutils-1.8.3.jar/commons-collections-3.2.1.jar/commons-fileupload-1.3.1.jar/commons-io-2.2.jar/commons-lang-2.5.jar/commons-lang3-3.2.jar/...

    struts2要用的jar包(仅仅是struts2的jar包 )

    asm-3.3.jar asm-commons-3.3.jar commons-fileupload-1.2.2.jar commons-io-2.4.jar commons-lang3-3.1.jar commons-logging-1.1.1.jar fastjson-1.1.24-20120814.043343-7.jar freemarker-2.3.19.jar jackson-core...

    Java各种Jar包

    欢迎下载Java各种Jar包.zip 此文件所包含的Java Jar包: ---MySQL mysql-connector-java-3.1.12-bin.jar ... javassist-3.11.0.GA.jar ognl-3.0.1.jar struts2-core-2.2.3.1.jar xwork-core-2.2.3.1.jar

    ssm框架整合jar包

    javassist-3.21.0-GA.jar log4j-1.2.17.jar mybatis-3.2.5.jar mybatis-spring-1.2.0.jar mysql.jar ognl-3.1.12.jar spring-aop-4.0.6.RELEASE.jar spring-aspects-4.0.6.RELEASE.jar spring-beans-4.0.6.RELEASE....

    Struts2jar包

    包含struts2常用的13个jar包: asm asm-commons asm-tree commons-fileupload commons-io commons-lang freemarker javassist log4j-api log4j-core ognl struts2-core xwork-core

    SSHjar包 .rar

    asm-3.3.jar asm-commons-3.3.jar asm-tree-3.3.jar com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar com.springsource.org.aopalliance-1.0.0.jar com.springsource.org.apache.commons.logging-1.1.1.jar ...

    mybatis3.4.1所需jar包

    搭建mybatis所需jar包和mysql3.1.13jar包。包括:slf4j-log4j12-1.7.21.jar、slf4j-api-1.7.21.jar、ognl-3.1.8.jar、mybatis-3.4.1.jar、log4j-core-2.3.jar、log4j-api-2.3.jar、log4j-1.2.17.jar、javassist-...

    web开发中常用的jar包

    activation.jar antlr-2.7.6.jar asm-3.3.jar asm-commons-3.3(1).jar asm-tree-3.3.jar c3p0-0.9.1.jar com.springsource.org.aopalliance-1.0.0.jar com.springsource.org.apache.commons.logging-1.1.1.jar ...

Global site tag (gtag.js) - Google Analytics