Bug 1492308 - 1. Generate natives binding for all JNIObject classes; r=snorp
authorJim Chen <nchen@mozilla.com>
Tue, 02 Oct 2018 19:59:28 +0000
changeset 495018 0f4cf0de3dfa19eea89f6d5c55ac7f4e980e0c90
parent 495017 b2a709a740cf5851f7491862e7509129be87f567
child 495019 8ab31240dbec5dbe913462a7d68dfa3f5526cdce
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1492308
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1492308 - 1. Generate natives binding for all JNIObject classes; r=snorp Right now we skip generating natives binding for a class if the class doesn't have native methods. However, we should still generate the natives binding for JNIObject classes because these classes can still be attached to C++ objects even without native methods. Differential Revision: https://phabricator.services.mozilla.com/D7106
mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/CodeGenerator.java
mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/utils/Utils.java
--- a/mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/CodeGenerator.java
+++ b/mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/CodeGenerator.java
@@ -561,49 +561,53 @@ public class CodeGenerator {
      * @return The bytes to be written to the wrappers file.
      */
     public String getWrapperFileContents() {
         cpp.append(
                 Utils.getIfdefFooter(options.ifdef));
         return cpp.toString();
     }
 
+    private boolean haveNatives() {
+        return nativesInits.length() > 0 || Utils.isJNIObject(cls);
+    }
+
     /**
      * Get the finalised bytes to go into the generated header file.
      *
      * @return The bytes to be written to the header file.
      */
     public String getHeaderFileContents() {
         if (this.callingThread == null) {
             this.callingThread = AnnotationInfo.CallingThread.ANY;
         }
 
         header.append(
                 "    static const mozilla::jni::CallingThread callingThread =\n" +
                 "            " + this.callingThread.nativeValue() + ";\n" +
                 "\n");
 
-        if (nativesInits.length() > 0) {
+        if (haveNatives()) {
             header.append(
                     "    template<class Impl> class Natives;\n");
         }
         header.append(
                 "};\n" +
                 "\n" +
                 Utils.getIfdefFooter(options.ifdef));
         return header.toString();
     }
 
     /**
      * Get the finalised bytes to go into the generated natives header file.
      *
      * @return The bytes to be written to the header file.
      */
     public String getNativesFileContents() {
-        if (nativesInits.length() == 0) {
+        if (!haveNatives()) {
             return "";
         }
         natives.append(
                 "    static const JNINativeMethod methods[" + numNativesInits + "];\n" +
                 "};\n" +
                 "\n" +
                 "template<class Impl>\n" +
                 "const JNINativeMethod " + clsName + "::Natives<Impl>::methods[] = {" + nativesInits + '\n' +
--- a/mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/utils/Utils.java
+++ b/mobile/android/annotations/src/main/java/org/mozilla/gecko/annotationProcessors/utils/Utils.java
@@ -338,9 +338,18 @@ public class Utils {
     }
 
     public static String getIfdefFooter(String ifdef) {
         if (ifdef.isEmpty()) {
             return "";
         }
         return "#endif // " + ifdef + "\n";
     }
+
+    public static boolean isJNIObject(Class<?> cls) {
+        for (; cls != null; cls = cls.getSuperclass()) {
+            if (cls.getName().equals("org.mozilla.gecko.mozglue.JNIObject")) {
+                return true;
+            }
+        }
+        return false;
+    }
 }