-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from csgordon/gcfixes
Adopt a couple fixes from @stephen-hansen and add tests for the bugs he found
- Loading branch information
Showing
4 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
data: | ||
|
||
code: | ||
triggerGC(recv): | ||
%cnt = 10 | ||
jump loopheader | ||
|
||
loopheader: | ||
if %cnt then doalloc else finish | ||
|
||
doalloc: | ||
%cnt = %cnt - 1 | ||
%blah = alloc(10) | ||
jump loopheader | ||
|
||
finish: | ||
ret 5 | ||
|
||
main: | ||
# Allocate for a diamond structure | ||
# We'll set up for: | ||
# a | ||
# / \ | ||
# b c | ||
# \ / | ||
# d | ||
%a = alloc(3) | ||
setelt(%a, 0, 0) | ||
%b = alloc(2) | ||
setelt(%b, 0, 0) | ||
%c = alloc(2) | ||
setelt(%c, 0, 0) | ||
%d = alloc(2) | ||
setelt(%d, 0, 0) | ||
|
||
# Create the diamond shape | ||
setelt(%a, 1, %b) | ||
setelt(%a, 2, %c) | ||
setelt(%b, 1, %d) | ||
setelt(%c, 1, %d) | ||
|
||
# get addresses for the slot maps for the GC | ||
%amap = %a - 8 | ||
%bmap = %b - 8 | ||
%cmap = %c - 8 | ||
%dmap = %d - 8 | ||
|
||
# Init a's slot map to b110 (6), b and c's to b010 (2), and d's to 2 (see below) | ||
store(%amap, 6) | ||
store(%bmap, 2) | ||
store(%cmap, 2) | ||
# Unlike previous gc tests, mark d's empty field as a pointer to check that the GC doesn't blindly dereference null | ||
# We'll overwrite it later before another GC (heap is 100 slots) so rest of test is unchanged | ||
store(%dmap, 2) | ||
setelt(%d, 1, 0) | ||
|
||
# Now we allocate enough to trigger a GC | ||
%lalala = call(triggerGC, 0) | ||
# At this point we've triggered a GC, which should have | ||
# preserved the diamond shape. | ||
# To check this we'll directly update d's value to 4096... | ||
setelt(%d, 1, 4096) | ||
|
||
# ... then check that following either path from a observes the same value | ||
%b2 = getelt(%a, 1) | ||
%dViab = getelt(%b2, 1) | ||
%c2 = getelt(%a, 2) | ||
%dViac = getelt(%c2, 1) | ||
|
||
# ... where by "check" we mean print for visual inspection | ||
%dvalViab = getelt(%dViab, 1) | ||
print(%dvalViab) | ||
%dvalViac = getelt(%dViac, 1) | ||
print(%dvalViac) | ||
ret %dvalViac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
data: | ||
|
||
code: | ||
triggerGC(recv): | ||
%cnt = 10 | ||
jump loopheader | ||
|
||
loopheader: | ||
if %cnt then doalloc else finish | ||
|
||
doalloc: | ||
%cnt = %cnt - 1 | ||
%blah = alloc(10) | ||
jump loopheader | ||
|
||
finish: | ||
ret 5 | ||
|
||
main: | ||
# Allocate for a diamond structure | ||
# We'll set up for: | ||
# a | ||
# / \ | ||
# b c | ||
# \ / | ||
# d | ||
%a = alloc(3) | ||
setelt(%a, 0, 0) | ||
%b = alloc(2) | ||
setelt(%b, 0, 0) | ||
%c = alloc(2) | ||
setelt(%c, 0, 0) | ||
%d = alloc(2) | ||
setelt(%d, 0, 0) | ||
|
||
# Create the diamond shape | ||
setelt(%a, 1, %b) | ||
setelt(%a, 2, %c) | ||
setelt(%b, 1, %d) | ||
setelt(%c, 1, %d) | ||
setelt(%d, 1, 47) | ||
|
||
# get addresses for the slot maps for the GC | ||
%amap = %a - 8 | ||
%bmap = %b - 8 | ||
%cmap = %c - 8 | ||
%dmap = %d - 8 | ||
|
||
# Init a's slot map to b110 (6), b and c's to b010 (2), and d's to 0 | ||
store(%amap, 6) | ||
store(%bmap, 2) | ||
store(%cmap, 2) | ||
store(%dmap, 0) | ||
|
||
# Now we allocate enough to trigger a GC | ||
%lalala = call(triggerGC, 0) | ||
|
||
|
||
# Now trigger *another* GC, to make sure we handle locals correctly on a second GC | ||
%lalala = call(triggerGC, 0) | ||
|
||
# At this point we've triggered a GC, which should have | ||
# preserved the diamond shape. | ||
# To check this we'll directly update d's value to 4096... | ||
setelt(%d, 1, 4096) | ||
|
||
# ... then check that following either path from a observes the same value | ||
%b2 = getelt(%a, 1) | ||
%dViab = getelt(%b2, 1) | ||
%c2 = getelt(%a, 2) | ||
%dViac = getelt(%c2, 1) | ||
|
||
# ... where by "check" we mean print for visual inspection | ||
%dvalViab = getelt(%dViab, 1) | ||
print(%dvalViab) | ||
%dvalViac = getelt(%dViac, 1) | ||
print(%dvalViac) | ||
ret %dvalViac | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters