Skip to content

runtime, x/mobile: go1.9 causes memory issue on Android #21044

Closed
@achojoao

Description

@achojoao

What version of Go are you using (go version)?

go version go1.9beta2 darwin/amd64 (same problem detected using go version go1.9beta1 darwin/amd64)

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jvicente/go"
GORACE=""
GOROOT="/Users/jvicente/sdk/go1.9beta2"
GOTOOLDIR="/Users/jvicente/sdk/go1.9beta2/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hk/wxyjvmbs4j3bbh_cfpr6j0c80000gn/T/go-build179128729=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

We have a custom native library implemented in Go and we are using it (via NDK-JNI) in an Android library project using gomobile. The final library is used in two completely different apps. We were using Go 1.8.3 version and it worked ok, until we had a problem on several Android devices (mostly Samsung devices) with Android 7 regarding PTHREAD_MAX. That problem was fixed in #19472 (reference), so we tried the new betas, 1.9beta1 and lately, 1.9beta2. The error with those Samsung with Android 7 have disappeared, but, now we have reports from users with Android 5 to 6.0.1 devices having memory issues in one of the apps.

List of devices with reported failures:

Samsung Galaxy S5 - Android 6.0.1 - ARMv7 32-bit
Samsung Galaxy A3 - Android 6.0.1 - ARMv8-A 64-bit
BQ Aquaris M5 - Android 6.0.1 - ARMv8-A 64-bit
Motorola XT1562 - Android 6.0.1 - ARMv8-A 64-bit
Samsung S4 - Android: 5.0.1 - ARMv7 32-bit

As yo can see below, we are obtaining two different errors: "index out of range" and "out of memory". Both errors appears the first time I call any method of the Go library via JNI. I'm very sure we are calling from the Java side to the native libraries. I have put some logs in the Go classes and methods, but I can't see any in the Android console, so no Go code from my library is being executed. I guess errors are throwed during the initialization process of the Go environment.

I've managed to get the failing Samsung Galaxy A3. Weird thing, from my point of view, is that I've tried both apps in this device and is failing only in one and not in the other. Both apps are using the same library. Failing one is heavier than the other (both in RAM use and HD) but analizing memory dump and other data I can't see anything out of normal (see attached files). I mean, it looks like there is enough free memory.

failing_app
working_app

What did you expect to see?

Normal execution of the app

What did you see instead?

After the errors occurred, the app is automatically crashing and closing.

For Samsung A3 (Android 6.0.1)

07-11 11:05:45.439 24692 25169 E Go : fatal error: index out of range
07-11 11:05:45.439 24692 25169 E Go : runtime stack:
07-11 11:05:45.449 24692 25169 E Go : runtime.throw(0x90074853, 0x12)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/panic.go:605 +0x78 fp=0x8ff89680 sp=0x8ff89674 pc=0x8ffe0554
07-11 11:05:45.449 24692 25169 E Go : runtime.panicCheckMalloc(0x9017c870, 0x90179430)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/panic.go:20 +0x60 fp=0x8ff89690 sp=0x8ff89680 pc=0x8ffdeacc
07-11 11:05:45.449 24692 25169 E Go : runtime.panicindex()
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/panic.go:27 +0x34 fp=0x8ff8969c sp=0x8ff89690 pc=0x8ffdeb44
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mheap).grow(0x90191558, 0x8, 0x0)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mheap.go:905 +0x2b0 fp=0x8ff896d0 sp=0x8ff8969c pc=0x8ffd8e38
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mheap).allocSpanLocked(0x90191558, 0x1, 0x9019dae0, 0x8fffd1a4)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mheap.go:795 +0x32c fp=0x8ff896f0 sp=0x8ff896d0 pc=0x8ffd8a08
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mheap).alloc_m(0x90191558, 0x1, 0x9017001e, 0x3cc3)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mheap.go:661 +0x144 fp=0x8ff89710 sp=0x8ff896f0 pc=0x8ffd8198
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mheap).alloc.func1()
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mheap.go:728 +0x3c fp=0x8ff89728 sp=0x8ff89710 pc=0x90009034
07-11 11:05:45.449 24692 25169 E Go : runtime.systemstack(0x8ff8973c)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/asm_arm.s:278 +0xb4 fp=0x8ff8972c sp=0x8ff89728 pc=0x9000abf4
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mheap).alloc(0x90191558, 0x1, 0x1001e, 0x1)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mheap.go:727 +0x64 fp=0x8ff89750 sp=0x8ff8972c pc=0x8ffd8570
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mcentral).grow(0x901927b8, 0x0)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mcentral.go:232 +0x98 fp=0x8ff89774 sp=0x8ff89750 pc=0x8ffc8ae0
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mcentral).cacheSpan(0x901927b8, 0x8ffb5c04)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mcentral.go:106 +0x374 fp=0x8ff897a0 sp=0x8ff89774 pc=0x8ffc85a0
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mcache).refill(0x994c7000, 0x3c01e, 0x8ffc5148)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mcache.go:123 +0x84 fp=0x8ff897b8 sp=0x8ff897a0 pc=0x8ffc80ac
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mcache).nextFree.func1()
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/malloc.go:553 +0x24 fp=0x8ff897c8 sp=0x8ff897b8 pc=0x90007f58
07-11 11:05:45.449 24692 25169 E Go : runtime.systemstack(0x8ff897ec)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/asm_arm.s:278 +0xb4 fp=0x8ff897cc sp=0x8ff897c8 pc=0x9000abf4
07-11 11:05:45.449 24692 25169 E Go : runtime.(*mcache).nextFree(0x994c7000, 0x1e, 0x0, 0x9019db20, 0x994c7000)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/malloc.go:552 +0x90 fp=0x8ff897f8 sp=0x8ff897cc pc=0x8ffc40c4
07-11 11:05:45.449 24692 25169 E Go : runtime.mallocgc(0xe0, 0x90118660, 0x1, 0x1)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/malloc.go:707 +0x658 fp=0x8ff89854 sp=0x8ff897f8 pc=0x8ffc490c
07-11 11:05:45.449 24692 25169 E Go : runtime.newobject(0x90118660, 0x8ffe3348)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/malloc.go:836 +0x2c fp=0x8ff89868 sp=0x8ff89854 pc=0x8ffc4c1c
07-11 11:05:45.449 24692 25169 E Go : runtime.malg(0x8000, 0x4ca9094d)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/proc.go:2884 +0x20 fp=0x8ff89884 sp=0x8ff89868 pc=0x8ffe939c
07-11 11:05:45.449 24692 25169 E Go : runtime.mpreinit(0x9018bf38)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/os_linux.go:302 +0x1c fp=0x8ff89894 sp=0x8ff89884 pc=0x8ffde6fc
07-11 11:05:45.449 24692 25169 E Go : runtime.mcommoninit(0x9018bf38)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/proc.go:536 +0xa4 fp=0x8ff898ac sp=0x8ff89894 pc=0x8ffe3388
07-11 11:05:45.449 24692 25169 E Go : runtime.schedinit()
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/proc.go:472 +0x44 fp=0x8ff898c8 sp=0x8ff898ac pc=0x8ffe2e90
07-11 11:05:45.449 24692 25169 E Go : runtime.rt0_go(0x1, 0x9017c3e8, 0xb6c8680f, 0xb6c867f5, 0x8ff89938, 0xb6c867f5, 0xb6c5e317, 0x8ff89978, 0x0, 0x929cf930, ...)
07-11 11:05:45.449 24692 25169 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/asm_arm.s:61 +0x8c fp=0x8ff89908 sp=0x8ff898c8 pc=0x9000a9b4

