Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change arena end ptr #1177

Merged
merged 28 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2f69066
use std::swap
stevenmeker Nov 19, 2024
fa25f36
make megabye_malloc() private member function; added data members cur…
stevenmeker Nov 19, 2024
a94b6a9
make ptr_diff() a simple subtraction
stevenmeker Nov 20, 2024
259290d
reimplement class arena
stevenmeker Nov 21, 2024
41a9975
deleted decl for megabyte_malloc(), fresh_block(), code cleaning
stevenmeker Nov 21, 2024
30a0b71
added initialize_semispace() to avoid relying on UB for initializatio…
stevenmeker Nov 22, 2024
62a8ee7
keep track of notional number of blocks in each semispace
stevenmeker Nov 22, 2024
3d5ebe8
more accurate simulation of old collection policy; deleted slow_alloc…
stevenmeker Nov 23, 2024
31321ea
used just a pointer addition for move_ptr()
stevenmeker Nov 25, 2024
f3972a9
made move_ptr() inline and added check for end of allocation
stevenmeker Nov 26, 2024
d8ef882
disable garbage collection to try and isolate bug
stevenmeker Nov 26, 2024
4318df9
re-enabled garbage collection - inifinte loop problem has disappeared
stevenmeker Nov 26, 2024
7a2df99
fixed formatting
stevenmeker Nov 27, 2024
a75b285
deleted MEM_BLOCK_START; removed corner case from collector
stevenmeker Nov 28, 2024
e27ec1b
fix call to initialize_semispace()
stevenmeker Dec 3, 2024
6af3f6b
deleted dead code youngspace_size() and arena_size()
stevenmeker Dec 4, 2024
bfba1ca
replaced memory_block_header and associated functionality
stevenmeker Dec 4, 2024
8e31c96
fix formatting; clean code and comments
stevenmeker Dec 4, 2024
9f2e3aa
fix formatting
stevenmeker Dec 4, 2024
98b8404
make arena_end_ptr() return char *
stevenmeker Dec 5, 2024
20c2006
Merge branch 'develop' into change_arena_end_ptr
stevenmeker Dec 6, 2024
a36e28f
pass reference to arena rather than arena end pointer
stevenmeker Dec 7, 2024
f871d8c
Merge branch 'develop' into change_arena_end_ptr
stevenmeker Dec 7, 2024
652637d
make evacuate() a member function of arena
stevenmeker Dec 7, 2024
aa1b445
make extern decls of youngspace and oldspace thread_local
stevenmeker Dec 9, 2024
7ecb011
Merge branch 'develop' into change_arena_end_ptr
stevenmeker Dec 9, 2024
52e182e
Remove static from REGISTER_ARENA
stevenmeker Dec 9, 2024
8c627bc
fix formatting
stevenmeker Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions include/runtime/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class arena {
initialize_semispace();
}

char *evacuate(char *scan_ptr);

