Broom 1.0.0
A thread-local C++ Garbage Collector
Loading...
Searching...
No Matches
Namespaces | Classes | Concepts | Typedefs | Enumerations | Functions | Variables
broom Namespace Reference

Namespaces

namespace  __impl
 
namespace  platform
 

Classes

class  Allocator
 
class  AllocatorCommonMetadata
 
class  AllocatorFrontMetadata
 
class  array
 
struct  Atomic
 
struct  BroomDisableGcScope
 
class  BroomLifetimeAnchor
 
struct  BroomNoDestructorScope
 
struct  BroomScope
 
struct  BroomSharingNoDestructorScope
 
class  BroomSharingPointer
 
struct  BroomSharingScope
 
class  BroomValue
 
class  deque
 
class  ExternalRoot
 
class  forward_list
 
class  FreeListAllocator
 
class  GarbageCollector
 
class  GcNode
 
class  list
 
class  map
 
class  MemoryRegion
 
class  MemorySpace
 
class  multimap
 
class  multiset
 
class  PreciseRoot
 
class  RootVisitor
 
class  set
 
class  unordered_map
 
class  unordered_multimap
 
class  unordered_multiset
 
class  unordered_set
 
class  vector
 
class  Visitor
 

Concepts

concept  StaticCastable
 
concept  ReinterpretCastable
 
concept  IsAllocatorMetadata
 

Typedefs

using AllocatorBackMetadata = AllocatorCommonMetadata
 
using MemoryAddress = uintptr_t
 
using UintPtr = uintptr_t
 
using IntPtr = intptr_t
 
template<typename T , typename Compare = std::less<typename broom::vector<T>::value_type>>
using priority_queue = std::priority_queue< T, broom::vector< T >, Compare >
 
template<typename T >
using queue = std::queue< T, broom::deque< T > >
 
template<typename T >
using stack = std::stack< T, broom::deque< T > >
 
using scope = BroomScope
 
using sharing_scope = BroomSharingScope
 
using no_destructor_scope = BroomNoDestructorScope
 
using sharing_no_destructor_scope = BroomSharingNoDestructorScope
 
using Destructor = std::add_pointer< void(const void *)>::type
 
using disable_gc_scope = BroomDisableGcScope
 
using gc_visitor = Visitor
 
using gc_root = BroomValue
 
template<typename T >
using sharing_ptr = BroomSharingPointer< T >
 
template<typename T >
using lifetime_anchor = BroomLifetimeAnchor< T >
 

Enumerations

enum class  MemoryPermissions { kReadOnly , kWriteOnly , kReadWrite , kNone }
 
enum class  MemoryPressure { kLight , kMedium , kCritical }
 
enum class  RootKind { kStack , kExternal , kPrecise , kRegular }
 

Functions

void thread_init (broom_configuration config)
 
void thread_teardown ()
 
void force_collection ()
 
void force_slow_collection ()
 
void register_external (const void *pointer, size_t size)
 
void unregister_external (const void *pointer)
 
template<typename T , typename U >
requires StaticCastable<U, T> && (!IsAllocatorMetadata<T>)
constexprSafeCast (U v)
 
template<typename T , typename U >
requires ReinterpretCastable<U, T> && (!StaticCastable<U, T>) && (!IsAllocatorMetadata<T>)
constexprSafeCast (U v)
 
template<typename T , typename U >
constexprUnsafeCast (U v)
 
template<size_t N, typename T >
requires std::is_integral_v<T> && (N > 0) && (N % 2 == 0)
constexpr bool IsAligned (T value)
 
template<size_t N, typename T >
requires (N > 0) && (N % 2 == 0)
constexpr bool IsAligned (T *value)
 
template<size_t N, typename T >
requires std::is_integral_v<T> && (N > 0) && (N % 2 == 0)
constexprRoundDown (T value)
 
template<size_t N, typename T >
requires std::is_integral_v<T> && (N > 0) && (N % 2 == 0)
constexprRoundUp (T value)
 
template<typename T >
requires std::is_unsigned_v<T>
constexpr bool AddOverflowChecked (T lhs, T rhs, T &destination)
 
BROOM_NOASAN BROOM_NOTSAN BROOM_NOINLINE void IterateStackAndVisitRootsImpl (RootVisitor *visitor, const void *const *stack_bottom, const void *const *stack_top)
 
template<typename T , typename... Args>
T * allocate (size_t count, Args &&... args)
 
template<typename T >
sharing_ptr< T > share (T *ptr, uint32_t count=1)
 

Variables

thread_local GarbageCollectort_gc = nullptr
 
constexpr const uintptr_t kNullUintPtr = 0
 
constexpr const intptr_t kNullIntPtr = 0
 
constexpr const MemoryAddress kNullMemoryAddress = 0
 
constexpr const int kPointerSize = sizeof(void*)
 
constexpr const int kUintPtrSize = sizeof(UintPtr)
 
constexpr const int kIntPtrSize = sizeof(IntPtr)
 
constexpr const size_t KB = 1024
 
constexpr const size_t MB = KB * 1024
 
constexpr const size_t GB = MB * 1024
 
