Tasks: Language Support for Event-Driven Programming

Similar documents
Why Threads Are A Bad Idea (for most purposes)

Resource Containers: A new facility for resource management in server systems

Real Time Programming: Concepts

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Scala Actors Library. Robert Hilbrich

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Replication on Virtual Machines

HelenOS IPC and Behavior Protocols

Compositional hardware virtualization. Raphael kena Poss University of Amsterdam January 11th, 2014

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Multi-core Programming System Overview

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Between Mutual Trust and Mutual Distrust: Practical Fine-grained Privilege Separation in Multithreaded Applications

Embedded Systems. 6. Real-Time Operating Systems

Object Oriented Database Management System for Decision Support System.

Operating Systems and Networks

LabVIEW Advanced Programming Techniques

Adding Panoramas to Google Maps Using Ajax

Chapter 2: OS Overview

Android Architecture. Alexandra Harrison & Jake Saxton

ELEC 377. Operating Systems. Week 1 Class 3

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Java the UML Way: Integrating Object-Oriented Design and Programming

Automatic Logging of Operating System Effects to Guide Application-Level Architecture Simulation

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

From L3 to sel4: What Have We Learnt in 20 Years of L4 Microkernels?

Operating System Overview. Otto J. Anshus

MA-WA1920: Enterprise iphone and ipad Programming

Example of Standard API

First-class User Level Threads

Web Server Architectures

Responders: Language Support for Interactive Applications

Networking Operating Systems (CO32010)

Embedded C Programming, Linux, and Vxworks. Synopsis

CSC 551: Web Programming. Spring 2004

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Programming Languages

Using Protothreads for Sensor Node Programming

Computing Concepts with Java Essentials

Habanero Extreme Scale Software Research Project

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Course Descriptions. preparation.

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

ODROID Multithreading in Android

Combining Events And Threads For Scalable Network Services

This tutorial will take you through step by step approach while learning Operating System concepts.

DIABLO VALLEY COLLEGE CATALOG

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

Sequential Performance Analysis with Callgrind and KCachegrind

Operating System Structures

Mobile Application Development Android

Crash Course in Java

Validating Java for Safety-Critical Applications

Computer Science Course Descriptions Page 1

Cloud Computing. Up until now

Mobile Web Design with HTML5, CSS3, JavaScript and JQuery Mobile Training BSP-2256 Length: 5 days Price: $ 2,895.00

OpenACC 2.0 and the PGI Accelerator Compilers

Java EE Web Development Course Program

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

Introducing PgOpenCL A New PostgreSQL Procedural Language Unlocking the Power of the GPU! By Tim Child

OKLAHOMA SUBJECT AREA TESTS (OSAT )

Frameworks & Android. Programmeertechnieken, Tim Cocx

Course Descriptions. CS 101 Intro to Computer Science

Performance Comparison of RTOS

: provid.ir

ADOBE AIR. Working with Data in AIR. David Tucker

Linux Process Scheduling Policy

Data Centers and Cloud Computing

Super Pro Net TM Network Key Installation and Operation

Lua as a business logic language in high load application. Ilya Martynov ilya@iponweb.net CTO at IPONWEB

Enterprise Mobile Application Development: Native or Hybrid?

ACTOR-BASED MODEL FOR CONCURRENT PROGRAMMING. Sander Sõnajalg

CSCI E 98: Managed Environments for the Execution of Programs

Lecture 1 Introduction to Android

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

Lecture 25 Symbian OS

No no-argument constructor. No default constructor found

Zing Vision. Answering your toughest production Java performance questions

Ambient-oriented Programming & AmbientTalk

Ubiquitous access Inherently distributed Many, diverse clients (single purpose rich) Unlimited computation and data on demand

Operating System Organization. Purpose of an OS

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

CSC 2405: Computer Systems II

TOWARDS A GREEN PROGRAMMING PARADIGM FOR MOBILE SOFTWARE DEVELOPMENT

Static Analysis of Virtualization- Obfuscated Binaries

SYSTEM ecos Embedded Configurable Operating System

Fachbereich Informatik und Elektrotechnik SunSPOT. Ubiquitous Computing. Ubiquitous Computing, Helmut Dispert

Web Performance, Inc. Testing Services Sample Performance Analysis

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Mutual Exclusion using Monitors

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

Real-world Java 4 beginners. Dima, Superfish github.com/dimafrid

Language Based Virtual Machines... or why speed matters. by Lars Bak, Google Inc

Secure Mobile Agent Systems Using Java: Where are We Heading?

Transcription:

