Reputation: 845
I'm working on an Android app consisting of Kotlin (for the UI/UX) and C++ (app logic). I'm using JNI to bridge C++ to Kotlin. When a new thread is created, AttachCurrentThread is invoked to attach the thread to JVM and when app is about to quit, DetachCurrentThread is invoked before killing the thread.
In a normal scenario, there is no problem. But when an exception occurs, the signal/exception is trapped in the signal handler (same as Linux's signal handler) or Kotlin's Thread.UncaughtExceptionHandler, both will abruptly terminate the process (after logging some diagnostic info). So, there won't be a chance to DetachCurrentThread
from JVM (and perform other cleanup activities). According to this post, not invoking DetachCurrentThread
can terminate the DVM.
After reading about DVM, ART etc., I have the following understanding -
From Android 5 onwards, Android uses ART instead of DVM. I'm visualizing ART as 'a form of JVM' + Android SDK. Every Android app gets its own instance of ART. So, when app gets terminated abruptly due to an exception, it will bring down the ART (like DVM?, since DetachCurrentThread
wasn't invoked) and it won't affect other apps in the device, which have their own ART. Since it doesn't affect other apps, it should be fine for my app to crash due to an exception.
Sources:
I originally had the following questions:
DetachCurrentThread
?Conclusions based on my understanding:
This post is mainly to confirm my understanding on impact of exceptions on ART, other potential consequences and to confirm the conclusions I've arrived at.
Upvotes: 0
Views: 29