NightFuryLxD
NightFuryLxD

Reputation: 845

Impact on ART due to process termination from exception

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:

  1. Does ART behave the same way as DVM i.e., it also terminates when app is killed without invoking DetachCurrentThread?
  2. Does every app get its own instance of ART?
  3. In the worst case, if my app gets terminated due to an exception and ART is also brought down, does it affect other apps (closely tied to question 2) or does it negatively impact my app, leading to consequences like getting kicked from Playstore?

Conclusions based on my understanding:

  1. Sill not sure of this :(.
  2. I think, yes, every app gets its own instance of ART.
  3. If every app gets is own instance of ART (as concluded from 2), app and ART will crash, but it shouldn't affect other apps in the user's device. It's definitely a negative experience, but not sure if there are other consequences.

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

Answers (0)

Related Questions