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

Garbage collector reimplementation #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
fix UB in generation check for Gc.Page.collect
  • Loading branch information
garrisonhh committed Feb 11, 2023
commit 821ad9c4f30684596e4383c7d9891cd2db4845de
10 changes: 7 additions & 3 deletions src/Gc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const Object = struct {

/// tracks live objects in a block of memory
const Page = struct {
// TODO instead use powers of 4 or 8?
const SET_SIZE = PAGE_LEN << 1;
/// the index into StateSet that represents the first object
const SET_BASE = PAGE_LEN;
Expand Down Expand Up @@ -94,6 +93,11 @@ const Page = struct {
self.chalkboard.unset(bit.index - 1);
}

/// whether an object lives
fn lives(self: *Page, index: usize) bool {
return self.get(Bit.of(index + SET_BASE));
}

/// estimates how full this page is to determine whether it is 'saturated'
/// (should be collected)
fn isSaturated(self: *const Page) bool {
Expand Down Expand Up @@ -128,9 +132,9 @@ const Page = struct {
}

for (self.data) |*obj, index| {
if (obj.generation != gen) {
obj.value.deinit(ally);
if (self.lives(index) and obj.generation != gen) {
self.setFree(index);
obj.value.deinit(ally);
}
}
}
Expand Down