3 Suppose your method looks like
6 T1 foo(T2 x, T3 y, ...)
9 where the `Ti` are Java types.
11 If `T1` is a primitive type or `void`, then the mangled MJI method looks
15 public static T1 foo__MT2MT3...__MT1(...)
18 where the `MTi` are the mangled versions of the `Ti`.
19 Mangling of types is described in the Mangling Types section below.
20 Note that `T1` appears twice, once not mangled (`T1`) and once mangled
21 (`MT1`). The `__` is two consecutive underscores: `_` followed by
24 As a not-so-special case, if `foo` has no arguments, then the mangled method
25 will have four consecutive underscores:
34 `public static T1 foo____MT1(...)`
37 If `T1` is not a primitive type, then the mangled `MJI` method looks like
40 `public static int foo__MT2MT3...__MT1`
43 where the `MTi` are as above. Note that `T1` only appears once in this
44 case. The method's return type is `int`. As before, a method with no
45 arguments gets mangled to something with four consecutive underscores.
47 Also, the use of generics is ignored when mangling names.
50 ## Mangling Constructors ##
51 Constructors are treated as methods named `$init` with return type `void`.
54 ## Mangling Static Initializers ##
55 Static initializers are treated as methods named `$clinit` with no
56 arguments and return type `void`. Thus, their MJI versions always
57 have the mangled signature:
60 public static void $clinit____V (MJIEnv env, int clsObjRef)
63 or the equivalent unmangled signature:
66 public static void $clinit (MJIEnv env, int clsObjRef)
71 - Convert primitives and `void` as follows
73 |Java Type|Mangled Type|
85 - Convert a non-array reference type `T` in package `x.y`
86 (e.g. `java.lang.String`) as follows
87 - `x.y.T` --> `Lx_y_T_2`
88 - Example: `java.lang.String` --> `Ljava_lang_String_2`
90 - Convert an array of primitive type `T`
91 (e.g. `byte[]`) as follows:
92 - `T[]` --> `_3MT` where `MT` is the mangled version of `T`
93 (e.g. for `T=byte`, `MT=B`)
94 - Example: `byte[]` --> `_3B`
96 - Convert an array of reference type `T` in package `x.y`
97 (e.g. `java.lang.String[]`) as follows:
98 - `x.y.T[]` --> `_3Lx_y_T_2`
99 - Example: `java.lang.String[]` --> `_3Ljava_lang_String_2`
102 ## Method Examples ##
104 `void` return type, single primitive argument:
107 public static void resetCounter(int id)
109 public static final void resetCounter__I__V(MJIEnv env, int objref, int id)
112 Primitive return type, no arguments:
115 public native boolean isArray()
117 public static boolean isArray____Z(MJIEnv env, int objref)
120 Primitive return type, single primitive argument:
123 public static double abs(double a)
125 public static double abs__D__D(MJIEnv env, int clsObjRef, double a)
128 Primitive return type, two primitive arguments:
131 public static long min(long a, long b)
133 public static long min__JJ__J(MJIEnv env, int clsObjRef, long a, long b)
137 `void` return type, arguments include an array of a primitive type:
140 public native void write (byte[] buf, int off, int len);
142 public static void write___3BII__V(MJIEnv env, int objref,
143 int bufRef, int off, int len)
147 `void` return type, argument is an array of a reference type:
150 public static void print(String s)
152 public static void print___3Ljava_lang_String_2__V(MJIEnv env, int clsRef, int argsRef)
155 Array of reference types returned, no arguments:
158 public native Annotation[] getAnnotations()
160 public static int getAnnotations_____3Ljava_lang_annotation_Annotation_2(MJIEnv env, int robj)
162 Notice there are 5 underscores before the `3L`: two marking the
163 arguments, two marking the return type, and one from the `_3`
166 Array of reference types using generics returned, no arguments:
169 public native Class<?>[] getParameterTypes()
171 public static int getParameterTypes_____3Ljava_lang_Class_2(MJIEnv env, int objref)
174 Note: the use of generics is ignored in the mangling.
178 ## Constructor Examples ##
180 Constructors are treated as though they were methods named `$init`
181 returning `void`, so the method examples above should also be helpful
182 for constructors. Here are a few more examples.
184 In the class `ConsoleOutputStream`:
187 public ConsoleOutputStream()
189 public static void $init____V(MJIEnv env, int objref)
192 In the class `AtomicLongFieldUpdater`:
195 protected AtomicLongFieldUpdater(Class<T> objClass, String fieldName)
197 public static void $init__Ljava_lang_Class_2Ljava_lang_String_2__V
198 (MJIEnv env, int objRef,
199 int tClsObjRef, int fNameRef)