Språk

FastNativeAttribute Class

Definition

Marks a native method to use faster Java Native Interface (JNI) transitions.

[Android.Runtime.Annotation("dalvik.annotation.optimization.FastNative")]
public class FastNativeAttribute : Attribute
[<Android.Runtime.Annotation("dalvik.annotation.optimization.FastNative")>]
type FastNativeAttribute = class
    inherit Attribute
Inheritance
FastNativeAttribute
Attributes

Remarks

While a fast native method executes, garbage collection cannot suspend the thread for essential work and may become blocked. Use with caution. Do not use this attribute on long-running methods, including usually fast but generally unbounded methods. Do not perform significant I/O or acquire native locks that can be held for a long time. Never acquire a native lock that can also be held while a thread invokes Java code, because doing so can cause deadlocks. Acquiring Java monitor locks is OK because ART allows thread suspension while acquiring them. This attribute has no effect on non-native methods.

This optimization is a CTS-tested public API starting in Android 14. For maximum compatibility, avoid calling fast native methods on Android 13 and earlier. Dynamic JNI linking works only on Android 12 and later; methods used on Android 8 through Android 11 must be explicitly registered with JNI RegisterNatives. The attribute is ignored on Android 7 and earlier.

Java documentation for dalvik.annotation.optimization.FastNative.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Name Description
FastNativeAttribute()

Initializes a new instance of the FastNativeAttribute class.

Applies to