Added clang support. A lot of the motion here is introducing a new offsetof because clang's seems broken?
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 ZONE()->reportOutOfMemory();
99 pool->base = (char *)(pool + 1);
100 pool->end = (char *)pool + bytesNeeded;
102 pool->ptr = pool->base + actualBytes;
109 PoolAllocationPolicy::reportOutOfMemory()
111 ZONE()->reportOutOfMemory();
115 PoolAllocationPolicy::reportAllocationOverflow()
117 ZONE()->reportError(Message_AllocationOverflow);
121 PoolAllocationPolicy::malloc(size_t bytes)
123 return ZONE()->pool().allocate(bytes);
127 PoolAllocationPolicy::free(void *ptr)