Add -gc=custom option (#3302)

* Add -gc=custom option
This commit is contained in:
Anuraag Agrawal
2023-01-29 04:24:56 +09:00
committed by GitHub
parent 13698b17f7
commit eebd2f648b
7 changed files with 67 additions and 6 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build (gc.conservative || gc.precise) && tinygo.wasm
//go:build (gc.conservative || gc.custom || gc.precise) && tinygo.wasm
package task
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !(gc.conservative || gc.precise) || !tinygo.wasm
//go:build !(gc.conservative || gc.custom || gc.precise) || !tinygo.wasm
package task
+55
View File
@@ -0,0 +1,55 @@
//go:build gc.custom
// +build gc.custom
package runtime
// This GC strategy allows an external GC to be plugged in instead of the builtin
// implementations.
//
// The interface defined in this file is not stable and can be broken at anytime, even
// across minor versions.
//
// runtime.markStack() must be called at the beginning of any GC cycle. //go:linkname
// on a function without a body can be used to access this internal function.
//
// The custom implementation must provide the following functions in the runtime package
// using the go:linkname directive:
//
// - func initHeap()
// - func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer
// - func free(ptr unsafe.Pointer)
// - func markRoots(start, end uintptr)
// - func GC()
//
//
// In addition, if targeting wasi, the following functions should be exported for interoperability
// with wasi libraries that use them. Note, this requires the export directive, not go:linkname.
//
// - func malloc(size uintptr) unsafe.Pointer
// - func free(ptr unsafe.Pointer)
// - func calloc(nmemb, size uintptr) unsafe.Pointer
// - func realloc(oldPtr unsafe.Pointer, size uintptr) unsafe.Pointer
import (
"unsafe"
)
// initHeap is called when the heap is first initialized at program start.
func initHeap()
// alloc is called to allocate memory. layout is currently not used.
func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer
// free is called to explicitly free a previously allocated pointer.
func free(ptr unsafe.Pointer)
// markRoots is called with the start and end addresses to scan for references.
// It is currently only called with the top and bottom of the stack.
func markRoots(start, end uintptr)
// GC is called to explicitly run garbage collection.
func GC()
func setHeapEnd(newHeapEnd uintptr) {
// Heap is in custom GC so ignore for when called from wasm initialization.
}
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build (gc.conservative || gc.precise) && tinygo.wasm
//go:build (gc.conservative || gc.custom || gc.precise) && tinygo.wasm
package runtime