Multi-Dispatch in the Java™ Virtual Machine

Slides:



Advertisements
Similar presentations
Operating Systems Components of OS
Advertisements

OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
OOP: Inheritance By: Lamiaa Said.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Load-time structural reflection in Java – Shigeru Chiba, 2000 May 27, 2004 Shimin.
Inheritance Lakshmish Ramaswamy. Example A Rectangle class with area method A Circle class with area method Array containing references to circles & rectangles.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Combining Static and Dynamic Data in Code Visualization David Eng Sable Research Group, McGill University PASTE 2002 Charleston, South Carolina November.
1 Inheritance and Polymorphism. 2 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common.
Introduction to Java. What is Java? A computer programming language that can be run as either an application or an applet. –What is the difference? It.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Programming Languages and Paradigms Object-Oriented Programming.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
An analysis of exam results in the Object-Oriented Programming course at „Politehnica” University of Timisoara Ioan Jurca.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Java Dynamic Proxy Bibliography: reflection/proxy.html
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 10 Inheritance and.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Software Development Introduction
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
CSCI 212 Object-Oriented Programming in Java. Prerequisite: CSCI 111 variable assignment statement while loop for loop post-increment (i++) strong typing.
Variations on Inheritance Object-Oriented Programming Spring
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
 2000 Prentice Hall, Inc. All rights reserved. Chapter 20 - Virtual Functions Outline 20.1Introduction 20.2Type Fields and switch Statements 20.3Virtual.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
RealTimeSystems Lab Jong-Koo, Lim
Software Engineering Algorithms, Compilers, & Lifecycle.
Software, IEE Proceedings, Vol.152, Num.3, June 2005,Page(s): Prasanthi.S March, Java-based component framework for dynamic reconfiguration.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Applications Active Web Documents Active Web Documents.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Methods Chapter 6.
Software Engineering Fall 2005
Interfaces Professor Evan Korth.
Week 4 Object-Oriented Programming (1): Inheritance
Inheritance, Polymorphism and the Object Memory Model
Multi-Dispatch in the Java VM
Chapter 9 Inheritance and Polymorphism
Chapter 19 Generics Dr. Clincy - Lecture.
Java Programming Language
MSIS 670 Object-Oriented Software Engineering
CSc 453 Interpreters & Interpretation
MSIS 655 Advanced Business Applications Programming
Inlining and Devirtualization Hal Perkins Autumn 2011
Inlining and Devirtualization Hal Perkins Autumn 2009
CMPE 135: Object-Oriented Analysis and Design March 14 Class Meeting
Procedure Linkages Standard procedure linkage Procedure has
Exception Handling.
CSc 453 Interpreters & Interpretation
Dynamic Binary Translators and Instrumenters
Presentation transcript:

Multi-Dispatch in the Java™ Virtual Machine Design, Implementation, and Evaluation Christopher Dutchyn Computing Science University of Alberta 11/8/2018 Multi-Dispatch Java

The Problem Production OO languages (C++, Java) select the method to run based on the dynamic type of a single argument only: We call this uni-dispatch } Color HPJet PScript .draw(Shape) The process of selecting code based on types is called “dispatch”. When the compile-time type is used, we call it “static dispatch”, when the execution-time type is used, we call it “dynamic dispatch”. 11/8/2018 Multi-Dispatch Java

The Goal We want method selection based on the dynamic types of more than one, and possibly all of the arguments: We call this multiple dispatch ( ) } Circle Ellipse Square Rectangle Color HPJet PScript .print We need multiple dispatch. It appears in many situations: binary operations: equals, compareTo graphical user interfaces: components & events drag and drop: document type & target cut and paste: clip type & target application 11/8/2018 Multi-Dispatch Java

Double Dispatch Solutions Type fields – switch on constant integers maintain types encoded as obscure numbers risk that some type fields might be omitted Typecases – if …instanceof …else if…else… risk that some types might not be tested for instanceof tests contain order dependencies Visitor pattern – sequence of uni-dispatches duplicates dispatcher code into many classes They encode the type hierarchy of the program into many different locations in the program, resulting in brittle, difficult to maintain, and error-prone code. 11/8/2018 Multi-Dispatch Java

Another Solution Perform a single dynamic dispatch operation that considers the dynamic types of all of the arguments We call this multi-dispatch. The code is cleaner; the language runtime is responsible for executing the correct implementation. 11/8/2018 Multi-Dispatch Java

Research Contributions Added dynamic multi-dispatch to Java without changing syntax or compiler, allowing programmer to select classes supporting multi-dispatch, without penalizing existing uni-dispatch, and maintaining reflection and existing APIs. Realizes the following benefits shorter, simpler, and more maintainable code, with equal or better performance than complex, error-prone double dispatch. Published COOTS 2001 Best student paper award. 11/8/2018 Multi-Dispatch Java

Multi-Dispatch At a Call Site Look up the uni-dispatch method If multi-dispatchable Walk the operand stack to obtain precise types HPJet and Circle instead of Printer and Shape Select the method that most closely matches the argument types: Verify return types conform Invoke new method We have to wait until uni-dispatch because (a) we need to know the number of arguments and the size of each one, and (b) we want to ensure that if a subclass implements VMD but superclass does not, then the subclass method invocations still are multi-dispatched. HPJet.print(Circle) 11/8/2018 Multi-Dispatch Java

Evaluation: Two Criteria Compatibility with uni-dispatch Do existing uni-dispatch Java programs continue to run correctly? What performance penalty does our additions impose on pure uni-dispatch programs? Performance versus double dispatch How does multi-dispatch compare with existing double dispatch techniques? Does multi-dispatch scale to full applications? 11/8/2018 Multi-Dispatch Java

Uni-Dispatch Java Support The java compiler, javac, is a large Java program that runs over a Java Virtual Machine. As part of constructing the JDK, javac runs on the just-constructed JVM to compile 5000+ classes comprising the Java Class Libraries. Our multi-dispatch JVMs host those compilations. 11/8/2018 Multi-Dispatch Java

Uni-Dispatch Overhead individual uni-dispatch times multi-invoker adds zero Inlined tests adds 2.5% sun.tools.* compile multi-dispatch adds 2-3% cache contention due to larger data structures class load overhead exaggerated by repeated loading 11/8/2018 Multi-Dispatch Java

Double vs. Multi-Dispatch Using existing event processing kernel from sun.awt.component 7 event types 7 components Comparison of original kernel typecases type fields Visitor multi-dispatch (SRP) 11/8/2018 Multi-Dispatch Java

Multi-Swing (and AWT) Modified 92 of 846 classes (11%) Replaced 171 conditionals (5%) Mean number of decision points reduced from 3.8 to 2.0 per method Added 57 new event subclasses Added 123 new multimethods Working with this real-world application reinforced 1) some of the issues regarding null parameters, return types, visibility, and type promotion. 11/8/2018 Multi-Dispatch Java

Multi-Swing Results The multi-dispatch version executes 8% fewer dispatches and the multi-dispatches represent approximately 7.7% of the dispatches. Total execution time is 0.3 seconds shorter (2%). 11/8/2018 Multi-Dispatch Java

Research Contributions Added dynamic multi-dispatch to Java without changing syntax or compiler, allowing programmer to select classes supporting multi-dispatch, without penalizing existing uni-dispatch, and maintaining reflection and existing APIs. Realizes the following benefits shorter, simpler, and more maintainable code, with equal or better performance than complex, error-prone double dispatch. Published COOTS 2001 Best student paper award. 11/8/2018 Multi-Dispatch Java