Tasks: Language Support for Event-Driven ming Outline The problem Example: Threads vs. Events The TaskJava language Jeffrey Fischer, Rupak Majumdar, and Todd Millstein UCLA Computer Science Dept. Related work Applications The Problem The Problem Current solutions for interleaved computation suffer a number of drawbacks Current solutions for interleaved computation suffer a number of drawbacks Multi-threaded servers Introduce concurrency Performance issues when using large number of threads Not suitable for some contexts (embedded systems, some OS kernels, business processes) Event-driven servers Must manually translate to continuation-passing style Difficult to follow control flow May lead to bugs! Cannot easily take advantage of language features such as inheritance and exceptions Our solution: TaskJava Code layout: threads vs. events High performance concurrency while preserving program structure. Multithreaded version Extension to Java ming model: Tasks look like threads, but run like events if (x==ok) { else { Compiler performs modular CPS translation Blocks in operating system Jeff Fischer, UCLA 1

Code layout: threads vs. events Code layout: threads vs. events Multithreaded version Event-driven version Multithreaded version Event-driven version if (x==ok) { else { Initiate call and return Continuation foo2(x) { if (x==ok) { else { if (x==ok) { else { runs continuation foo2(x) { if (x==ok) { else { Bugs in event-driven code Bugs in event-driven code cnt) { reg(e 1, e 2, nb2); cnt) { reg(e 1, e 2, nb2); foo2(result) { if (result==ok){ else { nb2(event) { if (event==e 1 ) { cnt(ok); else cnt(not_ok); Register events and callback with foo2(result) { scheduler if (result==ok){ else { nb2(event) { if (event==e 1 ) { cnt(ok); else cnt(not_ok); Bugs in event-driven code Code layout: TaskJava foo2(result) { if (result==ok){ else { Lost continuation bug if nb2 forgets to call foo2 Lost exception bug if nb2 forgets to pass error to foo2 cnt) { reg(e 1, e 2, nb2); nb2(event) { if (event==e 1 ) { cnt(ok); else cnt(not_ok); Source code async if (x==ok) { else { Compiled code blockingcall(buf, foo2(x) { if (x==ok) { else { Jeff Fischer, UCLA 2

TaskJava features Class WriteTask implements Task { void run() { The Task do { write(buffer); interface looks while (buffer.hasremaining()); like Java s Thread interface async void write(charbuffer buffer) throws IOException { Event e = wait(channel, Event.WRITE, Event.ERROR); switch (e.type()) { case Event.WRITE: ch.write(buffer); break; case Event.ERROR: throw new IOException(); TaskJava features Asychronous method call Class WriteTask implements Task { void run() { do { write(buffer); while (buffer.hasremaining()); async void write(charbuffer buffer) throws IOException { Event e = wait(channel, Event.WRITE, Event.ERROR); switch (e.type()) { case Event.WRITE: ch.write(buffer); break; case Event.ERROR: throw new IOException(); Method annotation TaskJava features Class WriteTask implements Task { void run() { do { write(buffer); while (buffer.hasremaining()); Yield until one async void write(charbuffer buffer) of the events throws IOException { occurs Event e = wait(channel, Event.WRITE, Event.ERROR); switch (e.type()) { case Event.WRITE: ch.write(buffer); break; case Event.ERROR: throw new IOException(); Errors signaled by throwing exceptions Translating TaskJava to Java Bodies of Task run and async methods split into continuation passing style Explicit callbacks introduced by compiler wait (Set) <>.register(set, new cb()) class provided as option to compiler Translating TaskJava: the tricky bits Local variables Move to heap if used across async calls Nested asynchronous calls Introduce temporary variables Loops Flatten and use switch statement to simulate goto s Exceptions Separate callbacks for error control flow Defined semantic rules and type system Prove key properties: Type soundness No lost continuations or lost exceptions Translation to Java Jeff Fischer, UCLA 3

E[Wait(es)] (E 2 [], es 2 ), (E 2 [], es 2 ), (E 2 [], es 2 ), (E 2 [], es 2 ), So, what s new? Type system tracks blocking methods Compiler translates only blocking methods Safe Coexists with existing libraries (E 2 [], es 2 ), Compiler generates scheduler-independent code Case study: web server with pure-event and thread-pooled schedulers Jeff Fischer, UCLA 4

Related work Related work: Cooperative Multitasking Cooperative multitasking Functional programming languages Other language approaches User-level threads through stack manipulation Many implementations E.g. [Engelschall 00], [von Behren, et. al. 03] Does not work for most VM-based languages is fixed Related work: Functional programming languages Scheme: avoid inversion of control issues in web programming First-class continuations [Graunke 01], [Queinnec 03] Whole program CPS transformations [Matthews, et. al. 04] Concurrent ML [Reppy 91] User-level pre-emptive threads and first class events Built on top of continuations Related work: Functional programming languages Continuations from generalized stack inspection [Pettyjohn, et al. 05] Implements Scheme continuations on.net VM Uses exception handlers and stack copying Related work: other language approaches Applications of TaskJava TAME: C++ Library for event-driven programming [Krohn and Kohler 06] Implements a localized CPS-transform via templates Emphasizes flexibility over safety TaskJava in embedded environments eb applications MAWL [Ball and Aktins 99] DSL for Web applications Scala actor library ming provides continuation as a closure Type system ensures that async call does not return values Jeff Fischer, UCLA 5

TaskJava for embedded applications Embedded systems generally cannot use threads Larger and non-deterministic memory usage scheduling TaskJava could address these issues Possible targets: Virgil, a Java-like language with static allocation Sqawk Java VM Embedded TaskJava: static memory allocation Annotations help in analyzing stack usage Restrictions No recursion No variables used across asynchronous calls Static number of tasks (how?) Is TaskJava still useful when compiling directly to hardware instruction set? TaskJava for web applications How TaskJava can help Challenges in server code for web applications: Servers make blocking calls to clients Java Servlet model is event-driven to avoid tying up threads Client makes control flow decisions From the scheduler s perspective, callbacks are first class continuations Callback may be saved, copied, called at any time Can build on ideas from web frameworks in languages like Scheme and Smalltalk Browser uses non-standard control flow model Backwards control flow via back button Forking control flow via new window and new tab Session management For more information Keep callbacks in a map, indexed by session id Options for continuation management: One continuation per session One continuation per web page Tasks: Language Support for Event-driven ming, PEPM 2007 http://cs.ucla.edu/~fischer Alternatively, encrypt callback and send all state to client Jeff Fischer, UCLA 6