From 4c66b1f5638f0fa8caf6e50aa83eddef8f8f4dd5 Mon Sep 17 00:00:00 2001 From: Steven Eker Date: Tue, 17 Dec 2024 01:25:41 +0100 Subject: [PATCH] initialize semispace on demand --- include/runtime/arena.h | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/include/runtime/arena.h b/include/runtime/arena.h index afbfca21b..5d71a56df 100644 --- a/include/runtime/arena.h +++ b/include/runtime/arena.h @@ -20,7 +20,6 @@ class arena { public: arena(char id) : allocation_semispace_id(id) { - initialize_semispace(); } ~arena() { @@ -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 @@ -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;