Class CEntryPointLiteral<T extends CFunctionPointer>
java.lang.Object
org.graalvm.nativeimage.c.function.CEntryPointLiteral<T>
A function pointer to an
entry point method
that can be, for example, handed
out to C code so that C code can call back into Java code. The method that is referred to must be
annotated with CEntryPoint
, which imposes certain restrictions.
The actual value of the function pointer is only available at run time. To prevent accidental
access to it during native image generation, the actual function
pointer
is encapsulated in this class. The call to getFunctionPointer()
fails with an
exception during native image generation.
Instances of this class can only be created during native image generation. It is not possible to look up a function by name at run time. The intended use case is therefore as follows:
// Function that is externally accessible @CEntryPoint static int myFunction(IsolateThread thread, int x, int y) { ... } // Invocation interface (for calls from Java, otherwise CFunctionPointer suffices) interface MyFunctionPointer extends CFunctionPointer { @InvokeCFunctionPointer int invoke(IsolateThread thread, int x, int y); } // Function pointer literal public static final CEntryPointLiteral<MyFunctionPointer> myFunctionLiteral = CEntryPointLiteral.create(MyClass.class, "myFunction", new Class<?>[]{IsolateThread.class, int.class, int.class}); // Call from Java void caller() { MyFunctionPointer fp = myFunctionLiteral.getFunctionPointer(); // entry point, could be returned to C code int fiftyeight = fp.invoke(CurrentIsolate.getCurrentThread(), 47, 11); }
- Since:
- 19.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends CFunctionPointer>
CEntryPointLiteral<T> Creates a new function pointer to an entry point.Returns the function pointer to the entry point.
-
Method Details
-
create
public static <T extends CFunctionPointer> CEntryPointLiteral<T> create(Class<?> definingClass, String methodName, Class<?>... parameterTypes) Creates a new function pointer to an entry point.- Since:
- 19.0
-
getFunctionPointer
Returns the function pointer to the entry point.- Since:
- 19.0
-