Skip to content

Commit

Permalink
turned arena_start_ptr() and arena_end_ptr() into member functions
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmeker committed Nov 15, 2024
1 parent 704840a commit a379fc8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
23 changes: 9 additions & 14 deletions include/runtime/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions runtime/alloc/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions runtime/lto/alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a379fc8

Please sign in to comment.