aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mem_js.go
diff options
context:
space:
mode:
authorRichard Musiol <mail@richard-musiol.de>2019-04-28 12:16:44 +0200
committerRichard Musiol <neelance@gmail.com>2019-04-30 08:25:33 +0000
commitc2d9eea1f1d5bc4c49e3a97384ffcb40b7dd52bf (patch)
tree19ededd9eab06f8f4279b0b3efd6da85e9acc3d5 /src/runtime/mem_js.go
parentdcb84828a6b1d7d4d9186bc6d752cc147e255162 (diff)
downloadgo-c2d9eea1f1d5bc4c49e3a97384ffcb40b7dd52bf.tar.gz
go-c2d9eea1f1d5bc4c49e3a97384ffcb40b7dd52bf.zip
runtime: do not use heap arena hints on wasm
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 <neelance@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/mem_js.go')
-rw-r--r--src/runtime/mem_js.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/runtime/mem_js.go b/src/runtime/mem_js.go
index fc6092b2bb..7da4beda2a 100644
--- a/src/runtime/mem_js.go
+++ b/src/runtime/mem_js.go
@@ -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)