Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on firefox android edition #1

Closed
free1139 opened this issue Dec 13, 2018 · 1 comment
Closed

Fail on firefox android edition #1

free1139 opened this issue Dec 13, 2018 · 1 comment

Comments

@free1139
Copy link

free1139 commented Dec 13, 2018

build.sh

#!/bin/sh

GOROOT=/usr/local/go1.11
PATH=$GOROOT/bin:/usr/local/bin:/sbin:/bin

GOARCH=wasm GOOS=js go build -o ../../public/wasm/main.wasm
wams ../../public/wasm/main.wasm
wams -pages 2048 -write ../../public/wasm/main.wasm
wams ../../public/wasm/main.wasm

go version

go version go1.11.2 linux/amd64

On android firefox, it throws the following exception

runtime: out of memory: cannot allocate 8192-byte block (0 in use) wasm_exec.js:54:11
fatal error: out of memory wasm_exec.js:54:11

runtime stack: wasm_exec.js:54:11
runtime.throw(0x3177f, 0xd) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/panic.go:608 +0x6 fp=0x191098 sp=0x191070 pc=0x11a50006 wasm_exec.js:54:11
runtime.(*mcache).refill(0x1912e0, 0x18dc2a) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/mcache.go:124 +0x11 fp=0x1910c0 sp=0x191098 pc=0x10e80011 wasm_exec.js:54:11
runtime.(*mcache).nextFree.func1() wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/malloc.go:749 +0x2 fp=0x1910d8 sp=0x1910c0 pc=0x12f40002 wasm_exec.js:54:11
runtime.(*mcache).nextFree(0x1912e0, 0x2a, 0x8, 0x172e48, 0x1736c0) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/malloc.go:748 +0x8 fp=0x191130 sp=0x1910d8 pc=0x109b0008 wasm_exec.js:54:11
runtime.mallocgc(0x180, 0x2b480, 0x18dc01, 0x1952e0) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/malloc.go:903 +0x8f fp=0x1911d8 sp=0x191130 pc=0x109c008f wasm_exec.js:54:11
runtime.newobject(0x2b480, 0x10970021) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/malloc.go:1032 +0x3 fp=0x191200 sp=0x1911d8 pc=0x109e0003 wasm_exec.js:54:11
runtime.malg(0x8000, 0x156fe19e12829700) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/proc.go:3285 +0x2 fp=0x191238 sp=0x191200 pc=0x120f0002 wasm_exec.js:54:11
runtime.mpreinit(0x1736c0) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/os_js.go:57 +0x2 fp=0x191250 sp=0x191238 pc=0x118c0002 wasm_exec.js:54:11
runtime.mcommoninit(0x1736c0) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/proc.go:624 +0xb fp=0x191280 sp=0x191250 pc=0x11d2000b wasm_exec.js:54:11
runtime.schedinit() wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/proc.go:546 +0xc fp=0x1912e0 sp=0x191280 pc=0x11cf000c wasm_exec.js:54:11
runtime.rt0_go(0x0, 0x0, 0x0, 0x0, 0x173060, 0x173060, 0x173060, 0x173060, 0x173060, 0x173060, ...) wasm_exec.js:54:11
/usr/local/go1.11/src/runtime/asm_wasm.s:20 +0x4 fp=0x1912e8 sp=0x1912e0 pc=0x13290004 wasm_exec.js:54:11
exit code: 2

@termonio
Copy link
Owner

The problem was and still is that Go files compiled to WebAssembly require lots of RAM during instantiation (tested with Go 1.11). I don't know exactly how much, but I observed allocations during the initialization of about 11000 pages (about 710MB) on my desktop machine. I guess that is the reason why 1GB of RAM is hard coded into the .wasm file generated by Go 1.11. wams can't do anything about the amount of memory the Go runtime requires during initialization. What wams can do is to change the hard coded 1GB into something smaller if the Go compiler has been modified to require less memory. twifkak has published such a patch, for instance. This way you can experiment with wams how much memory is needed without patching the runtime each time (but you do have to modify the Go compiler once to get a patch as provided by twifkak working).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants