Skip to content

Commit

Permalink
Add GC for Slice and Array
Browse files Browse the repository at this point in the history
Also fixed a bug with what children were getting freed for frames, arrays and so on because minusing 1 instead of headerSize
  • Loading branch information
JothamWong committed Apr 15, 2024
1 parent fb04d89 commit 27b0203
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/vm/oogavm-heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,10 +1180,11 @@ function mark(addr) {
mark(parent);
}
break;
case Tag.ARRAY:
case Tag.FRAME:
case Tag.ENVIRONMENT:
case Tag.STRUCT:
const numChildren = getSize(addr) - 1;
const numChildren = getSize(addr) - headerSize;
for (let i = 0; i < numChildren; i++) {
mark(getWord(addr + i + 1));
}
Expand All @@ -1199,6 +1200,11 @@ function mark(addr) {
mark(getWord(addr + headerSize + 1 + i));
}
break;
case Tag.SLICE:
for (let i = 0; i < getSliceLength(addr); i++) {
mark(getSliceValueAtIndex(addr, i));
}
break;
default:
// no special case for builtins, struct fields
return;
Expand Down Expand Up @@ -1320,6 +1326,13 @@ function updateReferences() {
setWord(curr + i + headerSize + 1, forwardedAddr);
}
break;
case Tag.SLICE:
for (let i = 0; i < getSliceLength(curr); i++) {
const originalChildAddr = getSliceValueAtIndex(curr, i);
const forwardedAddr = getForwardingAddress(originalChildAddr);
setSliceValue(curr, i, forwardedAddr);
}
break;
default:
// no special case for builtins, struct fields
break;
Expand Down

0 comments on commit 27b0203

Please sign in to comment.