PanamaPort is a library implementing the Foreign Function & Memory API for Android 8.0+ (API level 26)
This project contains 4 sublibraries:
- Core - the entire public API and implementation of the Panama project
- Unsafe - low-level implementation details and additional capabilities not provided by the original API
- LLVM - bindings to the built-in libLLVM.so Android library
- VarHandles - backport of java.lang.invoke.VarHandle which didn't exist in android 8.x
- JDK 21+
- Gradle 8.7+
- Android Gradle plugin 8.6.0+
- compileSdk 35+
Just add this library to the list of dependencies:
dependencies {
implementation 'io.github.vova7878.panama:Core:v0.1.0'
}
PanamaPort implements full Foreign Function & Memory API support, including:
- Downcall handles - allows Java code to call foreign functions
- Upcall stubs - allows foreign functions to call Java method handles
- Linker options such as captureCallState("errno") and even critical(allowHeapAccess: true)
- Access to native memory via VarHandles
- Management of memory segments via Arenas
- And much more
- Package java.lang.foreign moved to com.v7878.foreign package because it is a port and not part of the Java core library
- WrongThreadException class is also in the com.v7878.foreign package because it doesn't exist on android
- My implementation of VarHandle is used instead of java.lang.invoke.VarHandle
All non-standard apis added to the port are marked with @PortAPI annotation
This includes just useful methods:
MemoryLayout.valueLayout(Class<?>, ByteOrder)MemoryLayout.sequenceLayout(MemoryLayout)MemoryLayout.paddedStructLayout(MemoryLayout...)MemorySegment.nativeAddress()
Android-specific linker options:
Option.allowExceptions()andOption.JNIEnvArg(int)
Port of methods outside the java.lang.foreign package:
FileChannelUtils.map(FileChannel, MapMode, long, long, Arena)
Usually, to use the output of jextract, it is enough to fix package names. If something doesn't work properly, please create an issue
Examples are available in this repository. The same repository is where tests are ported from the OpenJ9 and Hotspot implementations