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

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

Issue 2361353002: Link stack frames of JNI stubs to JNI callbacks. (Closed)
Patch Set: Simplify - remove FakeStackFrame, etc. Created 4 years, 2 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: base/android/jni_generator/jni_generator.py
diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py
index 007fedf77fe0138aa3cc3c5722def6bda287a76a..4290219a54ab93a85e37e39c0b213b696033dd83 100755
--- a/base/android/jni_generator/jni_generator.py
+++ b/base/android/jni_generator/jni_generator.py
@@ -736,6 +736,7 @@ class InlHeaderFileGenerator(object):
${INCLUDES}
+${PROFILING_INCLUDES}
#include "base/android/jni_int_wrapper.h"
// Step 1: forward declarations.
@@ -770,6 +771,7 @@ $CLOSE_NAMESPACE
'CLOSE_NAMESPACE': self.GetCloseNamespaceString(),
'HEADER_GUARD': self.header_guard,
'INCLUDES': self.GetIncludesString(),
+ 'PROFILING_INCLUDES': self.GetProfilingIncludesString(),
}
assert ((values['JNI_NATIVE_METHODS'] == '') ==
(values['REGISTER_NATIVES'] == ''))
@@ -807,6 +809,11 @@ $CLOSE_NAMESPACE
includes = self.options.includes.split(',')
return '\n'.join('#include "%s"' % x for x in includes)
+ def GetProfilingIncludesString(self):
+ if not self.options.enable_profiling:
+ return ''
+ return '#include "base/compiler_specific.h"'
+
def GetKMethodsString(self, clazz):
ret = []
for native in self.natives:
@@ -1001,6 +1008,9 @@ ${NATIVES}
post_call = '.Release()'
return_declaration = ('base::android::ScopedJavaLocalRef<' + return_type +
'>')
+ profiling_entered_native = ''
+ if self.options.enable_profiling:
+ profiling_entered_native = 'JNI_PROFILING_ENTERED_NATIVE;'
values = {
'RETURN': return_type,
'RETURN_DECLARATION': return_declaration,
@@ -1010,6 +1020,7 @@ ${NATIVES}
'PARAMS_IN_CALL': params_in_call,
'POST_CALL': post_call,
'STUB_NAME': self.GetStubName(native),
+ 'PROFILING_ENTERED_NATIVE': profiling_entered_native,
}
if is_method:
@@ -1025,6 +1036,7 @@ ${NATIVES}
extern "C" __attribute__((visibility("default")))
${RETURN} ${STUB_NAME}(JNIEnv* env,
${PARAMS_IN_STUB}) {
+ ${PROFILING_ENTERED_NATIVE}
${P0_TYPE}* native = reinterpret_cast<${P0_TYPE}*>(${PARAM0_NAME});
CHECK_NATIVE_PTR(env, jcaller, native, "${NAME}"${OPTIONAL_ERROR_RETURN});
return native->${NAME}(${PARAMS_IN_CALL})${POST_CALL};
@@ -1036,6 +1048,7 @@ static ${RETURN_DECLARATION} ${NAME}(JNIEnv* env, ${PARAMS});
extern "C" __attribute__((visibility("default")))
${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) {
+ ${PROFILING_ENTERED_NATIVE}
return ${NAME}(${PARAMS_IN_CALL})${POST_CALL};
}
""")
@@ -1093,6 +1106,9 @@ ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) {
return_clause = 'return ' + return_type + '(env, ret);'
else:
return_clause = 'return ret;'
+ profiling_leaving_native = ''
+ if self.options.enable_profiling:
+ profiling_leaving_native = 'JNI_PROFILING_LEAVING_NATIVE;'
return {
'JAVA_CLASS': java_class,
'RETURN_TYPE': return_type,
@@ -1108,7 +1124,8 @@ ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS_IN_STUB}) {
'PARAMS_IN_CALL': params_in_call,
'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name,
'CHECK_EXCEPTION': check_exception,
- 'GET_METHOD_ID_IMPL': self.GetMethodIDImpl(called_by_native)
+ 'GET_METHOD_ID_IMPL': self.GetMethodIDImpl(called_by_native),
+ 'PROFILING_LEAVING_NATIVE': profiling_leaving_native,
}
@@ -1129,6 +1146,7 @@ ${FUNCTION_HEADER}
${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN});
jmethodID method_id =
${GET_METHOD_ID_IMPL}
+ ${PROFILING_LEAVING_NATIVE}
${RETURN_DECLARATION}
${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL},
method_id${PARAMS_IN_CALL})${POST_CALL};
@@ -1363,6 +1381,8 @@ See SampleForTests.java for more details.
option_parser.add_option('--native_exports_optional', action='store_true',
help='Support both explicit and native method'
'registration.')
+ option_parser.add_option('--enable_profiling', action='store_true',
+ help='Add additional profiling instrumentation.')
options, args = option_parser.parse_args(argv)
if options.jar_file:
input_file = ExtractJarInputFile(options.jar_file, options.input_file,

Powered by Google App Engine
This is Rietveld 408576698