Presentation is loading. Please wait.

Presentation is loading. Please wait.

On Implementing High Level Concurrency in Java G Stewart von Itzstein Mark Jasiunas University of South Australia.

Similar presentations


Presentation on theme: "On Implementing High Level Concurrency in Java G Stewart von Itzstein Mark Jasiunas University of South Australia."— Presentation transcript:

1 On Implementing High Level Concurrency in Java G Stewart von Itzstein Mark Jasiunas University of South Australia

2 The School of Computer & Information Science2 Overview Motivation Syntax Chemical Abstract Machine Compiler Pattern Matching Benchmarks Conclusion and Further Research

3 The School of Computer & Information Science3 Motivation Normal Java Thread Communication Via shared variable. Using synchronization. Piped Reader Writer. Not scalable. No direct support of runtime decisions on channel formation. Still via a shared variable hidden by API.

4 The School of Computer & Information Science4 Motivation Why is there no message passing for Java threads? Shared memory model defeats encapsulation. Concurrent application are hard to write correctly and understand. Visualise thread pools. What wait goes with what notify? People end up using notifyAll then select the correct thread putting all the others back to sleep. We need a higher level of abstraction to represent more complex concurrent problems. One just to has to teach an undergraduate class to see the creative interpretations of concurrency.

5 The School of Computer & Information Science5 Motivation Can we integrate dynamic communication channels into Java rather than add them as a library? Can we simplify thread creation? Can we simplify parameterized thread creation? Can we improve the code traceability (readability)?

6 The School of Computer & Information Science6 Motivation Join Java goes someway to solving some of these problems. Gives explicit defined communications channels. Simplifies thread creation. Can create thread with parameters. Code is simplified not necessary to use wait/notify in a lot of cases. Join Java is a superset language of Java.

7 The School of Computer & Information Science7 Join Java Syntax Compound method signatures (Join methods) Join fragments are individual method calls. Join method is a number of Join fragments and a method body. A method body is not executed until all Join fragments of the Join method have been called. The first method can be synchronous (normal Java return type) or asynchronous. The second and subsequent methods are asynchronous. Example //JoinFragment1 blocks JoinFragment2 does not block int JoinFragment1() & JoinFragment2(int val) { Return val; }

8 The School of Computer & Information Science8 Join Java Syntax Continued “signal” return representing asynchronous operation. A method of return type signal will not wait for completion of the method before returning. Convenient way of creating threads. Eg. signal thread1() {..} “ordered” modifier for class. Changes the rules in which Join methods are evaluated. How to handle ambiguous situations with respect to Join methods. Eg. ordered class JoinClass {..}

9 The School of Computer & Information Science9 Chemical Abstract Machine Need to represent the execution environment of Join Java. This is done by representing it as a chemical abstract machine. An individual method call (Join fragment) is an “atom”. A() All Join methods represent possible “molecules” A() & B() {…} A particular type of atom may be part of different molecules. A() & B() {…} C() & B() {…} A() & Z() {…} A() is in patterns 1 and 3 B() is in patterns 1 and 2

10 The School of Computer & Information Science10 Chemical Abstract Machine When you make a call to a Join fragment the atom representing the Join fragment is placed into the chemical machine. When all the required atoms to complete a molecule are in the pool, the atoms reacts changing the composition of the pool. Completed molecules are removed from the pool along with their component atoms

11 The School of Computer & Information Science11 Pattern Matcher This means that Join method resolution is inherently a pattern matching problem. We express the chemical abstract machine as a pattern matcher.

12 The School of Computer & Information Science12 Architecture of The Compiler Fairly standard Java compiler. Join Java adds; Addition of extra language features to parser. Addition of an extra semantic checking phase. Pretty printer. Translator phase that converts from Join Java AST to Java AST. Compiles to standard Java byte-code or standard Java source code from Join Java source code.

13 The School of Computer & Information Science13 Architecture of The Compiler Language extension generates standard Java byte code In the language prototype. Pattern matching code available as a compiled library Uses a library for matching rather than compiling all the code. Disadvantage : Have to supply runtime files. Advantage: Can rapidly prototype different designs. A final language version will generate all the code.

14 The School of Computer & Information Science14 Class Modifiers and Prototype Restrictions Additional class modifier ordered When used each Join method will be tested in the order in which they are declared. When no modifier is used non-deterministic choice is made. No subclassing of a Join enabled class All Join classes are declared final

15 The School of Computer & Information Science15 Example of a Join Java Program THREAD 1 … System.out.println (“Calling a()”); a(); System.out.println (“a finished”); Sleep(1); Fragment Pool (CHAM) JOIN METHOD void a() & b(int B) { System.out.println (“Both a and b have been called”); } THREAD 2 … System.out.println (“Calling b”); b(3); System.out.println (“b finished”); Sleep(1); … Output Pattern Matcher Calling a a() arrived Add a to Fragment Pool a Check state of Fragment pool: No patterns Block thread 1 Calling b B(3) b a&b found Thread 1 notified Both a and b have been called a finished b finished

16 The School of Computer & Information Science16 1 1 0 0 Pattern Matching Algorithms Linear Matching Just take the present state and compare it to all completion states one at a time. Is slow in the O(f*p). Where f = number of fragments. p = number of patterns. 0 1 1 01 0 1 0 A()&D() {} A()&B() {} B()&D() {} 1 0 9 0 Call to D arrives 0 0 9 0

17 The School of Computer & Information Science17 Pattern Matching Algorithms Tree Matching

18 The School of Computer & Information Science18 Pattern Matching Algorithms Tree Matching Advantages Prunes Search Space (Quicker) Average time is short (assuming some locality of Join methods). Disadvantages Pathological example of one Join fragment in all Join patterns becomes something like quadratic (viz linear matching)

19 The School of Computer & Information Science19 Pattern Matching Algorithms Precalculated Table Matcher

20 The School of Computer & Information Science20 Pattern Matching Algorithms Precalculated Table Matcher Advantages Can be precalculated at compile time in a final production version. Disadvantages Requires more memory. Memory footprint can be reduced by using symmetry. However, design of Join Java is one pattern matcher per class so the size of the pattern matcher does not get large.

21 The School of Computer & Information Science21 Benchmarking How fast is Join Java? Majority of cases not much difference to that of standard Java synchronized methods. Raw method call overhead is high in some cases. Usually due to prototype rather than any limiting factor. Not recommended to make every method a Join method Standard Java call != Join Java method call However, Synchronized Java call != Standard Java call Synchronized blocks are even slower.

22 The School of Computer & Information Science22 Benchmarking (pre-calculated tables) Time (10 -6 seconds) Standard Java InterpreterHot Spot Java Synchronized Method55.455.7 Java Synchronized Block Method61.3329.71 Join Java ParameterReturns InterpreterHot Spot 74.1471.69 67.9412.64 69.9414.51 70.00 157.61

23 The School of Computer & Information Science23 Benchmark Modified Café Benchmark on Precalculated Matcher Java Join Java

24 The School of Computer & Information Science24 Problems Hotspot Optimizations Adaptive inlining/Dynamic deoptimization. Fine for standard Java programs possibly not for Join Java translations. Hot spotting may be disrupted by the way the pattern matcher runs. If the code doesn’t appear the same to the hot spotting code it won’t optimize it. Unboxing Expensive (see -> translation on the previous page. No JVM support for boxing and unboxing (unlike.NET runtime).

25 The School of Computer & Information Science25 Conclusions & Future work Hotspot problems may fade in the next hotspot JVM which has on stack replacement. JVM hotspots code and replaces interpreted code as its running rather the next time its needed. Overheads in Java (boxing).Net has a VM instruction. May be able to optimize an open source JVM for Join patterns without changing the instruction set. Further Pattern Matching Algorithms Symmetric pattern matching

26 The School of Computer & Information Science26 Quote In the absence of explicit synchronization, an implementation is free to update the main memory in an order that may be surprising. Therefore the programmer who prefers to avoid surprises should use explicit synchronization.. James Gosling, Sun Microsystems


Download ppt "On Implementing High Level Concurrency in Java G Stewart von Itzstein Mark Jasiunas University of South Australia."

Similar presentations


Ads by Google