1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Compiler Task
Must correctly map the high-level constructs of the source language to the low-level target machine constructs.
OS Address mapping
Maps the logical addresses to physical addresses in memory
Virtual Memory Structure
Stack
Free Memory
Heap
Static
Code
Code contents
Generated target code
Static contents
Global constants and some objects
Stack contents
Stores activation records during procedure calls and starts from a higher address, growing downwards
Heap contents
Stores dynamically allocated data and starts from a lower address before growing upwards
Objects Storage
Stored in consecutive bytes, assigned the address of the first byte. Have to be allocated enough memory to hold them.
Stack
Where local variables are stored inside when the procedure containing the variable is called, then removed from the stack when the procedure finishes
Heap
Variables are stored in here when they outlive a procedure call and are manually de-allocated/garbage collected.
Activation Records/Stack Frames
Pushed onto the stack every time a function is called, and popped when a function returns
Stack Frame Contents
Local variables
Parameters
Return Addresses
Other temporaries
Stack pointer
Identifies where the current stack frame is on the stack
Access Link
Stores a link to the closest function surrounding a given function.
Stack Frame Layout
Data communicated between caller and callee placed at the bottom of the calleeās record
Parameters, return address, return value
Fixed-length variables in the middle
Variables for which the size is unknown are placed at the end
Dynamically sized array
In a calling sequence
Caller can store the parameters and return addresses onto the stack - gives control to the callee
Value of the program counter, gives control to the callee.
Callee saves register values and other status information
Callee initialises its local data, begins execution
In a return sequence
Callee can store the return value
Callee restores old register values
Callee jumps to the return address
Memory Manager
Keeps track of free memory
Memory Manager - Requesting Memory
Tries to produce some contiguous chunk of free memory
If not possible, requests more memory from the OS
If not possible, an error is returned
Memory Manager - Program Freeing Memory
Returns that memory to the pool of free memory
If the OS increased the memory, it is not returned to the OS
Memory Manager - Desired Properties
Space efficiency
Program efficiency
Low overhead
Further Consideration
Exploiting locality
Reduce fragmentation
Garbage Collection
Mark and sweep
Mark all unreachable objects, sweep the entire heap to free them up
Mark and compact
Move reachable objects to eliminate memory fragmentation.