Add some more API.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
21 #include "PoolAllocator.h"
26 PoolAllocator::PoolAllocator()
32 PoolAllocator::~PoolAllocator()
40 PoolAllocator::enter()
48 PoolAllocator::leave(char *pos)
54 PoolAllocator::unwind(char *pos)
57 if (pos && pos >= last_->base && pos < last_->end)
59 Pool *prev = last_->prev;
61 if (last_->size() <= kMaxReserveSize &&
62 (!reserved_ || reserved_->size() < last_->size()))
83 PoolAllocator::slowAllocate(size_t actualBytes)
85 size_t bytesNeeded = actualBytes + sizeof(Pool);
86 if (bytesNeeded < kDefaultPoolSize)
87 bytesNeeded = kDefaultPoolSize;
90 if (reserved_ && reserved_->size() >= bytesNeeded) {
94 pool = (Pool *)malloc(bytesNeeded);
96 throw std::bad_alloc();
97 pool->base = (char *)(pool + 1);
98 pool->end = (char *)pool + bytesNeeded;
100 pool->ptr = pool->base + actualBytes;
107 PoolAllocationPolicy::reportOutOfMemory()
114 PoolAllocationPolicy::reportAllocationOverflow()
121 PoolAllocationPolicy::malloc(size_t bytes)
123 void *ptr = ZONE()->pool().allocate(bytes);
130 PoolAllocationPolicy::free(void *ptr)