java.lang.StackOverflow Error for Android L previe

2019-05-12 20:23发布

Jumping straight to the topic, Android L introduces a ART as default runtime. I have a Sample Application, basically a document viewer. Most of the document viewing code including back buttons, Search,etc are written in C and the Android App uses JNI interface. I updated my code to make it build for Android L and it seems to open the document just fine. However, when pressing back button and closing the document, the Application seem to crash and the following backtrace is seen:

I/DEBUG   ( 1390): Abort message: 'art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: JNI CallIntMethodV called with pending exception 'java.lang.StackOverflowError' thrown in unknown throw location'
I/DEBUG   ( 1390): backtrace:
I/DEBUG   ( 1390):     #00 pc 000390d0  /system/lib/libc.so (tgkill+12)
I/DEBUG   ( 1390):     #01 pc 0001636d  /system/lib/libc.so (pthread_kill+64)
I/DEBUG   ( 1390):     #02 pc 00016e41  /system/lib/libc.so (raise+10)
I/DEBUG   ( 1390):     #03 pc 00013cdd  /system/lib/libc.so (__libc_android_abort+36)
I/DEBUG   ( 1390):     #04 pc 000125ac  /system/lib/libc.so (abort+4)
I/DEBUG   ( 1390):     #05 pc 00230fe9  /system/lib/libart.so (art::Runtime::Abort()+188)
I/DEBUG   ( 1390):     #06 pc 000b9571  /system/lib/libart.so     (art::LogMessage::~LogMessage()+1360)
I/DEBUG   ( 1390):     #07 pc 000c28cd  /system/lib/libart.so (art::JniAbort(char const*, char const*)+1124)
I/DEBUG   ( 1390):     #08 pc 000c2e11  /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+68)
I/DEBUG   ( 1390):     #09 pc 000c65e9  /system/lib/libart.so (art::ScopedCheck::ScopedCheck(_JNIEnv*, int, char const*)+1952)
I/DEBUG   ( 1390):     #10 pc 000cc8eb  /system/lib/libart.so (art::CheckJNI::CallIntMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list)+42)

Upon pressing back button, when file descriptor is supposed to close, CallIntMethodV is invoked, which ultimately fails in check JNI. Same code seems to work just fine on dalvik. I had to add the following flags to make JNI code compile fine for Android L preview:

-Wno-switch -Wno-sizeof-pointer-memaccess
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true

The key point is why it starts failing now on art, but not on dalvik. Any specific changes in CallIntMethodV causing the problem or compiler strictness is causing such error to be raised? Any pointers. I will be happy to provide additional details if required.

UPDATE: I temporarily disabled the call to File Close function that the native code calls into JNI and I do not seem to see any crash now.

1条回答
小情绪 Triste *
2楼-- · 2019-05-12 21:13

I would expect this problem has to do with a problem with references -- keeping a local reference around and using it on a different thread or something like that. I'm not sure what you meant by "native code calls into JNI to close the file", but perhaps you are passing a structure back to Java from JNI that needs to be flushed/released (so that the VM copies the data from the c structure back to the VM).

Apparently the ART has a few stricter jni checks than Dalvik. There is some detail on the Android site and further this page tells us how to debug them. You turn on checking for it on a real device using adb like this:

adb shell setprop debug.checkjni 1

Setting to to another value or rebooting the device will turn it off.

查看更多
登录 后发表回答