Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Unified Diff: trunk/src/base/android/jni_generator/jni_generator.py

Issue 492713002: Revert 290810 "Make class lookup lazy in jni_generator when usin..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: trunk/src/base/android/jni_generator/jni_generator.py
===================================================================
--- trunk/src/base/android/jni_generator/jni_generator.py (revision 290812)
+++ trunk/src/base/android/jni_generator/jni_generator.py (working copy)
@@ -731,7 +731,7 @@
def GetContent(self):
"""Returns the content of the JNI binding file."""
template = Template("""\
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -947,11 +947,11 @@
template = Template("""\
const int kMethods${JAVA_CLASS}Size = arraysize(kMethods${JAVA_CLASS});
- if (env->RegisterNatives(${JAVA_CLASS}_clazz(env),
+ if (env->RegisterNatives(g_${JAVA_CLASS}_clazz,
kMethods${JAVA_CLASS},
kMethods${JAVA_CLASS}Size) < 0) {
jni_generator::HandleRegistrationError(
- env, ${JAVA_CLASS}_clazz(env), __FILE__);
+ env, g_${JAVA_CLASS}_clazz, __FILE__);
return false;
}
""")
@@ -1122,10 +1122,11 @@
def GetCalledByNativeValues(self, called_by_native):
"""Fills in necessary values for the CalledByNative methods."""
- java_class = called_by_native.java_class_name or self.class_name
if called_by_native.static or called_by_native.is_constructor:
first_param_in_declaration = ''
- first_param_in_call = ('%s_clazz(env)' % java_class)
+ first_param_in_call = ('g_%s_clazz' %
+ (called_by_native.java_class_name or
+ self.class_name))
else:
first_param_in_declaration = ', jobject obj'
first_param_in_call = 'obj'
@@ -1159,7 +1160,7 @@
else:
return_clause = 'return ret;'
return {
- 'JAVA_CLASS': java_class,
+ 'JAVA_CLASS': called_by_native.java_class_name or self.class_name,
'RETURN_TYPE': return_type,
'OPTIONAL_ERROR_RETURN': optional_error_return,
'RETURN_DECLARATION': return_declaration,
@@ -1203,7 +1204,7 @@
${FUNCTION_HEADER}
/* Must call RegisterNativesImpl() */
CHECK_CLAZZ(env, ${FIRST_PARAM_IN_CALL},
- ${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN});
+ g_${JAVA_CLASS}_clazz${OPTIONAL_ERROR_RETURN});
jmethodID method_id =
${GET_METHOD_ID_IMPL}
${RETURN_DECLARATION}
@@ -1262,56 +1263,22 @@
}
ret += [template.substitute(values)]
ret += ''
-
- class_getter_methods = []
- if self.options.native_exports:
+ for clazz in called_by_native_classes:
template = Template("""\
// Leaking this jclass as we cannot use LazyInstance from some threads.
-base::subtle::AtomicWord g_${JAVA_CLASS}_clazz = 0;
-jclass ${JAVA_CLASS}_clazz(JNIEnv* env) {
- return base::android::LazyGetClass(env, k${JAVA_CLASS}ClassPath, \
- &g_${JAVA_CLASS}_clazz);
-}""")
- else:
- template = Template("""\
-// Leaking this jclass as we cannot use LazyInstance from some threads.
-jclass g_${JAVA_CLASS}_clazz = NULL;
-jclass ${JAVA_CLASS}_clazz(JNIEnv*) { return g_${JAVA_CLASS}_clazz; }""")
-
- for clazz in called_by_native_classes:
+jclass g_${JAVA_CLASS}_clazz = NULL;""")
values = {
'JAVA_CLASS': clazz,
}
- class_getter_methods += [template.substitute(values)]
-
- template = Template("""\
-#if __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-function"
-#endif
-${CLASS_GETER_METHODS}
-#if __clang__
-#pragma clang diagnostic pop
-#endif""")
- values = {
- 'CLASS_GETER_METHODS': '\n'.join(class_getter_methods)
- }
- ret += [template.substitute(values)]
+ ret += [template.substitute(values)]
return '\n'.join(ret)
def GetFindClasses(self):
"""Returns the imlementation of FindClass for all known classes."""
if self.init_native:
- if self.options.native_exports:
- template = Template("""\
- base::subtle::Release_Store(&g_${JAVA_CLASS}_clazz,
- static_cast<base::subtle::AtomicWord>(env->NewWeakGlobalRef(clazz));""")
- else:
- template = Template("""\
+ template = Template("""\
g_${JAVA_CLASS}_clazz = static_cast<jclass>(env->NewWeakGlobalRef(clazz));""")
else:
- if self.options.native_exports:
- return '\n'
template = Template("""\
g_${JAVA_CLASS}_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
base::android::GetClass(env, k${JAVA_CLASS}ClassPath).obj()));""")
@@ -1326,13 +1293,13 @@
if self.options.eager_called_by_natives:
template = Template("""\
env->Get${STATIC_METHOD_PART}MethodID(
- ${JAVA_CLASS}_clazz(env),
+ g_${JAVA_CLASS}_clazz,
"${JNI_NAME}", ${JNI_SIGNATURE});""")
else:
template = Template("""\
base::android::MethodID::LazyGet<
base::android::MethodID::TYPE_${STATIC}>(
- env, ${JAVA_CLASS}_clazz(env),
+ env, g_${JAVA_CLASS}_clazz,
"${JNI_NAME}",
${JNI_SIGNATURE},
&g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME});

Powered by Google App Engine
This is Rietveld 408576698