Object Initialization in X10 Yoav Zibin David Cunningham Igor Peshansky Vijay Saraswat IBM research in TJ Watson.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

1 Classes and Objects in Java Basics of Classes in Java.
Determinate Imperative Programming: The CF Model Vijay Saraswat IBM TJ Watson Research Center joint work with Radha Jagadeesan, Armando Solar- Lezama,
1 Polymorphisme. 2 // Polymorphisme: illustre le polymorphisme et Vector import java.util.*; public class TestPolymorphisme { public static void main.
ArrayList Difference of Array and ArrayList [Sample code] TestArrayList.java.
IBM Research: Software Technology © 2006 IBM Corporation 1 Programming Language X10 Christoph von Praun IBM Research HPC WPL Sandia National Labs December.
X10 Tutorial PSC Software Productivity Study May 23 – 27, 2005 Vivek Sarkar IBM T.J. Watson Research Center This work has been supported.
For(int i = 1; i
Tree Recursion Traditional Approach. Tree Recursion Consider the Fibonacci Number Sequence: Time: , 1, 1, 2, 3, 5, 8, 13, 21,... /
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Programming Methodology (1). Implementing Methods main.
Phil Campbell London South Bank University Java 1 First Steps.
Instructions for ??????????????????????????? What you will make What you will need What to do
Recipe for ??????????????????????????????? What you will make Ingredients What to do
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Multi-Dispatch in the Java Virtual Machine TM What is (dynamic) multi-dispatch? Method selection based on the types of … all (or more than one) of the.
Object Initialization in X10 Yoav Zibin (**) David Cunningham (*) Igor Peshansky (**) Vijay Saraswat (*) (*) IBM TJ Watson Research Center (**) Google.
SCJP 6.0 Lecturer Kuo-Yi Chen 151, 153, 154, 155, 156, 157
§3 Dynamic Programming Use a table instead of recursion 1. Fibonacci Numbers: F(N) = F(N – 1) + F(N – 2) int Fib( int N ) { if ( N
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Hand Trace and Output for: int digit = 0; int number = 1423; do { digit = number % 10; System.out.println(digit); number = number / 10; } while (number.
Yoshi
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
1 An Overview of the X10 Programming Language and X10 Development Tools Evelyn Duesterwald, Emmanuel Geay, Vijay Saraswat and David Grove IBM Research.
IBM’s X10 Presentation by Isaac Dooley CS498LVK Spring 2006.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Paradigmer i Programmering 4 a. Java 1.5 -Generics -Autoboxing/unboxing -New for sætning -Static imports -enum.
Register Conventions (1/4) °CalleR: the calling function °CalleE: the function being called °When callee returns from executing, the caller needs to know.
1 Motivation Dynamically allocated storage and pointers are an essential programming tools –Object oriented –Modularity –Data structure But –Error prone.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
C and Data Structures Baojian Hua
Closure and Environment Compiler Baojian Hua
Memory Layout C and Data Structures Baojian Hua
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Cs2220: Engineering Software Class 11: Subtyping and Inheritance Fall 2010 University of Virginia David Evans.
Welcome to ACM SIGPLAN X10 Workshop San Jose, CA.
1 Program Layout in memory –Code –Data Global variables –Stack Local variables & function Invocation Frames –Heap Dynamically allocated memory Today’s.
Chameleon Automatic Selection of Collections Ohad Shacham Martin VechevEran Yahav Tel Aviv University IBM T.J. Watson Research Center Presented by: Yingyi.
Java Dynamic Proxy Bibliography: reflection/proxy.html
Offset Length Description 0 2 An INT 20h instruction is stored here 2 2 Program ending address 4 1 Unused, reserved by DOS 5 5 Call to DOS function.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Methods. Overview Class/Library/static vs. Message/non-static return and void Parameters and arguments.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
A brief introduction to doxygen. What does a compiler do?  A compiler ignores comments and processes the code.  What does doxygen do? –It ignores the.
Polymorphism (generics) CSE 331 University of Washington.
Wel come To Seminar On C#.
Dynamic Programming & Memoization. When to use? Problem has a recursive formulation Solutions are “ordered” –Earlier vs. later recursions.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
CSI 3125, Preliminaries, page 1 Inheritance. CSI 3125, Preliminaries, page 2 Inheritance Using inheritance, can create a general class that defines traits.
UMBC CMSC 331 Case Classes in Scala Intro. Basic Properties Case classes are regular classes which export their constructor parameters and which provide.
Sum of natural numbers class SumOfNaturalNumbers {
Programming Languages Dan Grossman 2013
Agenda Warmup AP Exam Review: Litvin A2
X10: Performance and Productivity at Scale
Computer Programming Methodology Luminance
Subtyping Rules David Evans cs205: engineering software BlackBear
Concurring Concurrently
أنماط الإدارة المدرسية وتفويض السلطة الدكتور أشرف الصايغ
Case Classes in Scala Intro
Java Lesson 36 Mr. Kalmes.
Code Animation Examples
Using threads for long running tasks.
Lecture 13: Subtyping Rules Killer Bear Climber
Subtype Substitution Principle
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Object Initialization in X10 Yoav Zibin David Cunningham Igor Peshansky Vijay Saraswat IBM research in TJ Watson

Initialization Can be Tricky Reason 1: dynamic dispatching abstract class A { A() { System.out.println(me=+this.description()); } abstract String description(); } class B extends A { int b = 2; public String description() { return b=+b; }

Initialization Can be Tricky Reason 2: leaking a raw/uninitialized object class A { public static HashSet set = new HashSet(); A() { set.add(this); } class B extends A { final int b = 2; }

Initialization Can be Tricky Reason 3: concurrent and distributed code class Fib { val fib2:Int; // fib(n-2) val fib1:Int; // fib(n-1) val fib:Int; // fib(n) def this(n:Int) { finish { async { val p = here.next(); fib2 = at(p) n <=1? 0 : new Fib(n -2).fib; } fib1 = n <=0? 0 : n<=1? 1 : new Fib(n -1).fib; } fib = fib2+fib1; }

Desired Initialization Properties Cannot read uninitialized fields – C++: uninitialized fields have unspecified value – Java: fields are zero initialized Final fields – Written exactly once – Single value for final fields Immutable objects are thread-safe Simple (initialization order is clear) Flexible (ability to express common idioms) Type safe

X10 Initialization Rules Hard-hat design – Strict: E.g., mostly no dynamic dispatching, no leaking this. – Pros: has the desired properties (simple, type safe, etc) – Cons: Less flexible, e.g., cannot express cyclic immutable data-structures

Rules Overview Demonstrate the rules by examples Initialization is a cross-cutting concern – Dynamic dispatching and leaking this – Default/zero value – Properties – Generics – Concurrent and distributed programming – More in the paper: Inner classes, exceptions, closures, structs, serialization, cloning, and more…

this escaping this is raw in non-escaping methods (constructors and methods called from them) A raw this cannot escape or be aliased. class A { val f:Int; def this() { m1(); f = m3(); LeakIt.leak(this); // ERR } private def m1() { m2(); } final def m2() def m3() = 1; }

Has-zero Definition of has-zero – A type has-zero if it contains the zero value (which is either null, false, 0) (A struct and type parameter may also has-zero) A var field that lacks a field initializer and whose type has-zero, is implicitly added a zero initializer. class A { val i0:Int; //ERR var i1:Int; var i2:Int{self!=0}; //ERR }

Properties Properties are final fields that are initialized first using property(...); class A(a:Int) {} class B(b:Int) {b==a} extends A { val f1 = a+b; def this(x:Int) { super(x); val i1 = super.a; val i2 = this.f1; //ERR property(x); val i3 = this.f1; } Field initializers are executed after property(…) super init Properties init Field init

Generics haszero type predicate class B[T] {T haszero } { var f1:T; val f2 = Zero.get[T](); } class Usage { var b1:B[Int]; var b2:B[Int{self!=0}]; //ERR } class Array[T] { def this(size:Int) {T haszero} {…} def this(defaultElement:T,size:Int) {…} }

Concurrent programming finish and async A constructor must finish assigning to all fields class A { val f1:Int; val f2:Int; def this() { async f1 = 2; // ERR finish { async f2 = 3; }

Distributed programming at shifts execution to another place A raw this cannot be captured by an at. class A { val f:Int; def this() { at (here.next()) this.f = 1; //ERR: this escaped }

Definite assignment class A { var i:Int{self!=0}, j:Int{self!=0}; def this() { finish { asyncWriteI(); // asyncAssigned={i} writeJ(); // ERR } // assigned={i} writeJ();// assigned={i,j} } private def asyncWriteI () {// asyncAssigned={i} async i=1; } private def writeJ() {// reads={i} assigned={j} if (i==1) writeJ(); else this.j = 1; }

Previous work Java C++ Non-null types Masked types (Qi and Meyers) Detector uninitialized fields

Conclusion Java and C++ initialization is error-prone X10 initialization design – Strict: protects from errors – Simple – Flexible (but cannot express cyclic immutability) – Type safe – Final fields has a single value See paper for alternative designs (e.g., proto) Questions?