Class RuntimeForeignAccess
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidregisterForDirectUpcall(MethodHandle target, Object desc, Object... options) Registers a specific static method (denoted by a method handle) as a fast upcall target.static voidregisterForDowncall(Object desc, Object... options) Registers the provided function descriptor and options pair at image build time for downcalls into foreign code.static voidregisterForUpcall(Object desc, Object... options) Registers the provided function descriptor and options pair at image build time for upcalls from foreign code.
-
Method Details
-
registerForDowncall
Registers the provided function descriptor and options pair at image build time for downcalls into foreign code. Required to get a downcall method handle usingLinker.downcallHandle(MemorySegment, FunctionDescriptor, Linker.Option...)RESTRICTED for the same descriptor and options at runtime.Even though this method is weakly typed for compatibility reasons, runtime checks will be performed to ensure that the arguments have the expected type. It will be deprecated in favor of strongly typed variant as soon as possible.
This API is deprecated; use the
ForeignAccessinstead.- Parameters:
desc- AFunctionDescriptorto register for downcalls.options- An array ofLinker.Optionused for the downcalls.- Since:
- 23.1
-
registerForUpcall
Registers the provided function descriptor and options pair at image build time for upcalls from foreign code. Required to get an upcall stub function pointer usingLinker.upcallStub(MethodHandle, FunctionDescriptor, Arena, Linker.Option...)RESTRICTED for the same descriptor and options at runtime.Even though this method is weakly typed for compatibility reasons, runtime checks will be performed to ensure that the arguments have the expected type. It will be deprecated in favor of strongly typed variant as soon as possible.
This API is deprecated; use the
ForeignAccessinstead.- Parameters:
desc- AFunctionDescriptorto register for upcalls.options- An array ofLinker.Optionused for the upcalls.- Since:
- 24.1
-
registerForDirectUpcall
Registers a specific static method (denoted by a method handle) as a fast upcall target. This will create a specialized upcall stub that will invoke only the specified method, which is much faster than usingregisterForUpcall(Object, Object...)).The provided method handle must be a direct method handle. Those are most commonly created using
MethodHandles.Lookup.findStatic(Class, String, MethodType). However, a strict requirement is that it must be possible to create a non-empty descriptor for the method handle usingMethodHandle.describeConstable(). The denoted static method will also be registered for reflective access since run-time code will also create a method handle to denoted static method.Even though this method is weakly typed for compatibility reasons, runtime checks will be performed to ensure that the arguments have the expected type. It will be deprecated in favor of strongly typed variant as soon as possible.
This API is deprecated; use the
ForeignAccessinstead.- Parameters:
target- A direct method handle denoting a static method.desc- AFunctionDescriptorto register for upcalls.options- An array ofLinker.Optionused for the upcalls.- Since:
- 24.2
-