Skip to content

Commit 4ccda0b

Browse files
authored
feat: Make use of initial memory when initializing incremental GC (#1692)
1 parent 369c6fc commit 4ccda0b

File tree

134 files changed

+2820
-1124
lines changed

Some content is hidden

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

134 files changed

+2820
-1124
lines changed

src/asconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"options": {
77
"explicitStart": true,
88
"exportRuntime": true,
9-
"initialMemory": 256,
9+
"initialMemory": 768,
1010
"runtime": "incremental",
1111
"measure": true
1212
},

std/assembly/rt/itcms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ export function __collect(): void {
389389
// @ts-ignore: decorator
390390
@inline const IDLEFACTOR: usize = isDefined(ASC_GC_IDLEFACTOR) ? ASC_GC_IDLEFACTOR : 200;
391391

392-
/** Threshold of objects for the next scheduled GC step. */
392+
/** Threshold of memory used by objects to exceed before interrupting again. */
393393
// @ts-ignore: decorator
394-
@lazy var threshold: usize = GRANULARITY;
394+
@lazy var threshold: usize = ((<usize>memory.size() << 16) - __heap_base) >> 1;
395395

396396
/** Performs a reasonable amount of incremental GC steps. */
397397
function interrupt(): void {

tests/compiler/call-super.optimized.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
(data (i32.const 1488) "\0d\00\00\00 \00\00\00\00\00\00\00 ")
2525
(data (i32.const 1516) " \00\00\00\04\00\00\00 \00\00\00\00\00\00\00 \00\00\00\06\00\00\00 \00\00\00\00\00\00\00 \00\00\00\08\00\00\00 \00\00\00\00\00\00\00 \00\00\00\n\00\00\00 \00\00\00\00\00\00\00 \00\00\00\0c\00\00\00 ")
2626
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
27-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
27+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2828
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2929
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
3030
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -2200,6 +2200,14 @@
22002200
)
22012201
(func $~start
22022202
(local $0 i32)
2203+
memory.size
2204+
i32.const 16
2205+
i32.shl
2206+
i32.const 17980
2207+
i32.sub
2208+
i32.const 1
2209+
i32.shr_u
2210+
global.set $~lib/rt/itcms/threshold
22032211
i32.const 1216
22042212
call $~lib/rt/itcms/initLazy
22052213
global.set $~lib/rt/itcms/pinSpace

tests/compiler/call-super.untouched.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
(data (i32.const 464) "\0d\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00 \00\00\00\04\00\00\00 \00\00\00\00\00\00\00 \00\00\00\06\00\00\00 \00\00\00\00\00\00\00 \00\00\00\08\00\00\00 \00\00\00\00\00\00\00 \00\00\00\n\00\00\00 \00\00\00\00\00\00\00 \00\00\00\0c\00\00\00 \00\00\00\00\00\00\00")
2323
(table $0 1 funcref)
2424
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
25-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
25+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2626
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2727
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2828
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -2633,6 +2633,14 @@
26332633
global.set $~lib/memory/__stack_pointer
26342634
)
26352635
(func $start:call-super
2636+
memory.size
2637+
i32.const 16
2638+
i32.shl
2639+
global.get $~lib/memory/__heap_base
2640+
i32.sub
2641+
i32.const 1
2642+
i32.shr_u
2643+
global.set $~lib/rt/itcms/threshold
26362644
i32.const 192
26372645
call $~lib/rt/itcms/initLazy
26382646
global.set $~lib/rt/itcms/pinSpace

tests/compiler/class-implements.optimized.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(data (i32.const 1504) "\07\00\00\00 \00\00\00\00\00\00\00 ")
2424
(data (i32.const 1532) " \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\06\00\00\00 ")
2525
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
26-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
26+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2727
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2828
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2929
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -1483,6 +1483,14 @@
14831483
global.get $~lib/memory/__stack_pointer
14841484
i32.const 0
14851485
i32.store
1486+
memory.size
1487+
i32.const 16
1488+
i32.shl
1489+
i32.const 17948
1490+
i32.sub
1491+
i32.const 1
1492+
i32.shr_u
1493+
global.set $~lib/rt/itcms/threshold
14861494
i32.const 1168
14871495
call $~lib/rt/itcms/initLazy
14881496
global.set $~lib/rt/itcms/pinSpace

tests/compiler/class-implements.untouched.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
(data (i32.const 480) "\07\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\06\00\00\00 \00\00\00\00\00\00\00")
2323
(table $0 1 funcref)
2424
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
25-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
25+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2626
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2727
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2828
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -2500,6 +2500,14 @@
25002500
global.get $~lib/memory/__stack_pointer
25012501
i32.const 0
25022502
i32.store
2503+
memory.size
2504+
i32.const 16
2505+
i32.shl
2506+
global.get $~lib/memory/__heap_base
2507+
i32.sub
2508+
i32.const 1
2509+
i32.shr_u
2510+
global.set $~lib/rt/itcms/threshold
25032511
i32.const 144
25042512
call $~lib/rt/itcms/initLazy
25052513
global.set $~lib/rt/itcms/pinSpace

tests/compiler/class-overloading.optimized.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
(data (i32.const 1820) " \00\00\00\00\00\00\00 \00\00\00\03\00\00\00 \00\00\00\04\00\00\00 \00\00\00\04\00\00\00 \00\00\00\06\00\00\00 \00\00\00\07\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\t\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\0d\00\00\00 \00\00\00\10\00\00\00 ")
4242
(global $class-overloading/which (mut i32) (i32.const 1056))
4343
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
44-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
44+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
4545
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
4646
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
4747
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -2090,6 +2090,14 @@
20902090
global.get $~lib/memory/__stack_pointer
20912091
i64.const 0
20922092
i64.store
2093+
memory.size
2094+
i32.const 16
2095+
i32.shl
2096+
i32.const 18316
2097+
i32.sub
2098+
i32.const 1
2099+
i32.shr_u
2100+
global.set $~lib/rt/itcms/threshold
20932101
i32.const 1200
20942102
call $~lib/rt/itcms/initLazy
20952103
global.set $~lib/rt/itcms/pinSpace

tests/compiler/class-overloading.untouched.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
(table $0 1 funcref)
3333
(global $class-overloading/which (mut i32) (i32.const 32))
3434
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
35-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
35+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
3636
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
3737
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
3838
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -3383,6 +3383,14 @@
33833383
global.get $~lib/memory/__stack_pointer
33843384
i64.const 0
33853385
i64.store
3386+
memory.size
3387+
i32.const 16
3388+
i32.shl
3389+
global.get $~lib/memory/__heap_base
3390+
i32.sub
3391+
i32.const 1
3392+
i32.shr_u
3393+
global.set $~lib/rt/itcms/threshold
33863394
i32.const 176
33873395
call $~lib/rt/itcms/initLazy
33883396
global.set $~lib/rt/itcms/pinSpace

tests/compiler/class.optimized.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
(data (i32.const 1564) " ")
2828
(data (i32.const 1580) "\02\t")
2929
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
30-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
30+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
3131
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
3232
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
3333
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -1900,6 +1900,14 @@
19001900
end
19011901
)
19021902
(func $~start
1903+
memory.size
1904+
i32.const 16
1905+
i32.shl
1906+
i32.const 17972
1907+
i32.sub
1908+
i32.const 1
1909+
i32.shr_u
1910+
global.set $~lib/rt/itcms/threshold
19031911
i32.const 1168
19041912
call $~lib/rt/itcms/initLazy
19051913
global.set $~lib/rt/itcms/pinSpace

tests/compiler/class.untouched.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
(table $0 1 funcref)
2727
(global $class/Animal.ONE (mut i32) (i32.const 1))
2828
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
29-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
29+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
3030
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
3131
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
3232
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -2611,6 +2611,14 @@
26112611
)
26122612
(func $~start
26132613
call $start:class
2614+
memory.size
2615+
i32.const 16
2616+
i32.shl
2617+
global.get $~lib/memory/__heap_base
2618+
i32.sub
2619+
i32.const 1
2620+
i32.shr_u
2621+
global.set $~lib/rt/itcms/threshold
26142622
i32.const 144
26152623
call $~lib/rt/itcms/initLazy
26162624
global.set $~lib/rt/itcms/pinSpace

tests/compiler/constructor.optimized.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
(data (i32.const 1440) "\0d\00\00\00 \00\00\00\00\00\00\00 ")
2323
(data (i32.const 1468) " \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 ")
2424
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
25-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
25+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2626
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2727
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2828
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -1792,6 +1792,14 @@
17921792
)
17931793
(func $start:constructor
17941794
(local $0 i32)
1795+
memory.size
1796+
i32.const 16
1797+
i32.shl
1798+
i32.const 17932
1799+
i32.sub
1800+
i32.const 1
1801+
i32.shr_u
1802+
global.set $~lib/rt/itcms/threshold
17951803
i32.const 1168
17961804
call $~lib/rt/itcms/initLazy
17971805
global.set $~lib/rt/itcms/pinSpace

tests/compiler/constructor.untouched.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
(data (i32.const 416) "\0d\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00")
2222
(table $0 1 funcref)
2323
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
24-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
24+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2525
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2626
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2727
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -2391,6 +2391,14 @@
23912391
i32.const 0
23922392
)
23932393
(func $start:constructor
2394+
memory.size
2395+
i32.const 16
2396+
i32.shl
2397+
global.get $~lib/memory/__heap_base
2398+
i32.sub
2399+
i32.const 1
2400+
i32.shr_u
2401+
global.set $~lib/rt/itcms/threshold
23942402
i32.const 144
23952403
call $~lib/rt/itcms/initLazy
23962404
global.set $~lib/rt/itcms/pinSpace

tests/compiler/do.optimized.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(data (i32.const 1472) "\04\00\00\00 \00\00\00\00\00\00\00 ")
2424
(data (i32.const 1500) " ")
2525
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
26-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
26+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2727
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2828
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2929
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -1587,6 +1587,14 @@
15871587
call $~lib/builtins/abort
15881588
unreachable
15891589
end
1590+
memory.size
1591+
i32.const 16
1592+
i32.shl
1593+
i32.const 17892
1594+
i32.sub
1595+
i32.const 1
1596+
i32.shr_u
1597+
global.set $~lib/rt/itcms/threshold
15901598
i32.const 1200
15911599
call $~lib/rt/itcms/initLazy
15921600
global.set $~lib/rt/itcms/pinSpace

tests/compiler/do.untouched.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(table $0 1 funcref)
2424
(global $do/ran (mut i32) (i32.const 0))
2525
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
26-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
26+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2727
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2828
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2929
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -3095,6 +3095,14 @@
30953095
end
30963096
i32.const 0
30973097
global.set $do/ran
3098+
memory.size
3099+
i32.const 16
3100+
i32.shl
3101+
global.get $~lib/memory/__heap_base
3102+
i32.sub
3103+
i32.const 1
3104+
i32.shr_u
3105+
global.set $~lib/rt/itcms/threshold
30983106
i32.const 176
30993107
call $~lib/rt/itcms/initLazy
31003108
global.set $~lib/rt/itcms/pinSpace

tests/compiler/empty-exportruntime.optimized.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
(data (i32.const 1512) "\01\00\00\00(\00\00\00O\00b\00j\00e\00c\00t\00 \00i\00s\00 \00n\00o\00t\00 \00p\00i\00n\00n\00e\00d")
2626
(data (i32.const 1568) "\03\00\00\00 \00\00\00\00\00\00\00 ")
2727
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
28-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
28+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2929
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
3030
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
3131
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -1870,6 +1870,14 @@
18701870
unreachable
18711871
)
18721872
(func $~start
1873+
memory.size
1874+
i32.const 16
1875+
i32.shl
1876+
i32.const 17980
1877+
i32.sub
1878+
i32.const 1
1879+
i32.shr_u
1880+
global.set $~lib/rt/itcms/threshold
18731881
i32.const 1168
18741882
call $~lib/rt/itcms/initLazy
18751883
global.set $~lib/rt/itcms/pinSpace

tests/compiler/empty-exportruntime.untouched.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(data (i32.const 544) "\03\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
2424
(table $0 1 funcref)
2525
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
26-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
26+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2727
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2828
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2929
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -2529,6 +2529,14 @@
25292529
unreachable
25302530
)
25312531
(func $~start
2532+
memory.size
2533+
i32.const 16
2534+
i32.shl
2535+
global.get $~lib/memory/__heap_base
2536+
i32.sub
2537+
i32.const 1
2538+
i32.shr_u
2539+
global.set $~lib/rt/itcms/threshold
25322540
i32.const 144
25332541
call $~lib/rt/itcms/initLazy
25342542
global.set $~lib/rt/itcms/pinSpace

tests/compiler/empty-new.optimized.wat

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(data (i32.const 1384) "\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00t\00l\00s\00f\00.\00t\00s")
2121
(data (i32.const 1440) "\03\00\00\00 \00\00\00\00\00\00\00 ")
2222
(global $~lib/rt/itcms/total (mut i32) (i32.const 0))
23-
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 1024))
23+
(global $~lib/rt/itcms/threshold (mut i32) (i32.const 0))
2424
(global $~lib/rt/itcms/state (mut i32) (i32.const 0))
2525
(global $~lib/rt/itcms/visitCount (mut i32) (i32.const 0))
2626
(global $~lib/rt/itcms/pinSpace (mut i32) (i32.const 0))
@@ -1362,6 +1362,14 @@
13621362
)
13631363
(func $~start
13641364
(local $0 i32)
1365+
memory.size
1366+
i32.const 16
1367+
i32.shl
1368+
i32.const 17852
1369+
i32.sub
1370+
i32.const 1
1371+
i32.shr_u
1372+
global.set $~lib/rt/itcms/threshold
13651373
i32.const 1168
13661374
call $~lib/rt/itcms/initLazy
13671375
global.set $~lib/rt/itcms/pinSpace

0 commit comments

Comments
 (0)