The general organization of runtime storage: Code area Global/static area Stack Free space Heap Where, the arrows indicate the direction of growth of the stack and heap
The general organization of runtime storage: Code area Global/static area Stack ↓ Free space ↑ Heap Where, the arrows indicate the direction of growth of the stack and heap
Procedure activation record (An important unit of memory allocation) Memory allocated for the local data of a procedure or function An activation record must contains the following sections Space for arguments ( parameters Space for bookkeeping information, including return address Space for local data Space for local temporaries Note: this picture only illustrates the general organization of an activation record
Procedure activation record (An important unit of memory allocation) Memory allocated for the local data of a procedure or function. An activation record must contains the following sections: Space for arguments ( parameters ) Space for bookkeeping information, including return address Space for local data Space for local temporaries Note: this picture only illustrates the general organization of an activation record
Some parts of an activation record have the same size for all procedures Space for bookkeeping information Other parts of an activation record may remain fixed for each individual procedure Space for arguments and local data Some parts of activation record may be allocated automatically on procedure calls Storing the return address Other parts of activation record may need to be allocated explicitly by instructions generated by the compiler Local temporary space Depending on the language activation records may be allocated in different areas Fortran77 in the static area C and pascal in the stack area referred to as stack frames LISP in the heap area
• Some parts of an activation record have the same size for all procedures – Space for bookkeeping information • Other parts of an activation record may remain fixed for each individual procedure – Space for arguments and local data • Some parts of activation record may be allocated automatically on procedure calls: – Storing the return address • Other parts of activation record may need to be allocated explicitly by instructions generated by the compiler: – Local temporary space • Depending on the language, activation records may be allocated in different areas: – Fortran77 in the static area; – C and Pascal in the stack area; referred to as stack frames – LISP in the heap area
Processor registers are also part of the structure of the runtime environment Registers may be used to store temporaries, local variables. or even global variables In newer RisC processor, keep entire static area and whole activation records Special-purpose registers to keep track of execution Pc program counter · SP Stack pointer; FP frame pointer ° AP argument pointer
• Processor registers are also part of the structure of the runtime environment – Registers may be used to store temporaries, local variables, or even global variables; – In newer RISC processor, keep entire static area and whole activation records; – Special-purpose registers to keep track of execution • PC program counter; • SP stack pointer; • FP frame pointer; • AP argument pointer
The sequence of operations when calling the functions: calling sequence The allocation of memory for the activation record The computation and storing of the arguments The storing and setting of necessary registers to affect the call The additional operations when a procedure or function returns: return sequence (s call The placing of the return value where the caller can access it The readjustment of registers The possible releasing for activation record memory
• The sequence of operations when calling the functions: calling sequence – The allocation of memory for the activation record; – The computation and storing of the arguments; – The storing and setting of necessary registers to affect the call • The additional operations when a procedure or function returns: return sequence (VS call) – The placing of the return value where the caller can access it; – The readjustment of registers; – The possible releasing for activation record memory