runtime: unify GC interface
Make sure every to-be-implemented GC can use the same interface. As a result, a 1MB chunk of RAM is allocated on Unix systems on init instead of allocating on demand.
Этот коммит содержится в:
родитель
4fdffdf8b2
коммит
15a4afb22a
9 изменённых файлов: 37 добавлений и 47 удалений
|
@ -6,3 +6,8 @@ const GOARCH = "amd64"
|
||||||
|
|
||||||
// The bitness of the CPU (e.g. 8, 32, 64).
|
// The bitness of the CPU (e.g. 8, 32, 64).
|
||||||
const TargetBits = 64
|
const TargetBits = 64
|
||||||
|
|
||||||
|
// Align on word boundary.
|
||||||
|
func align(ptr uintptr) uintptr {
|
||||||
|
return (ptr + 7) &^ 7
|
||||||
|
}
|
||||||
|
|
|
@ -12,4 +12,12 @@ const GOARCH = "avr"
|
||||||
const TargetBits = 8
|
const TargetBits = 8
|
||||||
|
|
||||||
//go:extern _heap_start
|
//go:extern _heap_start
|
||||||
var heapStart unsafe.Pointer
|
var heapStartSymbol unsafe.Pointer
|
||||||
|
|
||||||
|
var heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||||
|
|
||||||
|
// Align on a word boundary.
|
||||||
|
func align(ptr uintptr) uintptr {
|
||||||
|
// No alignment necessary on the AVR.
|
||||||
|
return ptr
|
||||||
|
}
|
||||||
|
|
|
@ -12,4 +12,11 @@ const GOARCH = "arm"
|
||||||
const TargetBits = 32
|
const TargetBits = 32
|
||||||
|
|
||||||
//go:extern _heap_start
|
//go:extern _heap_start
|
||||||
var heapStart unsafe.Pointer
|
var heapStartSymbol unsafe.Pointer
|
||||||
|
|
||||||
|
var heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||||
|
|
||||||
|
// Align on word boundary.
|
||||||
|
func align(ptr uintptr) uintptr {
|
||||||
|
return (ptr + 3) &^ 3
|
||||||
|
}
|
||||||
|
|
|
@ -12,4 +12,11 @@ const GOARCH = "wasm"
|
||||||
const TargetBits = 32
|
const TargetBits = 32
|
||||||
|
|
||||||
//go:extern __heap_base
|
//go:extern __heap_base
|
||||||
var heapStart unsafe.Pointer
|
var heapStartSymbol unsafe.Pointer
|
||||||
|
|
||||||
|
var heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||||
|
|
||||||
|
// Align on word boundary.
|
||||||
|
func align(ptr uintptr) uintptr {
|
||||||
|
return (ptr + 3) &^ 3
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
// +build !linux
|
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var heapptr = uintptr(unsafe.Pointer(&heapStart))
|
// Ever-incrementing pointer: no memory is freed.
|
||||||
|
var heapptr = heapStart
|
||||||
|
|
||||||
func alloc(size uintptr) unsafe.Pointer {
|
func alloc(size uintptr) unsafe.Pointer {
|
||||||
// TODO: this can be optimized by not casting between pointers and ints so
|
// TODO: this can be optimized by not casting between pointers and ints so
|
||||||
|
|
|
@ -120,9 +120,3 @@ func abort() {
|
||||||
sleepWDT(WDT_PERIOD_2S)
|
sleepWDT(WDT_PERIOD_2S)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Align on a word boundary.
|
|
||||||
func align(ptr uintptr) uintptr {
|
|
||||||
// No alignment necessary on the AVR.
|
|
||||||
return ptr
|
|
||||||
}
|
|
||||||
|
|
|
@ -46,11 +46,6 @@ func abort() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Align on word boundary.
|
|
||||||
func align(ptr uintptr) uintptr {
|
|
||||||
return (ptr + 3) &^ 3
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implement memset for compiler-rt.
|
// Implement memset for compiler-rt.
|
||||||
//go:export memset
|
//go:export memset
|
||||||
func memset(ptr unsafe.Pointer, c byte, size uintptr) {
|
func memset(ptr unsafe.Pointer, c byte, size uintptr) {
|
||||||
|
|
|
@ -8,10 +8,14 @@ import (
|
||||||
|
|
||||||
func _Cfunc_putchar(c int) int
|
func _Cfunc_putchar(c int) int
|
||||||
func _Cfunc_usleep(usec uint) int
|
func _Cfunc_usleep(usec uint) int
|
||||||
func _Cfunc_calloc(nmemb, size uintptr) unsafe.Pointer
|
func _Cfunc_malloc(size uintptr) unsafe.Pointer
|
||||||
func _Cfunc_abort()
|
func _Cfunc_abort()
|
||||||
func _Cfunc_clock_gettime(clk_id uint, ts *timespec)
|
func _Cfunc_clock_gettime(clk_id uint, ts *timespec)
|
||||||
|
|
||||||
|
const heapSize = 1 * 1024 * 1024 // 1MB to start
|
||||||
|
|
||||||
|
var heapStart = uintptr(_Cfunc_malloc(heapSize))
|
||||||
|
|
||||||
type timeUnit int64
|
type timeUnit int64
|
||||||
|
|
||||||
const tickMicros = 1
|
const tickMicros = 1
|
||||||
|
@ -62,27 +66,3 @@ func abort() {
|
||||||
// panic() exits with exit code 2.
|
// panic() exits with exit code 2.
|
||||||
_Cfunc_abort()
|
_Cfunc_abort()
|
||||||
}
|
}
|
||||||
|
|
||||||
func alloc(size uintptr) unsafe.Pointer {
|
|
||||||
buf := _Cfunc_calloc(1, size)
|
|
||||||
if buf == nil {
|
|
||||||
runtimePanic("cannot allocate memory")
|
|
||||||
}
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|
||||||
func free(ptr unsafe.Pointer) {
|
|
||||||
//C.free(ptr) // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
func GC() {
|
|
||||||
// Unimplemented.
|
|
||||||
}
|
|
||||||
|
|
||||||
func KeepAlive(x interface{}) {
|
|
||||||
// Unimplemented. Only required with SetFinalizer().
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetFinalizer(obj interface{}, finalizer interface{}) {
|
|
||||||
// Unimplemented.
|
|
||||||
}
|
|
||||||
|
|
|
@ -44,11 +44,6 @@ func ticks() timeUnit {
|
||||||
return timestamp
|
return timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
// Align on word boundary.
|
|
||||||
func align(ptr uintptr) uintptr {
|
|
||||||
return (ptr + 3) &^ 3
|
|
||||||
}
|
|
||||||
|
|
||||||
// Abort executes the wasm 'unreachable' instruction.
|
// Abort executes the wasm 'unreachable' instruction.
|
||||||
func abort() {
|
func abort() {
|
||||||
trap()
|
trap()
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче