Merge "Add a comment about the leaks in JniConstants"
diff --git a/luni/src/main/native/JniConstants.cpp b/luni/src/main/native/JniConstants.cpp
index a6b7b9e..6f93d08 100644
--- a/luni/src/main/native/JniConstants.cpp
+++ b/luni/src/main/native/JniConstants.cpp
@@ -132,6 +132,15 @@
}
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;
}