J PPL Unit 2 Lecture 3 Life Time
J PPL Unit 2 Lecture 3 Life Time
LANGUAGES
Dr. D. C. Kiran
Associate Professor
Department of
Computer Science & Engineering
PRINCIPLES OF PROGRAMMING LANGUAGES
Dr. D. C. Kiran
Department of Computer Science and Engineering
PRINCIPLES OF PROGRAMMING LANGUAGES
Topics To Be Covered
• Activation Record
Lifetime
• Period of time when location is allocated to program
Scope
• Region of program text where declaration is visible
– Inner declaration of x hides outer: “hole in scope”
PRINCIPLES OF PROGRAMMING LANGUAGES
Run Time Environment
–Advantages:
efficiency – static constants in Java
efficiency - (direct addressing) and no run-time
allocate/deallocate
history-sensitive support
Disadvantages
• Overhead of allocation and de-allocation
• Subprograms cannot be history sensitive
• Inefficient references (indirect addressing)
PRINCIPLES OF PROGRAMMING LANGUAGES
Life Time of a Variable: Explicit Heap-Dynamic
fact(1)
1
fact(2) fact(2) fact(2)
2
fact(3) fact(3) fact(3) fact(3) fact(3)
6
main() main() main() main() main() main()
else return (3 * factorial else return (2 * factorial else return (1 * factorial (0));
(2)); (1));
PRINCIPLES OF PROGRAMMING LANGUAGES
Run Time Stack: Activation Record
High address
Parameter &
Heap Return value Activation
Record
Control link &
Saved status
Local temps
Low address
PRINCIPLES OF PROGRAMMING LANGUAGES
Run Time Stack: Activation Record
Temporaries temporaries
NIL 1008 sp
return value 1007
c 1006
b 1005
a 1004
ARI of function main
NIL 1003
NIL 1002
NIL 1001
fp return global env 1000
PRINCIPLES OF PROGRAMMING LANGUAGES
Run Time Stack: Call and Return Sequence
• Calling sequence
• Store return address
• Push fp as control link
• Copy sp to fp
• Push arguments
• Reserve space for local variables
• Return sequence
• Copy fp to sp
• Load control link into fp
• Jump to return address
• Change sp
PRINCIPLES OF PROGRAMMING LANGUAGES
Run Time Stack: Call Sequence
PRINCIPLES OF PROGRAMMING LANGUAGES
Run Time Stack: Call Sequence
PRINCIPLES OF PROGRAMMING LANGUAGES
Run Time Stack: Return Sequence
PRINCIPLES OF PROGRAMMING LANGUAGES
Run Time Stack: Return Sequence
NIL 1008 sp
return value 1007
c 1006
b 1005
a 1004
ARI of function main
NIL 1003
NIL 1002
NIL 1001
fp return global env 1000
PRINCIPLES OF PROGRAMMING LANGUAGES
Summary: Take Away
• Classification of Variables
Dr. D. C. Kiran
Department of Computer Science and Engineering
[email protected]
9829935135