Added clang support. A lot of the motion here is introducing a new offsetof because clang's seems broken?
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_jitcraft_heap_inl_h_
20 #define _include_jitcraft_heap_inl_h_
23 #include "Spaces-inl.h"
27 static inline Object *
28 InitAddressIntoObject(Address address, Map *map)
30 uintptr_t untagged = reinterpret_cast<uintptr_t>(address);
31 assert(IsAligned(untagged, kObjectAlignment));
33 Object *obj = reinterpret_cast<Object *>(address);
39 Heap::newObject(size_t bytes, Tenure age)
41 if (bytes >= HeapChunk::kLargeObjectThreshold)
42 return newLargeObject(bytes);
44 if (age == Tenure_Stack) {
45 if (Address addr = newStackObject(bytes))
50 if (age == Tenure_Default) {
51 if (Address addr = newSpace_.allocate(bytes))
55 if (Address addr = newSpace_.allocate(bytes))
60 // Try an old-space allocation.
61 if (Address addr = newOldObject(bytes))
64 // Uh-oh - perform a last-ditch collection.
67 return newOldObject(bytes);
71 Heap::allocate(Handle<Map> map, size_t bytes, Tenure age)
73 size_t actualBytes = Align(bytes, kObjectAlignment);
75 // All objects must be at least two words.
76 assert(actualBytes >= sizeof(Object *) * 2);
78 Address address = newObject(actualBytes, age);
83 return InitAddressIntoObject(address, map);
87 Heap::newStackObject(size_t bytes)
89 return lifoSpace_.allocate(bytes);
93 Heap::newOldObject(size_t bytes)
95 return oldSpace_.allocate(bytes);
99 Heap::newLargeObject(size_t bytes)
101 if (Address address = largeSpace_.allocate(bytes))
106 return largeSpace_.allocate(bytes);
110 Object::write(Zone *zone, Object **ptr, Object *obj)
117 #endif // _include_jitcraft_heap_inl_h_