Presentation is loading. Please wait.

Presentation is loading. Please wait.

IPT Readings on Instrumentation, Profiling, and Tracing Seminar presentation by Alessandra Gorla University of Lugano December 7, 2006.

Similar presentations


Presentation on theme: "IPT Readings on Instrumentation, Profiling, and Tracing Seminar presentation by Alessandra Gorla University of Lugano December 7, 2006."— Presentation transcript:

1 IPT Readings on Instrumentation, Profiling, and Tracing Seminar presentation by Alessandra Gorla University of Lugano December 7, 2006

2 Java Bytecode Analysis and Optimization Soot BCEL JABA Soot BCEL JABA

3 Overview  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

4 Introduction  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

5 Soot  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

6 Baf  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

7 Jimple  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 $)

8 Grimp  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

9 Optimization framework

10 Optimizations  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)

11 Experiments

12 BCEL  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

13 BCEL Class representation

14 BCEL Class editing

15 BCEL - 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

16 BCEL - Optimization example 5: aload_0 6: ifnull #13 9: iconst_0 10: goto #14 13: iconst_1 14: nop 15: ifne #36 18: iload_1 19: iconst_2 20: if_icmplt #27 23: iconst_0 24: goto #28 27: iconst_1 28: nop 29: ifne #36 32: iconst_0 33: goto #37 36: iconst_1 37: nop 38: ifeq #52 41: getstatic System.out 44: ldc "Ooops" 46: invokevirtual println 52: return 5: aload_0 6: ifnull #13 9: iconst_0 10: goto #14 13: iconst_1 14: nop 15: ifne #36 18: iload_1 19: iconst_2 20: if_icmplt #27 23: iconst_0 24: goto #28 27: iconst_1 28: nop 29: ifne #36 32: iconst_0 33: goto #37 36: iconst_1 37: nop 38: ifeq #52 41: getstatic System.out 44: ldc "Ooops" 46: invokevirtual println 52: return if((a == null) || (i < 2)) System.out.println("Ooops"); 10: aload_0 11: ifnull #19 14: iload_1 15: iconst_2 16: if_icmpge #27 19: getstatic System.out 22: ldc "Ooops" 24: invokevirtual println 27: return

17 JABA  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

18 JABA - CFG public void metodo(){ int x = 2; int c = 3; while(x > 0) { c++; x--; }

19 JABA - ICFG


Download ppt "IPT Readings on Instrumentation, Profiling, and Tracing Seminar presentation by Alessandra Gorla University of Lugano December 7, 2006."

Similar presentations


Ads by Google