15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang.foreign;
27
28 import java.lang.invoke.MethodHandle;
29 import java.lang.invoke.MethodType;
30 import java.util.Objects;
31 import java.util.Optional;
32 import java.util.List;
33
34 import jdk.internal.foreign.FunctionDescriptorImpl;
35 import jdk.internal.javac.PreviewFeature;
36
37 /**
38 * A function descriptor models the signature of a foreign function. A function descriptor is made up of zero or more
39 * argument layouts, and zero or one return layout. A function descriptor is used to create
40 * {@linkplain Linker#downcallHandle(MemorySegment, FunctionDescriptor, Linker.Option...) downcall method handles} and
41 * {@linkplain Linker#upcallStub(MethodHandle, FunctionDescriptor, Arena, Linker.Option...) upcall stubs}.
42 *
43 * @implSpec
44 * Implementing classes are immutable, thread-safe and <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>.
45 *
46 * @see MemoryLayout
47 * @since 19
48 */
49 @PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
50 public sealed interface FunctionDescriptor permits FunctionDescriptorImpl {
51
52 /**
53 * {@return the return layout (if any) of this function descriptor}
54 */
55 Optional<MemoryLayout> returnLayout();
56
57 /**
58 * {@return the argument layouts of this function descriptor (as an unmodifiable list)}.
59 */
60 List<MemoryLayout> argumentLayouts();
61
62 /**
63 * Returns a function descriptor with the given argument layouts appended to the argument layouts
64 * of this function descriptor.
65 * @param addedLayouts the argument layouts to append.
66 * @throws IllegalArgumentException if one of the layouts in {@code addedLayouts} is a padding layout.
67 * @return a new function descriptor, with the provided additional argument layouts.
68 */
69 FunctionDescriptor appendArgumentLayouts(MemoryLayout... addedLayouts);
|
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang.foreign;
27
28 import java.lang.invoke.MethodHandle;
29 import java.lang.invoke.MethodType;
30 import java.util.Objects;
31 import java.util.Optional;
32 import java.util.List;
33
34 import jdk.internal.foreign.FunctionDescriptorImpl;
35
36 /**
37 * A function descriptor models the signature of a foreign function. A function descriptor is made up of zero or more
38 * argument layouts, and zero or one return layout. A function descriptor is used to create
39 * {@linkplain Linker#downcallHandle(MemorySegment, FunctionDescriptor, Linker.Option...) downcall method handles} and
40 * {@linkplain Linker#upcallStub(MethodHandle, FunctionDescriptor, Arena, Linker.Option...) upcall stubs}.
41 *
42 * @implSpec
43 * Implementing classes are immutable, thread-safe and <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>.
44 *
45 * @see MemoryLayout
46 * @since 22
47 */
48 public sealed interface FunctionDescriptor permits FunctionDescriptorImpl {
49
50 /**
51 * {@return the return layout (if any) of this function descriptor}
52 */
53 Optional<MemoryLayout> returnLayout();
54
55 /**
56 * {@return the argument layouts of this function descriptor (as an unmodifiable list)}.
57 */
58 List<MemoryLayout> argumentLayouts();
59
60 /**
61 * Returns a function descriptor with the given argument layouts appended to the argument layouts
62 * of this function descriptor.
63 * @param addedLayouts the argument layouts to append.
64 * @throws IllegalArgumentException if one of the layouts in {@code addedLayouts} is a padding layout.
65 * @return a new function descriptor, with the provided additional argument layouts.
66 */
67 FunctionDescriptor appendArgumentLayouts(MemoryLayout... addedLayouts);
|