13 "Heap base must be aligned");
16 "Heap base must be in memory");
21 : memory_{std::move(memory)},
44 size = new_offset - ptr;
49 "overflow occurred while trying to allocate {} bytes at offset " 55 if (new_offset <=
size_) {
74 auto size = a_node.mapped();
75 auto [d_it, is_emplaced] =
deallocated_.emplace(ptr, size);
76 BOOST_ASSERT(is_emplaced);
82 d_it->second += node.mapped();
87 auto d_it_prev = std::prev(d_it);
88 if (d_it_prev->first + d_it_prev->second != d_it->first) {
91 d_it_prev->second += d_it->second;
96 auto d_it_next = std::next(d_it);
98 if (d_it->first + d_it->second ==
offset_) {
116 auto min_chunk_size = std::numeric_limits<WasmPointer>::max();
118 for (
const auto &[chunk_ptr, chunk_size] :
deallocated_) {
119 BOOST_ASSERT(chunk_size > 0);
120 if (chunk_size >= size and chunk_size < min_chunk_size) {
121 min_chunk_size = chunk_size;
123 if (min_chunk_size == size) {
134 const auto node = deallocated_.extract(ptr);
135 BOOST_ASSERT_MSG(!node.empty(),
136 "pointer to the node was received by searching list of " 137 "deallocated nodes, must not be none");
139 auto old_size = node.mapped();
140 if (old_size > size) {
141 auto new_ptr = ptr + size;
142 auto new_size = old_size - size;
143 BOOST_ASSERT(new_size > 0);
145 deallocated_[new_ptr] = new_size;
157 "Memory size exceeded when growing it on {} bytes, offset was 0x{:x}",
180 if (new_size >=
size_) {
189 return it !=
deallocated_.cend() ? std::make_optional(it->second)
196 return it !=
allocated_.cend() ? std::make_optional(it->second)
std::function< size_t()> getSize
uint32_t WasmSize
Size type is uint32_t because we are working in 32 bit address space.
std::function< void(size_t)> resize
#define SL_TRACE_FUNC_CALL(logger, ret,...)
size_t getAllocatedChunksNum() const
void resize(WasmSize size)
std::unordered_map< WasmPointer, WasmSize > allocated_
constexpr size_t kDefaultHeapBase
static constexpr T roundUpAlign(T t)
constexpr size_t kInitialMemorySize
std::map< WasmPointer, WasmSize > deallocated_
std::optional< WasmSize > deallocate(WasmPointer ptr)
static constexpr uint32_t kMaxMemorySize
size_t getDeallocatedChunksNum() const
uint32_t WasmPointer
type of wasm memory is 32 bit integer
WasmPointer growAlloc(WasmSize size)
WasmPointer freealloc(WasmSize size)
Logger createLogger(const std::string &tag)
std::optional< WasmSize > getAllocatedChunkSize(WasmPointer ptr) const
MemoryAllocator(MemoryHandle memory, size_t size, WasmPointer heap_base)
WasmPointer allocate(WasmSize size)
std::optional< WasmSize > getDeallocatedChunkSize(WasmPointer ptr) const
following methods are needed mostly for testing purposes