IndexVirtual Memoryasmjit::JitAllocator

asmjit::JitAllocator Class Reference [¶]

A simple implementation of memory manager that uses asmjit::VirtMem functions to manage virtual memory for JIT compiled code.

Implementation notes:

  • Granularity of allocated blocks is different than granularity for a typical C malloc. In addition, the allocator can use several memory pools having a different granularity to minimize the maintenance overhead. Multiple pools feature requires kFlagUseMultiplePools flag to be set.
  • The allocator doesn't store any information in executable memory, instead, the implementation uses two bit-vectors to manage allocated memory of each allocator-block. The first bit-vector called 'used' is used to track used memory (where each bit represents memory size defined by granularity) and the second bit vector called 'stop' is used as a sentinel to mark where the allocated area ends.
  • Internally, the allocator also uses RB tree to keep track of all blocks across all pools. Each inserted block is added to the tree so it can be matched fast during release() and shrink().

Public Members

Members

Classes

Member Functions

Construction & Destruction

Accessors

Alloc & Release

Statistics

Write Operations

JitAllocator::JitAllocator(
const CreateParams* params = nullptr
)explicitnoexcept[¶]

Creates a JitAllocator instance.

JitAllocator::~JitAllocator()noexcept[¶]

Destroys the JitAllocator instance and release all blocks held.

bool JitAllocator::is_initialized() constnodiscardnoexcept[¶]

Tests whether the JitAllocator has been initialized.

Remarks

This function is thread-safe.

void JitAllocator::reset()noexcept[¶]

Free all allocated memory - makes all pointers returned by alloc() invalid.

Remarks

This function is not thread-safe as it's designed to be used when nobody else is using the JitAllocator. The reason is that there is no reason to call reset() when the allocator is still in use by other threads.

JitAllocatorOptions JitAllocator::options() constnodiscardnoexcept[¶]

Returns allocator options, see Flags.

Remarks

This function is thread-safe.

bool JitAllocator::has_option() constnodiscardnoexcept[¶]

Tests whether the allocator has the given option set.

Remarks

This function is thread-safe.

uint32_t JitAllocator::block_size() constnodiscardnoexcept[¶]

Returns a base block size (a minimum size of block that the allocator would allocate).

Remarks

This function is thread-safe.

uint32_t JitAllocator::granularity() constnodiscardnoexcept[¶]

Returns granularity of the allocator.

Remarks

This function is thread-safe.

uint32_t JitAllocator::fill_pattern() constnodiscardnoexcept[¶]

Returns pattern that is used to fill unused memory if kFlagUseFillPattern is set.

Remarks

This function is thread-safe.

Error JitAllocator::alloc(
Out<Span> out,
size_t size
)nodiscardnoexcept[¶]

Allocates a new memory span of the requested size.

Remarks

This function is thread-safe.

Error JitAllocator::release(
void* rx
)noexcept[¶]

Releases a memory block returned by alloc().

Remarks

This function is thread-safe.

Error JitAllocator::shrink(
Span& span,
size_t new_size
)noexcept[¶]

Frees extra memory allocated with rx by shrinking it to the given new_size.

Remarks

This function is thread-safe.

Error JitAllocator::query(
Out<Span> out,
void* rx
) constnodiscardnoexcept[¶]

Queries information about an allocated memory block that contains the given rx, and writes it to out.

If the pointer is matched, the function returns Error::kOk and fills out with the corresponding span.

Remarks

This function is thread-safe.

Error JitAllocator::write(
Span& span,
size_t offset,
const void* src,
size_t size,
)noexcept[1/3][¶]

Makes the memory pointed out by span writable and writes data to ot at the given offset.

This function reads src and writes to span at offset the number of bytes a specified by size.

Use policy argument to specify an instruction cache flush behavior.

Error JitAllocator::write(
Span& span,
WriteFunc write_fn,
void* user_data,
)noexcept[2/3][¶]

Makes the memory pointed out by span writable and calls the provided callback function write_fn with user_data to perform the write operation.

Use policy argument to specify an instruction cache flush behavior.

template<class Lambda>
Error JitAllocator::write(
Span& span,
Lambda&& lambda_fn,
)noexcept[3/3][¶]

Makes the memory pointed out by span writable and calls the provided lambda function lambda_fn to perform the write operation.

Use policy argument to specify an instruction cache flush behavior.

Statistics JitAllocator::statistics() constnodiscardnoexcept[¶]

Returns JIT allocator statistics.

Remarks

This function is thread-safe.

Impl* JitAllocator::_impl[¶]

Allocator implementation (private).