mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 22:43:40 +00:00
runtime: remove extalloc
The extalloc collector has been broken for a while, and it doesn't seem reasonable to fix right now. In addition, after a recent change it no longer compiles. In the future similar functionality can hopefully be reintroduced, but for now this seems to be the most reasonable option.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
//go:build (darwin || (linux && !baremetal && !wasi)) && !nintendoswitch
|
||||
// +build darwin linux,!baremetal,!wasi
|
||||
// +build !nintendoswitch
|
||||
|
||||
@@ -200,13 +201,6 @@ func syscall_Exit(code int) {
|
||||
exit(code)
|
||||
}
|
||||
|
||||
func extalloc(size uintptr) unsafe.Pointer {
|
||||
return malloc(size)
|
||||
}
|
||||
|
||||
//export free
|
||||
func extfree(ptr unsafe.Pointer)
|
||||
|
||||
// TinyGo does not yet support any form of parallelism on an OS, so these can be
|
||||
// left empty.
|
||||
|
||||
@@ -217,3 +211,46 @@ func procPin() {
|
||||
//go:linkname procUnpin sync/atomic.runtime_procUnpin
|
||||
func procUnpin() {
|
||||
}
|
||||
|
||||
var heapSize uintptr = 128 * 1024 // small amount to start
|
||||
var heapMaxSize uintptr
|
||||
|
||||
var heapStart, heapEnd uintptr
|
||||
|
||||
func preinit() {
|
||||
// Allocate a large chunk of virtual memory. Because it is virtual, it won't
|
||||
// really be allocated in RAM. Memory will only be allocated when it is
|
||||
// first touched.
|
||||
heapMaxSize = 1 * 1024 * 1024 * 1024 // 1GB for the entire heap
|
||||
for {
|
||||
addr := mmap(nil, heapMaxSize, flag_PROT_READ|flag_PROT_WRITE, flag_MAP_PRIVATE|flag_MAP_ANONYMOUS, -1, 0)
|
||||
if addr == unsafe.Pointer(^uintptr(0)) {
|
||||
// Heap was too big to be mapped by mmap. Reduce the maximum size.
|
||||
// We might want to make this a bit smarter than simply halving the
|
||||
// heap size.
|
||||
// This can happen on 32-bit systems.
|
||||
heapMaxSize /= 2
|
||||
continue
|
||||
}
|
||||
heapStart = uintptr(addr)
|
||||
heapEnd = heapStart + heapSize
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// growHeap tries to grow the heap size. It returns true if it succeeds, false
|
||||
// otherwise.
|
||||
func growHeap() bool {
|
||||
if heapSize == heapMaxSize {
|
||||
// Already at the max. If we run out of memory, we should consider
|
||||
// increasing heapMaxSize on 64-bit systems.
|
||||
return false
|
||||
}
|
||||
// Grow the heap size used by the program.
|
||||
heapSize = (heapSize * 4 / 3) &^ 4095 // grow by around 33%
|
||||
if heapSize > heapMaxSize {
|
||||
heapSize = heapMaxSize
|
||||
}
|
||||
setHeapEnd(heapStart + heapSize)
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user