Skip to content

Fix makeGray misuse in GC (#2178) #2285

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 13 additions & 11 deletions std/assembly/rt/itcms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ function initLazy(space: Object): Object {
this.unlink();
this.linkTo(toSpace, this.isPointerfree ? i32(!white) : gray);
}

/** Marks this object need to be scanned */
needScan(): void {
if (state == STATE_MARK) {
this.makeGray();
} else {
this.unlink();
this.linkTo(fromSpace, white);
}
}
}

/** Visits all objects considered to be program roots. */
Expand Down Expand Up @@ -301,10 +311,10 @@ export function __link(parentPtr: usize, childPtr: usize, expectMultiple: bool):
if (expectMultiple) {
// Move the barrier "backward". Suitable for containers receiving multiple stores.
// Avoids a barrier for subsequent objects stored into the same container.
parent.makeGray();
parent.needScan();
} else {
// Move the barrier "forward". Suitable for objects receiving isolated stores.
child.makeGray();
child.needScan();
}
} else if (parentColor == transparent && state == STATE_MARK) {
// Pinned objects are considered 'black' during the mark phase.
Expand Down Expand Up @@ -350,15 +360,7 @@ export function __unpin(ptr: usize): void {
if (obj.color != transparent) {
throw new Error(E_NOT_PINNED);
}
if (state == STATE_MARK) {
// We may be right at the point after marking roots for the second time and
// entering the sweep phase, in which case the object would be missed if it
// is not only pinned but also a root. Make sure it isn't missed.
obj.makeGray();
} else {
obj.unlink();
obj.linkTo(fromSpace, white);
}
obj.needScan();
}

// @ts-ignore: decorator
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/call-super.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
if
i32.const 0
i32.const 144
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1488,7 +1488,7 @@
if
i32.const 0
i32.const 144
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2071,7 +2071,7 @@
if
i32.const 80
i32.const 144
i32.const 260
i32.const 270
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/call-super.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
if
i32.const 0
i32.const 1168
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -846,7 +846,7 @@
if
i32.const 0
i32.const 1168
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1073,7 +1073,7 @@
if
i32.const 1104
i32.const 1168
i32.const 260
i32.const 270
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/class-implements.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
if
i32.const 0
i32.const 96
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1490,7 +1490,7 @@
if
i32.const 0
i32.const 96
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2073,7 +2073,7 @@
if
i32.const 32
i32.const 96
i32.const 260
i32.const 270
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/class-implements.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
if
i32.const 0
i32.const 1120
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -860,7 +860,7 @@
if
i32.const 0
i32.const 1120
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/class-overloading-cast.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
if
i32.const 0
i32.const 96
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1499,7 +1499,7 @@
if
i32.const 0
i32.const 96
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2082,7 +2082,7 @@
if
i32.const 32
i32.const 96
i32.const 260
i32.const 270
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/class-overloading-cast.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
if
i32.const 0
i32.const 1120
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -882,7 +882,7 @@
if
i32.const 0
i32.const 1120
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/class-overloading.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
if
i32.const 0
i32.const 128
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1505,7 +1505,7 @@
if
i32.const 0
i32.const 128
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2088,7 +2088,7 @@
if
i32.const 64
i32.const 128
i32.const 260
i32.const 270
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/class-overloading.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
if
i32.const 0
i32.const 1152
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -906,7 +906,7 @@
if
i32.const 0
i32.const 1152
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down
28 changes: 22 additions & 6 deletions tests/compiler/class.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
if
i32.const 0
i32.const 96
i32.const 159
i32.const 169
i32.const 16
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1601,7 +1601,7 @@
if
i32.const 0
i32.const 96
i32.const 228
i32.const 238
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2184,7 +2184,7 @@
if
i32.const 32
i32.const 96
i32.const 260
i32.const 270
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2227,6 +2227,22 @@
memory.fill
local.get $3
)
(func $~lib/rt/itcms/Object#needScan (param $0 i32)
global.get $~lib/rt/itcms/state
i32.const 1
i32.eq
if
local.get $0
call $~lib/rt/itcms/Object#makeGray
else
local.get $0
call $~lib/rt/itcms/Object#unlink
local.get $0
global.get $~lib/rt/itcms/fromSpace
global.get $~lib/rt/itcms/white
call $~lib/rt/itcms/Object#linkTo
end
)
(func $~lib/rt/itcms/__link (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
Expand All @@ -2243,7 +2259,7 @@
if
i32.const 0
i32.const 96
i32.const 294
i32.const 304
i32.const 14
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2272,10 +2288,10 @@
local.get $2
if
local.get $4
call $~lib/rt/itcms/Object#makeGray
call $~lib/rt/itcms/Object#needScan
else
local.get $3
call $~lib/rt/itcms/Object#makeGray
call $~lib/rt/itcms/Object#needScan
end
else
local.get $5
Expand Down
Loading