public sealed interface FunctionDescriptor
FunctionDescriptor
is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A function descriptor models the signature of foreign functions. A function descriptor is made up of zero or more
argument layouts and zero or one return layout. A function descriptor is typically used when creating
downcall method handlesPREVIEW or
upcall stubsPREVIEW.
- Implementation Requirements:
- Implementing classes are immutable, thread-safe and value-based.
- Since:
- 19
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionappendArgumentLayouts
(MemoryLayoutPREVIEW... addedLayouts) Returns a function descriptor with the given argument layouts appended to the argument layout array of this function descriptor.Returns the argument layouts associated with this function descriptor (as an immutable list).changeReturnLayout
(MemoryLayoutPREVIEW newReturn) Returns a function descriptor with the given memory layout as the new return layout.Returns a function descriptor with the return layout dropped.insertArgumentLayouts
(int index, MemoryLayoutPREVIEW... addedLayouts) Returns a function descriptor with the given argument layouts inserted at the given index, into the argument layout array of this function descriptor.static FunctionDescriptorPREVIEW
of
(MemoryLayoutPREVIEW resLayout, MemoryLayoutPREVIEW... argLayouts) Creates a function descriptor with the given return and argument layouts.static FunctionDescriptorPREVIEW
ofVoid
(MemoryLayoutPREVIEW... argLayouts) Creates a function descriptor with the given argument layouts and no return layout.Returns the return layout (if any) associated with this function descriptor.Returns the method type consisting of the carrier types of the layouts in this function descriptor.
-
Method Details
-
returnLayout
Optional<MemoryLayoutPREVIEW> returnLayout()Returns the return layout (if any) associated with this function descriptor.- Returns:
- the return layout (if any) associated with this function descriptor
-
argumentLayouts
List<MemoryLayoutPREVIEW> argumentLayouts()Returns the argument layouts associated with this function descriptor (as an immutable list)..- Returns:
- the argument layouts associated with this function descriptor (as an immutable list)
-
appendArgumentLayouts
Returns a function descriptor with the given argument layouts appended to the argument layout array of this function descriptor.- Parameters:
addedLayouts
- the argument layouts to append.- Returns:
- the new function descriptor.
-
insertArgumentLayouts
Returns a function descriptor with the given argument layouts inserted at the given index, into the argument layout array of this function descriptor.- Parameters:
index
- the index at which to insert the argumentsaddedLayouts
- the argument layouts to insert at given index.- Returns:
- the new function descriptor.
- Throws:
IllegalArgumentException
- ifindex < 0 || index > argumentLayouts().size()
.
-
changeReturnLayout
Returns a function descriptor with the given memory layout as the new return layout.- Parameters:
newReturn
- the new return layout.- Returns:
- the new function descriptor.
-
dropReturnLayout
FunctionDescriptorPREVIEW dropReturnLayout()Returns a function descriptor with the return layout dropped. This is useful to model functions which return no values.- Returns:
- the new function descriptor.
-
toMethodType
MethodType toMethodType()Returns the method type consisting of the carrier types of the layouts in this function descriptor.The carrier type of a layout is determined as follows:
- If the layout is a
ValueLayout
PREVIEW the carrier type is determined throughValueLayout.carrier()
PREVIEW. - If the layout is a
GroupLayout
PREVIEW the carrier type isMemorySegment
PREVIEW. - If the layout is a
PaddingLayout
PREVIEW, orSequenceLayout
PREVIEW anIllegalArgumentException
is thrown.
- Returns:
- the method type consisting of the carrier types of the layouts in this function descriptor
- Throws:
IllegalArgumentException
- if one or more layouts in the function descriptor can not be mapped to carrier types (e.g. if they are sequence layouts or padding layouts).
- If the layout is a
-
of
static FunctionDescriptorPREVIEW of(MemoryLayoutPREVIEW resLayout, MemoryLayoutPREVIEW... argLayouts) Creates a function descriptor with the given return and argument layouts.- Parameters:
resLayout
- the return layout.argLayouts
- the argument layouts.- Returns:
- the new function descriptor.
-
ofVoid
Creates a function descriptor with the given argument layouts and no return layout.- Parameters:
argLayouts
- the argument layouts.- Returns:
- the new function descriptor.
-
FunctionDescriptor
when preview features are enabled.