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

Side by Side Diff: libadblockplus-android/jni/JniLogSystem.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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libadblockplus-android/jni/JniLogSystem.h ('k') | libadblockplus-android/jni/JniNotification.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "JniCallbacks.h" 18 #include "JniCallbacks.h"
19 #include "JniLogSystem.h"
20
21 // precached in JNI_OnLoad and released in JNI_OnUnload
22 JniGlobalReference<jclass>* logLevelClass;
23
24 void JniLogSystem_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved)
25 {
26 logLevelClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG("LogSys tem$LogLevel")));
27 }
28
29 void JniLogSystem_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved)
30 {
31 if (logLevelClass)
32 {
33 delete logLevelClass;
34 logLevelClass = NULL;
35 }
36 }
19 37
20 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) 38 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject)
21 { 39 {
22 try 40 try
23 { 41 {
24 return JniPtrToLong(new JniLogSystemCallback(env, callbackObject)); 42 return JniPtrToLong(new JniLogSystemCallback(env, callbackObject));
25 } 43 }
26 CATCH_THROW_AND_RETURN(env, 0) 44 CATCH_THROW_AND_RETURN(env, 0)
27 } 45 }
28 46
29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 47 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
30 { 48 {
31 delete JniLongToTypePtr<JniLogSystemCallback>(ptr); 49 delete JniLongToTypePtr<JniLogSystemCallback>(ptr);
32 } 50 }
33 51
34 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject) 52 JniLogSystemCallback::JniLogSystemCallback(JNIEnv* env, jobject callbackObject)
35 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem(), logLevelClas s(new JniGlobalReference<jclass>(env, env->FindClass(PKG("LogSystem$LogLevel"))) ) 53 : JniCallbackBase(env, callbackObject), AdblockPlus::LogSystem()
36 { 54 {
37 } 55 }
38 56
39 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel, 57 void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel,
40 const std::string& message, const std::string& source) 58 const std::string& message, const std::string& source)
41 { 59 {
42 JNIEnvAcquire env(GetJavaVM()); 60 JNIEnvAcquire env(GetJavaVM());
43 61
44 jmethodID method = env->GetMethodID( 62 jmethodID method = env->GetMethodID(
45 *JniLocalReference<jclass>(*env, 63 *JniLocalReference<jclass>(*env,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 static JNINativeMethod methods[] = 115 static JNINativeMethod methods[] =
98 { 116 {
99 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 117 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
100 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 118 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
101 }; 119 };
102 120
103 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_ registerNatives(JNIEnv *env, jclass clazz) 121 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_LogSystem_ registerNatives(JNIEnv *env, jclass clazz)
104 { 122 {
105 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 123 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
106 } 124 }
OLDNEW
« no previous file with comments | « libadblockplus-android/jni/JniLogSystem.h ('k') | libadblockplus-android/jni/JniNotification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld