Skip to content

Propagate mark after visiting pinned objects in minimal runtime #1650

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

Merged
merged 2 commits into from
Jan 31, 2021
Merged
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
12 changes: 8 additions & 4 deletions std/assembly/rt/itcms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ function initLazy(space: Object): Object {
/** Visits all objects considered to be program roots. */
function visitRoots(cookie: u32): void {
__visit_globals(cookie);
var iter = pinSpace.next;
while (iter != pinSpace) {
var pn = pinSpace;
var iter = pn.next;
while (iter != pn) {
if (DEBUG) assert(iter.color == transparent);
__visit_members(changetype<usize>(iter) + TOTAL_OVERHEAD, cookie);
iter = iter.next;
}
Expand Down Expand Up @@ -204,8 +206,10 @@ function step(): usize {
visitStack(VISIT_SCAN);
obj = iter.next;
while (obj != toSpace) {
obj.color = black;
__visit_members(changetype<usize>(obj) + TOTAL_OVERHEAD, VISIT_SCAN);
if (obj.color != black) {
obj.color = black;
__visit_members(changetype<usize>(obj) + TOTAL_OVERHEAD, VISIT_SCAN);
}
obj = obj.next;
}
let from = fromSpace;
Expand Down
24 changes: 12 additions & 12 deletions std/assembly/rt/tcms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,24 @@ export function __unpin(ptr: usize): void {
export function __collect(): void {
if (TRACE) trace("GC at", 1, total);

// Mark roots and add to toSpace
// Mark roots (add to toSpace)
__visit_globals(VISIT_SCAN);

// Mark what's reachable from roots
var black = i32(!white);
var to = toSpace;
var iter = to.next;
while (iter != to) {
if (DEBUG) assert(iter.color == black);
// Mark direct members of pinned objects (add to toSpace)
var pn = pinSpace;
var iter = pn.next;
while (iter != pn) {
if (DEBUG) assert(iter.color == transparent);
__visit_members(changetype<usize>(iter) + TOTAL_OVERHEAD, VISIT_SCAN);
iter = iter.next;
}

// Mark what's reachable from pinned objects
var pn = pinSpace;
iter = pn.next;
while (iter != pn) {
if (DEBUG) assert(iter.color == transparent);
// Mark what's reachable from toSpace
var black = i32(!white);
var to = toSpace;
iter = to.next;
while (iter != to) {
if (DEBUG) assert(iter.color == black);
__visit_members(changetype<usize>(iter) + TOTAL_OVERHEAD, VISIT_SCAN);
iter = iter.next;
}
Expand Down
40 changes: 32 additions & 8 deletions tests/compiler/call-super.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,36 @@
)
(func $~lib/rt/itcms/visitRoots
(local $0 i32)
(local $1 i32)
i32.const 1296
call $~lib/rt/itcms/__visit
i32.const 1104
call $~lib/rt/itcms/__visit
global.get $~lib/rt/itcms/pinSpace
local.tee $1
i32.load offset=4
i32.const -4
i32.and
local.set $0
loop $while-continue|0
local.get $0
global.get $~lib/rt/itcms/pinSpace
local.get $1
i32.ne
if
local.get $0
i32.load offset=4
i32.const 3
i32.and
i32.const 3
i32.ne
if
i32.const 0
i32.const 1168
i32.const 159
i32.const 16
call $~lib/builtins/abort
unreachable
end
local.get $0
i32.const 20
i32.add
Expand Down Expand Up @@ -969,13 +985,21 @@
global.get $~lib/rt/itcms/toSpace
i32.ne
if
local.get $0
local.get $1
call $~lib/rt/itcms/Object#set:color
local.get $0
i32.const 20
i32.add
call $~lib/rt/__visit_members
i32.load offset=4
i32.const 3
i32.and
i32.ne
if
local.get $0
local.get $1
call $~lib/rt/itcms/Object#set:color
local.get $0
i32.const 20
i32.add
call $~lib/rt/__visit_members
end
local.get $0
i32.load offset=4
i32.const -4
Expand Down Expand Up @@ -1022,7 +1046,7 @@
if
i32.const 0
i32.const 1168
i32.const 224
i32.const 228
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -1610,7 +1634,7 @@
if
i32.const 1104
i32.const 1168
i32.const 256
i32.const 260
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down
66 changes: 45 additions & 21 deletions tests/compiler/call-super.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,57 @@
i32.xor
i32.and
)
(func $~lib/rt/itcms/Object#get:color (param $0 i32) (result i32)
local.get $0
i32.load offset=4
i32.const 3
i32.and
)
(func $~lib/rt/itcms/visitRoots (param $0 i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
local.get $0
call $~lib/rt/__visit_globals
global.get $~lib/rt/itcms/pinSpace
call $~lib/rt/itcms/Object#get:next
local.set $1
local.get $1
call $~lib/rt/itcms/Object#get:next
local.set $2
loop $while-continue|0
local.get $2
local.get $1
global.get $~lib/rt/itcms/pinSpace
i32.ne
local.set $2
local.get $2
local.set $3
local.get $3
if
local.get $1
i32.const 1
drop
local.get $2
call $~lib/rt/itcms/Object#get:color
i32.const 3
i32.eq
i32.eqz
if
i32.const 0
i32.const 144
i32.const 159
i32.const 16
call $~lib/builtins/abort
unreachable
end
local.get $2
i32.const 20
i32.add
local.get $0
call $~lib/rt/__visit_members
local.get $1
local.get $2
call $~lib/rt/itcms/Object#get:next
local.set $1
local.set $2
br $while-continue|0
end
end
)
(func $~lib/rt/itcms/Object#get:color (param $0 i32) (result i32)
local.get $0
i32.load offset=4
i32.const 3
i32.and
)
(func $~lib/rt/itcms/Object#set:color (param $0 i32) (param $1 i32)
local.get $0
local.get $0
Expand Down Expand Up @@ -1435,13 +1453,19 @@
local.get $2
if
local.get $0
call $~lib/rt/itcms/Object#get:color
local.get $1
call $~lib/rt/itcms/Object#set:color
local.get $0
i32.const 20
i32.add
i32.const 0
call $~lib/rt/__visit_members
i32.ne
if
local.get $0
local.get $1
call $~lib/rt/itcms/Object#set:color
local.get $0
i32.const 20
i32.add
i32.const 0
call $~lib/rt/__visit_members
end
local.get $0
call $~lib/rt/itcms/Object#get:next
local.set $0
Expand Down Expand Up @@ -1487,7 +1511,7 @@
if
i32.const 0
i32.const 144
i32.const 224
i32.const 228
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down Expand Up @@ -2285,7 +2309,7 @@
if
i32.const 80
i32.const 144
i32.const 256
i32.const 260
i32.const 31
call $~lib/builtins/abort
unreachable
Expand Down
38 changes: 31 additions & 7 deletions tests/compiler/class-implements.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
)
(func $~lib/rt/itcms/visitRoots
(local $0 i32)
(local $1 i32)
global.get $class-implements/a
local.tee $0
if
Expand All @@ -73,15 +74,30 @@
i32.const 1056
call $~lib/rt/itcms/__visit
global.get $~lib/rt/itcms/pinSpace
local.tee $1
i32.load offset=4
i32.const -4
i32.and
local.set $0
loop $while-continue|0
local.get $0
global.get $~lib/rt/itcms/pinSpace
local.get $1
i32.ne
if
local.get $0
i32.load offset=4
i32.const 3
i32.and
i32.const 3
i32.ne
if
i32.const 0
i32.const 1120
i32.const 159
i32.const 16
call $~lib/builtins/abort
unreachable
end
local.get $0
i32.const 20
i32.add
Expand Down Expand Up @@ -990,13 +1006,21 @@
global.get $~lib/rt/itcms/toSpace
i32.ne
if
local.get $0
local.get $1
call $~lib/rt/itcms/Object#set:color
local.get $0
i32.const 20
i32.add
call $~lib/rt/__visit_members
i32.load offset=4
i32.const 3
i32.and
i32.ne
if
local.get $0
local.get $1
call $~lib/rt/itcms/Object#set:color
local.get $0
i32.const 20
i32.add
call $~lib/rt/__visit_members
end
local.get $0
i32.load offset=4
i32.const -4
Expand Down Expand Up @@ -1043,7 +1067,7 @@
if
i32.const 0
i32.const 1120
i32.const 224
i32.const 228
i32.const 20
call $~lib/builtins/abort
unreachable
Expand Down
Loading