JOVE. An Optimizing Compiler for Java. Allen Wirfs-Brock Instantiations Inc.

Similar documents
Java On Steroids: Sun s High-Performance Java Implementation. History

A Quantitative Evaluation of the Contribution of Native Code to Java Workloads

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1

Method-Level Phase Behavior in Java Workloads

Just-In-Time Compilers & Runtime Optimizers

Context Threading: A flexible and efficient dispatch technique for virtual machine interpreters

Field Analysis. Last time Exploit encapsulation to improve memory system performance

Jazz: A Tool for Demand-Driven Structural Testing

Dynamic Selection of Application-Specific Garbage Collectors

Intelligent Compilation

Experiences with Multi-threading and Dynamic Class Loading in a Java Just-In-Time Compiler

Java TM. Multi-Dispatch in the. Virtual Machine: Design and Implementation. Computing Science University of Saskatchewan

Reducing the Overhead of Dynamic Compilation

Phase-based Adaptive Recompilation in a JVM

Swift: A Register-based JIT Compiler for Embedded JVMs

Limits of Parallel Marking Garbage Collection....how parallel can a GC become?

The Segregated Binary Trees: Decoupling Memory Manager

YETI. GraduallY Extensible Trace Interpreter VEE Mathew Zaleski, Angela Demke Brown (University of Toronto) Kevin Stoodley (IBM Toronto)

Core JAVA Training Syllabus FEE: RS. 8000/-

Debunking Dynamic Optimization Myths

Mixed Mode Execution with Context Threading

Object Model. Object Oriented Programming Spring 2015

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

CSc 453 Interpreters & Interpretation

Towards Parallel, Scalable VM Services

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example

Java Overview An introduction to the Java Programming Language

OOPLs - call graph construction Compile-time analysis of reference variables and fields. Example

StackVsHeap SPL/2010 SPL/20

Interprocedural Analysis with Data-Dependent Calls. Circularity dilemma. A solution: optimistic iterative analysis. Example

Forth Meets Smalltalk. A Presentation to SVFIG October 23, 2010 by Douglas B. Hoffman

Improving Mobile Program Performance Through the Use of a Hybrid Intermediate Representation

Compiling Java For High Performance on Servers

Fast Track to Core Java 8 Programming for OO Developers (TT2101-J8) Day(s): 3. Course Code: GK1965. Overview

Compaq Interview Questions And Answers

Exploiting Prolific Types for Memory Management and Optimizations

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

Compact and Efficient Strings for Java

CS260 Intro to Java & Android 02.Java Technology

Just-In-Time Compilation

Trace Compilation. Christian Wimmer September 2009

The VMKit project: Java (and.net) on top of LLVM

CSE 501: Compiler Construction. Course outline. Goals for language implementation. Why study compilers? Models of compilation

Eliminating Exception Constraints of Java Programs for IA-64

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Java Performance Analysis for Scientific Computing

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Combined Object-Lambda Architectures

Reducing the Overhead of Dynamic Compilation

New Compiler Optimizations in the Java HotSpot Virtual Machine

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Object-Oriented Concepts and Design Principles

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Design, Implementation, and Evaluation of a Compilation Server

Using Java for Scientific Computing. Mark Bul EPCC, University of Edinburgh

VIRTUAL FUNCTIONS Chapter 10

OOPLs - call graph construction. Example executed calls

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

Implementing Higher-Level Languages. Quick tour of programming language implementation techniques. From the Java level to the C level.

Object Model. Object Oriented Programming Winter

Java 8 Programming for OO Experienced Developers

Lecture 9 Dynamic Compilation

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Improving Mobile Program Performance Through the Use of a Hybrid Intermediate Representation

Designing experiments Performing experiments in Java Intel s Manycore Testing Lab

Data Abstraction. Hwansoo Han

JAVA MOCK TEST JAVA MOCK TEST III

Dynamic Profiling & Comparison of Sun Microsystems JDK1.3.1 versus the Kaffe VM APIs

Online Subpath Profiling

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Java Programming Training for Experienced Programmers (5 Days)

Lecture 23: Object Lifetime and Garbage Collection

Lecture Notes on Programming Languages

Running class Timing on Java HotSpot VM, 1

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Virtual Machine Showdown: Stack Versus Registers

A Study of Cache Performance in Java Virtual Machines

C++ Important Questions with Answers

CS260 Intro to Java & Android 03.Java Language Basics

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Notes of the course - Advanced Programming. Barbara Russo

Inheritance, Polymorphism and the Object Memory Model

Jupiter: A Modular and Extensible JVM

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

On the Algorithm for Specializing Java Programs with Generic Types

Parley: Federated Virtual Machines

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

What are the characteristics of Object Oriented programming language?

Building Robust Embedded Software

A Trace-based Java JIT Compiler Retrofitted from a Method-based Compiler

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Transcription:

An Optimizing Compiler for Java Allen Wirfs-Brock Instantiations Inc.

Object-Orient Languages Provide a Breakthrough in Programmer Productivity Reusable software components Higher level abstractions Yield significant productivity improvements

The Rap on Object-Oriented Languages They re slow!!! C++ slower than C Smalltalk slower than C++ Java slower than C++

Why are OO Languages slow? Unconventional implementation techniques New, expensive fundamental operations Object-oriented design and programming techniques

There seems to be a delicate balancing act between OO The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again. productivity and execution performance

Why? Productivity comes from generalization Reusable class libraries Extensible frameworks Plugable components Abstract algorithms Implemented using Subclass refinement Polymorphic typing Polymorphic methods Accessor Methods Chains of delegation

Generality = Inefficiency Extra functionality that is present but not used Many calls of tiny methods Accessors methods Generic algorithms depend upon dynamic (polymorphic) method dispatch Late binding via polymorphism precludes static optimizations

It s an issue of binding time. Procedural designs and languages are fast, but inflexible because most decisions are bound very early, during coding. Object oriented designs are slow, but flexible because many decisions are bound very late, during program execution. Decisions made during coding Decisions made during execution Early Binding Performance Late Binding Flexibility

The Dilemma Late bound OO code is highly reusable, making programmer more productive over the course of developing several applications. Late bound OO code is inefficient. Early bound procedural code is generally not very reusable. Early bound procedural code can be very efficient.

Why can t we have both? Write program using, highly reusable object-oriented code. Execute them as very efficient, procedural code. Decisions made during coding Move object-oriented binding decisions earlier by making decisions at compilation time instead of during execution Decisions made during execution Early Binding Late Binding

No Don t OO Language Compilers already do this? Conventional C++, Eiffel, Java, etc. compilers generally don t perform compile-time bindings of object-oriented constructed. They don t know enough about a program to make these decisions so They implement object-oriented constructs via late binding during execution

What does a compiler need to know Complete class hierarchy All possible control paths through the program Initial values of variables The compiler needs to understand the whole program.

Whole Program Optimization By examining a whole program a compiler can: Determine exactly which classes, methods, and fields are actually used by the program. Which classes are actually instantiated The specific classes of objects that will be used at each expression within the program. The possible receivers for every method invocation Whether a method invocation actually needs to be polymorphic Determine which objects may be shared between threads etc...

Why is the time right for Whole Program Optimizing compilers? Very fast processors With very large main memories Wide spread use of object-oriented languages

Experimental Whole Program Optimizing Compilers for Objectoriented language Vortex Compiler University of Washington - Craig Chambers, Jeffrey Dean, et al Marmot Microsoft Research - Robert Fitzgerald, et al

First production-quality whole program optimizing compiler for Java Static deployment compiler for Java Aggressive, whole-program optimizer Creates single-file, native executables for deployment Supports JDK 1.1, 1.2, and 1.3 client or server Java applications

Java Development & Deployment Java Class Files Java Development Environment Java Virtual Machine Host Processor Runtime Support Optimizer Native (.exe) Application Windows 9x/NT

Jove Conceptual Architecture Java Class Files Data Flow Analysis I C C C Whole Program Model: Class Hierarchy C C C SSA Method Representation Type Info Procedure Integration Classic Compiler Optimizations Bytecode loader and translator C Native Code Generator I SSA Class Hierarchy Analysis SSA SSA SSA SSA SSA Native.exe file Polymorphic Strength Reduction Generality Elimination

Whole Program Object-Oriented Optimizations Generality elimination Class hierarchy analysis Polymorphic type elimination Polymorphic strength reduction Type check elimination, etc.

Generality Elimination class Customer refines Person{ public static Customer nextcustomer{ } protected String name; protected String address; protected int id; public String name() {return name;} public String address() {return address;} public String id() {return id;}} while ((c= Customer.nextCustomer())!= null) System.out.println(c.name());

Generality Elimination class Customer refines Person{ public static Customer nextcustomer{ } protected String name; protected String address; protected int id; public String name() {return name;} public String address() {return address;} public String id() {return id;}} while ((c= Customer.nextCustomer())!= null) System.out.println(c.name());... Assume that some program only uses the nextcustomer and name methods of Customer as shown above.

Generality Elimination class Customer refines Person{ public static Customer nextcustomer{ } protected String name; protected String address; protected int id; public String name() {return name;} public String address() {return address;} public String id() {return id;}} while ((c= Customer.nextCustomer())!= null) System.out.println(c.name());... The program does not need the methods id() and address() or the fields address and id. Generality elimination will remove these from the program model.

10000 Generality Elimination Program 1 Program 2 Eliminated Used 8000 48% Reduction in Methods & 31% Reduction in Fields 1899 22% Reduction in Methods* & 41% Reduction in Fields 6000 4000 6782 2000 941 345 819 0 1028 762 1160 Methods Fields Methods Fields *Eliminated 55% of java.lang methods

