Skip to content

Commit

Permalink
initialize semispace on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmeker committed Dec 17, 2024
1 parent dafdb9a commit 4c66b1f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions include/runtime/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class arena {
public:
arena(char id)
: allocation_semispace_id(id) {
initialize_semispace();
}

~arena() {
Expand Down Expand Up @@ -111,9 +110,9 @@ class arena {
//
// Current semispace where allocations are being made.
//
char *current_addr_ptr; // pointer to start of current address space
char *allocation_ptr; // next available location in current semispace
char *tripwire; // allocating past this triggers slow allocation
char *current_addr_ptr = nullptr; // pointer to start of current address space
char *allocation_ptr = nullptr; // next available location in current semispace
char *tripwire = nullptr; // allocating past this triggers slow allocation
mutable size_t
num_blocks; // notional number of BLOCK_SIZE blocks in current semispace
char allocation_semispace_id; // id of current semispace
Expand Down Expand Up @@ -155,18 +154,26 @@ extern thread_local bool time_for_collection;
size_t get_gc_threshold();

inline void *arena::kore_arena_alloc(size_t requested) {
if (allocation_ptr + requested >= tripwire) {
//
// We got close to or past the last location accessed in this address range so far,
// depending on the requested size and tripwire setting. This triggers a garbage
// collect when allowed.
//
time_for_collection = true;
if (tripwire == nullptr) {
//
// We move the tripwire to 1 past the end of our hyperblock so that we have
// a well defined comparison that will always be false until the next arena swap.
// Semispace not yet initialized.
//
tripwire = current_addr_ptr + HYPERBLOCK_SIZE;
initialize_semispace();
}
else if (allocation_ptr + requested >= tripwire) {
{
//
// We got close to or past the last location accessed in this address range so far,
// depending on the requested size and tripwire setting. This triggers a garbage
// collect when allowed.
//
time_for_collection = true;
//
// We move the tripwire to 1 past the end of our hyperblock so that we have
// a well defined comparison that will always be false until the next arena swap.
//
tripwire = current_addr_ptr + HYPERBLOCK_SIZE;
}
}
void *result = allocation_ptr;
allocation_ptr += requested;
Expand Down

0 comments on commit 4c66b1f

Please sign in to comment.