diff --git a/docs/html/guide/practices/design/jni.jd b/docs/html/guide/practices/design/jni.jd index 9980efdf0c3f4..ddfa0e3991f52 100644 --- a/docs/html/guide/practices/design/jni.jd +++ b/docs/html/guide/practices/design/jni.jd @@ -17,7 +17,7 @@ page.title=JNI Tips
UnsatisfiedLinkErrorFindClass find my class?All JNI 1.6 features are supported, with the following exceptions:
+All JNI 1.6 features are supported, with the following exception:
DefineClass is not implemented. Android does not use
Java bytecodes or class files, so passing in binary class data
doesn't work.NewLocalRef, NewGlobalRef, and
- DeleteWeakGlobalRef. (The spec strongly encourages
- programmers to create hard references to weak globals before doing
- anything with them, so this should not be at all limiting.)GetObjectRefType (new in JNI 1.6) is implemented but not fully
- functional — it can't always tell the difference between "local" and
- "global" references.For backward compatibility, you may need to be aware of:
+For backward compatibility with older Android releases, you may need to +be aware of:
Until Android 2.0 (Eclair), the '$' character was not properly converted to "_00024" during searches for method names. Working around this requires using explicit registration or moving the native methods out of inner classes. -
pthread_key_create
+ Until Android 2.0 (Eclair), it was not possible to use a pthread_key_create
destructor function to avoid the "thread must be detached before
exit" check. (The runtime also uses a pthread key destructor function,
so it'd be a race to see which gets called first.)
-
Until Android 2.2 (Froyo), weak global references were not implemented. Older versions will vigorously reject attempts to use them. You can use the Android platform version constants to test for support. -
Until Android 4.0 (Ice Cream Sandwich), weak global references could only
+ be passed to NewLocalRef, NewGlobalRef, and
+ DeleteWeakGlobalRef. (The spec strongly encourages
+ programmers to create hard references to weak globals before doing
+ anything with them, so this should not be at all limiting.)
+
From Android 4.0 (Ice Cream Sandwich) on, weak global references can be + used like any other JNI references.
Until Android 4.0 (Ice Cream Sandwich), local references were actually direct pointers. Ice Cream Sandwich added the indirection necessary to support better garbage collectors, but this means that lots - of JNI bugs are undetectable on older releases. + of JNI bugs are undetectable on older releases. See + JNI Local Reference Changes in ICS for more details. +
GetObjectRefType
+ Until Android 4.0 (Ice Cream Sandwich), as a consequence of the use of
+ direct pointers (see above), it was impossible to implement
+ GetObjectRefType correctly. Instead we used a heuristic
+ that looked through the weak globals table, the arguments, the locals
+ table, and the globals table in that order. The first time it found your
+ direct pointer, it would report that your reference was of the type it
+ happened to be examining. This meant, for example, that if
+ you called GetObjectRefType on a global jclass that happened
+ to be the same as the jclass passed as an implicit argument to your static
+ native method, you'd get JNILocalRefType rather than
+ JNIGlobalRefType.