io.vproxy.pni.graal.GraalPNIFunc Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pni-api-graal-jdk22 Show documentation
Show all versions of pni-api-graal-jdk22 Show documentation
panama native interface pni-api-graal-jdk22
The newest version!
package io.vproxy.pni.graal;
import io.vproxy.pni.PNIFunc;
import org.graalvm.nativeimage.IsolateThread;
import org.graalvm.nativeimage.c.function.CEntryPoint;
import org.graalvm.nativeimage.c.function.CEntryPointLiteral;
import org.graalvm.nativeimage.c.function.CFunctionPointer;
import org.graalvm.nativeimage.c.type.VoidPointer;
import java.lang.foreign.MemorySegment;
public class GraalPNIFunc {
private static final CEntryPointLiteral releaseFunc
= CEntryPointLiteral.create(GraalPNIFunc.class, "release", IsolateThread.class, long.class);
private static final CEntryPointLiteral invokeFunc
= CEntryPointLiteral.create(GraalPNIFunc.class, "invoke", IsolateThread.class, long.class, VoidPointer.class);
public static MemorySegment getReleaseFunctionPointer() {
return MemorySegment.ofAddress(releaseFunc.getFunctionPointer().rawValue());
}
public static MemorySegment getInvokeFunctionPointer() {
return MemorySegment.ofAddress(invokeFunc.getFunctionPointer().rawValue());
}
@SuppressWarnings("unused")
@CEntryPoint
public static void release(IsolateThread thread, long index) {
PNIFunc.release(index);
}
@SuppressWarnings("unused")
@CEntryPoint
public static void invoke(IsolateThread thread, long index, VoidPointer data) {
PNIFunc.call(index, MemorySegment.ofAddress(data.rawValue()));
}
}