APIdia Launch Partner
Top Description Methods
java.lang.foreign

public sealed Interface FunctionDescriptor

permits FunctionDescriptorImpl
Known Direct Implementers
jdk.internal.foreign.FunctionDescriptorImpl
Imports
jdk.internal.foreign.FunctionDescriptorImpl, java.lang.invoke.MethodHandle, .MethodType, java.util.List, .Objects, .Optional

A function descriptor models the signature of a foreign function. A function descriptor is made up of zero or more argument layouts, and zero or one return layout. A function descriptor is used to create downcall method handles and upcall stubs.

Implementation Specification

Implementing classes are immutable, thread-safe and value-based.

Since
22
See Also
MemoryLayout

Method Summary

Modifier and TypeMethod and Description
public FunctionDescriptor

Returns:

a new function descriptor, with the provided additional argument layouts
appendArgumentLayouts
(MemoryLayout...
the argument layouts to append
addedLayouts
)

Returns a function descriptor with the given argument layouts appended to the argument layouts of this function descriptor.

public List<MemoryLayout>

Returns:

the argument layouts of this function descriptor (as an unmodifiable list)
argumentLayouts
()

Returns the argument layouts of this function descriptor (as an unmodifiable list).

public FunctionDescriptor

Returns:

a new function descriptor, with the provided return layout
changeReturnLayout
(MemoryLayout
the new return layout
newReturn
)

Returns a function descriptor with the provided return layout.

public FunctionDescriptor

Returns:

a new function descriptor, with no return layout
dropReturnLayout
()

Returns a new function descriptor, with no return layout.

public FunctionDescriptor

Returns:

a new function descriptor, with the provided additional argument layouts
insertArgumentLayouts
(int
the index at which to insert the arguments
index
,
MemoryLayout...
the argument layouts to insert at given index
addedLayouts
)

Returns a function descriptor with the given argument layouts inserted at the given index, into the argument layout array of this function descriptor.

public static FunctionDescriptor

Returns:

a new function descriptor with the provided return and argument layouts
of
(MemoryLayout
the return layout
resLayout
,
MemoryLayout...
the argument layouts
argLayouts
)

Creates a function descriptor with the given return and argument layouts.

public static FunctionDescriptor

Returns:

a new function descriptor with the provided argument layouts
ofVoid
(MemoryLayout...
the argument layouts
argLayouts
)

Creates a function descriptor with the given argument layouts and no return layout.

public Optional<MemoryLayout>

Returns:

the return layout (if any) of this function descriptor
returnLayout
()

Returns the return layout (if any) of this function descriptor.

public MethodType

Returns:

the method type consisting of the carrier types of the layouts in this function descriptor
toMethodType
()

Returns the method type consisting of the carrier types of the layouts in this function descriptor.

Method Detail

appendArgumentLayoutsback to summary
public FunctionDescriptor appendArgumentLayouts(MemoryLayout... addedLayouts)

Returns a function descriptor with the given argument layouts appended to the argument layouts of this function descriptor.

Parameters
addedLayouts:MemoryLayout[]

the argument layouts to append

Returns:FunctionDescriptor

a new function descriptor, with the provided additional argument layouts

Exceptions
IllegalArgumentException:
if one of the layouts in addedLayouts is a padding layout
argumentLayoutsback to summary
public List<MemoryLayout> argumentLayouts()

Returns the argument layouts of this function descriptor (as an unmodifiable list).

Returns:List<MemoryLayout>

the argument layouts of this function descriptor (as an unmodifiable list)

changeReturnLayoutback to summary
public FunctionDescriptor changeReturnLayout(MemoryLayout newReturn)

Returns a function descriptor with the provided return layout.

Parameters
newReturn:MemoryLayout

the new return layout

Returns:FunctionDescriptor

a new function descriptor, with the provided return layout

Exceptions
IllegalArgumentException:
if newReturn is a padding layout
dropReturnLayoutback to summary
public FunctionDescriptor dropReturnLayout()

Returns a new function descriptor, with no return layout.

Returns:FunctionDescriptor

a new function descriptor, with no return layout

insertArgumentLayoutsback to summary
public FunctionDescriptor insertArgumentLayouts(int index, MemoryLayout... addedLayouts)

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:int

the index at which to insert the arguments

addedLayouts:MemoryLayout[]

the argument layouts to insert at given index

Returns:FunctionDescriptor

a new function descriptor, with the provided additional argument layouts

Exceptions
IllegalArgumentException:
  • if one of the layouts in addedLayouts is a padding layout
  • if index < 0 || index > argumentLayouts().size()
ofback to summary
public static FunctionDescriptor of(MemoryLayout resLayout, MemoryLayout... argLayouts)

Creates a function descriptor with the given return and argument layouts.

Parameters
resLayout:MemoryLayout

the return layout

argLayouts:MemoryLayout[]

the argument layouts

Returns:FunctionDescriptor

a new function descriptor with the provided return and argument layouts

Exceptions
IllegalArgumentException:
  • if resLayout is a padding layout
  • if one of the layouts in argLayouts is a padding layout
ofVoidback to summary
public static FunctionDescriptor ofVoid(MemoryLayout... argLayouts)

Creates a function descriptor with the given argument layouts and no return layout. This is useful to model functions that return no values.

Parameters
argLayouts:MemoryLayout[]

the argument layouts

Returns:FunctionDescriptor

a new function descriptor with the provided argument layouts

Exceptions
IllegalArgumentException:
if one of the layouts in argLayouts is a padding layout
returnLayoutback to summary
public Optional<MemoryLayout> returnLayout()

Returns the return layout (if any) of this function descriptor.

Returns:Optional<MemoryLayout>

the return layout (if any) of this function descriptor

toMethodTypeback to summary
public MethodType toMethodType()

Returns the method type consisting of the carrier types of the layouts in this function descriptor.

The carrier type of a layout L is determined as follows:

API Note

A function descriptor cannot, by construction, contain any padding layouts. As such, it is not necessary to specify how padding layout should be mapped to carrier types.

Returns:MethodType

the method type consisting of the carrier types of the layouts in this function descriptor