GCSIM
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
allocators Class Reference

simulates the allocations on the heap. More...

#include <allocators.hpp>

Public Member Functions

 allocators (heap_manager &heap_manager_ref, size_t thread_count)
 creates the instance of the allocators.
 
 ~allocators ()=default
 deletes the instance of the allocators.
 
void simulate_alloc (size_t tls_count, size_t global_count, size_t register_count, simulation_mode mode)
 starts the allocation simulation, stress mode.
 

Private Member Functions

void simulate_tls_alloc (thread_local_stack *tls, size_t scope_count, size_t allocs_per_scope)
 simulates allocation of a thread, stress mode.
 
void simulate_global_alloc (global_root *global, size_t global_allocs)
 simulates allocation of a global variable, stress mode.
 
void simulate_register_alloc (register_root *reg, size_t register_allocs)
 simulates allocation of a register variable, stress mode.
 
template<typename root , typename... args>
requires std::derived_from<root, root_set_base>
root * create_root (const std::string &key, args &&... arguments)
 creates the root for root-set-table.
 
template<typename fn >
void enqueue_simulation (const std::string &label, size_t index, fn &&simulate, std::latch &completion_latch)
 adds simulation to queue.
 
uint32_t generate_random_size ()
 generates the size of the object.
 

Static Private Member Functions

static constexpr const char * simulation_mode_name (simulation_mode mode)
 getter for the name of the mode of simulation.
 
static constexpr size_t tls_scope_count (simulation_mode mode)
 getter for tls scope count.
 
static constexpr size_t tls_allocs_per_scope (simulation_mode mode)
 getter for tls allocation count per scope.
 
static constexpr size_t tls_map_capacity (simulation_mode mode)
 getter for the initial capacity of the hash-map that maps tls variable to its index.
 
static constexpr size_t global_alloc_count (simulation_mode mode)
 getter for global allocation count.
 
static constexpr size_t register_alloc_count (simulation_mode mode)
 getter for register allocation count.
 

Private Attributes

heap_managerheap_manager_ref
 reference to a heap manager used by allocators.
 
thread_pool alloc_thread_pool
 allocators thread pool.
 

Static Private Attributes

static thread_local std::mt19937 rng {std::random_device{}() + std::hash<std::thread::id>{}(std::this_thread::get_id())}
 random number generator.
 
static thread_local std::uniform_int_distribution< int > category_dist
 distribution for object size category.
 
static thread_local std::uniform_int_distribution< uint32_t > small_dist
 distribution for small object size.
 
static thread_local std::uniform_int_distribution< uint32_t > medium_dist
 distribution for medium object size.
 
static thread_local std::uniform_int_distribution< uint32_t > large_dist
 distribution for large object size.
 

Detailed Description

simulates the allocations on the heap.

Constructor & Destructor Documentation

◆ allocators()

allocators::allocators ( heap_manager heap_manager_ref,
size_t  thread_count 
)

creates the instance of the allocators.

Parameters
heap_manager_ref- reference to a heap manager.
thread_count- number of thread in allocators thread pool.

◆ ~allocators()

allocators::~allocators ( )
default

deletes the instance of the allocators.

Member Function Documentation

◆ create_root()

template<typename root , typename... args>
requires std::derived_from<root, root_set_base>
root * allocators::create_root ( const std::string &  key,
args &&...  arguments 
)
inlineprivate

creates the root for root-set-table.

Template Parameters
root- type of the root.
...args- types of arguments for root construction.
Parameters
key- key of the root.
arguments- arguments for the construction.
Returns
pointer to a root-set-table element.

◆ enqueue_simulation()

template<typename fn >
void allocators::enqueue_simulation ( const std::string &  label,
size_t  index,
fn &&  simulate,
std::latch &  completion_latch 
)
inlineprivate

adds simulation to queue.

Template Parameters
fn- type of the function.
Parameters
label- name of caller.
index- index of the caller.
simulate- simulation function.
completion_latch- synchronization for simulation.

◆ generate_random_size()

