Title: An Efficient Compilation Framework for Languages Based on a Concurrent Process Calculus
1An 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
2Compiling Programming Languages
implementation is difficult analysis is not
general
3Intermediate 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
4Concurrent Process Calculus
- Key component of calculation
- Asynchronous process
- Communication channel
- Advantages
- Clear syntax and clear semantics
- Many theoretical results for optimization
P
3
P
P
C
3
P
P
5Goal
- Efficient implementation of a process calculus
Schematic code
HACL code
ML-like code
..
6Motivation
- Process calculus has some overheads which are not
- in sequential languages
- Dynamic process scheduling
- Channel communication
7Contribution
- A framework for compiling process calculus
efficiently - Optimization techniques applicable for software
multithreading
8Overview of This Presentation
- Target language HACL
- A basic execution
- Our enhanced execution
- To reduce scheduling overhead
- To reduce communication overhead
- Experimental results
9Target Language HACL
process definition
x0 (x1, , xn) P
process expression
parallel execution
P
P1 P2
channel creation
x. P
receive from e
e(x)gtP
send e2 to e1
e1 lt e2
process instantiation
e0 (e1, , en)
if e then P1 else P2
conditional
10Basic Execution Model (1/2)- process scheduling -
P1 P2 dynamic process creation
schedulable process
P2
P1
P
P2
P
P
scheduling pool
11Basic Execution Model (2/2)- channel -
channel ? pointer to memory space
r
value queue
r(x)gtP
r(y)gtQ
rlt12
rlt8
12
Q
rlt12
process queue
12 / x P
r(x)gtP
r(y)gtQ
8 / y Q
rlt8
12Inefficiencies of Basic Model
- Scheduling overhead
- Scheduling pool is manipulated every time
a process is created - Communication overhead
- Channel communication is always performed through
memory
13Our 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
14Compilation Overview
execution flow scheduling pool
implicit
HACL program
translation rule
a set of schedulable process expressions
F P1, P2, ..., Pn a sequential ML-like
program which schedules P1, P2, ..., Pn
execution flow scheduling pool
ML-like program
explicit
15Compilation with Static Scheduling (1/2)
code fragment for P3
16Compilation with Static Scheduling (2/2)
code fragment for P2
code fragment for P2
17Compilation Example
r.(r lt 5 r(x)gt P)
F (r.(r lt 5 r(x)gt P))
r new_channel()
if (r has a waiting process) then ( wake
up the process and ) else put_value(r, 5)
F (r lt 5 r(x)gt P)
F (r lt 5) , (r(x)gt P)
F r(x)gt P
if (r has a value) then x get_value(r)
F P else ( allocate a closure P in
heap and ... ) F
18Unboxed 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
19Example
r EMPTY_CHANNEL if (...) ... else r
5 VAL_TAG if (...) x r - VAL_TAG
... else ... ...
r 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 ...
ML-like code
Corresponding C code
Channel allocation and communication on a register
20When to allocate a space on heap?
two values are sent
an unboxed channel is duplicated
???
P1
P2
21Experimental 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
22Experimental Results (2/2)
23Related 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
24Related 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
25Conclusion
- 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
26Surface Languages for Process Calculi
surface language
intermediate language
machine code
27A Schedulable Closure and The Scheduling Stack
F f(r, x), P
f(r, x)
P