constexpr const size_t TB = GB * 1024
 
constexpr const int kPageSize = 4 * KB
 
constexpr const int kHugePageSize = 2 * MB
 

Typedef Documentation

◆ AllocatorBackMetadata

Definition at line 166 of file allocator.h.

◆ Destructor

Definition at line 245 of file broom.h.

◆ disable_gc_scope

A type alias for BroomDisableGcScope.

Definition at line 287 of file broom.h.

◆ gc_root

A type alias for BroomValue.

Definition at line 466 of file broom.h.

◆ gc_visitor

A type alias for Visitor.

Definition at line 374 of file broom.h.

◆ IntPtr

Definition at line 15 of file globals.h.

◆ lifetime_anchor

A type alias for BroomLifetimeAnchor.

Definition at line 686 of file broom.h.

◆ MemoryAddress

Definition at line 13 of file globals.h.

◆ no_destructor_scope

A type alias for BroomNoDestructorScope.

Definition at line 239 of file broom.h.

◆ priority_queue

template<typename T , typename Compare = std::less<typename broom::vector<T>::value_type>>
using broom::priority_queue = typedef std::priority_queue<T, broom::vector<T>, Compare>

A Broom-aware std::priority_queue adaptor.

Definition at line 13 of file broom-priority-queue.h.

◆ queue

template<typename T >
using broom::queue = typedef std::queue<T, broom::deque<T> >

A Broom-aware std::queue adaptor.

Definition at line 12 of file broom-queue.h.

◆ scope

A type alias for BroomScope.

Definition at line 231 of file broom.h.

◆ sharing_no_destructor_scope

A type alias for BroomSharingNoDestructorScope.

Definition at line 243 of file broom.h.

◆ sharing_ptr

A type alias for BroomSharingPointer.

Definition at line 680 of file broom.h.

◆ sharing_scope

A type alias for BroomSharingScope.

Definition at line 235 of file broom.h.

◆ stack

template<typename T >
using broom::stack = typedef std::stack<T, broom::deque<T> >

A Broom-aware std::stack adaptor.

Definition at line 12 of file broom-stack.h.

◆ UintPtr

Definition at line 14 of file globals.h.

Enumeration Type Documentation

◆ MemoryPermissions

Enumerator
kReadOnly 
kWriteOnly 
kReadWrite 
kNone 

Definition at line 111 of file allocator.h.

◆ MemoryPressure

Enumerator
kLight 
kMedium 
kCritical 

Definition at line 225 of file allocator.h.

◆ RootKind

Enumerator
kStack 
kExternal 
kPrecise 
kRegular 

Definition at line 14 of file roots.h.

Function Documentation

◆ AddOverflowChecked()

template<typename T >
requires std::is_unsigned_v<T>
constexpr bool broom::AddOverflowChecked ( lhs,
rhs,
T &  destination 
)
inlineconstexpr

Definition at line 92 of file globals.h.

◆ allocate()

template<typename T , typename... Args>
T * broom::allocate ( size_t  count,
Args &&...  args 
)

Broom's default allocation function. It allocates a memory region of count * sizeof(T) bytes, along with any metadata needed by the garbage collector. If there is a constructor to run for T, broom::allocate() will run it. The object is registered with the garbage collector and becomes managed, meaning that pointers to this object will be scanned during the tracing phase of garbage collection, can be collected if no references were found and if there is a destructor to run during collection, it will run it.

Parameters
countThe number of objects of type T to allocate.
argsThe arguments to forward to the constructor of T.

Definition at line 303 of file broom.h.

◆ force_collection()

BROOM_EXPORT void broom::force_collection ( )

As the name of the function suggests, broom::force_collection() forces the garbage collector to trace and collect any objects it couldn't find references for. See also force_slow_collection().

Definition at line 39 of file api.cc.

◆ force_slow_collection()

BROOM_EXPORT void broom::force_slow_collection ( )

broom::force_slow_collection() will run a full tracing and collection phase across all the known spaces and roots in the garbage collector. This function should be used sparingly, as it can take a long time to complete. Consider using force_collection() instead.

Definition at line 40 of file api.cc.

◆ IsAligned() [1/2]

template<size_t N, typename T >
requires (N > 0) && (N % 2 == 0)
constexpr bool broom::IsAligned ( T *  value)
inlineconstexpr

Definition at line 72 of file globals.h.

◆ IsAligned() [2/2]

template<size_t N, typename T >
requires std::is_integral_v<T> && (N > 0) && (N % 2 == 0)
constexpr bool broom::IsAligned ( value)
inlineconstexpr

Definition at line 66 of file globals.h.

◆ IterateStackAndVisitRootsImpl()

BROOM_NOASAN BROOM_NOTSAN BROOM_NOINLINE void broom::IterateStackAndVisitRootsImpl ( RootVisitor visitor,
const void *const stack_bottom,
const void *const stack_top 
)

Definition at line 49 of file root-visitor.cc.

◆ register_external()

BROOM_EXPORT void broom::register_external ( const void pointer,
size_t  size 
)

