Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.

14
Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Next Steps

Add Synchronous Trailing Methods. Benchmarking. Add parent types?

– eg A() : B() -> partOfInA