mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
wasm: scan globals conservatively
Make the GC globals scan phase conservative instead of precise on WebAssembly. This reduces code size at the risk of introducing some false positives. This is a stopgap measure to mitigate an issue with the precise scanning of globals that doesn't track all pointers. It works for regular globals but globals created in the interp package don't always have a type and therefore may be missed by the AddGlobalsBitmap pass. The same issue is present on Linux and macOS, but is not as noticeable there.
This commit is contained in:
committed by
Ron Evans
parent
ff5d0c9886
commit
d1e96fd0a8
@@ -14,6 +14,9 @@ const TargetBits = 32
|
||||
//go:extern __heap_base
|
||||
var heapStartSymbol [0]byte
|
||||
|
||||
//go:extern __global_base
|
||||
var globalsStartSymbol [0]byte
|
||||
|
||||
//export llvm.wasm.memory.size.i32
|
||||
func wasm_memory_size(index int32) int32
|
||||
|
||||
@@ -21,8 +24,10 @@ func wasm_memory_size(index int32) int32
|
||||
func wasm_memory_grow(index int32, delta int32) int32
|
||||
|
||||
var (
|
||||
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
|
||||
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
|
||||
globalsStart = uintptr(unsafe.Pointer(&globalsStartSymbol))
|
||||
globalsEnd = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||
)
|
||||
|
||||
const wasmPageSize = 64 * 1024
|
||||
|
||||
@@ -401,7 +401,7 @@ func markRoots(start, end uintptr) {
|
||||
}
|
||||
}
|
||||
|
||||
for addr := start; addr != end; addr += unsafe.Alignof(addr) {
|
||||
for addr := start; addr < end; addr += unsafe.Alignof(addr) {
|
||||
root := *(*uintptr)(unsafe.Pointer(addr))
|
||||
markRoot(addr, root)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// +build gc.conservative gc.extalloc
|
||||
// +build baremetal
|
||||
// +build baremetal wasm
|
||||
|
||||
package runtime
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// +build gc.conservative gc.extalloc
|
||||
// +build !baremetal
|
||||
// +build !baremetal,!wasm
|
||||
|
||||
package runtime
|
||||
|
||||
|
||||
Reference in New Issue
Block a user