Jcc

30
jcc:TimedDefault cc Programming in JAVA Vijay Saraswat, IBM Research Radha Jagadeesan, DePaul University Vineet Gupta, Google

description

& concept explained easily

Transcript of Jcc

Page 1: Jcc

jcc:TimedDefault cc Programmingin JAVA

Vijay Saraswat, IBM Research

Radha Jagadeesan, DePaul University

Vineet Gupta, Google

Page 2: Jcc

Concurrent programming in Java

Threads, shared heap, separate stack Synchronization based on locking

mutable objects in shared heap Rules to govern information flow between

thread-specific data structures (heap cache, stack) and shared store.

Page 3: Jcc

Concurrent programming in Java

`` Unfortunately the current specification has been found to be hard to understand and has subtle, often unintended, implications….. Several important issues [….] simply aren't discussed in the existing specification.''

Page 4: Jcc

Concurrent programming in Java

Concurrent execution in Java is the default.

Every line of Java code could be executed in parallel by multiple threads on the same object.

Page 5: Jcc

The Jcc model

jcc= JAVA −Threads +Vats +Promises +Agents

Page 6: Jcc

Jcc Design Goals

• Interoperability with Java: source code, JVM, and type system

• API for the programmer to add new constraint systems

• Support for reflective meta-programming• The implementation should be usable for

medium-sized programs.

Page 7: Jcc

Rest of the talk

An example Bank application The design elements of Jcc.

Page 8: Jcc

The bank application

Withdrawal

Deposit

Page 9: Jcc

The Bank application: Withdrawals

Withdrawals succeed if balance is large enough. If not, repeat withdrawal after each of the next n deposits. If balance still not large enough, it is rejected.

Page 10: Jcc

The bank application

RaviWithdrawalAccount1(zero)

Account2

Deposit(100) suspend

suspend

Page 11: Jcc

The bank application

RaviWithdrawalAccount1(25)

Account2

Deposit(100)Deposits

25

suspend

suspend

Page 12: Jcc

The bank application

RaviWithdrawalAccount1(100)

Account2

Deposit(100)Deposits

25 each

Page 13: Jcc

Rest of the talk

An example Bank application The design elements of Jcc.

Page 14: Jcc

Vats and ports

Stack

Heap

PortsLocal stack/heap

Single threaded

JVM = Multiple vats + Shared heap of immutable objects

Page 15: Jcc

Communication: Ports

Each port is located at a vat and is “read” only by code at that vat

Each port can have multiple writers/tellers at other vats

Objects written into ports are deep-copied from source to target vat

Page 16: Jcc

Vats and ports in the bank application

RaviWithdrawalAccount1(zero)

Account2

Deposit(100) suspend

suspend

Page 17: Jcc

Execution in a Vat

Process 1 message at a time to completion before getting another message: create new local heap objects invoke methods on objects in heap send objects to ports in another vat

All these operations do not block!

Bounded response guarantees?

Page 18: Jcc

Logical time

A logical time-step:

receive input

compute response

Correspondence to physical time if bounded response can be guaranteed cf. Esterel.

Page 19: Jcc

Logical time in the bank application

WithdrawalAccount1(zero)

Time steps: 0. Withdrawal(100) 1. Deposit(25) 2. Deposit(25) 3. Deposit(25) 4. Deposit(25)

Page 20: Jcc

Time based control constructs

1) next {S}. S is stored and executed in the next time instant.

2) always {S}: Run S at EVERY time instant

Oops! Many programs can be executing at the same time instant

Page 21: Jcc

Mutiple programs in the Account1 vat of the bank application

WithdrawalAccount1(zero)

Time steps: 0. Withdrawal(100): “withdrawal code” 1. Deposit(25): “withdrawal, deposit code” 2. Deposit(25): “withdrawal, deposit code” 3. Deposit(25): as above 4. Deposit(25): as above

Page 22: Jcc

Constraints for Intra-Vat communication

How to achieve determinate concurrency?Concurrent constraint programming!

Store

Page 23: Jcc

Constraint stores in Jcc

Each vat has its own store All items in a store are dropped at the end

of a time instant: programmer carries items into following time instant explicitly using next.

Constraints via promises (= typed logical variables) in Jcc.

Page 24: Jcc

Promises

Promise in Jcc = java.lang.Object in Java

1. Unrealized and unwatched. [new variables]

2. Realized [new constants]

3. Bound [o.equate(p) ]

4. Unrealized and watched

Page 25: Jcc

Watchers for promises

When (p) do S

If p is realized, run S.

Otherwise, suspend S on p. S is a watcher for p

Effect of p.equate(q)??

Page 26: Jcc

Watchers for promises

every (p) do S

run S in every time instant in which p is realized

Page 27: Jcc

Code for Account

public BankAccount() {

every (balanceUpdate) { // check if pending withdrawals // can be satisfied }

Page 28: Jcc

Code for Account

public Confirmation deposit(Integer amount){

Confirmation result = new Confirmation();when (amount) { // update balance result.equate(“Success”); }return result;}

Page 29: Jcc

Code for Account

public Confirmation withdraw(Integer amount){

Confirmation result = new Confirmation();when (amount) { // check balance // if balance sufficient

result.equate(“Success”); //if balance not sufficient, add to pending list

}return result;}

Page 30: Jcc

Conclusions

jcc= JAVA −Threads +Vats +Promises +Agents

Full power of Timed Default cc in Java.