Escolar Documentos
Profissional Documentos
Cultura Documentos
Activation Records
Modern Compiler Implementation in Java
Appel
Chapter 6
CMSC 432
Shon Vick
UMBC
Ex:
function f(x:int) : int =
let var y := x + x
in if y < 10 then f(y)
else y 1
end
UMBC
Higher-order Function
In Pseudo-C
int (*)() f(int x) {
int g(int y) {return
x+y;}
return g;
}
nested function
+
higher-order function
-> not in stack-mode
Pascal
-> no higher function
runtime stack
Local varialbes
Parameters
Return address
Temporaries
Register save area
incoming
args
frame
pointer
arg n
.
.
arg 1
Static link
prev
frame
local
variables
return address
temps
Push/pop frames
Access variables in deeper
frames -> nonlocal
variables
Stack frame
higher addresses
Stack Frames
saved
registers
outgoing
args
current
frame
arg n
.
.
arg 1
static link
stack
pointer
next
frame
4
UMBC
Frame Pointer
frame
pointer
stack
pointer
frame
pointer
stack
pointer
arg n
.
.
arg 1
: frame size
either fixed
or varies =>
Can be
determined
very late
5
5
UMBC
Registers
UMBC
Parameter Passing
function
Register windows
UMBC
frame
pointer
arg n
.
.
arg k+1
arg k
.
.
arg 1
register
save
area
UMBC
Return Address
g calls f : f returns
Can be saved
On stack
In special register
In special memory location
UMBC
Frame-resident Variables
10
UMBC
Escaped Variable
11
prettyprint
output
write
--output
show
n
ident
i,s
--output
--n
-- i,s
Static Links
Variable References
Static Links
Display
Lambda lifting
(passing all nonlocals
as parameters)
Procedure Calls
prettyprint
show
show
,
,
ident
UMBC
Lambda lifting
fptr mies(int i) {
int aap()
{return i+7;}
fptr mies(int i) {
int *_i = malloc(sizeof(i));
*_i = i;
return aap;
}
return closure(aap,_i);
}
nested
lifted
13
UMBC
Frames in MiniJava
Package Frame
PackageTemp
Package Util
BoolList.java
T(Mips/Sparcs)Frame.java
UMBC
Package Frame
15
UMBC
Frame.java
//
//
}
16
UMBC
For T machine
package T;
class Frame extends Frame.Frame {
/* real definitions of Frame */
.
}
UMBC
18
UMBC
Class Access
UMBC
UMBC
Representation of Frame
Descriptions
21
Local Variables
UMBC
allocLocal(bool)
Allocating Local
Storage in frame
with the Same
Name
function f() =
allocLocal()
allocLocal()
frame
pointer
v1 might
use same
space
stack
pointer
v1
v2
v3
let var v1 := 6
in
print(v1);
let var v2 := 7
in print(v2);
end
print(v1);
allocLocal()
let var v3 := 8
in print(v3);
end
print(v1);
end
UMBC
Escape Variables
24
UMBC
Calculating Escapes
25
UMBC
UMBC
UMBC
References
http://www.cs.rutgers.edu/~ryder/41
5/lectures/runtimeSyst3.pdf
http://pds.twi.tudelft.nl/~koen/compi
lerbouw/slides/week11.ppt
Modern Compiler Implementation in Java,
Appel , Cambridge University Press, Chapter 6
28