Bug 1277624 - Move JNI class name out of Context; r=snorp
authorJim Chen <nchen@mozilla.com>
Mon, 27 Jun 2016 14:49:55 -0400
changeset 302744 91ca677e449639f200e2612da7201a540f772195
parent 302743 eb9d3d2aa71d713697cd364e8956d8c9183e76ed
child 302745 6f2a56ca83e77b8fa88b7f0c5104d5b02f329762
push id78856
push usernchen@mozilla.com
push dateMon, 27 Jun 2016 18:53:20 +0000
treeherdermozilla-inbound@5c6ee7ceb0a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1277624
milestone50.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 1277624 - Move JNI class name out of Context; r=snorp Move the class name strings into ObjectBase, so that the strings can be overridden by derived classes in other namespaces.
build/annotationProcessors/CodeGenerator.java
widget/android/jni/Refs.h
widget/android/jni/Utils.cpp
--- a/build/annotationProcessors/CodeGenerator.java
+++ b/build/annotationProcessors/CodeGenerator.java
@@ -37,23 +37,24 @@ public class CodeGenerator {
         this.clsName = annotatedClass.generatedName;
 
         final String unqualifiedName = Utils.getUnqualifiedName(clsName);
         header.append(
                 "class " + clsName + " : public mozilla::jni::ObjectBase<" +
                         unqualifiedName + ", jobject>\n" +
                 "{\n" +
                 "public:\n" +
+                "    static const char name[];\n" +
+                "\n" +
                 "    explicit " + unqualifiedName + "(const Context& ctx) : ObjectBase<" +
                         unqualifiedName + ", jobject>(ctx) {}\n" +
                 "\n");
 
         cpp.append(
-                "template<> const char mozilla::jni::Context<" +
-                        clsName + ", jobject>::name[] =\n" +
+                "const char " + clsName + "::name[] =\n" +
                 "        \"" + cls.getName().replace('.', '/') + "\";\n" +
                 "\n");
 
         natives.append(
                 "template<class Impl>\n" +
                 "class " + clsName + "::Natives : " +
                         "public mozilla::jni::NativeImpl<" + unqualifiedName + ", Impl>\n" +
                 "{\n" +
--- a/widget/android/jni/Refs.h
+++ b/widget/android/jni/Refs.h
@@ -168,18 +168,16 @@ class Context : public Ref<Cls, Type>
     using Ref = jni::Ref<Cls, Type>;
 
     static jclass sClassRef; // global reference
 
 protected:
     JNIEnv* const mEnv;
 
 public:
-    static const char name[];
-
     static jclass RawClassRef()
     {
         return sClassRef;
     }
 
     Context()
         : Ref(nullptr)
         , mEnv(Ref::FindEnv())
@@ -188,17 +186,17 @@ public:
     Context(JNIEnv* env, Type instance)
         : Ref(instance)
         , mEnv(env)
     {}
 
     jclass ClassRef() const
     {
         if (!sClassRef) {
-            sClassRef = GetClassGlobalRef(mEnv, name);
+            sClassRef = GetClassGlobalRef(mEnv, Cls::name);
         }
         return sClassRef;
     }
 
     JNIEnv* Env() const
     {
         return mEnv;
     }
@@ -246,16 +244,17 @@ protected:
 public:
     using Ref = jni::Ref<Cls, Type>;
     using Context = jni::Context<Cls, Type>;
     using LocalRef = jni::LocalRef<Cls>;
     using GlobalRef = jni::GlobalRef<Cls>;
     using Param = const Ref&;
 
     static const bool isMultithreaded = true;
+    static const char name[];
 
     explicit ObjectBase(const Context& ctx) : mCtx(ctx) {}
 
     Cls* operator->()
     {
         return static_cast<Cls*>(this);
     }
 };
--- a/widget/android/jni/Utils.cpp
+++ b/widget/android/jni/Utils.cpp
@@ -42,29 +42,29 @@ DEFINE_PRIMITIVE_TYPE_ADAPTER(int32_t,  
 DEFINE_PRIMITIVE_TYPE_ADAPTER(int64_t,  jlong,    Long,    /*nothing*/);
 DEFINE_PRIMITIVE_TYPE_ADAPTER(float,    jfloat,   Float,   MOZ_JNICALL_ABI);
 DEFINE_PRIMITIVE_TYPE_ADAPTER(double,   jdouble,  Double,  MOZ_JNICALL_ABI);
 
 #undef DEFINE_PRIMITIVE_TYPE_ADAPTER
 
 } // namespace detail
 
-template<> const char Context<Object, jobject>::name[] = "java/lang/Object";
-template<> const char Context<TypedObject<jstring>, jstring>::name[] = "java/lang/String";
-template<> const char Context<TypedObject<jclass>, jclass>::name[] = "java/lang/Class";
-template<> const char Context<TypedObject<jthrowable>, jthrowable>::name[] = "java/lang/Throwable";
-template<> const char Context<TypedObject<jbooleanArray>, jbooleanArray>::name[] = "[Z";
-template<> const char Context<TypedObject<jbyteArray>, jbyteArray>::name[] = "[B";
-template<> const char Context<TypedObject<jcharArray>, jcharArray>::name[] = "[C";
-template<> const char Context<TypedObject<jshortArray>, jshortArray>::name[] = "[S";
-template<> const char Context<TypedObject<jintArray>, jintArray>::name[] = "[I";
-template<> const char Context<TypedObject<jlongArray>, jlongArray>::name[] = "[J";
-template<> const char Context<TypedObject<jfloatArray>, jfloatArray>::name[] = "[F";
-template<> const char Context<TypedObject<jdoubleArray>, jdoubleArray>::name[] = "[D";
-template<> const char Context<TypedObject<jobjectArray>, jobjectArray>::name[] = "[Ljava/lang/Object;";
+template<> const char ObjectBase<Object, jobject>::name[] = "java/lang/Object";
+template<> const char ObjectBase<TypedObject<jstring>, jstring>::name[] = "java/lang/String";
+template<> const char ObjectBase<TypedObject<jclass>, jclass>::name[] = "java/lang/Class";
+template<> const char ObjectBase<TypedObject<jthrowable>, jthrowable>::name[] = "java/lang/Throwable";
+template<> const char ObjectBase<TypedObject<jbooleanArray>, jbooleanArray>::name[] = "[Z";
+template<> const char ObjectBase<TypedObject<jbyteArray>, jbyteArray>::name[] = "[B";
+template<> const char ObjectBase<TypedObject<jcharArray>, jcharArray>::name[] = "[C";
+template<> const char ObjectBase<TypedObject<jshortArray>, jshortArray>::name[] = "[S";
+template<> const char ObjectBase<TypedObject<jintArray>, jintArray>::name[] = "[I";
+template<> const char ObjectBase<TypedObject<jlongArray>, jlongArray>::name[] = "[J";
+template<> const char ObjectBase<TypedObject<jfloatArray>, jfloatArray>::name[] = "[F";
+template<> const char ObjectBase<TypedObject<jdoubleArray>, jdoubleArray>::name[] = "[D";
+template<> const char ObjectBase<TypedObject<jobjectArray>, jobjectArray>::name[] = "[Ljava/lang/Object;";
 
 
 JNIEnv* sGeckoThreadEnv;
 
 namespace {
 
 JavaVM* sJavaVM;
 pthread_key_t sThreadEnvKey;