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

Side by Side Diff: base/android/jni_generator/jni_generator.py

Issue 2146753002: Android: Remove unneeded RegisterNatives() calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « base/android/java_runtime.cc ('k') | base/android/jni_utils.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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Extracts native methods from a Java file and generates the JNI bindings. 6 """Extracts native methods from a Java file and generates the JNI bindings.
7 If you change this, please run and update the tests.""" 7 If you change this, please run and update the tests."""
8 8
9 import collections 9 import collections
10 import errno 10 import errno
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 733
734 } // namespace 734 } // namespace
735 735
736 $OPEN_NAMESPACE 736 $OPEN_NAMESPACE
737 737
738 $CONSTANT_FIELDS 738 $CONSTANT_FIELDS
739 739
740 // Step 2: method stubs. 740 // Step 2: method stubs.
741 $METHOD_STUBS 741 $METHOD_STUBS
742 742
743 // Step 3: RegisterNatives.
744 $JNI_NATIVE_METHODS 743 $JNI_NATIVE_METHODS
745 $REGISTER_NATIVES 744 $REGISTER_NATIVES
746 $CLOSE_NAMESPACE 745 $CLOSE_NAMESPACE
747 746
748 #endif // ${HEADER_GUARD} 747 #endif // ${HEADER_GUARD}
749 """) 748 """)
750 values = { 749 values = {
751 'SCRIPT_NAME': self.options.script_name, 750 'SCRIPT_NAME': self.options.script_name,
752 'FULLY_QUALIFIED_CLASS': self.fully_qualified_class, 751 'FULLY_QUALIFIED_CLASS': self.fully_qualified_class,
753 'CLASS_PATH_DEFINITIONS': self.GetClassPathDefinitionsString(), 752 'CLASS_PATH_DEFINITIONS': self.GetClassPathDefinitionsString(),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 for clazz in all_classes: 809 for clazz in all_classes:
811 kmethods = self.GetKMethodsString(clazz) 810 kmethods = self.GetKMethodsString(clazz)
812 if kmethods: 811 if kmethods:
813 values = {'JAVA_CLASS': clazz, 812 values = {'JAVA_CLASS': clazz,
814 'KMETHODS': kmethods} 813 'KMETHODS': kmethods}
815 ret += [template.substitute(values)] 814 ret += [template.substitute(values)]
816 if not ret: return '' 815 if not ret: return ''
817 return '\n' + '\n'.join(ret) 816 return '\n' + '\n'.join(ret)
818 817
819 def GetJNINativeMethodsString(self): 818 def GetJNINativeMethodsString(self):
820 """Returns the implementation of the array of native methods.""" 819 """Returns the implementation of the array of native methods."""
no sievers 2016/07/13 01:47:47 maybe this should also have an early-out? can i ch
821 if self.options.native_exports and not self.options.native_exports_optional: 820 if self.options.native_exports and not self.options.native_exports_optional:
822 return '' 821 return ''
823 template = Template("""\ 822 template = Template("""\
824 static const JNINativeMethod kMethods${JAVA_CLASS}[] = { 823 static const JNINativeMethod kMethods${JAVA_CLASS}[] = {
825 ${KMETHODS} 824 ${KMETHODS}
826 }; 825 };
827 """) 826 """)
828 return self.SubstituteNativeMethods(template) 827 return self.SubstituteNativeMethods(template)
829 828
830 def GetRegisterNativesString(self): 829 def GetRegisterNativesString(self):
831 """Returns the code for RegisterNatives.""" 830 """Returns the code for RegisterNatives."""
831 natives = self.GetRegisterNativesImplString()
832 if not natives:
833 return ''
834
832 template = Template("""\ 835 template = Template("""\
833 ${REGISTER_NATIVES_SIGNATURE} { 836 ${REGISTER_NATIVES_SIGNATURE} {
834 ${EARLY_EXIT} 837 ${EARLY_EXIT}
835 ${CLASSES} 838 ${CLASSES}
836 ${NATIVES} 839 ${NATIVES}
837 return true; 840 return true;
838 } 841 }
839 """) 842 """)
840 signature = 'static bool RegisterNativesImpl(JNIEnv* env)' 843 signature = 'static bool RegisterNativesImpl(JNIEnv* env)'
841 early_exit = '' 844 early_exit = ''
842 if self.options.native_exports_optional: 845 if self.options.native_exports_optional:
843 early_exit = """\ 846 early_exit = """\
844 if (base::android::IsManualJniRegistrationDisabled()) return true; 847 if (base::android::IsManualJniRegistrationDisabled()) return true;
845 """ 848 """
846 849
847 natives = self.GetRegisterNativesImplString()
848 values = {'REGISTER_NATIVES_SIGNATURE': signature, 850 values = {'REGISTER_NATIVES_SIGNATURE': signature,
849 'EARLY_EXIT': early_exit, 851 'EARLY_EXIT': early_exit,
850 'CLASSES': self.GetFindClasses(), 852 'CLASSES': self.GetFindClasses(),
851 'NATIVES': natives, 853 'NATIVES': natives,
852 } 854 }
853 return template.substitute(values) 855 return template.substitute(values)
854 856
855 def GetRegisterNativesImplString(self): 857 def GetRegisterNativesImplString(self):
856 """Returns the shared implementation for RegisterNatives.""" 858 """Returns the shared implementation for RegisterNatives."""
857 if self.options.native_exports and not self.options.native_exports_optional: 859 if self.options.native_exports and not self.options.native_exports_optional:
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 static ${RETURN_TYPE} Java_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}(\ 1101 static ${RETURN_TYPE} Java_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}(\
1100 JNIEnv* env${FIRST_PARAM_IN_DECLARATION}${PARAMS_IN_DECLARATION})""") 1102 JNIEnv* env${FIRST_PARAM_IN_DECLARATION}${PARAMS_IN_DECLARATION})""")
1101 function_header_template = Template("""\ 1103 function_header_template = Template("""\
1102 ${FUNCTION_SIGNATURE} {""") 1104 ${FUNCTION_SIGNATURE} {""")
1103 function_header_with_unused_template = Template("""\ 1105 function_header_with_unused_template = Template("""\
1104 ${FUNCTION_SIGNATURE} __attribute__ ((unused)); 1106 ${FUNCTION_SIGNATURE} __attribute__ ((unused));
1105 ${FUNCTION_SIGNATURE} {""") 1107 ${FUNCTION_SIGNATURE} {""")
1106 template = Template(""" 1108 template = Template("""
1107 static base::subtle::AtomicWord g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0; 1109 static base::subtle::AtomicWord g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0;
1108 ${FUNCTION_HEADER} 1110 ${FUNCTION_HEADER}
1109 /* Must call RegisterNativesImpl() */
1110 CHECK_CLAZZ(env, ${FIRST_PARAM_IN_CALL}, 1111 CHECK_CLAZZ(env, ${FIRST_PARAM_IN_CALL},
1111 ${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN}); 1112 ${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN});
1112 jmethodID method_id = 1113 jmethodID method_id =
1113 ${GET_METHOD_ID_IMPL} 1114 ${GET_METHOD_ID_IMPL}
1114 ${RETURN_DECLARATION} 1115 ${RETURN_DECLARATION}
1115 ${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL}, 1116 ${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL},
1116 method_id${PARAMS_IN_CALL})${POST_CALL}; 1117 method_id${PARAMS_IN_CALL})${POST_CALL};
1117 ${CHECK_EXCEPTION} 1118 ${CHECK_EXCEPTION}
1118 ${RETURN_CLAUSE} 1119 ${RETURN_CLAUSE}
1119 }""") 1120 }""")
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 GenerateJNIHeader(input_file, output_file, options) 1392 GenerateJNIHeader(input_file, output_file, options)
1392 1393
1393 if options.depfile: 1394 if options.depfile:
1394 build_utils.WriteDepfile( 1395 build_utils.WriteDepfile(
1395 options.depfile, 1396 options.depfile,
1396 build_utils.GetPythonDependencies()) 1397 build_utils.GetPythonDependencies())
1397 1398
1398 1399
1399 if __name__ == '__main__': 1400 if __name__ == '__main__':
1400 sys.exit(main(sys.argv)) 1401 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « base/android/java_runtime.cc ('k') | base/android/jni_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698