Skip to content

Commit

Permalink
runtime: do not use heap arena hints on wasm
Browse files Browse the repository at this point in the history
The address space of WebAssembly's linear memory is contiguous, so
requesting specific addresses is not supported. Do not use heap arena
hints so we do not have unused memory ranges.

This fixes go1 benchmarks on wasm which ran out of memory since
https://golang.org/cl/170950.

Change-Id: I70115b18dbe43abe16dd5f57996343d97bf94760
Reviewed-on: https://go-review.googlesource.com/c/go/+/174203
Run-TryBot: Richard Musiol <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
  • Loading branch information
neelance authored and Richard Musiol committed Apr 30, 2019
1 parent dcb8482 commit c2d9eea
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/runtime/mem_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ var reserveEnd uintptr
func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer {
// TODO(neelance): maybe unify with mem_plan9.go, depending on how https://github.com/WebAssembly/design/blob/master/FutureFeatures.md#finer-grained-control-over-memory turns out

if v != nil {
// The address space of WebAssembly's linear memory is contiguous,
// so requesting specific addresses is not supported. We could use
// a different address, but then mheap.sysAlloc discards the result
// right away and we don't reuse chunks passed to sysFree.
return nil
}

if reserveEnd < lastmoduledatap.end {
reserveEnd = lastmoduledatap.end
}
if uintptr(v) < reserveEnd {
v = unsafe.Pointer(reserveEnd)
}
reserveEnd = uintptr(v) + n
v = unsafe.Pointer(reserveEnd)
reserveEnd += n

current := currentMemory()
needed := int32(reserveEnd/sys.DefaultPhysPageSize + 1)
Expand Down

0 comments on commit c2d9eea

Please sign in to comment.