Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android/jni/JniCallbacks.cpp

Issue 29354787: Issue 4442 - Cache class and ctors references in JNI_Load/UnLoad (Closed)
Patch Set: reverted to NewTuple Created Nov. 21, 2016, 8:25 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « libadblockplus-android/jni/JniCallbacks.h ('k') | libadblockplus-android/jni/JniFilter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libadblockplus-android/jni/JniCallbacks.cpp
diff --git a/libadblockplus-android/jni/JniCallbacks.cpp b/libadblockplus-android/jni/JniCallbacks.cpp
index d83a3b1e1f4329adda2d186abe199e124ad7687c..8eacee3d4c954d5cc956b18157f4cbfa8feedf0d 100644
--- a/libadblockplus-android/jni/JniCallbacks.cpp
+++ b/libadblockplus-android/jni/JniCallbacks.cpp
@@ -17,9 +17,25 @@
#include "JniCallbacks.h"
+// precached in JNI_OnLoad and released in JNI_OnUnload
+JniGlobalReference<jclass>* exceptionHandlerClass;
+
+void JniCallbacks_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved)
+{
+ exceptionHandlerClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG("JniExceptionHandler")));
+}
+
+void JniCallbacks_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved)
+{
+ if (exceptionHandlerClass)
+ {
+ delete exceptionHandlerClass;
+ exceptionHandlerClass = NULL;
+ }
+}
+
JniCallbackBase::JniCallbackBase(JNIEnv* env, jobject callbackObject)
- : callbackObject(new JniGlobalReference<jobject>(env, callbackObject)),
- exceptionLoggerClass(new JniGlobalReference<jclass>(env, env->FindClass(PKG("JniExceptionHandler"))))
+ : callbackObject(new JniGlobalReference<jobject>(env, callbackObject))
{
env->GetJavaVM(&javaVM);
}
@@ -31,10 +47,11 @@ JniCallbackBase::~JniCallbackBase()
void JniCallbackBase::LogException(JNIEnv* env, jthrowable throwable) const
{
- jmethodID logMethod = env->GetStaticMethodID(exceptionLoggerClass->Get(), "logException", "(Ljava/lang/Throwable;)V");
+ jmethodID logMethod = env->GetStaticMethodID(
+ exceptionHandlerClass->Get(), "logException", "(Ljava/lang/Throwable;)V");
if (logMethod)
{
- env->CallStaticVoidMethod(exceptionLoggerClass->Get(), logMethod, throwable);
+ env->CallStaticVoidMethod(exceptionHandlerClass->Get(), logMethod, throwable);
}
}
« no previous file with comments | « libadblockplus-android/jni/JniCallbacks.h ('k') | libadblockplus-android/jni/JniFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld