Fix Linux build.
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)
31 uintptr_t untagged = reinterpret_cast<uintptr_t>(address);
32 assert(IsAligned(untagged, kObjectAlignment));
35 Object *obj = reinterpret_cast<Object *>(address);
41 Heap::newObject(size_t bytes, Tenure age)
43 if (bytes >= HeapChunk::kLargeObjectThreshold)
44 return newLargeObject(bytes);
46 if (age == Tenure_Stack) {
47 if (Address addr = newStackObject(bytes))
52 if (age == Tenure_Default) {
53 if (Address addr = newSpace_.allocate(bytes))
57 if (Address addr = newSpace_.allocate(bytes))
62 // Try an old-space allocation.
63 if (Address addr = newOldObject(bytes))
66 // Uh-oh - perform a last-ditch collection.
69 return newOldObject(bytes);
73 Heap::allocate(Handle<Map> map, size_t bytes, Tenure age)
75 size_t actualBytes = Align(bytes, kObjectAlignment);
77 // All objects must be at least two words.
78 assert(actualBytes >= sizeof(Object *) * 2);
80 Address address = newObject(actualBytes, age);
85 return InitAddressIntoObject(address, map);
89 Heap::newStackObject(size_t bytes)
91 return lifoSpace_.allocate(bytes);
95 Heap::newOldObject(size_t bytes)
97 return oldSpace_.allocate(bytes);
101 Heap::newLargeObject(size_t bytes)
103 if (Address address = largeSpace_.allocate(bytes))
108 return largeSpace_.allocate(bytes);
112 Object::write(Zone *zone, Object **ptr, Object *obj)
119 #endif // _include_jitcraft_heap_inl_h_