An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

27
An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus Yoshihiro Oyama Kenjiro Taura Akinori Yonezawa Yonezawa Laboratory Department of Information Science University of Tokyo

description

An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus. Yoshihiro Oyama Kenjiro Taura Akinori Yonezawa Yonezawa Laboratory Department of Information Science University of Tokyo. many primitives. surface language. several essential primitives. - PowerPoint PPT Presentation

Transcript of An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Page 1: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

An Efficient Compilation Frameworkfor Languages Based on a Concurrent

Process Calculus

Yoshihiro Oyama Kenjiro Taura Akinori Yonezawa

Yonezawa Laboratory

Department of Information Science

University of Tokyo

Page 2: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

implementation is difficultanalysis is not general

Compiling Programming Languages

machine code

surface languagemany primitives

implementation becomes easyanalysis becomes general

several essential primitives

intermediate language

Page 3: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Intermediate Languages

Sequential languages– Quadruple

– Lambda calculus

– Continuation Passing Style (CPS) [Appel 92]

Concurrent languages– Pi-calculus [Milner 93]

– HACL [Kobayashi et al. 94]process calculus

Page 4: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Concurrent Process Calculus Key component of calculation

– Asynchronous process

– Communication channel

Advantages– Clear syntax and clear semantics

– Many theoretical results for optimization

P

P

P

P

C

P

3

3

Page 5: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Goal

Efficient implementation of a process calculus

ML-like code

Schematic code

HACL code

…..

focus of our research

straightforward translation

traditional techniques

Page 6: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Motivation

Process calculus has some overheads which are not

in sequential languages– Dynamic process scheduling

– Channel communication

Low efficiency with naïve implementation

A demand on a sophisticated implementation

reducing the overheads

Page 7: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Contribution

A framework for compiling process calculus efficiently

Optimization techniques applicable for software multithreading

Page 8: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Overview of This Presentation

Target language HACL A basic execution Our enhanced execution

– To reduce scheduling overhead

– To reduce communication overhead Experimental results

Page 9: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Target Language HACL

e ::= x | c | op(e1, …, en)expression

P ::= P1 | P2

$ x. Pe(x)=>Pe1 <= e2

if e then P1 else P2

e0 (e1, …, en)

parallel execution

channel creationreceive from esend e2 to e1

process instantiationconditional

process expression

x0 (x1, …, xn) = Pprocess definition

Page 10: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Basic Execution Model (1/2)- process scheduling -

P1 | P2 ……… dynamic process creation

P 1 P 2

both schedulable

scheduling pool

|

P

PPcontinuing execution P 2

schedulable process

Page 11: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Basic Execution Model (2/2)- channel -

channel ⇔ pointer to memory space

r

Q

r(y)=>Qr<=8

r<=12r(x)=>P

r<=12r(x)=>Pr(y)=>Qr<=812

value queue

process queue{ 12 / x } P

{8 / y} Q

Page 12: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Inefficiencies of Basic Model

Scheduling overhead– Scheduling pool is manipulated every time

a process is created

Communication overhead– Channel communication is always performed

through memory

Page 13: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Our Enhanced Execution Model

Static process scheduling– reduces the frequency of the runtime scheduling pool

manipulation– lines up code fragments for multiple process expressions

Unboxed channel framework– enables us to communicate values without memory– initially creates a channel on register– later allocates a channel on heap as necessary

Page 14: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Compilation Overview

HACL program

ML-like program

translation rule

execution flowscheduling pool

execution flowscheduling pool = explicit

= implicit

F { P1, P2, ..., Pn } = a sequential ML-like program

which schedules P1, P2, ..., Pn

a set of schedulable process expressions

Page 15: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Compilation with Static Scheduling (1/2)

=

F P1 P2 P3

code fragment for P1

F P2 P3code fragment for P2

F P3

code fragment for P3

Page 16: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Compilation with Static Scheduling (2/2)

=

F P2P1’r(x)=>

if (r has a value) then (* get the value from r *)

else (* allocate a closure for on heap *)

F P1’ P2

F P2

P1’

code fragment for P1’F P2 code fragment for P2

code fragment for P2

Page 17: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

F { (r <= 5 | r(x)=> P) }F { ($r.(r <= 5 | r(x)=> P)) }

F { r(x)=> P }

Compilation Example$r.(r <= 5 | r(x)=> P)

r = new_channel();

if (r has a value) then x = get_value(r); F { P }else (* allocate a closure P in heap and ... *)

F { }

F { (r <= 5) , (r(x)=> P) }if (r has a waiting process) then (* wake up the process and … *)else put_value(r, 5);

Page 18: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Unboxed Channel Scheme

Unboxed channel = channel allocated on register– No memory access to manipulate an unboxed channel

All channels are created as an unboxed channel

An unboxed channel is elevated to a heap-allocated one as necessary

Page 19: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Exampler = new_channel();if (r has a process) then ...else put_value(r, 5); if (r has a value) then x = get_value(r); F { P } else ...

r = EMPTY_CHANNEL;if (...) { ...} else { r = 5 + VAL_TAG; if (...) { x = r - VAL_TAG; ... } else { ... } ... }

ML-like code Corresponding C code

Channel allocation and communication on a register

Page 20: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

When to allocate a space on heap?

6 8

P1 P2

123

two values are sent

an unboxed channel is duplicated???

Page 21: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Experimental Results (1/2)

HACL is used as an intermediate language of Schematic [Taura et al. 96]

ML-like program is compiled to assembly-like C A native code is generated by GNU C compiler Runtime type checks are omitted SS20 (HyperSparc 150MHz)

Now implementing on a large-scale SMP

Page 22: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Experimental Results (2/2)

0.44 0.46 0.220.81 0.45 0.38

0.01.02.03.04.05.06.07.08.09.0

10.0

Nor

mal

ized

Ela

psed

Tim

eCSchematic (with static scheduling, with unboxed channel)Schematic (w/o static scheduling, with unboxed channel)Schematic (with static scheduling, w/ o unboxed channel)Schematic (w/o static scheduling, w/o unboxed channel)

Page 23: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Related Work (1/2)

Id [Schauser et al. 95], Fleng [Araki et al. 97]– Static scheduling sequentialization≒

– A does not depend on B ⇒ A | B → A ; B

Pict [Turner 96]– All channel communications need memory operation

– A receive (input) expression always allocate a closure whether a value is present or not

Page 24: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Related Work (2/2)

StackThreads [Taura et al. 94, 97]– An original proposal of unboxed channel

Linear channel [Kobayashi et al. 96, Igarashi 97]– Linear channel = channel used only once

– Some communications for linear channel is statically eliminated

CPS [Appel 92]– A compilation framework for sequential language

Page 25: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Conclusion

We proposed a framework compiling process calculus efficiently– Static scheduling

– Unboxed channel

A language based on a process calculus is executed only a few times slower than C

Page 26: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

Surface Languages for Process Calculi

surface language

intermediate language

machine code

concurrent functional language, concurrent OO language, etc...

Schematic [Taura et al. 96]Pict [Turner 96]

process calculusHACL

Pi-calculus

Page 27: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus

A Schedulable Closure and The Scheduling Stack

F { f(r, x), P }schedule f(r,x)first

Can we schedule f and Pstatically ???

scheduling stack ≒ a set of schedulable closures

Difficult. The schedulingpool is still necessary.

P

f(r, x)