broom::register_external() notifies the garbage collector about the presence of a new external root. This function should be called when you wish to store a managed (garbage collected) pointer in unmanaged memory (e.g. an object allocated using a non-Broom allocator). The memory region passed into this function will be scanned for managed pointers by the garbage collector during the tracing phase. See also unregister_external().

Parameters
pointerThe pointer to the base of a region to register as an external root.
sizeThe size of the region.

Definition at line 41 of file api.cc.

◆ RoundDown()

template<size_t N, typename T >
requires std::is_integral_v<T> && (N > 0) && (N % 2 == 0)
constexpr T broom::RoundDown ( value)
inlineconstexpr

Definition at line 78 of file globals.h.

◆ RoundUp()

template<size_t N, typename T >
requires std::is_integral_v<T> && (N > 0) && (N % 2 == 0)
constexpr T broom::RoundUp ( value)
inlineconstexpr

Definition at line 84 of file globals.h.

◆ SafeCast() [1/2]

template<typename T , typename U >
requires StaticCastable<U, T> && (!IsAllocatorMetadata<T>)
constexpr T broom::SafeCast ( U  v)
inlineconstexpr

Definition at line 48 of file globals.h.

◆ SafeCast() [2/2]

template<typename T , typename U >
requires ReinterpretCastable<U, T> && (!StaticCastable<U, T>) && (!IsAllocatorMetadata<T>)
constexpr T broom::SafeCast ( U  v)
inlineconstexpr

Definition at line 55 of file globals.h.

◆ share()

template<typename T >
sharing_ptr< T > broom::share ( T *  ptr,
uint32_t  count = 1 
)

broom::share() is the interface for creating BroomSharedPointers. It accepts two arguments, the pointer to share and how many times it should be shared. See BroomSharedPointer and BroomLifetimeAnchor for more details about sharing.

Parameters
ptrThe raw pointer to share.
countThe count describing how many times the sharing_ptr must be disposed for the garbage collector to unpin the allocation.
Returns
A sharing_ptr which is safe to be used by other threads.

Definition at line 699 of file broom.h.

◆ thread_init()

BROOM_EXPORT void broom::thread_init ( broom_configuration  config = {})

broom::thread_init() provides initialization for the garbage collection state on the current thread. This function should be called before attempting to use Broom APIs on a given thread. Broom also provides a RAII-style scope to automatically initialize and tear down the garbage collector state in a given thread via broom::scope. See also broom::thread_teardown().

Parameters
configThe configuration to initialize Broom on this thread with.

Definition at line 7 of file api.cc.

◆ thread_teardown()

BROOM_EXPORT void broom::thread_teardown ( )

broom::thread_teardown() should be called when the thread exits. Broom also provides a RAII-style scope to automatically initialize and tear down the garbage collector state in a given thread via broom::scope. See also broom::thread_init().

Definition at line 12 of file api.cc.

◆ unregister_external()

BROOM_EXPORT void broom::unregister_external ( const void pointer)

broom::unregister_external() notifies the garbage collector that the previously registered unmanaged memory that can contain managed pointers is no longer able to do so. This memory region will no longer be scanned for references to managed memory.

Parameters
pointerThe pointer to the base of a region to unregister as an external root.
sizeThe size of the region.

Definition at line 44 of file api.cc.

◆ UnsafeCast()

template<typename T , typename U >
constexpr T broom::UnsafeCast ( U  v)
inlineconstexpr

Definition at line 60 of file globals.h.

Variable Documentation

◆ GB

constexpr const size_t broom::GB = MB * 1024
constexpr

Definition at line 23 of file globals.h.

◆ KB

constexpr const size_t broom::KB = 1024
constexpr

Definition at line 21 of file globals.h.

◆ kHugePageSize

constexpr const int broom::kHugePageSize = 2 * MB
constexpr

Definition at line 27 of file globals.h.

◆ kIntPtrSize

constexpr const int broom::kIntPtrSize = sizeof(IntPtr)
constexpr

Definition at line 19 of file globals.h.

◆ kNullIntPtr

constexpr const intptr_t broom::kNullIntPtr = 0
constexpr

Definition at line 12 of file globals.h.

◆ kNullMemoryAddress

constexpr const MemoryAddress broom::kNullMemoryAddress = 0
constexpr

Definition at line 16 of file globals.h.

◆ kNullUintPtr

constexpr const uintptr_t broom::kNullUintPtr = 0
constexpr

Definition at line 11 of file globals.h.

◆ kPageSize

constexpr const int broom::kPageSize = 4 * KB
constexpr

Definition at line 26 of file globals.h.

◆ kPointerSize

constexpr const int broom::kPointerSize = sizeof(void*)
constexpr

Definition at line 17 of file globals.h.

◆ kUintPtrSize

constexpr const int broom::kUintPtrSize = sizeof(UintPtr)
constexpr

Definition at line 18 of file globals.h.

◆ MB

constexpr const size_t broom::MB = KB * 1024
constexpr

Definition at line 22 of file globals.h.

◆ t_gc

Definition at line 6 of file api.cc.

◆ TB

constexpr const size_t broom::TB = GB * 1024
constexpr

Definition at line 24 of file globals.h.