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.
This commit is contained in:
Ayke van Laethem
2018-11-17 14:11:58 +01:00
parent 4fdffdf8b2
commit 15a4afb22a
9 changed files with 37 additions and 47 deletions
+5 -25
View File
@@ -8,10 +8,14 @@ import (
func _Cfunc_putchar(c int) 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_clock_gettime(clk_id uint, ts *timespec)
const heapSize = 1 * 1024 * 1024 // 1MB to start
var heapStart = uintptr(_Cfunc_malloc(heapSize))
type timeUnit int64
const tickMicros = 1
@@ -62,27 +66,3 @@ func abort() {
// panic() exits with exit code 2.
_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.
}