mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-11 15:09:32 +00:00
runtime: eagerly mark Boehm global roots
This commit is contained in:
@@ -165,6 +165,9 @@ func libgc_size(ptr uintptr) uintptr
|
||||
//export GC_push_all
|
||||
func libgc_push_all(bottom, top uintptr)
|
||||
|
||||
//export GC_push_all_eager
|
||||
func libgc_push_all_eager(bottom, top uintptr)
|
||||
|
||||
//export GC_push_all_stack
|
||||
func libgc_push_all_stack(bottom, top uintptr)
|
||||
|
||||
|
||||
@@ -5,31 +5,12 @@ package runtime
|
||||
import "unsafe"
|
||||
|
||||
func markGlobals() {
|
||||
rangeCount := gcGlobalRootCount()
|
||||
if rangeCount == 0 {
|
||||
return
|
||||
for i := uintptr(0); i < gcGlobalRootCount(); i++ {
|
||||
addr := gcGlobalRoot(uintptr(i))
|
||||
// GC_push_all queues one range per call and overflows Boehm's mark
|
||||
// stack for programs with thousands of roots. Scan each range now.
|
||||
libgc_push_all_eager(uintptr(addr), uintptr(addr)+gcGlobalRootSize(i))
|
||||
}
|
||||
|
||||
var rootCount uintptr
|
||||
for i := uintptr(0); i < rangeCount; i++ {
|
||||
rootCount += gcGlobalRootSize(i) / unsafe.Sizeof(uintptr(0))
|
||||
}
|
||||
|
||||
// markRoots only accepts a range, so copy all global pointers into
|
||||
// contiguous scratch space for marking.
|
||||
roots := unsafe.Slice((*uintptr)(gcGlobalRootValues()), rootCount)
|
||||
var rootIndex uintptr
|
||||
for i := uintptr(0); i < rangeCount; i++ {
|
||||
addr := gcGlobalRoot(i)
|
||||
size := gcGlobalRootSize(i)
|
||||
for offset := uintptr(0); offset < size; offset += unsafe.Sizeof(uintptr(0)) {
|
||||
roots[rootIndex] = *(*uintptr)(unsafe.Add(addr, offset))
|
||||
rootIndex++
|
||||
}
|
||||
}
|
||||
|
||||
start := uintptr(unsafe.Pointer(&roots[0]))
|
||||
markRoots(start, start+rootCount*unsafe.Sizeof(roots[0]))
|
||||
}
|
||||
|
||||
// These functions are generated by the compiler from the pointer layouts of
|
||||
@@ -37,4 +18,3 @@ func markGlobals() {
|
||||
func gcGlobalRootCount() uintptr
|
||||
func gcGlobalRoot(index uintptr) unsafe.Pointer
|
||||
func gcGlobalRootSize(index uintptr) uintptr
|
||||
func gcGlobalRootValues() unsafe.Pointer
|
||||
|
||||
Reference in New Issue
Block a user