@@ -19,12 +19,11 @@ size_t const HYPERBLOCK_SIZE = (size_t)BLOCK_SIZE * 1024 * 1024;
19
19
class arena {
20
20
public:
21
21
arena (char id)
22
- : allocation_semispace_id(id) {
23
- initialize_semispace ();
24
- }
22
+ : allocation_semispace_id(id) { }
25
23
26
24
~arena () {
27
- munmap (current_addr_ptr, HYPERBLOCK_SIZE);
25
+ if (current_addr_ptr)
26
+ munmap (current_addr_ptr, HYPERBLOCK_SIZE);
28
27
if (collection_addr_ptr)
29
28
munmap (collection_addr_ptr, HYPERBLOCK_SIZE);
30
29
}
@@ -111,11 +110,12 @@ class arena {
111
110
//
112
111
// Current semispace where allocations are being made.
113
112
//
114
- char *current_addr_ptr; // pointer to start of current address space
115
- char *allocation_ptr; // next available location in current semispace
116
- char *tripwire; // allocating past this triggers slow allocation
117
- mutable size_t
118
- num_blocks; // notional number of BLOCK_SIZE blocks in current semispace
113
+ char *current_addr_ptr = nullptr ; // pointer to start of current address space
114
+ char *allocation_ptr
115
+ = nullptr ; // next available location in current semispace
116
+ char *tripwire = nullptr ; // allocating past this triggers slow allocation
117
+ mutable size_t num_blocks
118
+ = 0 ; // notional number of BLOCK_SIZE blocks in current semispace
119
119
char allocation_semispace_id; // id of current semispace
120
120
//
121
121
// Semispace where allocations will be made during and after garbage collect.
@@ -155,18 +155,25 @@ extern thread_local bool time_for_collection;
155
155
size_t get_gc_threshold ();
156
156
157
157
inline void *arena::kore_arena_alloc (size_t requested) {
158
- if (allocation_ptr + requested >= tripwire) {
159
- //
160
- // We got close to or past the last location accessed in this address range so far,
161
- // depending on the requested size and tripwire setting. This triggers a garbage
162
- // collect when allowed.
158
+ if (tripwire == nullptr ) {
163
159
//
164
- time_for_collection = true ;
160
+ // Semispace not yet initialized.
165
161
//
166
- // We move the tripwire to 1 past the end of our hyperblock so that we have
167
- // a well defined comparison that will always be false until the next arena swap.
168
- //
169
- tripwire = current_addr_ptr + HYPERBLOCK_SIZE;
162
+ initialize_semispace ();
163
+ } else if (allocation_ptr + requested >= tripwire) {
164
+ {
165
+ //
166
+ // We got close to or past the last location accessed in this address range so far,
167
+ // depending on the requested size and tripwire setting. This triggers a garbage
168
+ // collect when allowed.
169
+ //
170
+ time_for_collection = true ;
171
+ //
172
+ // We move the tripwire to 1 past the end of our hyperblock so that we have
173
+ // a well defined comparison that will always be false until the next arena swap.
174
+ //
175
+ tripwire = current_addr_ptr + HYPERBLOCK_SIZE;
176
+ }
170
177
}
171
178
void *result = allocation_ptr;
172
179
allocation_ptr += requested;
0 commit comments