Improving Rotor for Dynamically Typed Languages Fabio Mascarenhas and Roberto Ierusalimschy.

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

A Program Transformation For Faster Goal-Directed Search Akash Lal, Shaz Qadeer Microsoft Research.
Compiler Design PROJECT PRESENTATION : COMPILER FOR OBJECTIVE C Harshal Waghmare Jeet Kumar Nandan Kumar Vishal Agrawal.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
The Kernel Abstraction. Challenge: Protection How do we execute code with restricted privileges? – Either because the code is buggy or if it might be.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 5 Threads os5.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
ISBN Chapter 10 Implementing Subprograms.
Threads Load new page Page is loading Browser still responds to user (can read pages in other tabs)
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
Run time vs. Compile time
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for Threads.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection.
Procgen Chaz Pratt 11/3/2009. overview What is procgen? What we tried? What worked? What didn’t? Try again?
Comparative Programming Languages hussein suleman uct csc304s 2003.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 18 Exception Handling.
A Revolutionary Programming Pattern that Will Clean up your Code : Coroutines in C++ David Sackstein ACCU 2015.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
Continuations And Java Regis -
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 8: Semantic Analysis and Symbol Tables.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Object-Oriented Programming Chapter Chapter
Exceptions and Assertions Chapter 15 – CSCI 1302.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
CSE 425: Control Abstraction II Exception Handling Previous discussion focuses on normal control flow –Sometimes program reaches a point where it cannot.
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Introduction to Objects and Encapsulation Computer Science 4 Mr. Gerb Reference: Objective: Understand Encapsulation and abstract data types.
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
RealTimeSystems Lab Jong-Koo, Lim
Just-In-Time Compilation. Introduction Just-in-time compilation (JIT), also known as dynamic translation, is a method to improve the runtime performance.
Introduction to Operating Systems Concepts
Chapter 4 – Thread Concepts
Threads & Multithreading
Concurrency, Processes and Threads
Chapter 4 – Thread Concepts
Arrays and Linked Lists
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
What is Lua? Brandon Burgess Csc 415.
21 Threads.
Concurrency, Processes and Threads
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Concurrency, Processes and Threads
Exception Handling.
CS 5204 Operating Systems Lecture 5
CSc 453 Interpreters & Interpretation
JIT Compiler Design Maxine Virtual Machine Dhwani Pandya
Threads.
Presentation transcript:

Improving Rotor for Dynamically Typed Languages Fabio Mascarenhas and Roberto Ierusalimschy

PUC-Rio Improving Rotor for Dynamically Typed Languages Introduction 1 st RFP: Compiling Lua to the CLR Good performance, integration with rest of the CLR Issues found Inefficient coroutines Wrong weak map semantics Heavy codegen CLR 2.0 has lightweight codegen, but other issues remain

PUC-Rio Improving Rotor for Dynamically Typed Languages Coroutines Lightweight threads: no concurrent execution, explicit context switching Compared to full threads: easier to use (no race conditions to worry about), better performance Applications: producer/consumer, generators, iterators, event-based programming, cooperative multitasking Full coroutines: first-class, can switch context inside functions called by the main coroutine function

PUC-Rio Improving Rotor for Dynamically Typed Languages Symmetric x Asymmetric Symmetric coroutines: transfer operation switches to another coroutine Asymmetric coroutines: resume operation switches to a coroutine, yield switches back You can implement symmetric coroutines with asymmetric, and vice versa We decided to have asymmetric coroutines as the basic abstraction

PUC-Rio Improving Rotor for Dynamically Typed Languages Using Coroutines Creating Coroutine c = new Coroutine(obj.CoBody); Resuming (or starting) retval = c.Resume(obj); Yielding retval = Coroutine.Yield(obj); Coroutine body is a method that receives an object and returns an object Argument to Resume is passed to the body when the coroutine is started, and returned from Yield when resuming Argument to Yield is returned from Resume when yielding Uncaught exceptions propagate up the yield chain

PUC-Rio Improving Rotor for Dynamically Typed Languages Example – Tree traversal static object InOrder(object o) { if(o) { Node n = (Node)o; InOrder(n.Left); Coroutine.Yield(n.Key); InOrder(n.Right); } object o; Coroutine c = new Coroutine(Tree.InOrder); while(o = c.Resume(tree)) Console.WriteLine(o);

PUC-Rio Improving Rotor for Dynamically Typed Languages Implementation Issues Each coroutine needs its own stack Allocating and switching among these stacks: fiber API on Windows, ucontext functions on BSD/Linux/MacOS Coroutines x TLS Create a logical thread (CLR thread without an OS thread) for each coroutine? – heavy, coroutines are not threads, this is a hack Add a Coroutine native class to the runtime, to store coroutine- specific state, and modify the Thread class and the threading subsystem to work with it Propagating uncaught exceptions Enclose the coroutine body in a try/catch block and rethrow the exception inside Resume Implementation just started

PUC-Rio Improving Rotor for Dynamically Typed Languages Flexible GC Semantics You cant reproduce the semantics of the GC of some languages in the CLR Lua and its weak maps and reference queues Java and its phantom references Python and its weak maps and per-instance finalizers Weak maps can be used to implement property tables Phantom references/per-instance finalizers useful if you want to know when an object is unreachable but do not want to implement Finalize (and pay the associated cost)

PUC-Rio Improving Rotor for Dynamically Typed Languages Extending the Rotor GC Add per-instance callbacks Unreacheability callback without resurrection »Collect object after running callback Unreacheability callback with resurrection »Same as class finalizer Post-collection callback Reference queues and weak maps implemented with callbacks Transparent weak references?

PUC-Rio Improving Rotor for Dynamically Typed Languages Final Remarks Results still months away Changes for working with Rotor 2 should be minimal Update the Lua compiler to take advantage of the new features Contact: