4. Runtime environment Flashcards
runtime environment
- Runtime means program in execution
- Runtime environment is a state of target machine which includes software libraries, environment variables etc to provide services to the process running in the system
storage organization
- when the target programme executes then it runs in its own Logical address space in which value of each programme has its location
- The logical address space Is shared among the compiler operating system and target machine for management and organisation
- OS is used to map the logical address into physical address which is usually spread throughout the memory
- Runtime representation of the object programme in logical address space consists of data and programme areas
diagram is in the document
Runtime storage is subdivided into: - Generated executable code
- static Data objects
- dynamic data object heap
- Automatic data object stack
Static vs Dynamic Storage allocation
- The layout and allocation of data and memory locations in runtime environment are the key issues in storage management
- the two terms static and dynamic distinguish between compile time and runtime respectively
- Storage allocation decision is:
static: If it can be made by the compiler looking only at the text of the programme but not the execution of the programme
dynamic: If it can be decided only while the programme is executed
- Compilers use two strategies for dynamic storage allocation: - Stack storage
- Heap storage
stack storage
Stack a location, CD involves organisation and management of memory on the programme stack during execution of the programme
When a function is called, space is allocated on the stack for its local variables, parameters,return addresses and other necessary information
This memory is automatically reclaimed when the function returns
concepts related to managing function calls and local variables on the programme stack:
1. Activation trees
2. Activation records
3. Calling sequences
4. Variable - length data on the stack
- activation trees
- nested structures of function calls in the programme are called as activation trees
- Each node in the tree corresponds to a function call and its associated activation record
- The tree structure reflects the hierarchical nature of the function calls for the parent node representing calling functions and child notes representing called functions
- The root node is the activation of the main procedure that initiates the execution of the programme
eg: Quicksort algorithm
– The main function has three tasks
1) It calls readarray
2) Set the Sentinels
3) calls quicksort on the entire data array
eg:
file:///C:/Users/mural/OneDrive/Desktop/BSCS/3rd%20year/5th%20sem/CD/CD-UNIT-IV&V.pdf
2- Activation records
ARCAMLT
- Procedure calls and returns are usually managed by a runtime stack called as control stack
- Each live activation has a activation record( or frame)
- root of activation tree is at the bottom of the stack
- Current execution path specifies the content of the stack
- last activation record in the -top of this stack
- It is a data structure that stores information about Current status of the machine(a function call)
- It typically includes space for local variables, Function parameters, return addresses, And other necessary information
- Activation records are organised in stack like manner with each new function called pushing a new activation record out to the stack
General activation record units:
ARCAMLT - Actual parameters stores actual parameters which are used to send input to the called procedure
- Returned valuesStores return values
- control Link Stores address of activation record of the caller procedure
- Access link Stores information of the data outside of the local scope
- machine status Stores machine status such as registers programme counters etc before procedure is called
- Local data Stores local date of the procedure
- temporaries Stores temporary and intermediate values of an expression
3- calling sequence
- Sequence of operations needed to perform on an activation record when a function is called and return from
- This includes saving and restoring the stack pointer, Passing parameters and managing the written address
- Calling sequences are architecture sp…. using assembly language instructions
Designing calling sequences and the layout of activation record:
1. Values communicated between caller and callee are generally placed at the beginning of Callee’s activation record
2. Fixed length items - are generally placed at the middle ,it includes control link, access link and machine status fields
3. Items whose size may not be known early enough are placed at the end of activation record
4. We must locate the top of the stack pointer judicially— The common approach is to have it point to end fixed length fields in activation record
Variable length data on stack
- Stack a location can accommodate variable - length(size of the objects which are not known at the compile time) data structures such as arrays or dynamically allocated memory
- For example when a function allocates memory for variable length array it adjusts the stack point by the size of the array to allocate the necessary space
- Managing variable length data on the stack requires careful bookkeeping to ensure correct memory management and avoid stackoverflows
codeMemory locations for code are determined at compile time
———————.
static data Locations at static data can also be determined at compile time
————————-.
stack Data objects allocated at runtime
————————–.
free memory
——————-.
heap other dynamically allocated data objects at other dynamically allocated data objects at run time(malloc area in c)
access to non local data on stack
Access to non local data on stack:
1. Static or lexical scope
i. Access link
ii. display
2. Dynamic scope
i. Deep access
ii. shallow access
heap management
heap allocation is most flexible allocation scheme
Allocation and de allocation of memory can be done at any time and any place depending upon the user’s requirement
Heap allocation is used to allocate memory to the variables dynamically and when the variables are no more used than it is claimed back
There are two methods used for heat management:
a. Garbage collection
b. Reference counter
1) The memory manager:
it performs two basic functions
1. Allocation and deallocation
allocation:
When programme requests for memory from variable or object the manager produces a chunk of contiguous heap memory of requested size if Needed sizes not available it seeks to increase cheap storage space by getting consecutive bytes of virtual memory from os
- The space is exhausted the memory manager passes the information back to the application programme
deallocation
The memory manager returns de allocated space to the pool of free space so it can be reused to satisfy other allocation requests
— Properties we desire from memory managers:
2. Space efficiency(A memory manager should minimise the total heap space needed by the programme)
3. programme efficiency(the object that is required more must be placed in accessible region Which helps to run programme faster.)
4. Low overhead(if memory allocation and deallocation is done efficiently, then the programme reduces overhead in programme execution)
2) Memory hierarchy
The memory hierarchy involves organising memory to efficiently allocate and deallocate dynamic memory during programme execution.
Virtual memory
main memory
2nd level cache
first level cache
registers.
3) Locality in programmes
The locality makes use of memory hierarchy for increasing efficiency in the programme
Two localities
-temporary locality
- spatial locality
4) Reducing fragmentation
Fragmentation: due to allocation and deallocation memory contains free slots called holes
Strategies to reduce heap fragmentation -
1. Best fit
In this method, memory manager searches the entire list for Free slots and finds the hole, which is best possible, that can be used for allocation
2. next fit
In this free list of holes is simply scan to find large enough hole to hold the objects
3. managing free space
Mini free spaces are combined together to form a large hole
5) Manual de allocation requests
programme grammars must explicitly arrange for deallocation of data
Garbage collection
- Garbage collection is a process That automatically reclaims memory occupied by objects that are no longer reachable or used by the programmer
key Components
1. Identification of unreachable objects
Garbage collector identifies objects in the heap that are no longer reachable by the programme.
This is done by tracing the references from root objects and marking the objects that are reachable
2. Mark and sweep algorithms.Marking phase
Reachable objects are markedSweeping phase
Memory occupied by Unmarked objects is freed up
3. Reference counting
The reference count is incremented and reference to object is created
And is decreased when reference is removed
Objects with zero reference count are considered unreachable
4. generational garbage collection
Divide heap into generations:
Young
old
Young ones are collected more as they are more likely to become unreachable quickly
5. automatic memory management
Garbage collection automates the memory management, reducing risk of memory leaks
6. trade offs
There is trade offs between memory management and performance
The garbage collector must periodically stop the programmes execution to perform collection
Introduction to trace based collection
- Instead of collecting garbage as it is created, trace based collectors run to find unreachable objects and reclaim their space
- Trace based collector is run whenever the free space is exhausted on its amount drops below the threshold
Mark - and - sweep collector
This Garbage collection algorithms are straightforward that finds all the unreachable objects and put them on the list of free spaces
– Falling algorithm visits and marks all the reachable objects in first chasing step in and sweeps the entire heap to free up unreachable objects
Input* Route set performance free list quality with unallocated chunks of heap
—–Algorithm is in the document—-
file:///C:/Users/mural/OneDrive/Desktop/BSCS/3rd%20year/5th%20sem/CD/CD-UNIT-IV&V.pdf