For Samsung Galaxy S5 (Android 6.0.1)

07-11 11:41:18.474 23471 24803 E Go : runtime: out of memory: cannot allocate 65536-byte block (0 in use)
07-11 11:41:18.474 23471 24803 E Go : fatal error: out of memory
07-11 11:41:18.544 23471 24803 E Go : runtime stack:
07-11 11:41:18.544 23471 24803 E Go : runtime.throw(0x89983cef, 0xd)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/panic.go:605 +0x78 fp=0x884927a0 sp=0x88492794 pc=0x898f0554
07-11 11:41:18.544 23471 24803 E Go : runtime.(*mcache).refill(0x91b33000, 0x3c01e, 0x898d5148)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/mcache.go:125 +0xfc fp=0x884927b8 sp=0x884927a0 pc=0x898d8124
07-11 11:41:18.544 23471 24803 E Go : runtime.(*mcache).nextFree.func1()
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/malloc.go:553 +0x24 fp=0x884927c8 sp=0x884927b8 pc=0x89917f58
07-11 11:41:18.544 23471 24803 E Go : runtime.systemstack(0x884927ec)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/asm_arm.s:278 +0xb4 fp=0x884927cc sp=0x884927c8 pc=0x8991abf4
07-11 11:41:18.544 23471 24803 E Go : runtime.(*mcache).nextFree(0x91b33000, 0x1e, 0x0, 0x89aadb20, 0x91b33000)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/malloc.go:552 +0x90 fp=0x884927f8 sp=0x884927cc pc=0x898d40c4
07-11 11:41:18.544 23471 24803 E Go : runtime.mallocgc(0xe0, 0x89a28660, 0x1, 0x1)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/malloc.go:707 +0x658 fp=0x88492854 sp=0x884927f8 pc=0x898d490c
07-11 11:41:18.544 23471 24803 E Go : runtime.newobject(0x89a28660, 0x898f3348)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/malloc.go:836 +0x2c fp=0x88492868 sp=0x88492854 pc=0x898d4c1c
07-11 11:41:18.544 23471 24803 E Go : runtime.malg(0x8000, 0x14996bc1)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/proc.go:2884 +0x20 fp=0x88492884 sp=0x88492868 pc=0x898f939c
07-11 11:41:18.544 23471 24803 E Go : runtime.mpreinit(0x89a9bf38)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/os_linux.go:302 +0x1c fp=0x88492894 sp=0x88492884 pc=0x898ee6fc
07-11 11:41:18.544 23471 24803 E Go : runtime.mcommoninit(0x89a9bf38)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/proc.go:536 +0xa4 fp=0x884928ac sp=0x88492894 pc=0x898f3388
07-11 11:41:18.544 23471 24803 E Go : runtime.schedinit()
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/proc.go:472 +0x44 fp=0x884928c8 sp=0x884928ac pc=0x898f2e90
07-11 11:41:18.544 23471 24803 E Go : runtime.rt0_go(0x1, 0x89a8c3e8, 0xb6c9750b, 0xb6c974f1, 0x88492938, 0xb6c974f1, 0xb6c71c95, 0x88492978, 0x0, 0x82703930, ...)
07-11 11:41:18.544 23471 24803 E Go : /Users/jvicente/sdk/go1.9beta2/src/runtime/asm_arm.s:61 +0x8c fp=0x88492908 sp=0x884928c8 pc=0x8991a9b4

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions