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

Slides:



Advertisements
Similar presentations
Virtual Machines Matthew Dwyer 324E Nichols Hall
Advertisements

Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
ANALYSIS OF PROG. LANG. PROGRAM ANALYSIS Instructors: Crista Lopes Copyright © Instructors. 1.
1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Course Outline Traditional Static Program Analysis Software Testing
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
1 Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber
Advice Weaving in AspectJ Alex Gontmakher. Outline Possible implementation approaches Quick JVM primer AJC implementation Performance Evaluation.
Lab 9 Java Bytecode & The Jasmin Assembler
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
4/23/09Prof. Hilfinger CS 164 Lecture 261 IL for Arrays & Local Optimizations Lecture 26 (Adapted from notes by R. Bodik and G. Necula)
1 CS 201 Compiler Construction Lecture 1 Introduction.
Combining Static and Dynamic Data in Code Visualization David Eng Sable Research Group, McGill University PASTE 2002 Charleston, South Carolina November.
Intermediate Code. Local Optimizations
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Code Generation Introduction. Compiler (scalac, gcc) Compiler (scalac, gcc) machine code (e.g. x86, arm, JVM) efficient to execute i=0 while (i < 10)
Optimizing Compilers Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Application Security Tom Chothia Computer Security, Lecture 14.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
Research supported by IBM CAS, NSERC, CITO Context Threading: A flexible and efficient dispatch technique for virtual machine interpreters Marc Berndl.
1 Introduction to JVM Based on material produced by Bill Venners.
1 Java Bytecode Optimization Optimizing Java Bytecode for Embedded Systems Stefan Hepp.
Roopa.T PESIT, Bangalore. Source and Credits Dalvik VM, Dan Bornstein Google IO 2008 The Dalvik virtual machine Architecture by David Ehringer.
A Java Compiler Overview. October 21, 2003Shane A. Brewer2 Who Am I? Shane A. Brewer Masters Graduate.
Syntax Directed Translation Compiler Design Lecture (03/16//98) Computer Science Rensselaer Polytechnic.
Java Virtual Machine Case Study on the Design of JikesRVM.
Code Optimization 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
1 CS 201 Compiler Construction Introduction. 2 Instructor Information Rajiv Gupta Office: WCH Room Tel: (951) Office.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 1 Developed By:
Winter Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2.
#include "dump.h" int main ( int argc, char* argv[] ) { __asm { mov eax, 1// init eax to 1 mov ebx, esp; keep a copy of esp mov ecx, 3/* init ecx to 3.
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
Chap. 10, Intermediate Representations J. H. Wang Dec. 14, 2015.
Building a Java Interpreter CS 142 (b) 01/14. Lab Sessions Monday, Wednesday – 10am – noon – ICS 189 Send an or make an appointment with the TA.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 18: Code Safety and Virtual Machines
CS 153: Concepts of Compiler Design November 18 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
Chap. 10, Intermediate Representations J. H. Wang Dec. 27, 2011.
Recap: Printing Trees into Bytecodes To evaluate e 1 *e 2 interpreter –evaluates e 1 –evaluates e 2 –combines the result using * Compiler for e 1 *e 2.
SOOT By Joe Palmer Information taken from
© Dr. A. Williams, Fall Present Software Quality Assurance – Clover Lab 1 Tutorial / lab 2: Code instrumentation Goals of this session: 1.Create.
CS 536 © CS 536 Spring Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 15.
Phoenix Based Dynamic Slicing Debugging Tool Eric Cheng Lin Xu Matt Gruskin Ravi Ramaseshan Microsoft Phoenix Intern Team (Summer '06)
Spring 2016 Program Analysis and Verification
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Code Optimization Overview and Examples
High-level optimization Jakub Yaghob
Code Optimization.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CS216: Program and Data Representation
Java Virtual Machine (JVM)
Introduction to Algorithm Design
CS 201 Compiler Construction
Byte Code Verification
Code Optimization Overview and Examples Control Flow Graph
Compiler Design 21. Intermediate Code Generation
CS 153: Concepts of Compiler Design November 6 Class Meeting
Building a Java Interpreter
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Compiler Design 21. Intermediate Code Generation
CS 201 Compiler Construction
Presentation transcript:

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

Java Bytecode Analysis and Optimization Soot BCEL JABA Soot BCEL JABA

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

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

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

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

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

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

Optimization framework

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)

Experiments

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

BCEL Class representation

BCEL Class editing

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

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

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

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

JABA - ICFG