run init in a goroutine

This commit is contained in:
Jaden Weiss
2020-02-07 19:20:36 -05:00
committed by Ayke
parent 5d869f6042
commit 0759b70c50
7 changed files with 21 additions and 7 deletions
+1 -1
View File
@@ -180,7 +180,7 @@ func (b gcBlock) unmark() {
// No memory may be allocated before this is called. That means the runtime and
// any packages the runtime depends upon may not allocate memory during package
// initialization.
func init() {
func initHeap() {
totalSize := heapEnd - heapStart
// Allocate some memory to keep 2 bits of information about every block.
+4
View File
@@ -45,3 +45,7 @@ func KeepAlive(x interface{}) {
func SetFinalizer(obj interface{}, finalizer interface{}) {
// Unimplemented.
}
func initHeap() {
// Nothing to initialize.
}
+4
View File
@@ -27,3 +27,7 @@ func KeepAlive(x interface{}) {
func SetFinalizer(obj interface{}, finalizer interface{}) {
// Unimplemented.
}
func initHeap() {
// Nothing to initialize.
}
+4 -4
View File
@@ -26,10 +26,7 @@ func clock_gettime(clk_id int32, ts *timespec)
const heapSize = 1 * 1024 * 1024 // 1MB to start
var (
heapStart = uintptr(malloc(heapSize))
heapEnd = heapStart + heapSize
)
var heapStart, heapEnd uintptr
type timeUnit int64
@@ -50,6 +47,9 @@ func postinit() {}
// Entry point for Go. Initialize all packages and call main.main().
//go:export main
func main() int {
heapStart = uintptr(malloc(heapSize))
heapEnd = heapStart + heapSize
run()
// For libc compatibility.
+4
View File
@@ -22,6 +22,10 @@ func postinit() {}
//export _start
func _start() {
// These need to be initialized early so that the heap can be initialized.
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
run()
}
+3 -2
View File
@@ -14,9 +14,10 @@ func sleep(duration int64) {
// run is called by the program entry point to execute the go program.
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
func run() {
initAll()
postinit()
initHeap()
go func() {
initAll()
postinit()
callMain()
}()
scheduler()
+1
View File
@@ -16,6 +16,7 @@ func getSystemStackPointer() uintptr {
// run is called by the program entry point to execute the go program.
// With the "none" scheduler, init and the main function are invoked directly.
func run() {
initHeap()
initAll()
postinit()
callMain()