Handle-ize BytecodeEmitter.
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/.
18 #ifndef _include_jitcraft_spaces_h_
19 #define _include_jitcraft_spaces_h_
26 static const size_t kObjectAlignment = 8;
28 // The heap stack is designed for structures which are known to not escape the
29 // program stack, and can thus be quickly allocated in a LIFO manner.
33 OS::AlignableMapping map_;
39 static const size_t kStackSize = 1024 * 1024;
47 Address position() const {
50 inline Address allocate(size_t nbytes);
51 inline void unwind(Address to);
58 // Base address, from OS::AlignableMapping.
61 // End of the allocated region.
64 // Current allocation point.
68 static const size_t kMaxObjectSize = 1 * kGB;
69 static const size_t kDefaultSize = 256 * kKB;
70 static const size_t kAlignment = 256 * kKB;
72 // All objects must be allocated in the first kAlignment bytes of the
73 // chunk. Every object is at least 8 bytes (kPointerAlignment), so we
74 // reserve one mark bit for every possible object address in the chunk
75 // (including, for simplicity, unallocatable addresses at the start).
77 // The number of mark bits needed is:
79 // MaxObjectsPerChunk = kAlignment / kPointerAlignment
82 // The number of bytes needed for these mark bits is:
84 // NumMarkBytes = MaxObjectsPerChunk / 8
87 // The number of uint32s needed to store these bytes is:
89 // NumMarkWords = NumMarkBytes / sizeof(uint32)
91 static const size_t kMaxObjectsPerChunk = kAlignment / kObjectAlignment;
92 static const size_t kMarkBits = kMaxObjectsPerChunk;
93 static const size_t kMarkBytes = kMarkBits / 8;
94 static const size_t kMarkWords = kMarkBytes / sizeof(uint32);
96 static inline size_t offsetToMarkBits()
98 return Align(sizeof(HeapChunk), kObjectAlignment);
101 static inline size_t offsetToFirst()
103 assert(IsAligned(kMarkBytes, kObjectAlignment));
104 return offsetToMarkBits() + kMarkBytes;
108 static HeapChunk *New(HeapChunk *prev, size_t size);
109 static void Destroy(HeapChunk *chunk);
112 inline Address allocate(size_t nbytes);
124 return end() - base();
127 return reinterpret_cast<Address>(this) + offsetToFirst();
130 return reinterpret_cast<uint32 *>(reinterpret_cast<Address>(this) +
147 inline Address allocate(size_t nbytes);
148 Address allocateSlow(size_t nbytes);
153 #endif // _include_jitcraft_spaces_h_