SlideShare une entreprise Scribd logo
1  sur  30
jcc:TimedDefault cc
Programming
in JAVA
Vijay Saraswat, IBM Research
Radha Jagadeesan, DePaul University
Vineet Gupta, Google
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.
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.''
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.
The Jcc model
jcc= JAVA
−Threads
+Vats
+Promises
+Agents
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.
Rest of the talk
 An example Bank application
 The design elements of Jcc.
The bank application
Withdrawal
Deposit
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.
The bank application
Ravi
Withdrawal
Account1
(zero)
Account2
Deposit(100) suspend
suspend
The bank application
Ravi
Withdrawal
Account1
(25)
Account2
Deposit(100)
Deposits
25
suspend
suspend
The bank application
Ravi
Withdrawal
Account1
(100)
Account2
Deposit(100)
Deposits
25 each
Rest of the talk
 An example Bank application
 The design elements of Jcc.
Vats and ports
Stack
Heap
Ports
Local stack/heap
Single threaded
JVM =
Multiple vats
+
Shared heap of
immutable
objects
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
Vats and ports in the bank
application
Ravi
Withdrawal
Account1
(zero)
Account2
Deposit(100) suspend
suspend
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?
Logical time
A logical time-step:
receive input
compute response
Correspondence to physical time if bounded
response can be guaranteed cf. Esterel.
Logical time in the bank application
Withdrawal
Account1
(zero)
Time steps:
0. Withdrawal(100)
1. Deposit(25)
2. Deposit(25)
3. Deposit(25)
4. Deposit(25)
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
Mutiple programs in the Account1
vat of the bank application
Withdrawal
Account1
(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
Constraints for Intra-Vat
communication
How to achieve determinate concurrency?
Concurrent constraint programming!
Store
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.
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
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)??
Watchers for promises
 every (p) do S
run S in every time instant in which p is
realized
Code for Account
public BankAccount() {
every (balanceUpdate) {
// check if pending withdrawals
// can be satisfied
}
Code for Account
public Confirmation deposit(Integer amount){
Confirmation result = new Confirmation();
when (amount) {
// update balance
result.equate(“Success”);
}
return result;
}
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;
}
Conclusions
jcc= JAVA
−Threads
+Vats
+Promises
+Agents
Full power of Timed Default cc in Java.

Contenu connexe

En vedette

Introduction to oracle
Introduction to oracleIntroduction to oracle
Introduction to oracleSumit Tambe
 
Advanced dreamweaver
Advanced dreamweaverAdvanced dreamweaver
Advanced dreamweaverSumit Tambe
 
Birthday greeting 2009
Birthday greeting 2009Birthday greeting 2009
Birthday greeting 2009Sumit Tambe
 
12.ibm r50 ibm wireless setup
12.ibm r50 ibm wireless setup12.ibm r50 ibm wireless setup
12.ibm r50 ibm wireless setupSumit Tambe
 
Sql group functions(2)
Sql group functions(2)Sql group functions(2)
Sql group functions(2)Sumit Tambe
 
Virtualization strategies
Virtualization strategiesVirtualization strategies
Virtualization strategiesSumit Tambe
 
2123.a better waytoprint.universal print
2123.a better waytoprint.universal print2123.a better waytoprint.universal print
2123.a better waytoprint.universal printSumit Tambe
 
Advanced dreamweaver
Advanced dreamweaverAdvanced dreamweaver
Advanced dreamweaverSumit Tambe
 
Notes server setup
Notes server setupNotes server setup
Notes server setupSumit Tambe
 

En vedette (15)

Introduction to oracle
Introduction to oracleIntroduction to oracle
Introduction to oracle
 
Advanced dreamweaver
Advanced dreamweaverAdvanced dreamweaver
Advanced dreamweaver
 
Ms dos
Ms dosMs dos
Ms dos
 
Birthday greeting 2009
Birthday greeting 2009Birthday greeting 2009
Birthday greeting 2009
 
12.ibm r50 ibm wireless setup
12.ibm r50 ibm wireless setup12.ibm r50 ibm wireless setup
12.ibm r50 ibm wireless setup
 
Sql group functions(2)
Sql group functions(2)Sql group functions(2)
Sql group functions(2)
 
Ch1 2
Ch1 2Ch1 2
Ch1 2
 
Virtualization strategies
Virtualization strategiesVirtualization strategies
Virtualization strategies
 
2123.a better waytoprint.universal print
2123.a better waytoprint.universal print2123.a better waytoprint.universal print
2123.a better waytoprint.universal print
 
Advanced dreamweaver
Advanced dreamweaverAdvanced dreamweaver
Advanced dreamweaver
 
Cos413day3
Cos413day3Cos413day3
Cos413day3
 
Ccna2v3 mod07
Ccna2v3 mod07Ccna2v3 mod07
Ccna2v3 mod07
 
Notes server setup
Notes server setupNotes server setup
Notes server setup
 
Ch05
Ch05Ch05
Ch05
 
Java tut1
Java tut1Java tut1
Java tut1
 

