25
#include "precompiled.hpp"
26
#include "gc/shared/bufferNode.hpp"
27
#include "utilities/debug.hpp"
28
#include "memory/allocation.inline.hpp"
32
BufferNode::AllocatorConfig::AllocatorConfig(size_t size)
33
: _buffer_capacity(size)
35
assert(size >= 1, "Invalid buffer capacity %zu", size);
36
assert(size <= max_size(), "Invalid buffer capacity %zu", size);
39
void* BufferNode::AllocatorConfig::allocate() {
40
size_t byte_size = buffer_capacity() * sizeof(void*);
41
return NEW_C_HEAP_ARRAY(char, buffer_offset() + byte_size, mtGC);
44
void BufferNode::AllocatorConfig::deallocate(void* node) {
45
assert(node != nullptr, "precondition");
46
FREE_C_HEAP_ARRAY(char, node);
49
BufferNode::Allocator::Allocator(const char* name, size_t buffer_capacity) :
50
_config(buffer_capacity),
51
_free_list(name, &_config)
54
size_t BufferNode::Allocator::free_count() const {
55
return _free_list.free_count();
58
BufferNode* BufferNode::Allocator::allocate() {
59
auto internal_capacity = static_cast<InternalSizeType>(buffer_capacity());
60
return ::new (_free_list.allocate()) BufferNode(internal_capacity);
63
void BufferNode::Allocator::release(BufferNode* node) {
64
assert(node != nullptr, "precondition");
65
assert(node->next() == nullptr, "precondition");
66
assert(node->capacity() == buffer_capacity(),
67
"Wrong size %zu, expected %zu", node->capacity(), buffer_capacity());
69
_free_list.release(node);