koblas

FfmLibrary

One host library reached with java.lang.foreign, and the symbols bound out of it.

Every JVM binding koblas ships opens its library the same way: try each candidate name in turn, keep the first that both loads and carries a key symbol, and bind handles out of it lazily. This is that, so a binding contributes only its prototypes. The native targets have openNativeLibrary for the same reason.

Handles are bound with Linker.Option.critical by default, which lets a call read and write the Kotlin arrays handed to it in place rather than copying them.

Calls on the result use invokeExact, a signature-polymorphic call site: the descriptor lands in the bytecode, where invokeWithArguments would box every argument into a varargs array and pay a fixed cost per call that a short routine cannot amortise.

The exactness is load-bearing. invokeExact converts nothing, so an argument whose Kotlin type does not match its layout throws WrongMethodTypeException where invokeWithArguments would have widened it silently. Two consequences for the call sites: a routine called for effect whose descriptor returns a value still needs the cast, since Kotlin infers Unit in statement position and emits a void descriptor that will not match; and a safe-call chain has to be resolved to a local first, because as Unit? is the boxed Unit rather than void.

Types

Link copied to clipboard
object Companion

Opening a library, and the function descriptors a prototype is written with.

Properties

present

Whether a library resolved. A binding still has to check that the symbols it needs are in it.

Functions

contains

Whether name is exported, read with find, which is a lookup rather than a binding. Discovery asks this instead of binding, because Linker.downcallHandle is stack-hungry enough to overflow when it runs at the depth discovery reaches.

containsAll

Whether every one of names is exported.

handle

fun handle(name: String, descriptor: FunctionDescriptor, critical: Boolean = true): MethodHandle(source)

A handle for name, which the library is required to export.

handleOrNull

fun handleOrNull(name: String, descriptor: FunctionDescriptor, critical: Boolean = true): MethodHandle?(source)

A handle for name, or null when the library does not export it.

Pass critical = false for a routine that may block or start a thread, which a critical downcall is not allowed to do; the numeric routines, which run to completion over the arrays handed to them, are the reason critical is the default.

withFallback

This library, then other, searched in that order. For a host that splits one binding's symbols across two libraries, as a build shipping LAPACKE outside its OpenBLAS does.