FastNative
public
abstract
@interface
FastNative
implements
Annotation
| dalvik.annotation.optimization.FastNative |
An ART runtime built-in optimization for "native" methods to speed up JNI transitions.
This has the side-effect of disabling all garbage collections while executing a fast native
method. Use with extreme caution. Any long-running methods must not be marked with
@FastNative (including usually-fast but generally unbounded methods)!
Deadlock Warning:As a rule of thumb, do not acquire any locks during a fast native call if they aren't also locally released [before returning to managed code].
Say some code does:
fast_jni_call_to_grab_a_lock();
does_some_java_work();
fast_jni_call_to_release_a_lock();
This code can lead to deadlocks. Say thread 1 just finishes
fast_jni_call_to_grab_a_lock() and is in does_some_java_work().
GC kicks in and suspends thread 1. Thread 2 now is in fast_jni_call_to_grab_a_lock()
but is blocked on grabbing the native lock since it's held by thread 1.
Now thread suspension can't finish since thread 2 can't be suspended since it's doing
FastNative JNI.
Normal JNI doesn't have the issue since once it's in native code, it is considered suspended from java's point of view. FastNative JNI however doesn't do the state transition done by JNI.
Note that even in FastNative methods you are allowed to allocate objects and make upcalls into Java code. A call from Java to a FastNative function and back to Java is equivalent to a call from one Java method to another. What's forbidden in a FastNative method is blocking the calling thread in some non-Java code and thereby preventing the thread from responding to requests from the garbage collector to enter the suspended state.
Has no effect when used with non-native methods.
Summary
Inherited methods | |
|---|---|