0% found this document useful (0 votes)
56 views7 pages

Runtime Environment

CD

Uploaded by

MRCET CSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views7 pages

Runtime Environment

CD

Uploaded by

MRCET CSE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Runtime Environment

Compiler must cooperate with OS and other system software to support


implementation of different abstractions (names, scopes, bindings, data types,
operators, procedures, parameters, flow-of-control) on the target machine.

Compiler does this by Run-Time Environment in which it assumes its target


programs are being executed.

Run-Time Environment deals with

– Layout and allocation of storage


–Access to variable and data
– Linkage between procedures
– Parameter passing
– interface to OS, I/O devices

 At run time, we need a system to map names (in the source program) to
storage on the machine.
 Allocation and deallocation of memory is handled by a run- time support
system typically linked and loaded along with the compiled target code.
 One of the primary responsibilities of the run-time system is to manage
activations of procedures
Procedure Activations
 Each execution of a procedure is called as activation of that procedure.
 An execution of a procedure P starts at the beginning of the procedure
body;
 When a procedure P is completed, it returns control to the point
immediately after the place where P was called.
 Lifetime of an activation of a procedure P is the sequence of steps
between the first and the last steps in execution of P (including the other
procedures called by P).
 If A and B are procedure activations, then their lifetimes are either non-
overlapping or are nested.
 If a procedure is recursive, a new activation can begin before an earlier
activation of the same procedure has ended.

Activation Tree
 A tree that represents the way the control enters and leaves the
activations is known as the activation tree.
 In an activation tree:–
 Each node represents an activation of a procedure.
 The root represents the activation of the main program.
 The node A is a parent of the node B if the control flows from A to B.
 The node A is left to the node B if the lifetime of A occurs before the
lifetime of B.

Activation Tree
Activation Tree

 Control stack is a run time stack which is used to keep track of the live
procedure activations i.e. it is used to find out the procedures whose
execution have not been completed.
 When it is called (activation begins) then the procedure name will push
on to the stack and when it returns (activation ends) then it will popped.
 Activation record is used to manage the information needed by a single
execution of a procedure.
 An activation record is pushed into the stack when a procedure is called
and it is popped when the control returns to the caller function
Activation Record
Activation Record

Creation of Activation Record


 Who allocates an activation record of a procedure?
 – Some part is created by the caller of that procedure before that
procedure is entered
 – Some part of the activation record of a procedure is created by that
procedure itself immediately after that procedure is entered.
 Who de-allocates?
 – Callee de-allocates the part allocated by Callee.
 – Caller de-allocates the part allocated by Caller

Storage Allocation
 Runtime environment manages runtime memory requirements for the
following entities:
 Code:
It is known as the text part of a program that does not change at
runtime. Its memory requirements are known at the compile time.
 Procedures :
Their text part is static but they are called in a random manner. That is
why, stack storage is used to manage procedure calls and activations.
 Variables :
Variables are known at the runtime only, unless they are global or
constant. Heap memory allocation scheme is used for managing
allocation and de allocation of memory for variables in runtime

Storage Allocation Strategies


There are three different storage allocation strategies based on runtime
storage.

They are:

• Static Allocation

• Stack Allocation

• Heap Allocation

Static Allocation
 Storage is allocated at compile time
 Static storage has fixed allocation that does not change during program
execution
 As bindings do not change at runtime, no runtime support is required
 At compile time, compiler can fill the address at which the target code
can find the data it operates on.
 FORTRAN uses the static allocation strategy.
 For each procedure in the program, allocate a space for its activation
record.
 A.R.‘s can be allocated in the static data area.

Limitations
 Size of data objects should be known at compile time.
 Recursion is not supported.
 Data structures cannot be created at runtime.
 Waste lots of space when procedures are inactive.
 No dynamic allocation

Advantages
 No stack manipulation or indirect access to names, i.e., faster in
accessing variables.
 Values are retained from one procedure call to the next if block
structure is not allowed.
 For example: static variables in C

Stack Allocation
 Stack allocation manages the runtime storage as a stack, i.e., control
stack
 Activation records are pushed and popped as activation begins and end
respectively.
 Locals are always bound to fresh storage in each activation, because a
new activation is onto a stack when a call is made.
 Values of locals are deleted as activation ends.
 The data structure can be created dynamically for stack allocation.
 A register (stack pointer or SP) points to top of stack.
 A register (frame pointer or FP) points to start of current A.R

Limitations
 Values of locals cannot be retained once activation ends.
 The memory addressing can be done using pointers and indexed
registers.
 This type of allocation is slower than static allocation

Heap Allocation
 Storage can be allocated and deallocated in any order.
 If the values of non-local variables must be retained even after the
activation record then such a retaining is not possible by stack allocation.
 It is used for retaining of local variables.
 The heap allocation allocates the continuous block of memory when
required for storage of activation records.
 This allocated memory can be deallocated when activation ends.
 Free space can be further reused by heap manager.
 It supports for recursion and data structures can be created at runtime

Limitations
 It takes more time to compute.
 Memory management is more complicated

You might also like