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

Post on 19-Jan-2016

212 views 0 download

Transcript of 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

Overview

Motivation Syntax Changes Asynchronous Methods Message Passing State Charts/Diagram

Motivation

Despite the relative simplicity of Javas’ threading model, writing concurrent

programs in Java can still be strange and confusing.

Tim Lindholm, Javasoft

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.

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.

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)

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();

}

}

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

}

}

State Diagrams

Conversion of State Diagrams to Code

A

C

B

b

a

x

y

State Diagram

State Diagram Code

class statediagram {

public statediagram() { A(); }

void x() & A() { C(); }

void b() & A() { B(); }

void a() & B() { A(); }

void y() & C() { B(); }

}

State Charts

Conversion of State Charts to Code

c

A B

inA

inB

F

x

. State Chart

D Ey

inD

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() {}

}

Compiler

Translation of Join Patterns– Tree Structure Representation.

root

A&B A&C

CAB

Structure of Pattern Matcher

Next Steps

Add Synchronous Trailing Methods. Benchmarking. Add parent types?

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