1. ASM Core API - Class
Taegeon Lee
t76lee@uwaterloo.ca
Advisor: Prof. Doo-Hwan Bae
bae@se.kaist.ac.kr
Teaching Assistant: Jiyoung Song
jysong@se.kaist.ac.kr
3. Motivations
Introduction Background Overall Approach Methodology Experiments Results Conclusion Discussion
ASMlibrarydesignedto work on compiledjavaclasses.
There are some techniquessuch as programanalysis,generationand
transformation.
It is supposedto be fast andsmall.
Advantagesof working on compiledcode
Thesourcecodeisnotneeded.So,programtransformationscan beusedonany
applications.
Itbecomespossibletoanalyze,generateortransformclassesat runtimelodedin
JVM.
3/14ASM Core API – Class
5. Classes
• Structure
Overview/ Internal names/ Type descriptors/ Method descriptors
• Interfacesandcomponents
Parsing classes / Generating classes/ Transforming classes/ Removing
class members/ Adding class members
• Tools
Type/ TraceClassVisitor/ CheckClassAdapter/ ASMifier
5/14
6. Structure
Introduction Background Overall Approach Methodology Experiments Results Conclusion Discussion
Overview
Compiledclasscontainsmodifiers,name,superclass,interfacesand annotations.
Differencesbetweensource andcompliedclasses
6/14ASM Core API – Class
Source file Compiled class
• Contains several classes • Describes only one class
• Doesn’t contain comments,
but can contain class, field,
method and code attribute
s
• Doesn’t contain a package
and import section
• Contains a constant pool se
ction [e.g) array]
Another important difference is that Java types are represented different in compiled
And same source classes.
7. Structure
Introduction Background Overall Approach Methodology Experiments Results Conclusion Discussion
[1]Overallstructure ofacompiledclass
7/14ASM Core API – Class
A tree of objects representing the class
Event based API – faster, less memory
Advantage : since no need to create and store in memory
Disadvantage : implementing class transformation can be more difficult since only one element of the class is available at any given time
The object based API : indeed class generator or transformer components that operate on object trees can be composed the links between them representing the order of transformations
Z- boolean
C- char
B- bytes
S- short
I- int
F- float
J- long
D- double
More detailed explanation of reader, writer, visitor class is on pg.14
Both approaches are valid ( depends on what you need) for adding class member.
visitEnd approach is preferred and correct tho.