// Allocates the requested number of bytes as a contiguous region and returns a
// pointer to the first allocated byte.
void *kore_arena_alloc(size_t requested);
Expand All @@ -33,7 +35,7 @@ class arena {
// Returns a pointer to a location holding the address of last allocated
// byte in the given arena plus 1.
// This address is nullptr if nothing has been allocated ever in that arena.
char **arena_end_ptr() { return &allocation_ptr; }
char *arena_end_ptr() { return allocation_ptr; }

// Clears the current allocation space by setting its start back to its first
// block. It is used during garbage collection to effectively collect all of the
Expand Down Expand Up @@ -73,9 +75,9 @@ class arena {
// 3rd argument: the address of last allocated byte in the arena plus 1
// Return value: starting pointer + size unless this points to unallocated space
// in which case nullptr is returned
static char *move_ptr(char *ptr, size_t size, char const *arena_end_ptr) {
static char *move_ptr(char *ptr, size_t size, char const *end_ptr) {
char *next_ptr = ptr + size;
return (next_ptr == arena_end_ptr) ? nullptr : next_ptr;
return (next_ptr == end_ptr) ? nullptr : next_ptr;
}

// Returns the ID of the semispace where the given address was allocated.
Expand Down Expand Up @@ -132,7 +134,7 @@ inline char arena::get_arena_semispace_id_of_object(void *ptr) {

// Macro to define a new arena with the given ID. Supports IDs ranging from 0 to
// 127.
#define REGISTER_ARENA(name, id) static thread_local arena name(id)
#define REGISTER_ARENA(name, id) thread_local arena name(id)

#ifdef __MACH__
//
Expand Down
1 change: 1 addition & 0 deletions runtime/alloc/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "runtime/alloc.h"
#include "runtime/arena.h"
#include "runtime/collect.h"
#include "runtime/header.h"

extern size_t const VAR_BLOCK_SIZE = BLOCK_SIZE;
Expand Down
22 changes: 11 additions & 11 deletions runtime/collect/collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <cstring>

extern "C" {
extern thread_local arena youngspace;
extern thread_local arena oldspace;

char **young_alloc_ptr(void);
char **old_alloc_ptr(void);
char *youngspace_ptr(void);
char *oldspace_ptr(void);

Expand Down Expand Up @@ -245,7 +245,7 @@ static void migrate_root(void *curr_block, layoutitem *args, unsigned i) {
}
}

static char *evacuate(char *scan_ptr, char **alloc_ptr) {
char *arena::evacuate(char *scan_ptr) {
auto *curr_block = (block *)scan_ptr;
uint64_t const hdr = curr_block->h.hdr;
uint16_t layout_int = layout_hdr(hdr);
Expand All @@ -255,7 +255,7 @@ static char *evacuate(char *scan_ptr, char **alloc_ptr) {
migrate_child(curr_block, layout_data->args, i, false);
}
}
return arena::move_ptr(scan_ptr, get_size(hdr, layout_int), *alloc_ptr);
return move_ptr(scan_ptr, get_size(hdr, layout_int), arena_end_ptr());
}

// Contains the decision logic for collecting the old generation.
Expand Down Expand Up @@ -293,43 +293,43 @@ void kore_collect(
if (!last_alloc_ptr) {
last_alloc_ptr = youngspace_ptr();
}
char *current_alloc_ptr = *young_alloc_ptr();
char *current_alloc_ptr = youngspace.arena_end_ptr();
#endif
kore_alloc_swap(collect_old);
#ifdef GC_DBG
for (int i = 0; i < 2048; i++) {
numBytesLiveAtCollection[i] = 0;
}
#endif
char *previous_oldspace_alloc_ptr = *old_alloc_ptr();
char *previous_oldspace_alloc_ptr = oldspace.arena_end_ptr();
for (int i = 0; i < nroots; i++) {
migrate_root(roots, type_info, i);
}
migrate_static_roots();
char *scan_ptr = youngspace_ptr();
if (scan_ptr != *young_alloc_ptr()) {
if (scan_ptr != youngspace.arena_end_ptr()) {
MEM_LOG("Evacuating young generation\n");
while (scan_ptr) {
scan_ptr = evacuate(scan_ptr, young_alloc_ptr());
scan_ptr = youngspace.evacuate(scan_ptr);
}
}
if (collect_old || !previous_oldspace_alloc_ptr) {
scan_ptr = oldspace_ptr();
} else {
scan_ptr = previous_oldspace_alloc_ptr;
}
if (scan_ptr != *old_alloc_ptr()) {
if (scan_ptr != oldspace.arena_end_ptr()) {
MEM_LOG("Evacuating old generation\n");
while (scan_ptr) {
scan_ptr = evacuate(scan_ptr, old_alloc_ptr());
scan_ptr = oldspace.evacuate(scan_ptr);
}
}
#ifdef GC_DBG
ssize_t numBytesAllocedSinceLastCollection
= arena::ptr_diff(current_alloc_ptr, last_alloc_ptr);
assert(numBytesAllocedSinceLastCollection >= 0);
fwrite(&numBytesAllocedSinceLastCollection, sizeof(ssize_t), 1, stderr);
last_alloc_ptr = *young_alloc_ptr();
last_alloc_ptr = youngspace.arena_end_ptr();
fwrite(
numBytesLiveAtCollection, sizeof(numBytesLiveAtCollection[0]),
sizeof(numBytesLiveAtCollection) / sizeof(numBytesLiveAtCollection[0]),
Expand Down
10 changes: 1 addition & 9 deletions runtime/lto/alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ char *oldspace_ptr() {
return oldspace.arena_start_ptr();
}

char **young_alloc_ptr() {
return youngspace.arena_end_ptr();
}

char **old_alloc_ptr() {
return oldspace.arena_end_ptr();
}

char youngspace_collection_id() {
return youngspace.get_arena_collection_semispace_id();
}
Expand Down Expand Up @@ -81,7 +73,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 != *(youngspace.arena_end_ptr()) - 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
Loading