Package-level declarations

Core bindings: all JNI types, the JNI object with version constants, the Invocation API (createJavaVM, attachCurrentThread, …), every function of the JNI JniEnv interface, and Kotlin utilities around them.

Getting a JNI environment

JNI functions require a JniEnv in context (context(env: JniEnv)).

Version constants live on the JNI object (JNI.v1 … JNI.v24). Pass the version you need to getEnv / attachCurrentThread / createJavaVM.

Types

JNI types are null-safe and grouped by purpose:

Functions

Usage is close to the C++ style: env->FindClass(className.c_str()) becomes findClass(className.utf8). The differences:

  1. Type safety - no jobject casts; null-safety throughout.

  2. Errors as exceptions - functions that return a JNI error code throw a Kotlin exception instead (JniThreadDetachedException, JniVersionException, JniOutOfMemoryException, JniVmAlreadyExistsException).

  3. context(JniEnv) - the environment is never passed as an ordinary parameter.

  4. Modified UTF-8 - strings that cross into JNI must be null-terminated modified UTF-8. Prefer String.modifiedUtf8, or the Kotlin String overloads below. Standard String.utf8 differs only for '\u0000' and non-BMP characters, so it is safe when the string has neither.

The full JniEnv surface is covered: class operations (findClass, defineClass, superclass, isAssignableFrom, registerNatives/unregisterNatives, and on desktop module since JDK 9), exceptions (throwEx, throwNew, pendingException, handleJvmException, printStackTrace, clearException, isExceptionThrown, fatalError), local references (deleteLocalRef, newLocalRef, pushLocalFrame, popLocalFrame, refFrame/fromRefFrame), monitors (monitorEnter, monitorExit), strings (newString, length, getChars, getUTFChars, getRegion, getUTFRegion, utfLength, and on desktop utfLengthLong since JDK 24, getCharsCritical), arrays (newXArray, getRegion, setRegion, getElements, releaseElements with an ApplyChangesMode, getElementsCritical), object fields and methods (see #package-iogithubmimimishkinjnibindingaccessors for the typed variants), reflection (fromReflectedMethod, toReflectedMethod, …), direct buffers (newDirectByteBuffer, address, capacity) and, on desktop, isVirtualThread since JDK 21.

Kotlin String overloads

Most lookup and message APIs have overloads that take a Kotlin String instead of a CValuesRef<ByteVar>. They encode with String.modifiedUtf8 and throw when the lookup fails, instead of returning null:

context(env: JniEnv, autofreeScope: AutofreeScope)
fun example() {
val clazz = findClass("java/lang/String")
val mid = clazz.methodId("length", "()I")
throwNew(clazz, "something went wrong")
}

Available for findClass, defineClass, methodId / staticMethodId, fieldId / staticFieldId, throwNew, fatalError, attachCurrentThread / attachCurrentThreadAsDaemon, withEnvAttaching, and registerNatives { register(name, sig, fn) }.

Utilities

Core bindings: all JNI types, the JNI object with version constants, the Invocation API (createJavaVM, attachCurrentThread, …), every function of the JNI JniEnv interface, and Kotlin utilities around them.

Getting a JNI environment

JNI functions require a JniEnv in context (context(env: JniEnv)).

Version constants live on the JNI object (JNI.v1 … JNI.v24). Pass the version you need to getEnv / attachCurrentThread / createJavaVM.

Types

JNI types are null-safe and grouped by purpose:

Functions

Usage is close to the C++ style: env->FindClass(className.c_str()) becomes findClass(className.utf8). The differences:

  1. Type safety - no jobject casts; null-safety throughout.

  2. Errors as exceptions - functions that return a JNI error code throw a Kotlin exception instead (JniThreadDetachedException, JniVersionException, JniOutOfMemoryException, JniVmAlreadyExistsException).

  3. context(JniEnv) - the environment is never passed as an ordinary parameter.

  4. Modified UTF-8 - strings that cross into JNI must be null-terminated modified UTF-8. Prefer String.modifiedUtf8, or the Kotlin String overloads below. Standard String.utf8 differs only for '\u0000' and non-BMP characters, so it is safe when the string has neither.

The full JniEnv surface is covered: class operations (findClass, defineClass, superclass, isAssignableFrom, registerNatives/unregisterNatives, and on desktop module since JDK 9), exceptions (throwEx, throwNew, pendingException, handleJvmException, printStackTrace, clearException, isExceptionThrown, fatalError), local references (deleteLocalRef, newLocalRef, pushLocalFrame, popLocalFrame, refFrame/fromRefFrame), monitors (monitorEnter, monitorExit), strings (newString, length, getChars, getUTFChars, getRegion, getUTFRegion, utfLength, and on desktop utfLengthLong since JDK 24, getCharsCritical), arrays (newXArray, getRegion, setRegion, getElements, releaseElements with an ApplyChangesMode, getElementsCritical), object fields and methods (see #package-iogithubmimimishkinjnibindingaccessors for the typed variants), reflection (fromReflectedMethod, toReflectedMethod, …), direct buffers (newDirectByteBuffer, address, capacity) and, on desktop, isVirtualThread since JDK 21.

Kotlin String overloads

Most lookup and message APIs have overloads that take a Kotlin String instead of a CValuesRef<ByteVar>. They encode with String.modifiedUtf8 and throw when the lookup fails, instead of returning null:

context(env: JniEnv, autofreeScope: AutofreeScope)
fun example() {
val clazz = findClass("java/lang/String")
val mid = clazz.methodId("length", "()I")
throwNew(clazz, "something went wrong")
}

Available for findClass, defineClass, methodId / staticMethodId, fieldId / staticFieldId, throwNew, fatalError, attachCurrentThread / attachCurrentThreadAsDaemon, withEnvAttaching, and registerNatives { register(name, sig, fn) }.

Utilities

Core bindings: all JNI types, the JNI object with version constants, the Invocation API (createJavaVM, attachCurrentThread, …), every function of the JNI JniEnv interface, and Kotlin utilities around them.

Getting a JNI environment

JNI functions require a JniEnv in context (context(env: JniEnv)).

Version constants live on the JNI object (JNI.v1 … JNI.v24). Pass the version you need to getEnv / attachCurrentThread / createJavaVM.

Types

JNI types are null-safe and grouped by purpose:

Functions

Usage is close to the C++ style: env->FindClass(className.c_str()) becomes findClass(className.utf8). The differences:

  1. Type safety - no jobject casts; null-safety throughout.

  2. Errors as exceptions - functions that return a JNI error code throw a Kotlin exception instead (JniThreadDetachedException, JniVersionException, JniOutOfMemoryException, JniVmAlreadyExistsException).

  3. context(JniEnv) - the environment is never passed as an ordinary parameter.

  4. Modified UTF-8 - strings that cross into JNI must be null-terminated modified UTF-8. Prefer String.modifiedUtf8, or the Kotlin String overloads below. Standard String.utf8 differs only for '\u0000' and non-BMP characters, so it is safe when the string has neither.

The full JniEnv surface is covered: class operations (findClass, defineClass, superclass, isAssignableFrom, registerNatives/unregisterNatives, and on desktop module since JDK 9), exceptions (throwEx, throwNew, pendingException, handleJvmException, printStackTrace, clearException, isExceptionThrown, fatalError), local references (deleteLocalRef, newLocalRef, pushLocalFrame, popLocalFrame, refFrame/fromRefFrame), monitors (monitorEnter, monitorExit), strings (newString, length, getChars, getUTFChars, getRegion, getUTFRegion, utfLength, and on desktop utfLengthLong since JDK 24, getCharsCritical), arrays (newXArray, getRegion, setRegion, getElements, releaseElements with an ApplyChangesMode, getElementsCritical), object fields and methods (see #package-iogithubmimimishkinjnibindingaccessors for the typed variants), reflection (fromReflectedMethod, toReflectedMethod, …), direct buffers (newDirectByteBuffer, address, capacity) and, on desktop, isVirtualThread since JDK 21.

Kotlin String overloads

Most lookup and message APIs have overloads that take a Kotlin String instead of a CValuesRef<ByteVar>. They encode with String.modifiedUtf8 and throw when the lookup fails, instead of returning null:

context(env: JniEnv, autofreeScope: AutofreeScope)
fun example() {
val clazz = findClass("java/lang/String")
val mid = clazz.methodId("length", "()I")
throwNew(clazz, "something went wrong")
}

Available for findClass, defineClass, methodId / staticMethodId, fieldId / staticFieldId, throwNew, fatalError, attachCurrentThread / attachCurrentThreadAsDaemon, withEnvAttaching, and registerNatives { register(name, sig, fn) }.

Utilities

Types

Link copied to clipboard
sealed class _jarray : _jobject

The underlying open opaque type for JArray.

Link copied to clipboard

The underlying opaque type for JBooleanArray.

Link copied to clipboard

The underlying opaque type for JByteArray.

Link copied to clipboard
open class _jbyteBuffer(rawPtr: NativePtr) : _jobject

The underlying open opaque type for JByteBuffer.

Link copied to clipboard

The underlying opaque type for JCharArray.

Link copied to clipboard
class _jclass(rawPtr: NativePtr) : _jobject

The underlying opaque type for JClass.

Link copied to clipboard

The underlying opaque type for JDoubleArray.

Link copied to clipboard

The underlying opaque type for JFieldID.

Link copied to clipboard

The underlying opaque type for JFloatArray.

Link copied to clipboard

The underlying opaque type for JIntArray.

Link copied to clipboard

The underlying opaque type for JLongArray.

Link copied to clipboard

The underlying opaque type for JMethodID.

Link copied to clipboard
open class _jobject(rawPtr: NativePtr) : CPointed

The underlying open opaque type for JObject, allowing to create typesafe API when, for example JClass can be safely cast to JObject but not vise versa.

Link copied to clipboard
open class _jobjectArray(rawPtr: NativePtr) : _jarray

The underlying open opaque type for JObjectArray.

Link copied to clipboard

The underlying sealed opaque type for JPrimitiveArray.

Link copied to clipboard

The underlying opaque type for JShortArray.

Link copied to clipboard
class _jstring(rawPtr: NativePtr) : _jobject

The underlying opaque type for JString.

Link copied to clipboard
open class _jthrowable(rawPtr: NativePtr) : _jobject

The underlying open opaque type for JThrowable.

Link copied to clipboard

Specifies the mode for applying changes in releaseElements and releaseElementsCritical functions.

Link copied to clipboard

C array of JValue.

Link copied to clipboard
typealias JArgumentsBuilder = (JValue.() -> Unit) -> Unit

Special type that exposes methods to add arguments:

Link copied to clipboard
typealias JArray = JRef<_jarray>

Pointer to an array.

Link copied to clipboard

Type allowing to operate with Invocation API.

Link copied to clipboard
actual typealias JavaVMAttachArgs = platform.android.JavaVMAttachArgs
typealias JavaVMAttachArgs = platform.android.JavaVMAttachArgs

Thread attachment arguments.

actual typealias JavaVMAttachArgs = jni.JavaVMAttachArgs
typealias JavaVMAttachArgs = jni.JavaVMAttachArgs

Thread attachment arguments.

Thread attachment arguments.

Link copied to clipboard
actual typealias JavaVMInitArgs = platform.android.JavaVMInitArgs
typealias JavaVMInitArgs = platform.android.JavaVMInitArgs

Java VM initialization arguments structure.

actual typealias JavaVMInitArgs = jni.JavaVMInitArgs
typealias JavaVMInitArgs = jni.JavaVMInitArgs

Java VM initialization arguments structure.

expect class JavaVMInitArgs : CStructVar

Java VM initialization arguments structure.

Link copied to clipboard

Special type that exposes option method to add VM options. It's used in buildJavaVMInitArgs function.

Link copied to clipboard
actual typealias JavaVMOption = platform.android.JavaVMOption
typealias JavaVMOption = platform.android.JavaVMOption

Java VM initialization option.

actual typealias JavaVMOption = jni.JavaVMOption
typealias JavaVMOption = jni.JavaVMOption

Java VM initialization option.

expect class JavaVMOption : CStructVar

Java VM initialization option.

Link copied to clipboard
typealias JBoolean = UByte

JVM interprets boolean values as unsigned byte.

Link copied to clipboard

Pointer to a boolean[] object.

Link copied to clipboard
typealias JByte = Byte

JVM interprets byte values the same way as Kotlin.

Link copied to clipboard

Pointer to a byte[] object.

Link copied to clipboard

Pointer to java.nio.ByteBuffer.

Link copied to clipboard
typealias JChar = UShort

JVM interprets char values as unsigned short.

Link copied to clipboard

Pointer to a char[] object.

Link copied to clipboard
typealias JClass = JRef<_jclass>

Pointer to java.lang.Class.

Link copied to clipboard
typealias JDouble = Double

JVM interprets double values the same way as Kotlin.

Link copied to clipboard

Pointer to a double[] object.

Link copied to clipboard

Java unique field ID.

Link copied to clipboard
typealias JFloat = Float

JVM interprets float values the same way as Kotlin.

Link copied to clipboard

Pointer to a float[] object.

Link copied to clipboard
typealias JInt = Int

JVM interprets int values the same way as Kotlin.

Link copied to clipboard

Pointer to an int[] object.

Link copied to clipboard
typealias JLong = Long

JVM interprets long values the same way as Kotlin.

Link copied to clipboard

Pointer to a long[] object.

Link copied to clipboard

Java unique method ID.

Link copied to clipboard
object JNI

Functions and utilities to work with JNI (Java Native Interface).

Link copied to clipboard

Type allowing to operate with Native JNI API.

Link copied to clipboard
class JniLazy<out T>(initializer: context(JniEnv, MemScope) () -> T)

Allows declaring lazy values that requires JniEnv to be initialized.

Link copied to clipboard
actual typealias JniNativeMethod = JNINativeMethod
typealias JniNativeMethod = JNINativeMethod

Represents a native method specification.

actual typealias JniNativeMethod = JNINativeMethod
typealias JniNativeMethod = JNINativeMethod

Represents a native method specification.

Represents a native method specification.

Link copied to clipboard

Special type that exposes method JNINativeMethodRegistry.register to register native methods. Is used in registerNatives function.

Link copied to clipboard

JNI_ENOMEM: the Java VM could not allocate the memory the call needs.

Link copied to clipboard

JNI_EDETACHED: the current thread is not attached to the Java VM.

Link copied to clipboard
typealias JniVersion = Int

Java version that corresponds to the new JNI API.

Link copied to clipboard

JNI_EVERSION: the requested JNI version is not supported by the Java VM.

Link copied to clipboard

JNI_EEXIST: a Java VM has already been created in this process, and JNI does not support more than one.

Link copied to clipboard
typealias JObject = JRef<_jobject>

Pointer to java.lang.Object.

Link copied to clipboard

Pointer to an array of an object type.

Link copied to clipboard

Represents the type of JNI reference.

Link copied to clipboard

Pointer to a primitive array.

Link copied to clipboard
typealias JRef<T> = CPointer<out T>

Helper typealias to simplify working with JObject and its descendants.

Link copied to clipboard
typealias JShort = Short

JVM interprets short values the same way as Kotlin.

Link copied to clipboard

Pointer to a short[] object.

Link copied to clipboard
typealias JString = JRef<_jstring>

Pointer to java.lang.String.

Link copied to clipboard

Pointer to java.lang.Throwable.

Link copied to clipboard
actual typealias JValue = jvalue
typealias JValue = jvalue

Union in which JNI expect arguments to pass to Java functions.

actual typealias JValue = jvalue
typealias JValue = jvalue

Union in which JNI expect arguments to pass to Java functions.

expect class JValue : CStructVar

Union in which JNI expect arguments to pass to Java functions.

Link copied to clipboard
typealias JVoid = Unit

Allows explicitly specifying that a function doesn't return any value in the same way as if it returned something and we've used JBoolean, JByte, JChar or others.

Link copied to clipboard
typealias JWeak = JObject

Pointer to java.lang.Object which is not counted by GC.

Link copied to clipboard
actual typealias Raw_JniInvokeInterface = JNIInvokeInterface
typealias Raw_JniInvokeInterface = JNIInvokeInterface

The underlying type for JavaVM.

actual typealias Raw_JniInvokeInterface = JNIInvokeInterface_
typealias Raw_JniInvokeInterface = JNIInvokeInterface_

The underlying type for JavaVM.

The underlying type for JavaVM.

Link copied to clipboard
actual typealias Raw_JniNativeInterface = JNINativeInterface
typealias Raw_JniNativeInterface = JNINativeInterface

The underlying type for JniEnv.

actual typealias Raw_JniNativeInterface = JNINativeInterface_
typealias Raw_JniNativeInterface = JNINativeInterface_

The underlying type for JniEnv.

The underlying type for JniEnv.

Properties

Link copied to clipboard

Fetches and returns the starting address of the memory region referenced by the given direct java.nio.Buffer.

Link copied to clipboard

Union field of type boolean.

Link copied to clipboard

Union field of type byte.

Link copied to clipboard

Converts this JObject to the jobject pointer of the underlying platform bindings.

Link copied to clipboard
context(env: JniEnv)
val JByteBuffer.capacity: Long

Fetches and returns the capacity of the memory region referenced by the given direct java.nio.Buffer. The capacity is the number of elements that the memory region contains.

Link copied to clipboard

Union field of type char.

Link copied to clipboard

Union field of type double.

Link copied to clipboard

Union field of type float.

Link copied to clipboard

Whether unrecognized options are ignored.

Link copied to clipboard

Union field of type int.

Link copied to clipboard
context(env: JniEnv)
val isExceptionThrown: Boolean

A convenient way to check for pending exceptions without creating a local reference to the exception object.

Link copied to clipboard
context(env: JniEnv)
val JObject.javaClass: JClass

The class of the object.

Link copied to clipboard
context(env: JniEnv, placement: NativePlacement)
val javaVM: JavaVM

JavaVM interface associated with the current thread.

Link copied to clipboard
context(placement: NativePlacement)
val JNI.javaVMs: List<JavaVM>

All Java VMs that have been created in the order they are created.

Link copied to clipboard
context(env: JniEnv)
val jniVersion: JniVersion

The version of the native method interface.

Link copied to clipboard
context(env: JniEnv)
val JArray.length: Int

The number of elements in the array.

context(env: JniEnv)
val JString.length: Int

The length (the count of Unicode characters) of a Java string.

Link copied to clipboard

Union field of type long.

Link copied to clipboard

Converts a String into a null-terminated, modified UTF-8 encoded byte sequence for interoperation with JNI functions.

Link copied to clipboard
context(env: JniEnv)
val JClass.module: JObject

Returns the java.lang.Module object for the module that the class is a member of. If the class is not in a named module, then the unnamed module of the class loader for the class is returned. If the class represents an array type, then this function returns the Module object for the element type. If the class represents a primitive type or void, then the Module object for the java.base module is returned.

Link copied to clipboard
context(autofreeScope: AutofreeScope)
var JavaVMOption.option: String?

The option as a Kotlin string.

Link copied to clipboard
Link copied to clipboard

Exception object currently in the process of being thrown, or null if there is no one.

Link copied to clipboard
actual var JValue.ref: JObject?

Union field of an object type.

actual var JValue.ref: JObject?

Union field of an object type.

expect var JValue.ref: JObject?

Union field of an object type.

Link copied to clipboard

Returns the type of the object referred to by the obj argument.

Link copied to clipboard

Union field of type short.

Link copied to clipboard
context(env: JniEnv)
val JClass.superclass: JClass?

If this class represents any class other than the class Object, then it is the object that represents the superclass of the class specified by this class.

Link copied to clipboard
context(env: JniEnv)
val JString.utfLength: Int

The length in bytes of the modified UTF-8 representation of a string.

Link copied to clipboard
context(env: JniEnv)
val JString.utfLengthLong: Long

The length in bytes of the modified UTF-8 representation of a string.

Functions

Link copied to clipboard
context(env: JniEnv)
fun JClass.allocObject(): JObject?

Allocates a new Java object without invoking any of the constructors for the object.

Link copied to clipboard
inline fun <T> JArgumentsBuilder.any(value: T?)

Tries to add value of any type to arguments. Only JObject and not-null primitives are supported.

Link copied to clipboard

Returns an Iterable over the elements of the object array. As the array may contain null elements or elements of a different type, this iterable is strongly typed.

Link copied to clipboard
context(autofreeScope: AutofreeScope)
inline fun JavaVM.attachCurrentThread(version: JniVersion, name: String, group: JObject? = null): JniEnv

Alias for JavaVM.attachCurrentThread which accepts the thread name as a Kotlin String.

context(autofreeScope: AutofreeScope)
fun JavaVM.attachCurrentThread(version: JniVersion, name: CValuesRef<ByteVar>? = null, group: JObject? = null): JniEnv

Attaches the current thread to a Java VM. Returns a JniEnv.

Link copied to clipboard
context(autofreeScope: AutofreeScope)
inline fun JavaVM.attachCurrentThreadAsDaemon(version: JniVersion, name: String, group: JObject? = null): JniEnv

Alias for JavaVM.attachCurrentThreadAsDaemon which accepts the thread name as a Kotlin String.

context(autofreeScope: AutofreeScope)
fun JavaVM.attachCurrentThreadAsDaemon(version: JniVersion, name: CValuesRef<ByteVar>? = null, group: JObject? = null): JniEnv

Same semantics as attachCurrentThread, but the newly created java.lang.Thread instance is a daemon.

Link copied to clipboard
inline fun JArgumentsBuilder.boolean(value: Boolean)

Add boolean value to arguments.

Link copied to clipboard
context(placement: NativePlacement)
inline fun buildJavaVMInitArgs(version: JniVersion, optionsCount: Int, ignoreUnrecognized: Boolean = false, block: JavaVMInitArgsBuilder.() -> Unit): JavaVMInitArgs

Allocates and initializes JavaVMInitArgs.

Link copied to clipboard
inline fun JArgumentsBuilder.byte(value: Byte)

Add byte value to arguments.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callBooleanMethod(methodId: JMethodID, args: JArguments): Boolean

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callByteMethod(methodId: JMethodID, args: JArguments): Byte

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callCharMethod(methodId: JMethodID, args: JArguments): Char

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callDoubleMethod(methodId: JMethodID, args: JArguments): Double

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callFloatMethod(methodId: JMethodID, args: JArguments): Float

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callIntMethod(methodId: JMethodID, args: JArguments): Int

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callLongMethod(methodId: JMethodID, args: JArguments): Long

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
inline fun <R> JObject.callMethod(methodId: JMethodID, args: JArguments): R

Unifies usage of call<type>Method methods.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualBooleanMethod(clazz: JClass, methodId: JMethodID, args: JArguments): Boolean

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualByteMethod(clazz: JClass, methodId: JMethodID, args: JArguments): Byte

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualCharMethod(clazz: JClass, methodId: JMethodID, args: JArguments): Char

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualDoubleMethod(clazz: JClass, methodId: JMethodID, args: JArguments): Double

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualFloatMethod(clazz: JClass, methodId: JMethodID, args: JArguments): Float

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualIntMethod(clazz: JClass, methodId: JMethodID, args: JArguments): Int

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualLongMethod(clazz: JClass, methodId: JMethodID, args: JArguments): Long

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
inline fun <R> JObject.callNonvirtualMethod(clazz: JClass, methodId: JMethodID, args: JArguments): R

Unifies usage of callNonvirtual<type>Method methods, returning method with the appropriate type wrapped in lambda.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualObjectMethod(clazz: JClass, methodId: JMethodID, args: JArguments): JObject?

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualShortMethod(clazz: JClass, methodId: JMethodID, args: JArguments): Short

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callNonvirtualVoidMethod(clazz: JClass, methodId: JMethodID, args: JArguments)

Invokes an instance (nonstatic) method on a Java object, according to the specified class and method ID. The methodId argument must be obtained by calling methodId on the class clazz.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callObjectMethod(methodId: JMethodID, args: JArguments): JObject?

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callShortMethod(methodId: JMethodID, args: JArguments): Short

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticBooleanMethod(methodId: JMethodID, args: JArguments): Boolean

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticByteMethod(methodId: JMethodID, args: JArguments): Byte

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticCharMethod(methodId: JMethodID, args: JArguments): Char

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticDoubleMethod(methodId: JMethodID, args: JArguments): Double

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticFloatMethod(methodId: JMethodID, args: JArguments): Float

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticIntMethod(methodId: JMethodID, args: JArguments): Int

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticLongMethod(methodId: JMethodID, args: JArguments): Long

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
inline fun <R> JClass.callStaticMethod(methodId: JMethodID, args: JArguments): R

Unifies usage of callStatic<type>Method methods, returning method with the appropriate type wrapped in lambda.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticObjectMethod(methodId: JMethodID, args: JArguments): JObject?

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticShortMethod(methodId: JMethodID, args: JArguments): Short

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.callStaticVoidMethod(methodId: JMethodID, args: JArguments)

Invokes a static method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling staticMethodId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.callVoidMethod(methodId: JMethodID, args: JArguments)

Invokes an instance (nonstatic) method on a Java object, according to the specified method ID. The methodId argument must be obtained by calling methodId.

Link copied to clipboard
inline fun JArgumentsBuilder.char(value: Char)

Add char value to arguments.

Link copied to clipboard
context(env: JniEnv)
fun clearException()

Clears any exception that is currently being thrown. If no exception is currently being thrown, this routine has no effect.

Link copied to clipboard
context(env: JniEnv)
inline fun JByteArray.copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = this.length): ByteArray

Copies a region of this JVM byte[] into destination using getRegion and returns destination.

Link copied to clipboard

Loads and initializes a Java VM. The current thread becomes the main thread.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun defineClass(name: String, loader: JObject?, classBuf: CPointer<ByteVar>, classBufLen: Int): JClass

Alias for defineClass which accepts the class name as a Kotlin String.

context(env: JniEnv, autofreeScope: AutofreeScope)
fun defineClass(name: CValuesRef<ByteVar>?, loader: JObject?, classBuf: CPointer<ByteVar>, classBufLen: Int): JClass?

Loads a class from a classBuf of raw class data.

Link copied to clipboard
context(env: JniEnv)
fun JObject.deleteGlobalRef()

Deletes the global reference pointed to by the receiver.

Link copied to clipboard
context(env: JniEnv)
fun JObject.deleteLocalRef()

Deletes the local reference pointed to by the receiver.

Link copied to clipboard
context(env: JniEnv)
fun JWeak.deleteWeakGlobalRef()

Delete the VM resources needed for the given weak global reference.

Link copied to clipboard

Unloads a Java VM and reclaims its resources.

Link copied to clipboard

Detaches the current thread from a Java VM. All Java monitors held by this thread are released. All Java threads waiting for this thread to die are notified.

Link copied to clipboard
context(env: JniEnv)
fun ensureLocalCapacity(capacity: Int)

Ensures that at least a given number of local references can be created in the current thread.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun fatalError(message: String): Nothing

Alias for fatalError which accepts the message as a Kotlin String.

context(env: JniEnv, autofreeScope: AutofreeScope)
fun fatalError(message: CValuesRef<ByteVar>?): Nothing

Raises a fatal error and does not expect the VM to recover.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun JClass.fieldId(name: String, sig: String): JFieldID

Alias for JClass.fieldId which accepts the field name and sig as Kotlin Strings.

context(env: JniEnv, autofreeScope: AutofreeScope)
fun JClass.fieldId(name: CValuesRef<ByteVar>, sig: CValuesRef<ByteVar>): JFieldID?

Returns the field ID for an instance (nonstatic) field of a class. The field is specified by its name and signature. The get<type>Field and set<type>Field families of accessor functions use field IDs to retrieve object fields.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun findClass(name: String): JClass

Alias for findClass which accepts the class name as a Kotlin String.

context(env: JniEnv, autofreeScope: AutofreeScope)
fun findClass(name: CValuesRef<ByteVar>): JClass?

In JDK release 1.1, this function loads a locally defined class. It searches the directories and zip files specified by the CLASSPATH environment variable for the class with the specified name.

Link copied to clipboard
inline fun JArgumentsBuilder.float(value: Float)

Add float value to arguments.

Link copied to clipboard
context(env: JniEnv)
inline fun <T : JRef<O>, O : _jobject> fromRefFrame(capacity: Int, block: () -> T?): T?

Executes the block in a new local reference frame, in which at least a given number of local references can be created. Then pops the frame, freeing all the local references except the result of the block and return it.

Link copied to clipboard

Converts a java.lang.reflect.Field to a field ID.

Link copied to clipboard

Converts a java.lang.reflect.Method or java.lang.reflect.Constructor object to a method ID.

Link copied to clipboard
context(env: JniEnv)
operator fun JObjectArray.get(index: Int): JObject?

Returns an element of an Object array. The index must be within the range of the array.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getBooleanField(fieldID: JFieldID): Boolean

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getByteField(fieldID: JFieldID): Byte

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getCharField(fieldID: JFieldID): Char

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard

Returns a pointer to the array of Unicode characters and a boolean value isCopy which specifies whether the array is a copy (true - a copy, `false - the underlying array of the string, which means that any changes to it will be reflected on the original string).

Link copied to clipboard

The semantics of this function is similar to getChars function. If possible, the VM returns a pointer to string elements; otherwise, a copy is made. However, there are significant restrictions on how these functions can be used. In a code segment enclosed by getCharsCritical/releaseCharsCritical calls, the native code must not issue arbitrary JNI calls, or cause the current thread to block.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getDoubleField(fieldID: JFieldID): Double

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard

Returns the body of the primitive array and a boolean value isCopy which specifies whether the array is a copy (true - a copy, `false - the real array body, which means that any changes to it will be reflected on the jvm array).

Link copied to clipboard

The semantics of this function is very similar to the getElements. If possible, the VM returns a pointer to the primitive array; otherwise, a copy is made. However, there are significant restrictions on how these functions can be used.

Link copied to clipboard
context(placement: NativePlacement)
fun JavaVM.getEnv(version: JniVersion): JniEnv

If the current thread is not attached to the VM or the specified version is not supported, throw an exception. Otherwise, returns JniEnv.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getFloatField(fieldID: JFieldID): Float

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getIntField(fieldID: JFieldID): Int

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getLongField(fieldID: JFieldID): Long

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getObjectField(fieldID: JFieldID): JObject?

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JBooleanArray.getRegion(start: Int, len: Int, buf: CArrayPointer<UByteVar>)

Copies a region of a boolean[] array into a buffer buf.

context(env: JniEnv)
fun JByteArray.getRegion(start: Int, len: Int, buf: CArrayPointer<ByteVar>)

Copies a region of a byte[] array into a buffer buf.

context(env: JniEnv)
fun JCharArray.getRegion(start: Int, len: Int, buf: CArrayPointer<UShortVar>)

Copies a region of a char[] array into a buffer buf.

context(env: JniEnv)
fun JDoubleArray.getRegion(start: Int, len: Int, buf: CPointer<DoubleVar>)

Copies a region of a double[] array into a buffer buf.

context(env: JniEnv)
fun JFloatArray.getRegion(start: Int, len: Int, buf: CPointer<FloatVar>)

Copies a region of a float[] array into a buffer buf.

context(env: JniEnv)
fun JIntArray.getRegion(start: Int, len: Int, buf: CPointer<IntVar>)

Copies a region of a int[] array into a buffer buf.

context(env: JniEnv)
fun JLongArray.getRegion(start: Int, len: Int, buf: CPointer<LongVar>)

Copies a region of a long[] array into a buffer buf.

context(env: JniEnv)
fun JShortArray.getRegion(start: Int, len: Int, buf: CArrayPointer<ShortVar>)

Copies a region of a short[] array into a buffer buf.

context(env: JniEnv)
fun JString.getRegion(start: Int, len: Int, buf: CArrayPointer<UShortVar>)

Copies len number of Unicode characters beginning at offset start to the given buffer buf.

Link copied to clipboard
context(env: JniEnv)
fun JObject.getShortField(fieldID: JFieldID): Short

Returns the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticBooleanField(fieldID: JFieldID): Boolean

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticByteField(fieldID: JFieldID): Byte

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticCharField(fieldID: JFieldID): Char

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticDoubleField(fieldID: JFieldID): Double

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticFloatField(fieldID: JFieldID): Float

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticIntField(fieldID: JFieldID): Int

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticLongField(fieldID: JFieldID): Long

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticObjectField(fieldID: JFieldID): JObject?

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.getStaticShortField(fieldID: JFieldID): Short

Returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard

Returns a pointer to an array of bytes representing the string in modified UTF-8 encoding and a boolean value isCopy which specifies whether the array is a copy (true - a copy, `false - the underlying array of the string, which means that any changes to it will be reflected on the original string).

Link copied to clipboard
context(env: JniEnv)
fun JString.getUTFRegion(start: Int, len: Int, buf: CArrayPointer<ByteVar>)

Translates len number of Unicode characters beginning at offset start into modified UTF-8 encoding and place the result in the given buffer buf.

Link copied to clipboard
context(env: JniEnv)
inline fun handleJvmException(block: (JThrowable) -> Unit)

Convenient way to write

Link copied to clipboard
context(env: JniEnv)
infix fun JObject?.instanceOf(clazz: JClass): Boolean

Tests whether an object is an instance of a class.

Link copied to clipboard
inline fun JArgumentsBuilder.int(value: Int)

Add int value to arguments.

Link copied to clipboard
context(env: JniEnv)
infix fun JClass.isAssignableFrom(other: JClass): Boolean

Determines whether this class can be safely cast to other.

Link copied to clipboard
context(env: JniEnv)
infix fun JObject?.isSame(other: JObject?): Boolean

Tests whether two references point to the same Java object.

Link copied to clipboard

Tests whether an object is a virtual Thread.

Link copied to clipboard
context(env: JniEnv)
operator fun JObjectArray.iterator(): Iterator<JObject?>

Returns an iterator over the elements of the object array. As the array may contain null elements or elements of a different type, this iterator is strongly typed.

Link copied to clipboard
context(placement: NativePlacement)
inline fun jArgs(count: Int, block: JArgumentsBuilder.() -> Unit): JArguments

Allocates and initializes JArguments.

Link copied to clipboard
inline fun <T> jniLazy(noinline initializer: context(JniEnv, MemScope) () -> T): JniLazy<T>

Creates a new instance of the JniLazy that uses the specified initialization function initializer.

Link copied to clipboard
context(env: JniEnv)
fun <T : JRef<O>, O : _jobject> T.localIntoGlobalRef(): T?

Converts ordinal local ref into a global one.

Link copied to clipboard
context(env: JniEnv)
fun <T : JRef<O>, O : _jobject> T.localIntoWeakRef(): T?

Converts ordinal local ref into a global weak one.

Link copied to clipboard
inline fun JArgumentsBuilder.long(value: Double)
inline fun JArgumentsBuilder.long(value: Long)

Add long value to arguments.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun JClass.methodId(name: String, sig: String): JMethodID

Alias for JClass.methodId which accepts the method name and sig as Kotlin Strings.

context(env: JniEnv, autofreeScope: AutofreeScope)
fun JClass.methodId(name: CValuesRef<ByteVar>, sig: CValuesRef<ByteVar>): JMethodID?

Returns the method ID for an instance (nonstatic) method of a class or interface. The method may be defined in one of the this@GetMethodID’s supertypes and inherited by this@GetMethodID. The method is determined by its name and signature.

Link copied to clipboard
context(env: JniEnv)
fun monitorEnter(obj: JObject)

Enters the monitor associated with the underlying Java object referred to by obj.

Link copied to clipboard
context(env: JniEnv)
fun monitorExit(obj: JObject)

The current thread must be the owner of the monitor associated with the underlying Java object referred to by obj. The thread decrements the counter indicating the number of times it has entered this monitor. If the value of the counter becomes zero, the current thread releases the monitor.

Link copied to clipboard
context(env: JniEnv)
fun newBooleanArray(length: Int): JBooleanArray?

Constructs a new boolean[] array object.

Link copied to clipboard
context(env: JniEnv)
fun newByteArray(length: Int): JByteArray?

Constructs a new byte[] array object.

Link copied to clipboard
context(env: JniEnv)
fun newCharArray(length: Int): JCharArray?

Constructs a new char[] array object.

Link copied to clipboard
context(env: JniEnv)
fun newDirectByteBuffer(address: COpaquePointer, capacity: Long): JByteBuffer?

Allocates and returns a direct java.nio.ByteBuffer referring to the block of memory starting at the memory address address and extending capacity bytes. The byte order of the returned buffer is always big-endian (high byte first; java.nio.ByteOrder.BIG_ENDIAN).

Link copied to clipboard
context(env: JniEnv)
fun newDoubleArray(length: Int): JDoubleArray?

Constructs a new double[] array object.

Link copied to clipboard
context(env: JniEnv)
fun newFloatArray(length: Int): JFloatArray?

Constructs a new float[] array object.

Link copied to clipboard
context(env: JniEnv)
fun <T : JRef<O>, O : _jobject> T.newGlobalRef(): T?

Creates and returns a new global reference to the object referred to by the receiver. The receiver may be a global or local reference.

Link copied to clipboard
context(env: JniEnv)
fun newIntArray(length: Int): JIntArray?

Constructs a new int[] array object.

Link copied to clipboard
context(env: JniEnv)
fun <T : JRef<O>, O : _jobject> T.newLocalRef(): T?

Creates and returns a new local reference that refers to the same object. The receiver may be a global or a local reference.

Link copied to clipboard
context(env: JniEnv)
fun newLongArray(length: Int): JLongArray?

Constructs a new long[] array object.

Link copied to clipboard
context(env: JniEnv)
fun JClass.newObject(methodId: JMethodID, args: JArguments): JObject?

Constructs a new Java object. The methodId indicates which constructor method to invoke. This ID must be obtained by calling methodId with "<init>" as the method name and void (V) as the return type.

Link copied to clipboard
context(env: JniEnv)
fun newObjectArray(length: Int, elementClass: JClass, initialElement: JObject? = null): JObjectArray?

Constructs a new array holding objects in class elementClass. All elements are initially set to initialElement.

Link copied to clipboard
context(env: JniEnv)
fun newShortArray(length: Int): JShortArray?

Constructs a new short[] array object.

Link copied to clipboard
context(env: JniEnv)
fun newString(unicodeChars: CArrayPointer<UShortVar>, len: Int): JString?

Constructs a new java.lang.String object from an array of Unicode characters.

Link copied to clipboard
context(env: JniEnv)
fun newStringUTF(bytes: CArrayPointer<ByteVar>): JString?

Constructs a new java.lang.String object from an array of characters in modified UTF-8 encoding.

Link copied to clipboard
context(env: JniEnv)
fun <T : JRef<O>, O : _jobject> T.newWeakGlobalRef(): T?

Creates a new weak global reference. The weak global reference will not prevent garbage collection of the given object.

Link copied to clipboard
context(autofreeScope: AutofreeScope)
inline fun JavaVMInitArgsBuilder.option(optionString: String, extraInfo: COpaquePointer? = null)
Link copied to clipboard
context(env: JniEnv)
inline fun popLocalFrame()

Pops off the current local reference frame and frees all the local references.

context(env: JniEnv)
fun <T : JRef<O>, O : _jobject> popLocalFrame(result: T? = null): T?

Pops off the current local reference frame, frees all the local references and returns a local reference in the previous local reference frame for the given result object.

Link copied to clipboard
context(env: JniEnv)
fun printStackTrace()

Prints an exception and a backtrace of the stack to a system error-reporting channel, such as stderr.

Link copied to clipboard
context(env: JniEnv)
fun pushLocalFrame(capacity: Int)

Creates a new local reference frame, in which at least a given number of local references can be created.

Link copied to clipboard
inline fun JArgumentsBuilder.ref(value: JObject?)

Add Object value to arguments.

Link copied to clipboard
context(env: JniEnv)
inline fun <T> refFrame(capacity: Int, block: () -> T): T

Executes the block in a new local reference frame, in which at least a given number of local references can be created. Then pops the frame, freeing all the local references and returns the result of block.

Link copied to clipboard
context(autofreeScope: AutofreeScope)
inline fun JNINativeMethodRegistry.register(name: String, signature: String, functionPointer: JRef<CFunction<*>>)

Alias for JNINativeMethodRegistry.register which accepts name and signature as Kotlin Strings.

context(autofreeScope: AutofreeScope)
inline fun JNINativeMethodRegistry.register(name: CValuesRef<ByteVar>, signature: CValuesRef<ByteVar>, functionPointer: JRef<CFunction<*>>)

Register new JniNativeMethod with specified name, signature and functionPointer.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun JClass.registerNatives(count: Int, block: JNINativeMethodRegistry.() -> Unit)

Registers native methods with the class specified by the clazz argument.

context(env: JniEnv)
fun JClass.registerNatives(methods: CArrayPointer<JniNativeMethod>, methodsCount: Int)

Registers native methods with the class specified by the receiver. The methods parameter specifies a list of triples that contain the names, signatures and function pointers of the native methods.

Link copied to clipboard

Informs the VM that the native code no longer needs access to chars. The chars argument is a pointer obtained from string using getChars.

Link copied to clipboard

The semantics of this function is similar to releaseChars function. Informs the VM that the native code no longer needs access to carray. However, there are significant restrictions on how these functions can be used. In a code segment enclosed by getCharsCritical/releaseCharsCritical calls, the native code must not issue arbitrary JNI calls, or cause the current thread to block.

Link copied to clipboard

Informs the VM that the native code no longer needs access to elems. The elems argument is a pointer derived from the receiver using the getElements function. If necessary, this function copies back all changes made to elems to the original array.

Link copied to clipboard

The semantics of this function is very similar to the releaseElements.

Link copied to clipboard

Informs the VM that the native code no longer needs access to utf. The utf argument is a pointer derived from string using getUTFChars.

Link copied to clipboard
context(env: JniEnv)
operator fun JObjectArray.set(index: Int, value: JObject?)

Sets an element of an Object array. The index must be within the range of the array.

context(env: JniEnv)
inline fun JByteArray.set(source: ByteArray, offset: Int = 0, startIndex: Int = 0, endIndex: Int = source.size)

Writes a region of the Kotlin source array into this JVM byte[] starting at offset using setRegion.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setBooleanField(fieldID: JFieldID, value: Boolean)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setByteField(fieldID: JFieldID, value: Byte)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setCharField(fieldID: JFieldID, value: Char)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard

Retrieves the default initialization arguments for the Java VM.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setDoubleField(fieldID: JFieldID, value: Double)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setFloatField(fieldID: JFieldID, value: Float)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setIntField(fieldID: JFieldID, value: Int)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setLongField(fieldID: JFieldID, value: Long)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setObjectField(fieldID: JFieldID, value: JObject?)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JBooleanArray.setRegion(start: Int, len: Int, buf: CArrayPointer<UByteVar>)

Copies back a region of a boolean[] array from a buffer buf.

context(env: JniEnv)
fun JByteArray.setRegion(start: Int, len: Int, buf: CArrayPointer<ByteVar>)

Copies back a region of a byte[] array from a buffer buf.

context(env: JniEnv)
fun JCharArray.setRegion(start: Int, len: Int, buf: CArrayPointer<UShortVar>)

Copies back a region of a char[] array from a buffer buf.

context(env: JniEnv)
fun JDoubleArray.setRegion(start: Int, len: Int, buf: CPointer<DoubleVar>)

Copies back a region of a double[] array from a buffer buf.

context(env: JniEnv)
fun JFloatArray.setRegion(start: Int, len: Int, buf: CPointer<FloatVar>)

Copies back a region of a float[] array from a buffer buf.

context(env: JniEnv)
fun JIntArray.setRegion(start: Int, len: Int, buf: CPointer<IntVar>)

Copies back a region of a int[] array from a buffer buf.

context(env: JniEnv)
fun JLongArray.setRegion(start: Int, len: Int, buf: CPointer<LongVar>)

Copies back a region of a long[] array from a buffer buf.

context(env: JniEnv)
fun JShortArray.setRegion(start: Int, len: Int, buf: CArrayPointer<ShortVar>)

Copies back a region of a short[] array from a buffer buf.

Link copied to clipboard
context(env: JniEnv)
fun JObject.setShortField(fieldID: JFieldID, value: Short)

Sets the value of an instance (nonstatic) field of an object. The field to access is specified by a field ID obtained by calling fieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticBooleanField(fieldID: JFieldID, value: Boolean)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticByteField(fieldID: JFieldID, value: Byte)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticCharField(fieldID: JFieldID, value: Char)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticDoubleField(fieldID: JFieldID, value: Double)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticFloatField(fieldID: JFieldID, value: Float)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticIntField(fieldID: JFieldID, value: Int)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticLongField(fieldID: JFieldID, value: Long)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticObjectField(fieldID: JFieldID, value: JObject?)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
context(env: JniEnv)
fun JClass.setStaticShortField(fieldID: JFieldID, value: Short)

Sets the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling staticFieldId.

Link copied to clipboard
inline fun JArgumentsBuilder.short(value: Short)

Add short value to arguments.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun JClass.staticFieldId(name: String, sig: String): JFieldID

Alias for JClass.staticFieldId which accepts the field name and sig as Kotlin Strings.

context(env: JniEnv, autofreeScope: AutofreeScope)
fun JClass.staticFieldId(name: CValuesRef<ByteVar>, sig: CValuesRef<ByteVar>): JFieldID?

Returns the field ID for a static field of a class. The field is specified by its name and signature. The getStatic<type>Field and setStatic<type>Field families of accessor functions use field IDs to retrieve static fields.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun JClass.staticMethodId(name: String, sig: String): JMethodID

Alias for JClass.staticMethodId which accepts the method name and sig as Kotlin Strings.

context(env: JniEnv, autofreeScope: AutofreeScope)
fun JClass.staticMethodId(name: CValuesRef<ByteVar>, sig: CValuesRef<ByteVar>): JMethodID?

Returns the method ID for a static method of a class. The method is specified by its name and signature.

Link copied to clipboard
context(env: JniEnv)
fun throwEx(throwable: JThrowable)

Causes a java.lang.Throwable object to be thrown.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun throwNew(clazz: JClass, message: String)

Alias for throwNew which accepts the message as a Kotlin String.

context(env: JniEnv, autofreeScope: AutofreeScope)
fun throwNew(clazz: JClass, message: CValuesRef<ByteVar>?)

Constructs an exception object from the specified clazz with the message and causes that exception to be thrown.

Link copied to clipboard
context(env: JniEnv)
inline fun ByteArray.toJArray(): JByteArray?

Converts Kotlin ByteArray into JVM byte[] using setRegion.

context(env: JniEnv)
inline fun DoubleArray.toJArray(): JDoubleArray?

Converts Kotlin DoubleArray into JVM double[] using setRegion.

context(env: JniEnv)
inline fun FloatArray.toJArray(): JFloatArray?

Converts Kotlin FloatArray into JVM float[] using setRegion.

context(env: JniEnv)
inline fun IntArray.toJArray(): JIntArray?

Converts Kotlin IntArray into JVM int[] using setRegion.

context(env: JniEnv)
inline fun LongArray.toJArray(): JLongArray?

Converts Kotlin LongArray into JVM long[] using setRegion.

context(env: JniEnv)
inline fun ShortArray.toJArray(): JShortArray?

Converts Kotlin ShortArray into JVM short[] using setRegion.

context(env: JniEnv)
inline fun UByteArray.toJArray(): JBooleanArray?

Converts Kotlin UByteArray into JVM boolean[] using setRegion.

context(env: JniEnv)
inline fun UShortArray.toJArray(): JCharArray?

Converts Kotlin UShortArray into JVM char[] using setRegion.

Link copied to clipboard

Converts Kotlin boolean to JVM boolean.

Link copied to clipboard
inline fun Char.toJChar(): JChar

Converts Kotlin char to JVM char.

Link copied to clipboard
context(env: JniEnv, autofreeScope: AutofreeScope)
inline fun String.toJString(): JString?

Converts Kotlin string into JVM string.

Link copied to clipboard
context(env: JniEnv)
inline fun JBooleanArray.toKArray(length: Int = this.length): UByteArray

Converts JVM boolean[] into Kotlin UByteArray using getRegion.

context(env: JniEnv)
inline fun JByteArray.toKArray(length: Int = this.length): ByteArray

Converts JVM byte[] into Kotlin ByteArray using getRegion.

context(env: JniEnv)
inline fun JCharArray.toKArray(length: Int = this.length): UShortArray

Converts JVM char[] into Kotlin UShortArray using getRegion.

context(env: JniEnv)
inline fun JDoubleArray.toKArray(length: Int = this.length): DoubleArray

Converts JVM double[] into Kotlin DoubleArray using getRegion.

context(env: JniEnv)
inline fun JFloatArray.toKArray(length: Int = this.length): FloatArray

Converts JVM float[] into Kotlin FloatArray using getRegion.

context(env: JniEnv)
inline fun JIntArray.toKArray(length: Int = this.length): IntArray

Converts JVM int[] into Kotlin IntArray using getRegion.

context(env: JniEnv)
inline fun JLongArray.toKArray(length: Int = this.length): LongArray

Converts JVM long[] into Kotlin LongArray using getRegion.

context(env: JniEnv)
inline fun JShortArray.toKArray(length: Int = this.length): ShortArray

Converts JVM short[] into Kotlin ShortArray using getRegion.

Link copied to clipboard

Converts JVM boolean to Kotlin boolean.

Link copied to clipboard
inline fun JChar.toKChar(): Char

Converts JVM char to Kotlin char.

Link copied to clipboard
context(env: JniEnv, placement: NativePlacement)
inline fun JString.toKString(): String?

Converts JVM string into Kotlin string.

Link copied to clipboard
context(env: JniEnv)
fun JFieldID.toReflectedField(cls: JClass, isStatic: Boolean): JObject?

Converts a field ID derived from cls to a java.lang.reflect.Field object. isStatic must be set to true if fieldID refers to a static field.

Link copied to clipboard
context(env: JniEnv)
fun JMethodID.toReflectedMethod(cls: JClass, isStatic: Boolean): JObject?

Converts a method ID derived from cls to a java.lang.reflect.Method or java.lang.reflect.Constructor object. isStatic must be set to true if the method ID refers to a static field.

Link copied to clipboard
context(env: JniEnv)
fun JClass.unregisterNatives()

Unregisters native methods of a receiver class. The class goes back to the state before it was linked or registered with its native method functions.

Link copied to clipboard
inline fun <T : JRef<O>, O : _jobject> JObject.unsafeCast(): T

Casts to any JObject descendant.

Link copied to clipboard
inline fun <R> JniEnv.use(block: context(MemScope, JniEnv) () -> R): R

Alias for memScoped { context(env) { /* your code */ } } allowing to write less boilerplate code.

Link copied to clipboard
inline fun <R> JavaVM.useEnv(version: JniVersion, block: context(MemScope, JniEnv) () -> R): R

Alias for memScoped { vm.withEnv(version) { /* your code */ } } allowing to write less boilerplate code.

Link copied to clipboard
inline fun <R> JavaVM.useEnvAttaching(version: JniVersion, block: context(MemScope, JniEnv) () -> R): R

Alias for memScoped { vm.withEnvAttaching(version) { /* your code */ } } allowing to write less boilerplate code.

Link copied to clipboard
context(placement: NativePlacement)
inline fun <T> JavaVM.withEnv(version: JniVersion, block: context(JniEnv) () -> T): T

Executes a block of code within the context of a JNI environment of version version of the current thread. If the current thread is not attached to the JavaVM or the specified version is not supported, an exception will be thrown.

Link copied to clipboard
context(autofreeScope: AutofreeScope)
inline fun <T> JavaVM.withEnvAttaching(version: JniVersion, name: String, group: JObject? = null, block: context(JniEnv) () -> T): T

Alias for withEnvAttaching which accepts the thread name as a Kotlin String encoded as modified UTF-8 with String.modifiedUtf8.

context(autofreeScope: AutofreeScope)
inline fun <T> JavaVM.withEnvAttaching(version: JniVersion, name: CValuesRef<ByteVar>? = null, group: JObject? = null, block: context(JniEnv) () -> T): T

Attaches the current thread to the Java VM, executes the provided block of code within the attached environment and then detaches the thread upon completion.

Link copied to clipboard

inline fun <T : JRef<O>, O : _jobject> COpaquePointer?.wrap(): T?

Converts the platform's jobject pointer to JObject or its descendant.