Runtime System
Runtime System
4
Activation Tree
Sort
r q(1,9)
5
Control stack
• Flow of control in program corresponds to
depth first traversal of activation tree
• Name binding
environment state
name storage value
7
Storage organization
• The runtime storage
might be subdivided into code
8
Activation Record
• temporaries: used in expression
evaluation
Temporaries
• local data: field for local data local data
• Constraints
Sort Sort
readarray readarray
Sort Sort
qsort(1,9)
readarray qsort(1,9)
Sort Sort
readarray qsort(1,9) qsort(1,9)
array
A
array Long length
B data
array
C
activation of
Q
arrays of Q
17
Dangling references
Referring to locations which have been deallocated
main()
{int *p;
p = dangle(); /* dangling reference */
}
int *dangle();
{
int i=23;
return &i;
}
18
Heap Allocation
• Stack allocation cannot be used if:
– The values of the local variables must be retained when
an activation ends
– A called activation outlives the caller
swap(i,a[i])
temp = i
i = a[i]
a[i] = temp 28