ObjectWeb ASM
Encyclopedia
The ASM library is a project of the ObjectWeb consortium. It provides a simple API for decomposing, modifying, and recomposing binary Java classes (i.e. bytecode
). The project was originally conceived and developed by Eric Bruneton. ASM is Java-centric at present, and does not currently have a backend that exposes other bytecode implementations (such as .NET
bytecode, Python
bytecode, etc.).
oriented API. ASM also provides, on top of this visitor API, a tree API that represents classes as object constructs. Both APIs can be used for modifying the binary bytecode, as well as generating new bytecode (via injection of new code into the existing code, or through generation of new classes altogether.) The ASM library has been used in several diverse applications, such as:
Bytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...
). The project was originally conceived and developed by Eric Bruneton. ASM is Java-centric at present, and does not currently have a backend that exposes other bytecode implementations (such as .NET
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
bytecode, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
bytecode, etc.).
Uses
ASM provides a simple library that exposes the internal aggregate components of a given Java class through its visitorVisitor pattern
In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying those...
oriented API. ASM also provides, on top of this visitor API, a tree API that represents classes as object constructs. Both APIs can be used for modifying the binary bytecode, as well as generating new bytecode (via injection of new code into the existing code, or through generation of new classes altogether.) The ASM library has been used in several diverse applications, such as:
- Performance and Profiling
- Instrumentation calls that capture performance metrics can be injected into Java class binaries to examine memory/coverage data. (For example, injecting instrumentation at entry/exit points.)
- Implementation of New Language Semantics
- For example, Groovy uses ASM to generate its bytecode. Also, Aspect-Oriented additions to the Java language have been implemented by using ASM to decompose class structures for point-cut identification, and then again when reconstituting the class by injecting aspect-related code back into the binary. (See: AspectWerkzAspectWerkzAspectWerkz is a dynamic, lightweight and high-performance AOP/AOSD framework for Java. It has been merged with the AspectJ project, which supports AspectWerkz functionality since AspectJ 5....
)
Invokedynamic
Since version 3.2, ASM has added support for the newinvokedynamic
code, which allows method invocation relying on dynamic type checking on the latest JDK 7 binaries, thus easing support for dynamically typed languages.External links
- ASM Library - The ASM Project Home Page.
- ASM-Based Project Listing - A listing of projects that make use of the ASM Library.
- ObjectWeb Home - The ObjectWeb Home Page.
- AspectWerkz - The AspectWerkz Project Home Page. (One of the high-visibility projects that makes use of ASM.)
- Bytecode Visualizer LT - free Eclipse plugin for viewing and debugging Java bytecode which makes use of ASM library