Skip to content

Commit 7e9e6ab

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 75e2959 + 790cab9 commit 7e9e6ab

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

include/runtime/arena.h

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ size_t const HYPERBLOCK_SIZE = (size_t)BLOCK_SIZE * 1024 * 1024;
1919
class arena {
2020
public:
2121
arena(char id)
22-
: allocation_semispace_id(id) {
23-
initialize_semispace();
24-
}
22+
: allocation_semispace_id(id) { }
2523

2624
~arena() {
27-
munmap(current_addr_ptr, HYPERBLOCK_SIZE);
25+
if (current_addr_ptr)
26+
munmap(current_addr_ptr, HYPERBLOCK_SIZE);
2827
if (collection_addr_ptr)
2928
munmap(collection_addr_ptr, HYPERBLOCK_SIZE);
3029
}
@@ -111,11 +110,12 @@ class arena {
111110
//
112111
// Current semispace where allocations are being made.
113112
//
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
119119
char allocation_semispace_id; // id of current semispace
120120
//
121121
// Semispace where allocations will be made during and after garbage collect.
@@ -155,18 +155,25 @@ extern thread_local bool time_for_collection;
155155
size_t get_gc_threshold();
156156

157157
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) {
163159
//
164-
time_for_collection = true;
160+
// Semispace not yet initialized.
165161
//
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+
}
170177
}
171178
void *result = allocation_ptr;
172179
allocation_ptr += requested;

0 commit comments

Comments
 (0)