an efficient compilation framework for languages based on a concurrent process calculus
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 PresentationTRANSCRIPT
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
implementation is difficultanalysis is not general
Compiling Programming Languages
machine code
surface languagemany primitives
implementation becomes easyanalysis becomes general
several essential primitives
intermediate language
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
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
Goal
Efficient implementation of a process calculus
ML-like code
Schematic code
HACL code
…..
focus of our research
straightforward translation
traditional techniques
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
Contribution
A framework for compiling process calculus efficiently
Optimization techniques applicable for software multithreading
Overview of This Presentation
Target language HACL A basic execution Our enhanced execution
– To reduce scheduling overhead
– To reduce communication overhead Experimental results
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
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
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
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
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
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
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
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
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);
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
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
When to allocate a space on heap?
6 8
P1 P2
123
two values are sent
an unboxed channel is duplicated???
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
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)
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
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
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
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
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)