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

Slides:



Advertisements
Similar presentations
Operating Systems Components of OS
Advertisements

Part IV: Memory Management
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
Concurrency The need for speed. Why concurrency? Moore’s law: 1. The number of components on a chip doubles about every 18 months 2. The speed of computation.
Programming Types of Testing.
Hastings Purify: Fast Detection of Memory Leaks and Access Errors.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Programming Languages Structure
CS 201 Functions Debzani Deb.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CS 104 Introduction to Computer Science and Graphics Problems Software and Programming Language (2) Programming Languages 09/26/2008 Yang Song (Prepared.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Scala Actors -Terrance Dsilva.  Thankfully, Scala offers a reasonable, flexible approach to concurrency  Actors aren’t a concept unique to Scala.
Introduction to High-Level Language Programming
Modern Concurrency Abstractions for C# by Nick Benton, Luca Cardelli & C´EDRIC FOURNET Microsoft Research.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
1 Developing Native Device for MPJ Express Advisor: Dr. Aamir Shafi Co-advisor: Ms Samin Khaliq.
Introduction and Overview Questions answered in this lecture: What is an operating system? How have operating systems evolved? Why study operating systems?
ICOM 5995: Performance Instrumentation and Visualization for High Performance Computer Systems Lecture 7 October 16, 2002 Nayda G. Santiago.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Lecture 10 : Introduction to Java Virtual Machine
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
JAVA Java is a programming language and computing platform first released by Sun Microsystems in It was first developed by James Gosling at Sun Microsystems,
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
CS 153: Concepts of Compiler Design August 26 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Computing Simulation in Orders Based Transparent Parallelizing Pavlenko Vitaliy Danilovich, Odessa National Polytechnic University Burdeinyi Viktor Viktorovych,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Implementation of Join Semantics in Java G Stewart von Itzstein University of South Australia.
Introduction to OOP CPS235: Introduction.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
CS223: Software Engineering
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Introduction to Programming 1 1 2Introduction to Java.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Topic 2: Hardware and Software
Component 1.6.
Visit for more Learning Resources
Chapter 4: Threads.
Lecture 1: Introduction to JAVA
Java Primer 1: Types, Classes and Operators
Semantic Analysis with Emphasis on Name Analysis
Introduction Enosis Learning.
Introduction Enosis Learning.
Programming Languages
Introduction CSC 111.
Java History, Editions, Version Features
1.3.7 High- and low-level languages and their translators
Presentation transcript:

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

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

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.

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.

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)?

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.

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; }

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 {..}

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

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

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.

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.

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.

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

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

The School of Computer & Information Science 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 A()&D() {} A()&B() {} B()&D() {} Call to D arrives

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

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)

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

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.

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.

The School of Computer & Information Science22 Benchmarking (pre-calculated tables) Time (10 -6 seconds) Standard Java InterpreterHot Spot Java Synchronized Method Java Synchronized Block Method Join Java ParameterReturns InterpreterHot Spot

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

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).

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

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