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::isInitialized() constnoexcept[¶]

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() constnoexcept[¶]

Returns allocator options, see Flags.

Remarks
This function is thread-safe.

bool JitAllocator::hasOption() constnoexcept[¶]

Tests whether the allocator has the given option set.

Remarks
This function is thread-safe.

uint32_t JitAllocator::blockSize() constnoexcept[¶]

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() constnoexcept[¶]

Returns granularity of the allocator.

Remarks
This function is thread-safe.

uint32_t JitAllocator::fillPattern() constnoexcept[¶]

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

Remarks
This function is thread-safe.

Error JitAllocator::alloc(
Span& out,
size_t size
)noexcept[¶]

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 newSize
)noexcept[¶]

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

Remarks
This function is thread-safe.

Error JitAllocator::query(
Span& out,
void* rx
) constnoexcept[¶]

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 kErrorOk 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 writeFunc,
void* userData,
)noexcept[2/3][¶]

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

Use policy argument to specify an instruction cache flush behavior.

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

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

Use policy argument to specify an instruction cache flush behavior.

Statistics JitAllocator::statistics() constnoexcept[¶]

Returns JIT allocator statistics.

Remarks
This function is thread-safe.

Impl* JitAllocator::_impl[¶]

Allocator implementation (private).