Class Hierarchy Analysis abstract class Person{ public String name() {return John Doe ; } class Customer refines Person{ public static Customer nextcustomer(){ } protected String name; public String name() {return name;} } Person is an abstract class whose only subclass is Customer. Customer.name() overrides Person.name() hence Person.name() can be eliminated and Customer.name() is not polymorphic.

Class Hierarchy Analysis abstract class Person{ public String name() {return John Doe ; } class Customer refines Person{ public static Customer nextcustomer(){ } protected String name; public String name() {return name;} } Person is an abstract class whose only subclass is Customer. Customer.name() overrides Person.name().

Class Hierarchy Analysis abstract class Person{ public String name() {return John Doe ; } class Customer refines Person{ public static Customer nextcustomer(){ } protected String name; public String name() {return name;} } Because Customer.name() overrides Person.name() which is an instance method of an abstract class and because there are no other subclasses of Person, Person.name() can be eliminated and Customer.name() is not polymorphic.

Polymorphic Type Elimination String Classify (Object p) { if (p instanceof Customer) return Customer ; if (p instanceof Employee) return Employee ; return Generic Person ;}...Classify(Customer.nextCustomer())... Classify is method whose parameter is declared as type Object but its only invocation is passing the result of a methods whose result type is Customer.

Polymorphic Type Elimination String Classify (Object Customer p { if (p instanceof Customer) return Customer ; if (p instanceof Employee) return Employee ; return Generic Person ;}...Classify(Customer.nextCustomer())... The compiler can now treat the argument type of Classify as if it was declared to be Customer which has been determined to be a non-polymorphic type for this program. Under this assumption the first instanceof test will always be true and it and subsequent code can be eliminated.

Polymorphic Type Elimination String Classify (Customer p { return Customer ; }...Classify(Customer.nextCustomer())... Customer // inlined call to Classify The simplified version of Classify can then be easily inlined at its call site. Because the result of nextcustomer() is not used that call is also eliminated.

Polymorphic Strength String Classify2 (Object Customer p) { if (hashtable[p.hashcode()] ==p { Reduction } hashcode() can be strength reduced from a dynamic polymorphic call into a static call (and probably...classify2(customer.nextcustomer())... inlined)

Call Site Optimization Dynamic Call Sites Static Call Sites 25000 Program 1 Program 2 20000 96% Reduction in Dynamic Call Sites 55% Overall Reduction in Call Sites 91% Reduction in Dynamic Call Sites 70% Overall Reduction in Call Sites 15000 15828 10000 5000 1441 3470 130 6102 5209 0 1111 1938 Before After Before After

The Runtime Scalable Runtime Architecture designed to support extremely large Java programs Low memory overhead objects Precise multi-generational garbage collection Native multi-threading or single threaded Multi-threaded garbage collection Fast method dispatch and type checks

Message Dispatch Type Inclusion Testing Selector table dispatch for polymorphic calls Row displacement compacting No extra dispatch overhead for interfaces Compact encoded tables for very fast type inclusion testing (checkcast & instanceof) Constant time tests Test is a 4 instruction sequence on Intel architecture

Why are OO Languages slow? Using, Java programs are fast! Unconventional implementation techniques Compiled native code instead of a virtual machine New, expensive fundamental operations Implemented by efficient runtime system Object-oriented design and programming techniques Overhead eliminated using whole program optimizations.

1.6 1.4 1.2 1 Richards Benchmarks 2.0 Client HotSpot 1.3.0-C HotSpot 1.0.1g JDK 1.2.2-5 symcjit IBM JDK 1.1.8 0.8 0.6 0.4 0.2 0 Gibbons Gibbons_final Gibbons_no_switch More object-oriented Deutsch_no_acc Deutsch_acc_final Deutsch_acc_virtual Deutsch_acc_interface Smaller is better

600 500 2.0 vs. Hotspot 1.3.0 Running a Complex Object-Oriented Program ( itself) 493 400 300 200 100 292 Optimized by Compiling javac 1.3 Running on Hotspot Compiling javac 1.3 0 Elapsed Time Smaller is better

400% SPECjvm Benchmarks for Various JVMs Normalized to 2.0 350% 300% 250% 200% 150% 2.0 Client HotSpot 1.3.0-C HotSpot 1.0.1g JDK 1.2.2-5 symcjit IBM JDK 1.1.8 100% 100% 50% 0% 201_Compress 202_jess 205_raytrace 209_DB 213_javac 222_mpegaudio 227_mtrt 228_jack Smaller is better

Applicability Whole program optimization requires a static program structure. Unconstrained reflection impedes optimizations. Dynamically composed programs not supported. All classes are available at deployment time. Use New classes loaded from network during execution. Use a JIT

But Many existing Java Class.forName() Reflection programs use: Depend upon native methods that use reflection (via JNI) Jove accommodates such programs by providing a declarative mechanism for: Identifying classes that will be dynamically loaded Identifying specific classes, methods, and fields that are accessed via reflection Identifying classes, methods, and fields that are accessed from native methods using JNI

Beware of Attractive Nuisance Features Don t use dynamic class loading to initialize data arrays Use interfaces instead of method reflection Don t use reflection to implement polymorphic static methods Don t use reflection to implement configuration flags - instead use interfaces for actual data flags.

Conclusion Using Static, whole-program optimization techniques we can reap the full productivity benefits of Object-Oriented programming without sacrificing runtime performance Allen Wirfs-Brock Instantiations, Inc. www.instantiations.com Allen_Wirfs-Brock@Instantiations.com