summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--luni/src/main/native/JniConstants.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/luni/src/main/native/JniConstants.cpp b/luni/src/main/native/JniConstants.cpp
index a6b7b9e8d0..6f93d081f3 100644
--- a/luni/src/main/native/JniConstants.cpp
+++ b/luni/src/main/native/JniConstants.cpp
@@ -132,6 +132,15 @@ void JniConstants::Initialize(JNIEnv* env) {
}
void JniConstants::Invalidate() {
+ // This method is called when a new runtime instance is created. There is no
+ // notification of a runtime instance being destroyed in the JNI interface
+ // so we piggyback on creation. Since only one runtime is supported at a
+ // time, we know the constants are invalid when JNI_CreateJavaVM() is
+ // called.
+ //
+ // Clean shutdown would require calling DeleteGlobalRef() for each of the
+ // class references, but JavaVM is unavailable because ART only calls this
+ // once all threads are unregistered.
std::lock_guard guard(g_constants_mutex);
g_constants_valid = false;
}