Skip to content

Commit b204216

Browse files
authored
fix: Propagate mark after visiting pinned objects in minimal runtime (AssemblyScript#1650)
1 parent 99e77a7 commit b204216

File tree

136 files changed

+5291
-2132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+5291
-2132
lines changed

std/assembly/rt/itcms.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ function initLazy(space: Object): Object {
153153
/** Visits all objects considered to be program roots. */
154154
function visitRoots(cookie: u32): void {
155155
__visit_globals(cookie);
156-
var iter = pinSpace.next;
157-
while (iter != pinSpace) {
156+
var pn = pinSpace;
157+
var iter = pn.next;
158+
while (iter != pn) {
159+
if (DEBUG) assert(iter.color == transparent);
158160
__visit_members(changetype<usize>(iter) + TOTAL_OVERHEAD, cookie);
159161
iter = iter.next;
160162
}
@@ -204,8 +206,10 @@ function step(): usize {
204206
visitStack(VISIT_SCAN);
205207
obj = iter.next;
206208
while (obj != toSpace) {
207-
obj.color = black;
208-
__visit_members(changetype<usize>(obj) + TOTAL_OVERHEAD, VISIT_SCAN);
209+
if (obj.color != black) {
210+
obj.color = black;
211+
__visit_members(changetype<usize>(obj) + TOTAL_OVERHEAD, VISIT_SCAN);
212+
}
209213
obj = obj.next;
210214
}
211215
let from = fromSpace;

std/assembly/rt/tcms.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,24 @@ export function __unpin(ptr: usize): void {
203203
export function __collect(): void {
204204
if (TRACE) trace("GC at", 1, total);
205205

206-
// Mark roots and add to toSpace
206+
// Mark roots (add to toSpace)
207207
__visit_globals(VISIT_SCAN);
208208

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

219-
// Mark what's reachable from pinned objects
220-
var pn = pinSpace;
221-
iter = pn.next;
222-
while (iter != pn) {
223-
if (DEBUG) assert(iter.color == transparent);
218+
// Mark what's reachable from toSpace
219+
var black = i32(!white);
220+
var to = toSpace;
221+
iter = to.next;
222+
while (iter != to) {
223+
if (DEBUG) assert(iter.color == black);
224224
__visit_members(changetype<usize>(iter) + TOTAL_OVERHEAD, VISIT_SCAN);
225225
iter = iter.next;
226226
}

tests/compiler/call-super.optimized.wat

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,36 @@
4747
)
4848
(func $~lib/rt/itcms/visitRoots
4949
(local $0 i32)
50+
(local $1 i32)
5051
i32.const 1296
5152
call $~lib/rt/itcms/__visit
5253
i32.const 1104
5354
call $~lib/rt/itcms/__visit
5455
global.get $~lib/rt/itcms/pinSpace
56+
local.tee $1
5557
i32.load offset=4
5658
i32.const -4
5759
i32.and
5860
local.set $0
5961
loop $while-continue|0
6062
local.get $0
61-
global.get $~lib/rt/itcms/pinSpace
63+
local.get $1
6264
i32.ne
6365
if
66+
local.get $0
67+
i32.load offset=4
68+
i32.const 3
69+
i32.and
70+
i32.const 3
71+
i32.ne
72+
if
73+
i32.const 0
74+
i32.const 1168
75+
i32.const 159
76+
i32.const 16
77+
call $~lib/builtins/abort
78+
unreachable
79+
end
6480
local.get $0
6581
i32.const 20
6682
i32.add
@@ -969,13 +985,21 @@
969985
global.get $~lib/rt/itcms/toSpace
970986
i32.ne
971987
if
972-
local.get $0
973988
local.get $1
974-
call $~lib/rt/itcms/Object#set:color
975989
local.get $0
976-
i32.const 20
977-
i32.add
978-
call $~lib/rt/__visit_members
990+
i32.load offset=4
991+
i32.const 3
992+
i32.and
993+
i32.ne
994+
if
995+
local.get $0
996+
local.get $1
997+
call $~lib/rt/itcms/Object#set:color
998+
local.get $0
999+
i32.const 20
1000+
i32.add
1001+
call $~lib/rt/__visit_members
1002+
end
9791003
local.get $0
9801004
i32.load offset=4
9811005
i32.const -4
@@ -1022,7 +1046,7 @@
10221046
if
10231047
i32.const 0
10241048
i32.const 1168
1025-
i32.const 224
1049+
i32.const 228
10261050
i32.const 20
10271051
call $~lib/builtins/abort
10281052
unreachable
@@ -1610,7 +1634,7 @@
16101634
if
16111635
i32.const 1104
16121636
i32.const 1168
1613-
i32.const 256
1637+
i32.const 260
16141638
i32.const 31
16151639
call $~lib/builtins/abort
16161640
unreachable

tests/compiler/call-super.untouched.wat

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,39 +66,57 @@
6666
i32.xor
6767
i32.and
6868
)
69+
(func $~lib/rt/itcms/Object#get:color (param $0 i32) (result i32)
70+
local.get $0
71+
i32.load offset=4
72+
i32.const 3
73+
i32.and
74+
)
6975
(func $~lib/rt/itcms/visitRoots (param $0 i32)
7076
(local $1 i32)
7177
(local $2 i32)
78+
(local $3 i32)
7279
local.get $0
7380
call $~lib/rt/__visit_globals
7481
global.get $~lib/rt/itcms/pinSpace
75-
call $~lib/rt/itcms/Object#get:next
7682
local.set $1
83+
local.get $1
84+
call $~lib/rt/itcms/Object#get:next
85+
local.set $2
7786
loop $while-continue|0
87+
local.get $2
7888
local.get $1
79-
global.get $~lib/rt/itcms/pinSpace
8089
i32.ne
81-
local.set $2
82-
local.get $2
90+
local.set $3
91+
local.get $3
8392
if
84-
local.get $1
93+
i32.const 1
94+
drop
95+
local.get $2
96+
call $~lib/rt/itcms/Object#get:color
97+
i32.const 3
98+
i32.eq
99+
i32.eqz
100+
if
101+
i32.const 0
102+
i32.const 144
103+
i32.const 159
104+
i32.const 16
105+
call $~lib/builtins/abort
106+
unreachable
107+
end
108+
local.get $2
85109
i32.const 20
86110
i32.add
87111
local.get $0
88112
call $~lib/rt/__visit_members
89-
local.get $1
113+
local.get $2
90114
call $~lib/rt/itcms/Object#get:next
91-
local.set $1
115+
local.set $2
92116
br $while-continue|0
93117
end
94118
end
95119
)
96-
(func $~lib/rt/itcms/Object#get:color (param $0 i32) (result i32)
97-
local.get $0
98-
i32.load offset=4
99-
i32.const 3
100-
i32.and
101-
)
102120
(func $~lib/rt/itcms/Object#set:color (param $0 i32) (param $1 i32)
103121
local.get $0
104122
local.get $0
@@ -1435,13 +1453,19 @@
14351453
local.get $2
14361454
if
14371455
local.get $0
1456+
call $~lib/rt/itcms/Object#get:color
14381457
local.get $1
1439-
call $~lib/rt/itcms/Object#set:color
1440-
local.get $0
1441-
i32.const 20
1442-
i32.add
1443-
i32.const 0
1444-
call $~lib/rt/__visit_members
1458+
i32.ne
1459+
if
1460+
local.get $0
1461+
local.get $1
1462+
call $~lib/rt/itcms/Object#set:color
1463+
local.get $0
1464+
i32.const 20
1465+
i32.add
1466+
i32.const 0
1467+
call $~lib/rt/__visit_members
1468+
end
14451469
local.get $0
14461470
call $~lib/rt/itcms/Object#get:next
14471471
local.set $0
@@ -1487,7 +1511,7 @@
14871511
if
14881512
i32.const 0
14891513
i32.const 144
1490-
i32.const 224
1514+
i32.const 228
14911515
i32.const 20
14921516
call $~lib/builtins/abort
14931517
unreachable
@@ -2285,7 +2309,7 @@
22852309
if
22862310
i32.const 80
22872311
i32.const 144
2288-
i32.const 256
2312+
i32.const 260
22892313
i32.const 31
22902314
call $~lib/builtins/abort
22912315
unreachable

tests/compiler/class-implements.optimized.wat

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
)
5757
(func $~lib/rt/itcms/visitRoots
5858
(local $0 i32)
59+
(local $1 i32)
5960
global.get $class-implements/a
6061
local.tee $0
6162
if
@@ -73,15 +74,30 @@
7374
i32.const 1056
7475
call $~lib/rt/itcms/__visit
7576
global.get $~lib/rt/itcms/pinSpace
77+
local.tee $1
7678
i32.load offset=4
7779
i32.const -4
7880
i32.and
7981
local.set $0
8082
loop $while-continue|0
8183
local.get $0
82-
global.get $~lib/rt/itcms/pinSpace
84+
local.get $1
8385
i32.ne
8486
if
87+
local.get $0
88+
i32.load offset=4
89+
i32.const 3
90+
i32.and
91+
i32.const 3
92+
i32.ne
93+
if
94+
i32.const 0
95+
i32.const 1120
96+
i32.const 159
97+
i32.const 16
98+
call $~lib/builtins/abort
99+
unreachable
100+
end
85101
local.get $0
86102
i32.const 20
87103
i32.add
@@ -990,13 +1006,21 @@
9901006
global.get $~lib/rt/itcms/toSpace
9911007
i32.ne
9921008
if
993-
local.get $0
9941009
local.get $1
995-
call $~lib/rt/itcms/Object#set:color
9961010
local.get $0
997-
i32.const 20
998-
i32.add
999-
call $~lib/rt/__visit_members
1011+
i32.load offset=4
1012+
i32.const 3
1013+
i32.and
1014+
i32.ne
1015+
if
1016+
local.get $0
1017+
local.get $1
1018+
call $~lib/rt/itcms/Object#set:color
1019+
local.get $0
1020+
i32.const 20
1021+
i32.add
1022+
call $~lib/rt/__visit_members
1023+
end
10001024
local.get $0
10011025
i32.load offset=4
10021026
i32.const -4
@@ -1043,7 +1067,7 @@
10431067
if
10441068
i32.const 0
10451069
i32.const 1120
1046-
i32.const 224
1070+
i32.const 228
10471071
i32.const 20
10481072
call $~lib/builtins/abort
10491073
unreachable

0 commit comments

Comments
 (0)