Similaire à Jcc

Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive Design Patterns: a talk by Typesafe's Dr. Roland KuhnReactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive Design Patterns: a talk by Typesafe's Dr. Roland KuhnZalando Technology
 
Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9Trayan Iliev
 
Module-related pages
Module-related pagesModule-related pages
Module-related pagesbutest
 
Module-related pages
Module-related pagesModule-related pages
Module-related pagesbutest
 
5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptxMohamedBilal73
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the tradeshinolajla
 
Real-time Programming in Java
Real-time Programming in JavaReal-time Programming in Java
Real-time Programming in JavaAleš Plšek
 
Talent42 2014 Sam Wholley -
Talent42 2014 Sam Wholley - Talent42 2014 Sam Wholley -
Talent42 2014 Sam Wholley - Talent42
 
Towards a Scalable Non-Blocking Coding Style
Towards a Scalable Non-Blocking Coding StyleTowards a Scalable Non-Blocking Coding Style
Towards a Scalable Non-Blocking Coding StyleAzul Systems Inc.
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.jsratankadam
 
Node.js Enterprise Middleware
Node.js Enterprise MiddlewareNode.js Enterprise Middleware
Node.js Enterprise MiddlewareBehrad Zari
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous ApplicationsJohan Edstrom
 
SAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilitiesSAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilitiesAndrey Karpov
 
Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSupun Dissanayake
 

Similaire à Jcc (20)

Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive Design Patterns: a talk by Typesafe's Dr. Roland KuhnReactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
 
NoSQL and ACID
NoSQL and ACIDNoSQL and ACID
NoSQL and ACID
 
Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9
 
Module-related pages
Module-related pagesModule-related pages
Module-related pages
 
Module-related pages
Module-related pagesModule-related pages
Module-related pages
 
5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx5.7 Parallel Processing - Reactive Programming.pdf.pptx
5.7 Parallel Processing - Reactive Programming.pdf.pptx
 
Reactive Design Patterns
Reactive Design PatternsReactive Design Patterns
Reactive Design Patterns
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Introduction to Storm
Introduction to StormIntroduction to Storm
Introduction to Storm
 
Node js internal
Node js internalNode js internal
Node js internal
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
 
What's Inside a JVM?
What's Inside a JVM?What's Inside a JVM?
What's Inside a JVM?
 
Real-time Programming in Java
Real-time Programming in JavaReal-time Programming in Java
Real-time Programming in Java
 
Talent42 2014 Sam Wholley -
Talent42 2014 Sam Wholley - Talent42 2014 Sam Wholley -
Talent42 2014 Sam Wholley -
 
Towards a Scalable Non-Blocking Coding Style
Towards a Scalable Non-Blocking Coding StyleTowards a Scalable Non-Blocking Coding Style
Towards a Scalable Non-Blocking Coding Style
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.js
 
Node.js Enterprise Middleware
Node.js Enterprise MiddlewareNode.js Enterprise Middleware
Node.js Enterprise Middleware
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
 
SAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilitiesSAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilities
 
Solve it Differently with Reactive Programming
Solve it Differently with Reactive ProgrammingSolve it Differently with Reactive Programming
Solve it Differently with Reactive Programming
 

Jcc

  • 1. jcc:TimedDefault cc Programming in JAVA Vijay Saraswat, IBM Research Radha Jagadeesan, DePaul University Vineet Gupta, Google
  • 2. 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.
  • 3. 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.''
  • 4. 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.
  • 5. The Jcc model jcc= JAVA −Threads +Vats +Promises +Agents
  • 6. 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.
  • 7. Rest of the talk  An example Bank application  The design elements of Jcc.
  • 9. 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.
  • 13. Rest of the talk  An example Bank application  The design elements of Jcc.
  • 14. Vats and ports Stack Heap Ports Local stack/heap Single threaded JVM = Multiple vats + Shared heap of immutable objects
  • 15. 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
  • 16. Vats and ports in the bank application Ravi Withdrawal Account1 (zero) Account2 Deposit(100) suspend suspend
  • 17. 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?
  • 18. Logical time A logical time-step: receive input compute response Correspondence to physical time if bounded response can be guaranteed cf. Esterel.
  • 19. Logical time in the bank application Withdrawal Account1 (zero) Time steps: 0. Withdrawal(100) 1. Deposit(25) 2. Deposit(25) 3. Deposit(25) 4. Deposit(25)
  • 20. 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
  • 21. Mutiple programs in the Account1 vat of the bank application Withdrawal Account1 (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
  • 22. Constraints for Intra-Vat communication How to achieve determinate concurrency? Concurrent constraint programming! Store
  • 23. 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.
  • 24. 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
  • 25. 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)??
  • 26. Watchers for promises  every (p) do S run S in every time instant in which p is realized
  • 27. Code for Account public BankAccount() { every (balanceUpdate) { // check if pending withdrawals // can be satisfied }
  • 28. Code for Account public Confirmation deposit(Integer amount){ Confirmation result = new Confirmation(); when (amount) { // update balance result.equate(“Success”); } return result; }
  • 29. 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; }