manages the memory on the heap.
More...
#include <heap-manager.hpp>
|
| static constexpr std::chrono::milliseconds | MIN_GC_INTERVAL {100} |
| | minimum time between GC runs.
|
| |
| static constexpr std::chrono::seconds | PERIODIC_GC_INTERVAL {1} |
| | periodic gc interval.
|
| |
manages the memory on the heap.
◆ heap_manager() [1/3]
| heap_manager::heap_manager |
( |
size_t |
hm_thread_count, |
|
|
size_t |
gc_thread_count = 1 |
|
) |
| |
creates the instance of the heap manager.
- Parameters
-
| gc_thread_count | - size of gc thread pool, defaults to 1. |
initializes the segments on the heap, initializes free memory tables.
◆ ~heap_manager()
| heap_manager::~heap_manager |
( |
| ) |
|
|
default |
deletes the instance of the heap manager.
◆ heap_manager() [2/3]
deleted copy constructor.
◆ heap_manager() [3/3]
deleted move constructor.
◆ add_root()
| void heap_manager::add_root |
( |
std::string |
key, |
|
|
std::unique_ptr< root_set_base > |
base |
|
) |
| |
adds new root to a root-set-table.
- Parameters
-
| key | - name of the root. |
| base | - element of the root-set-table. |
◆ allocate()
| header * heap_manager::allocate |
( |
uint32_t |
bytes | ) |
|
tries to allocate memory on the heap.
- Parameters
-
| bytes | - number of bytes that need to be allocated. |
- Returns
- pointer to header of the object if allocation is successful, nullptr otherwise.
◆ allocate_from_segment()
| header * heap_manager::allocate_from_segment |
( |
size_t |
segment_index, |
|
|
uint32_t |
bytes |
|
) |
| |
|
private |
allocates object on the heap segment.
- Parameters
-
| segment_index | - index of the segment. |
| bytes | - required memory. |
- Returns
- pointer to the header of the object.
◆ clear_roots()
| void heap_manager::clear_roots |
( |
| ) |
|
|
noexcept |
removes all roots from the root-set-table.
◆ coalesce_segment()
| void heap_manager::coalesce_segment |
( |
size_t |
segment_index | ) |
|
|
private |
merges free blocks on the segment.
- Parameters
-
| segment_index | - index of the segment. |
◆ coalesce_segments()
| void heap_manager::coalesce_segments |
( |
| ) |
|
|
private |
merges free blocks of segments.
- Warning
- must be called during the STW, after gc finishes collecting.
◆ collect_garbage()
| void heap_manager::collect_garbage |
( |
| ) |
|
starts the garbage collection.
"Stop the world", mark & sweep collection and coalescing of segments.
- Warning
- can be called by client, but it may be expensive if called frequently.
◆ find_suitable_segment()
| int heap_manager::find_suitable_segment |
( |
uint32_t |
bytes | ) |
|
|
privatenoexcept |
finds a segment that can store required bytes.
- Parameters
-
| bytes | - number of bytes that need to be allocated. |
- Returns
- index of the segment if segment can allocate enough bytes, -1 otherwise.
◆ get_root()
| root_set_base * heap_manager::get_root |
( |
const std::string & |
key | ) |
|
getter for the root from the root-set-table.
- Parameters
-
- Returns
- pointer to a root.
◆ get_segment()
| segment & heap_manager::get_segment |
( |
size_t |
segment_index | ) |
|
|
private |
getter for the segment based on index.
- Parameters
-
| segment_index | - index of the segment. |
- Returns
- reference to a segment.
◆ get_segment_category_index()
| size_t heap_manager::get_segment_category_index |
( |
size_t |
segment_index | ) |
const |
|
privatenoexcept |
getter for the index of the segment based on object size category.
- Parameters
-
| segment_index | - index of the segment 0 to (n-1). |
- Returns
- index of the segment in an object category.
◆ operator=() [1/2]
deleted assignment operator.
◆ operator=() [2/2]
deleted move assignment operator.
◆ periodic_gc_loop()
| void heap_manager::periodic_gc_loop |
( |
std::stop_token |
stop_token | ) |
|
|
private |
periodic garbage collection loop.
- Parameters
-
| stop_token | - token for stopping periodic gc. |
◆ remove_root()
| void heap_manager::remove_root |
( |
const std::string & |
key | ) |
|
removes root from the root-set-table.
- Parameters
-
| key | - const reference to a name of the root-set-table. |
◆ should_run_gc()
| bool heap_manager::should_run_gc |
( |
| ) |
const |
|
privatenoexcept |
checks if enough time has passed since last garbage collection.
- Returns
- true if gc should run, false otherwise.
◆ free_memory_table
table containing the linked lists of free memory for each segment.
◆ gc
◆ gc_in_progress
| std::atomic<bool> heap_manager::gc_in_progress {false} |
|
private |
indicates whether gc is currently running.
◆ gc_timer_thread
| std::jthread heap_manager::gc_timer_thread |
|
private |
◆ heap_manager_thread_pool
thread pool for coalescing segments.
◆ heap_memory
| heap heap_manager::heap_memory |
|
private |
segmented memory for object allocation.
◆ last_gc_time_ms
| std::atomic<uint64_t> heap_manager::last_gc_time_ms |
|
private |
last time garbage collection was done.
◆ last_large_segment
large object segment that was used last, default to last.
◆ last_medium_segment
medium object segment that was used last, default to last.
◆ last_small_segment
small object segment that was used last, default to last.
◆ MIN_GC_INTERVAL
| constexpr std::chrono::milliseconds heap_manager::MIN_GC_INTERVAL {100} |
|
staticconstexprprivate |
minimum time between GC runs.
◆ PERIODIC_GC_INTERVAL
| constexpr std::chrono::seconds heap_manager::PERIODIC_GC_INTERVAL {1} |
|
staticconstexprprivate |
◆ root_set
table containing the roots.
◆ root_set_mutex
| std::mutex heap_manager::root_set_mutex |
|
private |
locks the root-set-table.
◆ segment_locks
The documentation for this class was generated from the following files: