`
月迷津渡
  • 浏览: 102207 次
  • 性别: 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)

    在Javassist中,我们可以通过`javassist.ClassPool`,`javassist.CtClass`,`javassist.CtMethod`等类来创建和修改类及方法。 **ASM**: ASM是一个底层的Java字节码操控和分析框架,它可以用来动态生成类或者增强已...

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

    在这个“JavaAgent: Javassist与Asm JavaAgent字节码动态编程项目”中,我们将深入探讨如何利用Javassist和ASM这两个库来实现JavaAgent。 首先,Javassist是一个开源的Java字节码操作框架,它使得开发者可以在运行...

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

    本篇文章将深入探讨如何利用Apt、Javassist和ASM这三种不同的技术来实现组件化框架中的路由跳转功能。 首先,让我们了解一下Apt(Annotation Processing Tool)。Apt是Java提供的一种预编译处理工具,它可以解析源...

    Javassistjar包

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

    javassist-3.14.0-GA

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

    javassist反射工具

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

    javassist-3.15.0-GA

    总结来说,"javassist-3.15.0-GA"是Java开发中的一个重要工具,它使得在运行时动态修改和增强Java代码成为可能,广泛应用于AOP、动态代理、代码生成等领域。通过深入理解和熟练运用Javaassist,开发者可以提高代码的...

    Javassist 修改class字节码

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

    javassist.jar源码

    5. **性能**:Javaassist的性能比基于源代码的字节码操作工具(如ASM或BCEL)稍逊一筹,因为它的操作基于源代码级别的抽象,而不是直接操作字节码。然而,对于大多数应用来说,这种性能差异是可以接受的,尤其是考虑...

    Android代码-jaop

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

    javassist-3.7.GA.zip

    4. **简单API**:相比于其他字节码操作工具如ASM,Javaassist的API设计得更加友好和直观,使得开发者更容易上手。 在Struts2.2.1框架中,Javaassist可能被用于以下几个方面: 1. **拦截器(Interceptor)**:Struts...

    javassist-3.9.0.GA.jar.zip

    它提供了一个简单的API,使得字节码操作变得相对直观,减少了对底层ASM或BCEL库的直接依赖。 1. **类转换(Class Transformation)**:Javaassist通过` CtClass `对象来表示Java类,我们可以加载一个已经存在的类,...

    动态代理-jdk、cglib、javassist.zip

    javassist是一个开源的分析、转换和操作Java字节码的库。相比于CGLIB,javassist提供了更高级的API,可以直接编辑类的字节码,而不仅仅是生成新的字节码。它不仅可以用作动态代理,还可以用于AOP(面向切面编程)和...

    03 - ASM和ClassFile - 简书1

    ASM和ClassFile是Java世界中的两个重要概念,它们在字节码操作和理解Java虚拟机(JVM)内部工作原理方面起着关键作用。 首先,ClassFile是Java编译器生成的字节码文件的结构,它以二进制形式存储了类或接口的所有元...

    asm-3.2-bin.zip

    8. **与其他库的集成**:ASM可以与其他Java库结合使用,如CGLIB(用于创建子类)和Javassist(另一种字节码操作库),以扩展其功能。 9. **文档与社区支持**:ASM提供了详细的API文档和一些示例代码,帮助开发者...

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

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

    javassist使用手册

    它以其易用性和灵活性而受到开发者的欢迎,相比其他如ASM这样的底层字节码库,Javaassist提供了一种更高层次的API,使得开发者可以更加便捷地修改、创建和分析Java类。以下是对Javaassist关键特性和使用的详细解释:...

    asm-tree-20041228.180559.jar.zip

    1. 编译器和转换工具:如Javassist、ByteBuddy等,它们利用ASM来生成或转换字节码。 2. AOP(面向切面编程)框架:如AspectJ,通过ASM在运行时插入切面代码。 3. 性能监控和分析工具:如JProfiler,可能会使用ASM来...

    Javassist如何操作Java 字节码

    Javassist的出现使得开发者无需深入理解底层字节码指令就能方便地操作类、方法和字段,降低了字节码操作的难度。下面将详细介绍Javassist的主要特点、常用类以及如何使用它进行字节码操作。 一、Javassist的特点 1....

    求职宝典-Java 基础面试题

    Javassist和ASM则是更底层的字节码库,可以直接编辑和生成类的字节码,提供更灵活的代理实现。 序列化(Serialization)和反序列化(Deserialization)是Java中用于持久化对象和跨进程通信的关键技术。对象实现...

Global site tag (gtag.js) - Google Analytics