Sie sind auf Seite 1von 5

03-05-2014

1
Department of CSE, MIT, Manipal
Run Time Environments
Department of CSE, MIT, Manipal
Introduction
Compiler must cooperate with OS.
Creates and manages the runtime
environment .
Compiler must do the storage allocation
and provide access to variables and data.
Memory management
Stack allocation
Heap management

Department of CSE, MIT, Manipal
Storage organization

Department of CSE, MIT, Manipal
Static and dynamic storage
allocation
Static: Compile time
Dynamic: Runtime allocation
Many compilers use some combination of
following
Stack storage: for local variables, parameters and so
on
Heap storage: Data that may outlive the call to the
procedure that created it
Stack allocation is a valid allocation for
procedures since procedure calls are nested
03-05-2014
2
Department of CSE, MIT, Manipal
Stack allocation of space
Each time procedure is called, activation
record is pushed.
Each time procedure is returned,
activation record is popped.
Department of CSE, MIT, Manipal
Department of CSE, MIT, Manipal
int a[11];
void readArray() { /*reads 9 ints into a[1]-a[9] */
}

int partition(int m, int n) { /*picks a separator value v, and
partitions a[m..n] so that a[m..p-1] are less than v,
a[p]=v and a[p+1,n] are equal to or greater than v.
Returns p. */
}

void quicksort(int m, int n) {
int I;
if (n > m){
i=partition(m,n);
quicksort(m,i-1);
quicksort(i+1,n);
}
}

main() {
readArray();
a[0] =-9999;
a[10]= 9999;
quicksort(1,9);
}
enter main()
enter readArray()
leave readArray()
enter quicksort()
enter partition(1,9)
leave partition(1,9)
enter quicksort(1,3)

leave quicksort(1,3)
enter quicksort(5,9)

leave quicksort(5,9)
leave quicksort(1,9)
leave main()
Department of CSE, MIT, Manipal
Activation Tree
m
r
q(1,9)
p(1,9) q(1,3) q(5,9)
p(1,3) q(1,0) q(2,3)
p(2,3) q(2,1) q(3,3)
p(5,9) q(5,5) q(7,9)
p(7,9) q(7,7) q(9,9)
Suppose that control lies within a particular activiation
Of some procedure, N, of the activation tree. The stack
Corresponds to the ancestors of node N.
03-05-2014
3
Department of CSE, MIT, Manipal
Three cases nested procedure
termination
1. Activation of q terminates normally. P
resumes.
2. Activation of q or some procedure called
by q , aborts. P aborts
3. Activation of q terminates because of
exception which it cannot handle, but P
may handle. P continues to handle it but
If P cannot, it will terminate with q and
exception may be handled by some other
open activation for a procedure
Department of CSE, MIT, Manipal
Possible Activations

Department of CSE, MIT, Manipal
Activation tree

Department of CSE, MIT, Manipal
Activation tree[contd..]
Sequence of Procedure calls preorder
traversal
Sequence of Return calls postorder
traversal
Node N and its ancestors are alive
03-05-2014
4
Department of CSE, MIT, Manipal
Activation Record
Procedure Calls and returns are managed
by control stack.
Each live activation has an activation
record on control stack.
Department of CSE, MIT, Manipal
`

Activation record
Pts to act rec
of caller
Department of CSE, MIT, Manipal

Department of CSE, MIT, Manipal
calling sequence
Procedure calls are implemented by
calling sequence.
Principles
Values communicated beginning of callees
record
Fixed length fields middle
Data whose length is unknown end




03-05-2014
5
Department of CSE, MIT, Manipal

Das könnte Ihnen auch gefallen