uint32_t allocators::generate_random_size ( )
private

generates the size of the object.

Returns
amount of bytes object needs for allocation.

◆ global_alloc_count()

static constexpr size_t allocators::global_alloc_count ( simulation_mode  mode)
inlinestaticconstexprprivate

getter for global allocation count.

Parameters
mode- mode of the simulation.
Returns
number of allocation for global variable.

◆ register_alloc_count()

static constexpr size_t allocators::register_alloc_count ( simulation_mode  mode)
inlinestaticconstexprprivate

getter for register allocation count.

Parameters
mode- mode of the simulation.
Returns
number of allocation for register.

◆ simulate_alloc()

void allocators::simulate_alloc ( size_t  tls_count,
size_t  global_count,
size_t  register_count,
simulation_mode  mode 
)

starts the allocation simulation, stress mode.

Parameters
tls_count- number of threads that are allocating objects.
global_count- number of global variables that are referencing objects.
register_count- number of register variables that are referencing objects.
mode- mode of the simulation.

◆ simulate_global_alloc()

void allocators::simulate_global_alloc ( global_root global,
size_t  global_allocs 
)
private

simulates allocation of a global variable, stress mode.

Parameters
global- pointer to a global root.
global_allocs- number of allocations for global variable.

◆ simulate_register_alloc()

void allocators::simulate_register_alloc ( register_root reg,
size_t  register_allocs 
)
private

simulates allocation of a register variable, stress mode.

Parameters
register- pointer to a register root.
register_allocs- number of allocations for register.

◆ simulate_tls_alloc()

void allocators::simulate_tls_alloc ( thread_local_stack tls,
size_t  scope_count,
size_t  allocs_per_scope 
)
private

simulates allocation of a thread, stress mode.

Parameters
tls- pointer to a thread local stack.
scope_count- number of scopes.
allocs_per_scope- number of allocations per scope.

◆ simulation_mode_name()

static constexpr const char * allocators::simulation_mode_name ( simulation_mode  mode)
inlinestaticconstexprprivate

getter for the name of the mode of simulation.

Parameters
mode- simulation mode.
Returns
name of the mode.

◆ tls_allocs_per_scope()

static constexpr size_t allocators::tls_allocs_per_scope ( simulation_mode  mode)
inlinestaticconstexprprivate

getter for tls allocation count per scope.

Parameters
mode- mode of the simulation.
Returns
number of allocation for tls per scope.

◆ tls_map_capacity()

static constexpr size_t allocators::tls_map_capacity ( simulation_mode  mode)
inlinestaticconstexprprivate

getter for the initial capacity of the hash-map that maps tls variable to its index.

Parameters
mode- mode of the simulation.
Returns
initial capacity of the hash-map.

◆ tls_scope_count()

static constexpr size_t allocators::tls_scope_count ( simulation_mode  mode)
inlinestaticconstexprprivate

getter for tls scope count.

Parameters
mode- mode of the simulation.
Returns
number of scopes for tls.

Member Data Documentation

◆ alloc_thread_pool

thread_pool allocators::alloc_thread_pool
private

allocators thread pool.

◆ category_dist

thread_local std::uniform_int_distribution< int > allocators::category_dist
staticprivate

distribution for object size category.

◆ heap_manager_ref

heap_manager& allocators::heap_manager_ref
private

reference to a heap manager used by allocators.

◆ large_dist

thread_local std::uniform_int_distribution< uint32_t > allocators::large_dist
staticprivate

distribution for large object size.

◆ medium_dist

thread_local std::uniform_int_distribution< uint32_t > allocators::medium_dist
staticprivate

distribution for medium object size.

◆ rng

thread_local std::mt19937 allocators::rng {std::random_device{}() + std::hash<std::thread::id>{}(std::this_thread::get_id())}
staticprivate

random number generator.

◆ small_dist

thread_local std::uniform_int_distribution< uint32_t > allocators::small_dist
staticprivate

distribution for small object size.


The documentation for this class was generated from the following files: