readings on instrumentation, profiling, and tracing
DESCRIPTION
Readings on Instrumentation, Profiling, and Tracing. IPT. Seminar presentation by Alessandra Gorla University of Lugano December 7, 2006. Java Bytecode Analysis and Optimization. Soot BCEL JABA. Overview. Introduction Tools Soot - a Java Bytecode Optimization Framework - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/1.jpg)
IPT Readings on
Instrumentation, Profiling, and Tracing
Seminar presentation byAlessandra Gorla
University of LuganoDecember 7, 2006
![Page 2: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/2.jpg)
Java Bytecode Analysis and Optimization
Java Bytecode Analysis and Optimization
Soot
BCEL
JABA
Soot
BCEL
JABA
![Page 3: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/3.jpg)
OverviewOverview
Introduction Tools
Soot - a Java Bytecode Optimization Framework
BCEL - Byte Code Engineering Library JABA - JAva Bytecode Analyzer
Introduction Tools
Soot - a Java Bytecode Optimization Framework
BCEL - Byte Code Engineering Library JABA - JAva Bytecode Analyzer
![Page 4: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/4.jpg)
IntroductionIntroduction
Java application are usually much slower than C and C++ applications.
Possible approaches to solve the problem Bytecode optimizers
Significant optimizations. Create new classes Bytecode annotators
Create new classes with annotations Bytecode manipulation tools
Manipulate bytecode in its original form Java application packagers
Compress and/or obfuscate code Java native compilers
Compile Java to native executables
Java application are usually much slower than C and C++ applications.
Possible approaches to solve the problem Bytecode optimizers
Significant optimizations. Create new classes Bytecode annotators
Create new classes with annotations Bytecode manipulation tools
Manipulate bytecode in its original form Java application packagers
Compress and/or obfuscate code Java native compilers
Compile Java to native executables
![Page 5: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/5.jpg)
SootSoot
Bytecode optimizer framework Intraprocedural optimization Whole program optimization
Three intermediate representations Baf: streamlined representation of the bytecode Jimple: typed 3-address representation Grimp: Jimple aggregated version
Bytecode optimizer framework Intraprocedural optimization Whole program optimization
Three intermediate representations Baf: streamlined representation of the bytecode Jimple: typed 3-address representation Grimp: Jimple aggregated version
![Page 6: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/6.jpg)
BafBaf
Constant pool abstraction
Give type to dup and swap instructions
Local vars are given explicit names
Constant pool abstraction
Give type to dup and swap instructions
Local vars are given explicit names
![Page 7: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/7.jpg)
JimpleJimple
3- address code representation (not for jsr)
Stack is replaced by additional local vars (prefixed by $)
3- address code representation (not for jsr)
Stack is replaced by additional local vars (prefixed by $)
![Page 8: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/8.jpg)
GrimpGrimp
Much easier to read than Baf of Jimple
Has a representation of the new operator
Aggregate expressions
Much easier to read than Baf of Jimple
Has a representation of the new operator
Aggregate expressions
![Page 9: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/9.jpg)
Optimization frameworkOptimization framework
![Page 10: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/10.jpg)
OptimizationsOptimizations
Intraprocedural optimizations Constant propagation and folding Conditional and unconditional branch elimination Copy propagation Dead assignment and unreachable code elimination Expression aggregation
Whole program optimization (call graph) Method inlining (Devirtualization of method calls)
Intraprocedural optimizations Constant propagation and folding Conditional and unconditional branch elimination Copy propagation Dead assignment and unreachable code elimination Expression aggregation
Whole program optimization (call graph) Method inlining (Devirtualization of method calls)
![Page 11: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/11.jpg)
ExperimentsExperiments
![Page 12: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/12.jpg)
BCELBCEL
Bytecode manipulation library Written in Java Opensource Offers capabilities to inspect, edit and create Java
binary classes Package to represent class Package to dynamically generate and modify classes Code examples, utilities
Bytecode manipulation library Written in Java Opensource Offers capabilities to inspect, edit and create Java
binary classes Package to represent class Package to dynamically generate and modify classes Code examples, utilities
![Page 13: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/13.jpg)
BCEL Class representationBCEL Class representation
![Page 14: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/14.jpg)
BCEL Class editingBCEL Class editing
![Page 15: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/15.jpg)
BCEL - Optimization exampleBCEL - Optimization example
Push 0 or 1 to the stack to evaluate boolean expressions
Combination of boolean expressions: Keep pushing 0s and 1s to the stack
Algorithm to apply: Replace IfInstruction branch target with ifne
branch target
Push 0 or 1 to the stack to evaluate boolean expressions
Combination of boolean expressions: Keep pushing 0s and 1s to the stack
Algorithm to apply: Replace IfInstruction branch target with ifne
branch target
![Page 16: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/16.jpg)
BCEL - Optimization exampleBCEL - Optimization example5: aload_06: ifnull #139: iconst_010: goto #1413: iconst_114: nop15: ifne #3618: iload_119: iconst_220: if_icmplt #2723: iconst_024: goto #2827: iconst_128: nop29: ifne #3632: iconst_033: goto #3736: iconst_137: nop38: ifeq #5241: getstatic System.out44: ldc "Ooops"46: invokevirtual println52: return
5: aload_06: ifnull #139: iconst_010: goto #1413: iconst_114: nop15: ifne #3618: iload_119: iconst_220: if_icmplt #2723: iconst_024: goto #2827: iconst_128: nop29: ifne #3632: iconst_033: goto #3736: iconst_137: nop38: ifeq #5241: getstatic System.out44: ldc "Ooops"46: invokevirtual println52: return
if((a == null) || (i < 2))
System.out.println("Ooops");
10: aload_011: ifnull #1914: iload_115: iconst_216: if_icmpge #2719: getstatic System.out22: ldc "Ooops"24: invokevirtual println27: return
![Page 17: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/17.jpg)
JABAJABA
Bytecode analyzer library Graphs representation
Control Flow Graph Class Control Flow Graph Interclass Control Flow Graph
Bytecode analyzer library Graphs representation
Control Flow Graph Class Control Flow Graph Interclass Control Flow Graph
![Page 18: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/18.jpg)
JABA - CFGJABA - CFG
public void metodo(){int x = 2;
int c = 3; while(x > 0) {
c++; x--; } }
![Page 19: Readings on Instrumentation, Profiling, and Tracing](https://reader035.vdocuments.mx/reader035/viewer/2022062723/56813f9e550346895daa8f4b/html5/thumbnails/19.jpg)
JABA - ICFGJABA - ICFG