0% found this document useful (0 votes)
46 views27 pages

Run - Time Environment

This document discusses run-time environments and storage organization. It covers: - Activation records which contain information for procedure calls and are managed by a call stack. - Different storage allocation strategies including static allocation at compile time, stack allocation which manages storage as a stack, and heap allocation which dynamically allocates and deallocates memory as needed. - How the compiler allocates storage and provides access to variables. Memory is subdivided and allocation can occur statically, via the stack, or dynamically from the heap.

Uploaded by

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

Run - Time Environment

This document discusses run-time environments and storage organization. It covers: - Activation records which contain information for procedure calls and are managed by a call stack. - Different storage allocation strategies including static allocation at compile time, stack allocation which manages storage as a stack, and heap allocation which dynamically allocates and deallocates memory as needed. - How the compiler allocates storage and provides access to variables. Memory is subdivided and allocation can occur statically, via the stack, or dynamically from the heap.

Uploaded by

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

Module 5

Run-Time Environments
Outline
Source Language Issues
Procedures
Activation Trees(5marks)
Control Stacks
The scope of declaration
Bindings of names
Storage organization( 10 marks)
Subdivision of run time Memory
Activation records( 7 marks)

-Storage Allocation Strategies(10 marks)


- Static allocation
-Stack Allocation
- Heap allocation
-Parameter passing mechanisms(10 mark)-
Assignment
Compiler must do the storage
allocation and provide access to
variables and data
Memory management
Stack allocation
Heap management
Garbage collection
Storage Organization
Static vs. Dynamic 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
Activation Trees
A program is a sequence of instructions
combined into a number of procedures.
 Instructions in a procedure are executed
sequentially.
 A procedure has a start and an end
delimiter and everything inside it is called
the body of the procedure.
Procedure identifier and the sequence of
finite instructions inside it make up the
body of the procedure.
Activation Trees: example
The execution of a procedure is called its
activation.
 An activation record contains all the
necessary information required to call a
procedure.
 An activation record may contain the
following units (depending upon the source
language used).
Temporaries : stores temporary and intermediate
values of an expression.
Local Data :stores local data of the called
procedure.
Machine Status: stores machine status such as
Registers, Program Counter etc., before the
procedure is called.
Control Link :stores the address of activation
record of the caller procedure.
Access Link: stores the information of data which is
Activation records
Procedure calls and returns are usaully managed
by a run-time stack called the control stack.
Each live activation has an activation record
(sometimes called a frame)
The root of activation tree is at the bottom of the
stack
The current execution path specifies the content
of the stack with the last activation has record in
the top of the stack.
A General Activation Record
Activation Record
Temporary values
Local data
A saved machine status
An “access link”
A control link
Space for the return value of the called function
The actual parameters used by the calling
procedure
Designing Calling Sequences
Values communicated between caller and callee
are generally placed at the beginning of callee’s
activation record
Fixed-length items: are generally placed at the
middle
Items whose size may not be known early enough:
are placed at the end of activation record
We must locate the top-of-stack pointer
judiciously: a common approach is to have it point
to the end of fixed length fields.
Division of tasks between caller and callee
calling sequence
The caller evaluates the actual parameters
The caller stores a return address and the
old value of top-sp into the callee's
activation record.
The callee saves the register values and
other status information.
The callee initializes its local data and
begins execution.
corresponding return sequence
The callee places the return value next to the
parameters
Using information in the machine-status field, the
callee restores top-sp and other registers, and then
branches to the return address that the caller placed in
the status field.
Although top-sp has been decremented, the caller
knows where the return value is, relative to the current
value of top-sp; the caller therefore may use that value.
Access to dynamically allocated arrays
Memory Manager
Two basic functions:
Allocation
Deallocation
Properties of memory managers:
Space efficiency
Program efficiency
Low overhead
Typical Memory Hierarchy Configurations
Storage Allocation Strategies
1. Static allocation – allocates storage at
compile time
2. Stack allocation - manages run time
storage as stack
3. Heap allocation – allocates and de-
allocates storage area as needed
at runtime.
Static allocation
 In static allocation, names are bound to
storage locations
 This property allows values of local names
to be retained across the complete program
At the compile time compiler determines
how much storage should be allocated for
each object.
At the compile time, compiler determines
the following
1 . Where the activation records go, relative
to target code
2 . Where the addresses should be filled in
the records
3 . The address for the procedure calls
Limitations
Size & position of data objects must be
known at compile time.
Recursive procedures are restricted.
Data objects cannot be created
dynamically.
E.g.: Fortran
STACK ALLOCATION
Storage is organized as a stack
Activation records are pushed and
popped as activation begin and end
Storage for locals in each call of a
procedure is contained in
the activation record for that call
 
STACK ALLOCATION
 The values of locals are deleted when
the activation ends
A register can be used to mark the top
of stack.
At run time an activation record can
be allocated and de-allocated by
incrementing and decrementing register.
Heap Allocation
Stack is used for static memory allocation and Heap for
dynamic memory allocation

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy