SlideShare a Scribd company logo
UNIT IV RUN TIME
ENVIRONMENT
Run-time Environment- Source Language
Issues-Storage Organization-Storage
Allocation-Parameter Passing-Symbol Tables-
Dynamic Storage Allocation
Ms.S.Kalavathi,ASP/CSE
Run time environment
Runtime environment is a state of the target machine,
which may include software libraries, environment
variables, etc., to provide services to the processes
running in the system.
•the layout and allocation of storage locations for the objects
named in the source program,
•the mechanisms used by the target program to access variables,
the linkages between procedures,
•the mechanisms for passing parameters, and the interfaces to
the operating system, input/output devices, and other programs.
•Facilitate the process communication between the process and
the runtime environment Ms.S.Kalavathi,ASP/CSE
Run time environment tasks
1. Memory management when program is running.
• Allocating and deallocating memory locations on the
fly.
2. Passing parameters to functions.
3. Interfacing between program and computer resources.
4. Manages runtime memory requirements such as
1. Code
2. Procedures
3. Variables
Ms.S.Kalavathi,ASP/CSE
Source language issues
1. Scope and lifetime of variables
1. Local and global variables
2. Static and dynamic variables
2. Procedures
1. Based on the types of parameter formal / actual
3. Activation tree
1. Corresponds to procedure call of a program
2. Whenever a procedure is called, an activation tree is created
to hold the local variables of the called procedure.
Ms.S.Kalavathi,ASP/CSE
Memory management
Compiler must do the storage allocation and provide access
to variables and data
Memory management
Stack allocation
Heap management
Garbage collection
Ms.S.Kalavathi,ASP/CSE
Storage organization
• The management and organization of this logical address space is
shared between the compiler, operating system, and target
machine.
• The operating system maps the logical addresses into physical
addresses, which are usually spread throughout memory.
• The run-time representation of an object program in the
logical address space consists of data and program
Ms.S.Kalavathi,ASP/CSE
Run time environment -storage
allocation
Ms.S.Kalavathi,ASP/CSE
Storage organization
Ms.S.Kalavathi,ASP/CSE
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
Ms.S.Kalavathi,ASP/CSE
– Storage Allocation Strategies
•static allocation lays out storage for all data objects at
compile time.
–Restrictions:
»size of object must be known and alignment requirements
must be known at compile time.
»No recursion.
»No dynamic data structure
•Stack allocation manages the run time storage as a stack
–The activation record is pushed on as a function is entered.
–The activation record is popped off as a function exits.
–Restrictions:
»values of locals cannot be retained when an activation ends.
»A called activation cannot outlive a caller.
Ms.S.Kalavathi,ASP/CSE
Ms.S.Kalavathi,ASP/CSE
Ms.S.Kalavathi,ASP/CSE
Ms.S.Kalavathi,ASP/CSE
Ms.S.Kalavathi,ASP/CSE
Static allocation – activation record
Activations of a procedure can be represented as a tree called activation tree.
1.Each node represents activation of a program.
2.Root represents activation of main program.
3.Node for procedure a is parent of node for procedure b if and only if control flows
from a to b.
4.Node for a is to the left of node for b if and only of lifetime of a occurs before lifetime
of b.
5.Lifetime of activation of a procedure is the sequence of steps between first and last
steps in procedure body, including time spent on executing other procedures called by
the procedure.
Ms.S.Kalavathi,ASP/CSE
Stack allocation – activation tree
Stack allocation would not be feasible if procedure calls, or
activations of procedures, did not nest in time.
Ms.S.Kalavathi,ASP/CSE
Activation tree
Ms.S.Kalavathi,ASP/CSE
Activation record
• Procedure calls and returns are usually managed by a run-
time stack called the control stack.
• Each live activation has an activation record on the control
stack, with the root of the activation tree at the bottom, and
the entire sequence of activation records on the stack
corresponding to the path in the activation tree to the
activation where control currently resides.
• The latter activation has its record at the top of the stack.
Ms.S.Kalavathi,ASP/CSE
Activation record
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 outside the local scope.
Actual
Parameters
Stores actual parameters, i.e., parameters which are used to
send input to the called procedure.
Return Value Stores return values.
Ms.S.Kalavathi,ASP/CSE
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
Ms.S.Kalavathi,ASP/CSE
Heap management
The heap is the portion of the store that is used for data that
lives indefinitely, or until the program explicitly deletes it.
The memory manager keeps track of all the free space in
heap storage at all times.
It performs two basic functions:
Allocation
Deallocation
•Heap allocation -- allocates and deallocates stroage as needed at runtime from a
data area known as heap.
–Most flexible: no longer requires the activation of procedures to be
LIFO.
–Most inefficient: need true dynamic memory management.
Ms.S.Kalavathi,ASP/CSE
Division of tasks between caller and callee
Ms.S.Kalavathi,ASP/CSE
• A possible calling sequence:
– The caller evaluates actuals and push the actuals on the stack
– The caller saves return address(pc) the old value of sp into the
stack
– The caller increments the sp
– The callee saves registers and other status information
– The callee initializes its local variables and begin execution.
• A possible return sequence:
– The callee places a return value next to the activation record of the
caller.
– The callee restores other registers and sp and return (jump to pc).
– The caller copies the return value to its activation record.
• In today’s processors, there is usually special support for
efficiently realizing calling/return sequence: executing
procedures is too important!!
Ms.S.Kalavathi,ASP/CSE
• Access to nonlocal variables.
– Nonlocal variables in C (without nested procedures):
•Still have nested scopes (blocks).
•Solution:
–All data declared outside procedures are static.
–Other names must be at the activation record at the top of
the stack, can be accessed from sp.
»Treat a block as a parameter-less procedure
»Allocates space for all blocks in a procedure.
Ms.S.Kalavathi,ASP/CSE
Access to dynamically allocated arrays
Ms.S.Kalavathi,ASP/CSE
• Access to nonlocal variables.
– Nonlocal variables in PASCAL (with nested
procedures):
•the scheme for C will break.
Ms.S.Kalavathi,ASP/CSE
• Access to nonlocal variables.
– Nonlocal variables in PASCAL (with nested
procedures):
•The scheme for C will break (static for all non-
locals).
•Access links
–If p is nested immediately within q in the source text, then
the access link in an activation record for p points to the
access link in the record for the most recent activation of q.
–A procedure p at nesting depth n_p accesses a nonlocal a at
nesting depth n_a: (1) following n_p – n_a links and (2)
using the relative offset in the activation record.
Ms.S.Kalavathi,ASP/CSE
Ms.S.Kalavathi,ASP/CSE
Ms.S.Kalavathi,ASP/CSE
• Display:
•An alternative to access link ( a faster method to
access nonlocals ).
•Using an array d of pointers to activation records, the
array is called a display.
–Referencing nonlocal variables always requires only two
memory references.
•Suppose control is in a procedure p at nesting depth j,
then the first j-1 elements of the display point to the
most recent activation of the procedures that lexically
enclose procedure p, and d[j] points to the activation
of p.
Ms.S.Kalavathi,ASP/CSE
• Setting up the display:
•When a new activation record for a procedure at
nesting depth k:
–save the value of d[k] in the new activation record
–set d[k] to point to the new activation record.
Ms.S.Kalavathi,ASP/CSE
– Parameter passing
•The method to associate actual parameters with
formal parameters.
•The parameter passing method will effect the code
generated.
•Call-by-value:
–The actual parameters are evaluated and their r-values are
passed to the called procedure.
–Implementation:
»a formal parameter is treated like a local name, so the
storage for the formals is in the activation record of the
called procedure.
»The caller evaluates the actual parameters and places
their r-values in the storage for the formals.
Ms.S.Kalavathi,ASP/CSE
– Call-by-reference:
•also called call-by address or call-by-location.
•The caller passes to the called procedure a pointer to
the storage address of each actual parameter.
–Actuall parameter must have an address -- only variables
make sense, an expression will not (location of the
temporary that holds the result of the expression will be
passed).
– Copy-restore:
•A hybrid between call-by-value and call-by-
reference.
–The actual parameters are evaluated and its r-values are
passed to the called procedure as in call-by-value.
–When the control returns, the r-value of the formal
parameters are copied back into the l-value of the actuals.
Ms.S.Kalavathi,ASP/CSE
Example 1: illustrates call by value, value-result, reference
begin
integer n;
procedure p(k: integer);
begin
n := n+1;
k := k+4;
print(n);
end;
n := 0;
p(n);
print(n);
end;
Note that when using call by reference, n and k are
aliased.
Output:
call by value: 1 1
call by value-result: 1 4
call by reference: 5 5
Ms.S.Kalavathi,ASP/CSE

More Related Content

PPT
Runtimeenvironment
PPTX
Activation Racords and Run-time Environments _11_10_2024.pptx
PDF
Run time storage
PPTX
Lecture 14 run time environment
PDF
Intermediate code optimization Unit-4.pdf
PPTX
Operating Systems Process Management.pptx
PPTX
Compiler Design Unit 4
PPTX
Lecture 15 run timeenvironment_2
Runtimeenvironment
Activation Racords and Run-time Environments _11_10_2024.pptx
Run time storage
Lecture 14 run time environment
Intermediate code optimization Unit-4.pdf
Operating Systems Process Management.pptx
Compiler Design Unit 4
Lecture 15 run timeenvironment_2

Similar to U4-p2 Run TIme Environment SOurce language.ppt (20)

PPTX
10 implementing subprograms
PPTX
Compiler Design_Run time environments.pptx
PPT
Chap3.ppt
PPTX
Run time administration
PPTX
The End of a Myth: Ultra-Scalable Transactional Management
PDF
Structured Streaming Use-Cases at Apple
PPTX
Apache Apex Fault Tolerance and Processing Semantics
PDF
09 implementing+subprograms
PPTX
February 2017 HUG: Exactly-once end-to-end processing with Apache Apex
PDF
TAU Performance tool using OpenPOWER
PPT
Part 1 - PROCESS CONCEPTS
PPT
Test automation process _ QTP
PPT
Test automation process
PPT
The process states
PPT
Processes this has stuff about processes and deifntions.ppt
PPTX
Processes in Operating System
PPT
Os4 2
PDF
Concurrency
PDF
Flink Forward SF 2017: Joe Olson - Using Flink and Queryable State to Buffer ...
PPT
Intro to tsql
10 implementing subprograms
Compiler Design_Run time environments.pptx
Chap3.ppt
Run time administration
The End of a Myth: Ultra-Scalable Transactional Management
Structured Streaming Use-Cases at Apple
Apache Apex Fault Tolerance and Processing Semantics
09 implementing+subprograms
February 2017 HUG: Exactly-once end-to-end processing with Apache Apex
TAU Performance tool using OpenPOWER
Part 1 - PROCESS CONCEPTS
Test automation process _ QTP
Test automation process
The process states
Processes this has stuff about processes and deifntions.ppt
Processes in Operating System
Os4 2
Concurrency
Flink Forward SF 2017: Joe Olson - Using Flink and Queryable State to Buffer ...
Intro to tsql
Ad

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Institutional Correction lecture only . . .
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Classroom Observation Tools for Teachers
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Lesson notes of climatology university.
Insiders guide to clinical Medicine.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
TR - Agricultural Crops Production NC III.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
PPH.pptx obstetrics and gynecology in nursing
GDM (1) (1).pptx small presentation for students
Institutional Correction lecture only . . .
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
RMMM.pdf make it easy to upload and study
Module 4: Burden of Disease Tutorial Slides S2 2025
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Supply Chain Operations Speaking Notes -ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
Classroom Observation Tools for Teachers
Sports Quiz easy sports quiz sports quiz
Computing-Curriculum for Schools in Ghana
Lesson notes of climatology university.
Ad

U4-p2 Run TIme Environment SOurce language.ppt

  • 1. UNIT IV RUN TIME ENVIRONMENT Run-time Environment- Source Language Issues-Storage Organization-Storage Allocation-Parameter Passing-Symbol Tables- Dynamic Storage Allocation Ms.S.Kalavathi,ASP/CSE
  • 2. Run time environment Runtime environment is a state of the target machine, which may include software libraries, environment variables, etc., to provide services to the processes running in the system. •the layout and allocation of storage locations for the objects named in the source program, •the mechanisms used by the target program to access variables, the linkages between procedures, •the mechanisms for passing parameters, and the interfaces to the operating system, input/output devices, and other programs. •Facilitate the process communication between the process and the runtime environment Ms.S.Kalavathi,ASP/CSE
  • 3. Run time environment tasks 1. Memory management when program is running. • Allocating and deallocating memory locations on the fly. 2. Passing parameters to functions. 3. Interfacing between program and computer resources. 4. Manages runtime memory requirements such as 1. Code 2. Procedures 3. Variables Ms.S.Kalavathi,ASP/CSE
  • 4. Source language issues 1. Scope and lifetime of variables 1. Local and global variables 2. Static and dynamic variables 2. Procedures 1. Based on the types of parameter formal / actual 3. Activation tree 1. Corresponds to procedure call of a program 2. Whenever a procedure is called, an activation tree is created to hold the local variables of the called procedure. Ms.S.Kalavathi,ASP/CSE
  • 5. Memory management Compiler must do the storage allocation and provide access to variables and data Memory management Stack allocation Heap management Garbage collection Ms.S.Kalavathi,ASP/CSE
  • 6. Storage organization • The management and organization of this logical address space is shared between the compiler, operating system, and target machine. • The operating system maps the logical addresses into physical addresses, which are usually spread throughout memory. • The run-time representation of an object program in the logical address space consists of data and program Ms.S.Kalavathi,ASP/CSE
  • 7. Run time environment -storage allocation Ms.S.Kalavathi,ASP/CSE
  • 9. 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 Ms.S.Kalavathi,ASP/CSE
  • 10. – Storage Allocation Strategies •static allocation lays out storage for all data objects at compile time. –Restrictions: »size of object must be known and alignment requirements must be known at compile time. »No recursion. »No dynamic data structure •Stack allocation manages the run time storage as a stack –The activation record is pushed on as a function is entered. –The activation record is popped off as a function exits. –Restrictions: »values of locals cannot be retained when an activation ends. »A called activation cannot outlive a caller. Ms.S.Kalavathi,ASP/CSE
  • 15. Static allocation – activation record Activations of a procedure can be represented as a tree called activation tree. 1.Each node represents activation of a program. 2.Root represents activation of main program. 3.Node for procedure a is parent of node for procedure b if and only if control flows from a to b. 4.Node for a is to the left of node for b if and only of lifetime of a occurs before lifetime of b. 5.Lifetime of activation of a procedure is the sequence of steps between first and last steps in procedure body, including time spent on executing other procedures called by the procedure. Ms.S.Kalavathi,ASP/CSE
  • 16. Stack allocation – activation tree Stack allocation would not be feasible if procedure calls, or activations of procedures, did not nest in time. Ms.S.Kalavathi,ASP/CSE
  • 18. Activation record • Procedure calls and returns are usually managed by a run- time stack called the control stack. • Each live activation has an activation record on the control stack, with the root of the activation tree at the bottom, and the entire sequence of activation records on the stack corresponding to the path in the activation tree to the activation where control currently resides. • The latter activation has its record at the top of the stack. Ms.S.Kalavathi,ASP/CSE
  • 19. Activation record 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 outside the local scope. Actual Parameters Stores actual parameters, i.e., parameters which are used to send input to the called procedure. Return Value Stores return values. Ms.S.Kalavathi,ASP/CSE
  • 20. 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 Ms.S.Kalavathi,ASP/CSE
  • 21. Heap management The heap is the portion of the store that is used for data that lives indefinitely, or until the program explicitly deletes it. The memory manager keeps track of all the free space in heap storage at all times. It performs two basic functions: Allocation Deallocation •Heap allocation -- allocates and deallocates stroage as needed at runtime from a data area known as heap. –Most flexible: no longer requires the activation of procedures to be LIFO. –Most inefficient: need true dynamic memory management. Ms.S.Kalavathi,ASP/CSE
  • 22. Division of tasks between caller and callee Ms.S.Kalavathi,ASP/CSE
  • 23. • A possible calling sequence: – The caller evaluates actuals and push the actuals on the stack – The caller saves return address(pc) the old value of sp into the stack – The caller increments the sp – The callee saves registers and other status information – The callee initializes its local variables and begin execution. • A possible return sequence: – The callee places a return value next to the activation record of the caller. – The callee restores other registers and sp and return (jump to pc). – The caller copies the return value to its activation record. • In today’s processors, there is usually special support for efficiently realizing calling/return sequence: executing procedures is too important!! Ms.S.Kalavathi,ASP/CSE
  • 24. • Access to nonlocal variables. – Nonlocal variables in C (without nested procedures): •Still have nested scopes (blocks). •Solution: –All data declared outside procedures are static. –Other names must be at the activation record at the top of the stack, can be accessed from sp. »Treat a block as a parameter-less procedure »Allocates space for all blocks in a procedure. Ms.S.Kalavathi,ASP/CSE
  • 25. Access to dynamically allocated arrays Ms.S.Kalavathi,ASP/CSE
  • 26. • Access to nonlocal variables. – Nonlocal variables in PASCAL (with nested procedures): •the scheme for C will break. Ms.S.Kalavathi,ASP/CSE
  • 27. • Access to nonlocal variables. – Nonlocal variables in PASCAL (with nested procedures): •The scheme for C will break (static for all non- locals). •Access links –If p is nested immediately within q in the source text, then the access link in an activation record for p points to the access link in the record for the most recent activation of q. –A procedure p at nesting depth n_p accesses a nonlocal a at nesting depth n_a: (1) following n_p – n_a links and (2) using the relative offset in the activation record. Ms.S.Kalavathi,ASP/CSE
  • 30. • Display: •An alternative to access link ( a faster method to access nonlocals ). •Using an array d of pointers to activation records, the array is called a display. –Referencing nonlocal variables always requires only two memory references. •Suppose control is in a procedure p at nesting depth j, then the first j-1 elements of the display point to the most recent activation of the procedures that lexically enclose procedure p, and d[j] points to the activation of p. Ms.S.Kalavathi,ASP/CSE
  • 31. • Setting up the display: •When a new activation record for a procedure at nesting depth k: –save the value of d[k] in the new activation record –set d[k] to point to the new activation record. Ms.S.Kalavathi,ASP/CSE
  • 32. – Parameter passing •The method to associate actual parameters with formal parameters. •The parameter passing method will effect the code generated. •Call-by-value: –The actual parameters are evaluated and their r-values are passed to the called procedure. –Implementation: »a formal parameter is treated like a local name, so the storage for the formals is in the activation record of the called procedure. »The caller evaluates the actual parameters and places their r-values in the storage for the formals. Ms.S.Kalavathi,ASP/CSE
  • 33. – Call-by-reference: •also called call-by address or call-by-location. •The caller passes to the called procedure a pointer to the storage address of each actual parameter. –Actuall parameter must have an address -- only variables make sense, an expression will not (location of the temporary that holds the result of the expression will be passed). – Copy-restore: •A hybrid between call-by-value and call-by- reference. –The actual parameters are evaluated and its r-values are passed to the called procedure as in call-by-value. –When the control returns, the r-value of the formal parameters are copied back into the l-value of the actuals. Ms.S.Kalavathi,ASP/CSE
  • 34. Example 1: illustrates call by value, value-result, reference begin integer n; procedure p(k: integer); begin n := n+1; k := k+4; print(n); end; n := 0; p(n); print(n); end; Note that when using call by reference, n and k are aliased. Output: call by value: 1 1 call by value-result: 1 4 call by reference: 5 5 Ms.S.Kalavathi,ASP/CSE