diff --git a/include/runtime/arena.h b/include/runtime/arena.h index c9c55e08a..220f8030b 100644 --- a/include/runtime/arena.h +++ b/include/runtime/arena.h @@ -14,6 +14,15 @@ class arena { public: arena(char id) : allocation_semispace_id(id) {} void *kore_arena_alloc(size_t requested); + + // Returns the address of the first byte that belongs in the given arena. + // Returns 0 if nothing has been allocated ever in that arena. + char *arena_start_ptr() const; + + // Returns a pointer to a location holding the address of last allocated + // byte in the given arena plus 1. + // This address is 0 if nothing has been allocated ever in that arena. + char **arena_end_ptr(); // return the total number of allocatable bytes currently in the arena in its // active semispace. @@ -55,12 +64,6 @@ class arena { size_t num_blocks; size_t num_collection_blocks; char allocation_semispace_id; - // - // These functions need to be friends because they are called from LLVM code. - // - friend char *arena_start_ptr(const arena *arena); - friend char **arena_end_ptr(arena *arena); - //friend bool youngspace_almost_full(size_t threshold); }; using memory_block_header = struct { @@ -112,14 +115,6 @@ inline void return result; } -// Returns the address of the first byte that belongs in the given arena. -// Returns 0 if nothing has been allocated ever in that arena. -char *arena_start_ptr(const arena *); - -// Returns a pointer to a location holding the address of last allocated -// byte in the given arena plus 1. -// This address is 0 if nothing has been allocated ever in that arena. -char **arena_end_ptr(arena *); // Given a starting pointer to an address allocated in an arena and a size in // bytes, this function returns a pointer to an address allocated in the diff --git a/runtime/alloc/arena.cpp b/runtime/alloc/arena.cpp index f22928df6..0342bf0d0 100644 --- a/runtime/alloc/arena.cpp +++ b/runtime/alloc/arena.cpp @@ -189,13 +189,14 @@ __attribute__((always_inline)) void arena::arena_clear() { } __attribute__((always_inline)) char * -arena_start_ptr(const arena *arena) { - return arena->first_block ? arena->first_block + sizeof(memory_block_header) - : nullptr; +arena::arena_start_ptr() const { + return first_block ? first_block + sizeof(memory_block_header) + : nullptr; } -__attribute__((always_inline)) char **arena_end_ptr(arena *arena) { - return &arena->block; +__attribute__((always_inline)) char ** +arena::arena_end_ptr() { + return █ } char *move_ptr(char *ptr, size_t size, char const *arena_end_ptr) { diff --git a/runtime/lto/alloc.cpp b/runtime/lto/alloc.cpp index 289e55a2f..0cd79a3f8 100644 --- a/runtime/lto/alloc.cpp +++ b/runtime/lto/alloc.cpp @@ -16,19 +16,19 @@ REGISTER_ARENA(oldspace, OLDSPACE_ID); REGISTER_ARENA(alwaysgcspace, ALWAYSGCSPACE_ID); char *youngspace_ptr() { - return arena_start_ptr(&youngspace); + return youngspace.arena_start_ptr(); } char *oldspace_ptr() { - return arena_start_ptr(&oldspace); + return oldspace.arena_start_ptr(); } char **young_alloc_ptr() { - return arena_end_ptr(&youngspace); + return youngspace.arena_end_ptr(); } char **old_alloc_ptr() { - return arena_end_ptr(&oldspace); + return oldspace.arena_end_ptr(); } char youngspace_collection_id() { @@ -85,7 +85,7 @@ kore_resize_last_alloc(void *oldptr, size_t newrequest, size_t last_size) { newrequest = (newrequest + 7) & ~7; last_size = (last_size + 7) & ~7; - if (oldptr != *arena_end_ptr(&youngspace) - last_size) { + if (oldptr != *(youngspace.arena_end_ptr()) - last_size) { MEM_LOG( "May only reallocate last allocation. Tried to reallocate %p to %zd\n", oldptr, newrequest);