Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.
-
Upload
lillian-walton -
Category
Documents
-
view
212 -
download
0
Transcript of Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.
![Page 1: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/1.jpg)
Implementation of Join Semantics in Java
G Stewart von Itzstein
University of South Australia
![Page 2: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/2.jpg)
Overview
Motivation Syntax Changes Asynchronous Methods Message Passing State Charts/Diagram
![Page 3: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/3.jpg)
Motivation
Despite the relative simplicity of Javas’ threading model, writing concurrent
programs in Java can still be strange and confusing.
Tim Lindholm, Javasoft
![Page 4: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/4.jpg)
Motivation
Why is there no message passing in Java threads? Shared memory model defeats encapsulation Concurrent application are hard to understand.
– Visualise, Barrier Synchronisation, Thread Pools– We need a higher level of abstraction to represent
more complex concurrent problems.
![Page 5: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/5.jpg)
Syntax
Chemical Abstract Machine Two changes to the Java Syntax
– “signal” return representing asynchronous operation.– Compound method signatures (join patterns)
A Method body is not executed until all methods have been called.
The first method can be synchronous (normal Java) or asynchronous (signal return type).
The second and subsequent methods must be asynchronous.
![Page 6: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/6.jpg)
Chemical Abstract Machine
All Join Patterns Represent Available “Molecules”
A Method is an Atom. When you make a call to a method is made the
call is placed into the chemical machine. When a complete join pattern is in the machine it
reacts changing the composition of the pool (executing the code associated with the join pattern)
![Page 7: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/7.jpg)
Asynchronous Methods
class threader {
signal thread1() {
//code
System.out.println(“Hello World”);
//code
}
public static void main(String[] argv) {
threader x = new threader();
x.thread1();
x.thread1();
}
}
![Page 8: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/8.jpg)
Message Passing
class Message {
public Message() {thread1();thread2();}
String receiver() & sender(String value) {
return value;
}
signal thread1() {
//do some work that produces a string value
sender(value);
}
signal thread2() {
String value = receiver();
//use value
}
}
![Page 9: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/9.jpg)
State Diagrams
Conversion of State Diagrams to Code
A
C
B
b
a
x
y
State Diagram
![Page 10: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/10.jpg)
State Diagram Code
class statediagram {
public statediagram() { A(); }
void x() & A() { C(); }
void b() & A() { B(); }
void a() & B() { A(); }
void y() & C() { B(); }
}
![Page 11: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/11.jpg)
State Charts
Conversion of State Charts to Code
c
A B
inA
inB
F
x
. State Chart
D Ey
inD
![Page 12: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/12.jpg)
State Chart Code
class StateChart {
public StateChart() { inA(); inD(); D(); A();}
void y() & D() & inD() {
E(); inD();
}
void x() & A() & inA() {
B(); inA();
}
void c() & inA() & inD() {
}
//clean up
void leaveA() & A() {}
void leaveA() & B() {}
}
![Page 13: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/13.jpg)
Compiler
Translation of Join Patterns– Tree Structure Representation.
root
A&B A&C
CAB
Structure of Pattern Matcher
![Page 14: Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697c02c1a28abf838cd9194/html5/thumbnails/14.jpg)
Next Steps
Add Synchronous Trailing Methods. Benchmarking. Add parent types?
– eg A() : B() -> partOfInA