RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 11 Memory Management C makes it easy to shoot.
Advertisements

Programming Languages and Paradigms
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
Chapter 10 Storage Management Implementation details beyond programmer’s control Storage/CPU time trade-off Binding times to storage.
Run-Time Storage Organization
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Run time vs. Compile time
Catriel Beeri Pls/Winter 2004/5 environment 68  Some details of implementation As part of / extension of type-checking: Each declaration d(x) associated.
Semantics of Calls and Returns
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Chapter 9: Subprogram Control
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
Name Binding and Object Lifetimes Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Concepts Lecture.
Runtime Environments What is in the memory? Runtime Environment2 Outline Memory organization during program execution Static runtime environments.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Runtime Environments Compiler Construction Chapter 7.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Basic Semantics Associating meaning with language entities.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
COMP3190: Principle of Programming Languages
Chap 9 Run-time Storage Consider the C program : static int x; int abc(int y) { float z; static int w;  abc(z);  malloc(20) } main {  abc(3)
CSC 8505 Compiler Construction Runtime Environments.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms
Subprograms - implementation. Calling a subprogram  transferring control to a subprogram: save conditions in calling program pass parameters allocate.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
ISBN Chapter 10 Implementing Subprograms.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Implementing Subprograms
Storage Allocation Mechanisms
Chapter 10 : Implementing Subprograms
Implementing Subprograms
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
Implementing Subprograms
CS 153: Concepts of Compiler Design November 28 Class Meeting
The Procedure Abstraction Part IV: Allocating Storage & Establishing Addressability Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights.
Implementing Subprograms
Implementing Subprograms
Memory Allocation CS 217.
Implementing Subprograms
PZ09A - Activation records
Topic 3-b Run-Time Environment
Binding Times Binding is an association between two things Examples:
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
UNIT V Run Time Environments.
Languages and Compilers (SProg og Oversættere)
Programming Languages
Name Binding and Object Lifetimes
Run Time Environments 薛智文
Runtime Environments What is in the memory?.
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Run-time environments
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Implementing Subprograms
CMPE 152: Compiler Design May 2 Class Meeting
Presentation transcript:

RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University Taipei, TAIWAN

Program layout (1/2) typical program layout each block can be allocated to a “segment” under segmented memory system operand stack is required for some computer; Its size can be determined at compile-time highest address heap space stack space have to check collision dynamic static data literal pool program code for library and separately compiled modules static added by linker/loader static data literal pool read only program code read only reserved locations eg. used by O.S lowest address

Program layout (2/2) for load-and-go compiler highest address static data and literal pool heap space stack space generated iteratively program code library modules reserved locations lowest address

Static allocation space is allocated in fixed location for the life-time of a program applicable only when the number and size of data objects is known at compile-time suitable for global variables literals (or put them on a separate “literal pool” ) the only choice for early language (e.g. without recursion) preferable to address a data object as (DataArea, Offset) and binding DataArea at link-time

Heap allocation space is allocated and freed at any time and in any order suitable for dynamic memory allocation/deallocation allocation -- in demand best-fit first-fit circular-first-fit QUIZ: comparison deallocation no deallocation (work for implementations with a large virtual memory) explicit deallocation implicit deallocation single reference reference count mark-and-sweep garbage collection [ + compaction] free-space representation -- bit map, linked list

Stack allocation (1/2) suitable for recursive call activation record (AR) -- data space required for a call push / pop, when “call” / “return” example -- procedure p(a:integer) is b: real; c: array (1..10) of real; d,e : array (1..N) of integer; begin b := c(a) * 2.51; end; 2.51 is stored in literal pool dope vector -- fixed size descriptor for dynamic array; containing size and bounds of array (determined at run-time) space for e determined at run-time space for d pointer to e pointer to d dope vector determined at compile-time c b a control information register Offset = 0

Stack allocation (2/2) when too many recursive calls Þ too many AR Þ too many registers solutions: display registers & static and dynamic chains QUIZ: coroutine? QUIZ: variable declaration within block?

Display registers (1/2) observation (by scoping rules) --at most one active scope for one static nesting level at any time example -- active scopes (display) of P1 R1 Q1 Q2 S1 S2 R2 P2 P3 Q3 R3 P() int a Q() int b R() int c S() int d P;a,Q,R;b,S;d P;a,Q,R;b,S P;a,Q,R;c P;a,Q,R program runtime stack R3: c 2 1 Q3: b, S 2 1 P3: a, Q, R 1 P2: a, Q, R 1 R2: c 2 1 S2: d 3 2 1 S1: d 3 2 1 Q2: b, S 2 1 Q1: b, S 2 1 R1: c 2 1 1 P1: a, Q, R

Display registers (2/2) strategy -- allocating one display register for one static nesting level have to be modified when routine call / return QUIZ: detailed implementation

Static and dynamic chains using one register only; point to uppermost AR static chain -- alternative implementation of a display dynamic chain -- list of AR entry on run-time stack, to restore activation register example -- runtime stack active scopes (display) of P1 R1 Q1 Q2 S1 S2 R2 P2 P3 Q3 R3 R3: c P1: a, Q, R Q1: b, S R1: c S2: d Q2: b, S R2: c P2: a, Q, R Q3: b, S S1: d P3: a, Q, R 1 2 3 activation register dynamic chain static chain

Advanced features formal procedure QUIZ: how?