CriticalNative

An alias for android dalvik.annotation.optimization.CriticalNative.

The Java method must be static and may not take or return references, arrays included. Using RegisterNatives instead of exposing JNI functions is highly recommended for such functions.

Note that using such functions on Android 7- will cause crashes.

expect annotation class CriticalNative(source)

Marks a function as not requiring JNI environment and a class/object reference.

Marks a function as not requiring JNI environment and a class/object reference. A function will be exposed to JVM like a regular JNI function AND almost the same one with JavaCritical_ prefix (instead of standard Java_) will be exposed.

Restrictions HotSpot puts on the method (see the JDK-7013347 RFE that introduced them): it must be static, synchronized and throwing are not allowed, and the parameters must be primitives or primitive arrays.

Two JNI functions will be generated: ordinal and critical one. Which of the two symbols a given call goes through is up to the JVM: critical is only taken once the call site has been compiled and inlined, and only on a JVM that supports it. The mechanism is undocumented and unsupported, and Project Panama's FFM API is the intended replacement.

@Target(allowedTargets = [AnnotationTarget.FUNCTION])
actual annotation class CriticalNative(source)

Marks a JniActual function as a JNI critical native function. Such a function does not receive a JniEnv or a JClass/JObject reference. Its parameters and return value must be primitives or primitive arrays only.

On Android this works as expected, thanks to the platform's built-in critical native support. On the JVM it may only work up to JDK 22, is undocumented, and requires the legacy ExposeFunctions binding mode. Prefer ProjectPanama instead.