diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayouts.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayouts.java index 0f2f7c3b2a7..606d9192423 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayouts.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayouts.java @@ -51,22 +51,22 @@ private MemoryLayouts() { /** * A value layout constant with size of one byte, and byte order set to {@link ByteOrder#LITTLE_ENDIAN}. */ - public static final ValueLayout BITS_8_LE = SharedLayouts.BITS_8_LE; + public static final ValueLayout BITS_8_LE = MemoryLayout.ofValueBits(8, ByteOrder.LITTLE_ENDIAN); /** * A value layout constant with size of two bytes, and byte order set to {@link ByteOrder#LITTLE_ENDIAN}. */ - public static final ValueLayout BITS_16_LE = SharedLayouts.BITS_16_LE; + public static final ValueLayout BITS_16_LE = MemoryLayout.ofValueBits(16, ByteOrder.LITTLE_ENDIAN); /** * A value layout constant with size of four bytes, and byte order set to {@link ByteOrder#LITTLE_ENDIAN}. */ - public static final ValueLayout BITS_32_LE = SharedLayouts.BITS_32_LE; + public static final ValueLayout BITS_32_LE = MemoryLayout.ofValueBits(32, ByteOrder.LITTLE_ENDIAN); /** * A value layout constant with size of eight bytes, and byte order set to {@link ByteOrder#LITTLE_ENDIAN}. */ - public static final ValueLayout BITS_64_LE = SharedLayouts.BITS_64_LE; + public static final ValueLayout BITS_64_LE = MemoryLayout.ofValueBits(64, ByteOrder.LITTLE_ENDIAN); /** * A value layout constant with size of one byte, and byte order set to {@link ByteOrder#BIG_ENDIAN}. @@ -142,473 +142,4 @@ private MemoryLayouts() { * A value layout constant whose size is the same as that of a Java {@code double}, and byte order set to {@link ByteOrder#nativeOrder()}. */ public static final ValueLayout JAVA_DOUBLE = MemoryLayout.ofValueBits(64, ByteOrder.nativeOrder()); - - /** - * The {@code _Bool} native type. - */ - public static final ValueLayout C_BOOL; - - /** - * The {@code unsigned char} native type. - */ - public static final ValueLayout C_UCHAR; - - /** - * The {@code signed char} native type. - */ - public static final ValueLayout C_SCHAR ; - - /** - * The {@code char} native type. - */ - public static final ValueLayout C_CHAR; - - /** - * The {@code short} native type. - */ - public static final ValueLayout C_SHORT; - - /** - * The {@code unsigned short} native type. - */ - public static final ValueLayout C_USHORT; - - /** - * The {@code int} native type. - */ - public static final ValueLayout C_INT; - - /** - * The {@code unsigned int} native type. - */ - public static final ValueLayout C_UINT; - - /** - * The {@code long} native type. - */ - public static final ValueLayout C_LONG; - - /** - * The {@code unsigned long} native type. - */ - public static final ValueLayout C_ULONG; - - /** - * The {@code long long} native type. - */ - public static final ValueLayout C_LONGLONG; - - /** - * The {@code unsigned long long} native type. - */ - public static final ValueLayout C_ULONGLONG; - - /** - * The {@code float} native type. - */ - public static final ValueLayout C_FLOAT; - - /** - * The {@code double} native type. - */ - public static final ValueLayout C_DOUBLE; - - /** - * The {@code long double} native type. - */ - public static final ValueLayout C_LONGDOUBLE; - - /** - * The {@code T*} native type. - */ - public static final ValueLayout C_POINTER; - - static { - SystemABI abi = SharedUtils.getSystemABI(); - switch (abi.name()) { - case ABI_SYSV -> { - C_BOOL = SysV.C_BOOL; - C_UCHAR = SysV.C_UCHAR; - C_SCHAR = SysV.C_SCHAR; - C_CHAR = SysV.C_CHAR; - C_SHORT = SysV.C_SHORT; - C_USHORT = SysV.C_USHORT; - C_INT = SysV.C_INT; - C_UINT = SysV.C_UINT; - C_LONG = SysV.C_LONG; - C_ULONG = SysV.C_ULONG; - C_LONGLONG = SysV.C_LONGLONG; - C_ULONGLONG = SysV.C_ULONGLONG; - C_FLOAT = SysV.C_FLOAT; - C_DOUBLE = SysV.C_DOUBLE; - C_LONGDOUBLE = SysV.C_LONGDOUBLE; - C_POINTER = SysV.C_POINTER; - } - case ABI_WINDOWS -> { - C_BOOL = WinABI.C_BOOL; - C_UCHAR = WinABI.C_UCHAR; - C_SCHAR = WinABI.C_SCHAR; - C_CHAR = WinABI.C_CHAR; - C_SHORT = WinABI.C_SHORT; - C_USHORT = WinABI.C_USHORT; - C_INT = WinABI.C_INT; - C_UINT = WinABI.C_UINT; - C_LONG = WinABI.C_LONG; - C_ULONG = WinABI.C_ULONG; - C_LONGLONG = WinABI.C_LONGLONG; - C_ULONGLONG = WinABI.C_ULONGLONG; - C_FLOAT = WinABI.C_FLOAT; - C_DOUBLE = WinABI.C_DOUBLE; - C_LONGDOUBLE = WinABI.C_LONGDOUBLE; - C_POINTER = WinABI.C_POINTER; - } - case ABI_AARCH64 -> { - C_BOOL = AArch64ABI.C_BOOL; - C_UCHAR = AArch64ABI.C_UCHAR; - C_SCHAR = AArch64ABI.C_SCHAR; - C_CHAR = AArch64ABI.C_CHAR; - C_SHORT = AArch64ABI.C_SHORT; - C_USHORT = AArch64ABI.C_USHORT; - C_INT = AArch64ABI.C_INT; - C_UINT = AArch64ABI.C_UINT; - C_LONG = AArch64ABI.C_LONG; - C_ULONG = AArch64ABI.C_ULONG; - C_LONGLONG = AArch64ABI.C_LONGLONG; - C_ULONGLONG = AArch64ABI.C_ULONGLONG; - C_FLOAT = AArch64ABI.C_FLOAT; - C_DOUBLE = AArch64ABI.C_DOUBLE; - C_LONGDOUBLE = AArch64ABI.C_LONGDOUBLE; - C_POINTER = AArch64ABI.C_POINTER; - } - default -> throw new IllegalStateException("Unsupported ABI: " + abi.name()); - } - } - - /** - * This class defines layout constants modelling standard primitive types supported by the x64 SystemV ABI. - */ - public static final class SysV { - private SysV() { - //just the one - } - - /** - * The {@code _Bool} native type. - */ - public static final ValueLayout C_BOOL = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.BOOL); - - - /** - * The {@code unsigned char} native type. - */ - public static final ValueLayout C_UCHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_CHAR); - - - /** - * The {@code signed char} native type. - */ - public static final ValueLayout C_SCHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.SIGNED_CHAR); - - - /** - * The {@code char} native type. - */ - public static final ValueLayout C_CHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.CHAR); - - /** - * The {@code short} native type. - */ - public static final ValueLayout C_SHORT = SharedLayouts.BITS_16_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.SHORT); - - /** - * The {@code unsigned short} native type. - */ - public static final ValueLayout C_USHORT = SharedLayouts.BITS_16_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_SHORT); - - /** - * The {@code int} native type. - */ - public static final ValueLayout C_INT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.INT); - - /** - * The {@code unsigned int} native type. - */ - public static final ValueLayout C_UINT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_INT); - - /** - * The {@code long} native type. - */ - public static final ValueLayout C_LONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG); - - /** - * The {@code unsigned long} native type. - */ - public static final ValueLayout C_ULONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_LONG); - - - /** - * The {@code long long} native type. - */ - public static final ValueLayout C_LONGLONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG_LONG); - - /** - * The {@code unsigned long long} native type. - */ - public static final ValueLayout C_ULONGLONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_LONG_LONG); - - /** - * The {@code float} native type. - */ - public static final ValueLayout C_FLOAT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.FLOAT); - - /** - * The {@code double} native type. - */ - public static final ValueLayout C_DOUBLE = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.DOUBLE); - - /** - * The {@code long double} native type. - */ - public static final ValueLayout C_LONGDOUBLE = MemoryLayout.ofValueBits(128, ByteOrder.LITTLE_ENDIAN) - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG_DOUBLE); - - /** - * The {@code complex long double} native type. - */ - public static final GroupLayout C_COMPLEX_LONGDOUBLE = MemoryLayout.ofStruct(C_LONGDOUBLE, C_LONGDOUBLE) - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.COMPLEX_LONG_DOUBLE); - - /** - * The {@code T*} native type. - */ - public static final ValueLayout C_POINTER = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.POINTER); - } - - /** - * This class defines layout constants modelling standard primitive types supported by the x64 Windows ABI. - */ - public static final class WinABI { - /** - * The {@code _Bool} native type. - */ - public static final ValueLayout C_BOOL = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.BOOL); - - /** - * The {@code unsigned char} native type. - */ - public static final ValueLayout C_UCHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_CHAR); - - /** - * The {@code signed char} native type. - */ - public static final ValueLayout C_SCHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.SIGNED_CHAR); - - /** - * The {@code char} native type. - */ - public static final ValueLayout C_CHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.CHAR); - - /** - * The {@code short} native type. - */ - public static final ValueLayout C_SHORT = SharedLayouts.BITS_16_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.SHORT); - - /** - * The {@code unsigned short} native type. - */ - public static final ValueLayout C_USHORT = SharedLayouts.BITS_16_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_SHORT); - - /** - * The {@code int} native type. - */ - public static final ValueLayout C_INT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.INT); - - /** - * The {@code unsigned int} native type. - */ - public static final ValueLayout C_UINT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_INT); - - /** - * The {@code long} native type. - */ - public static final ValueLayout C_LONG = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG); - - /** - * The {@code unsigned long} native type. - */ - public static final ValueLayout C_ULONG = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_LONG); - - /** - * The {@code long long} native type. - */ - public static final ValueLayout C_LONGLONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG_LONG); - - /** - * The {@code unsigned long long} native type. - */ - public static final ValueLayout C_ULONGLONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_LONG_LONG); - - /** - * The {@code float} native type. - */ - public static final ValueLayout C_FLOAT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.FLOAT); - - /** - * The {@code double} native type. - */ - public static final ValueLayout C_DOUBLE = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.DOUBLE); - - /** - * The {@code long double} native type. - */ - public static final ValueLayout C_LONGDOUBLE = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG_DOUBLE); - - /** - * The {@code T*} native type. - */ - public static final ValueLayout C_POINTER = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.POINTER); - - public static ValueLayout asVarArg(ValueLayout l) { - return l.withAttribute(Windowsx64ABI.VARARGS_ATTRIBUTE_NAME, "true"); - } - } - - /** - * This class defines layout constants modelling standard primitive types supported by the AArch64 ABI. - */ - public static final class AArch64ABI { - /** - * The {@code _Bool} native type. - */ - public static final ValueLayout C_BOOL = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.BOOL); - - /** - * The {@code unsigned char} native type. - */ - public static final ValueLayout C_UCHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_CHAR); - - /** - * The {@code signed char} native type. - */ - public static final ValueLayout C_SCHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.SIGNED_CHAR); - - /** - * The {@code char} native type. - */ - public static final ValueLayout C_CHAR = SharedLayouts.BITS_8_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.CHAR); - - /** - * The {@code short} native type. - */ - public static final ValueLayout C_SHORT = SharedLayouts.BITS_16_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.SHORT); - - /** - * The {@code unsigned short} native type. - */ - public static final ValueLayout C_USHORT = SharedLayouts.BITS_16_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_SHORT); - - /** - * The {@code int} native type. - */ - public static final ValueLayout C_INT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.INT); - - /** - * The {@code unsigned int} native type. - */ - public static final ValueLayout C_UINT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_INT); - - /** - * The {@code long} native type. - */ - public static final ValueLayout C_LONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG); - - /** - * The {@code unsigned long} native type. - */ - public static final ValueLayout C_ULONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_LONG); - - /** - * The {@code long long} native type. - */ - public static final ValueLayout C_LONGLONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG_LONG); - - /** - * The {@code unsigned long long} native type. - */ - public static final ValueLayout C_ULONGLONG = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.UNSIGNED_LONG_LONG); - - /** - * The {@code float} native type. - */ - public static final ValueLayout C_FLOAT = SharedLayouts.BITS_32_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.FLOAT); - - /** - * The {@code double} native type. - */ - public static final ValueLayout C_DOUBLE = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.DOUBLE); - - /** - * The {@code long double} native type. - */ - public static final ValueLayout C_LONGDOUBLE = MemoryLayout.ofValueBits(128, ByteOrder.LITTLE_ENDIAN) - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.LONG_DOUBLE); - - /** - * The {@code T*} native type. - */ - public static final ValueLayout C_POINTER = SharedLayouts.BITS_64_LE - .withAttribute(SystemABI.NATIVE_TYPE, SystemABI.Type.POINTER); - } - - private static class SharedLayouts { // Separate class to prevent circular clinit references - public static final ValueLayout BITS_8_LE = MemoryLayout.ofValueBits(8, ByteOrder.LITTLE_ENDIAN); - public static final ValueLayout BITS_16_LE = MemoryLayout.ofValueBits(16, ByteOrder.LITTLE_ENDIAN); - public static final ValueLayout BITS_32_LE = MemoryLayout.ofValueBits(32, ByteOrder.LITTLE_ENDIAN); - public static final ValueLayout BITS_64_LE = MemoryLayout.ofValueBits(64, ByteOrder.LITTLE_ENDIAN); - } } diff --git a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SystemABI.java b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SystemABI.java index cd5891e02f0..14575285043 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SystemABI.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SystemABI.java @@ -34,12 +34,13 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; +import java.nio.ByteOrder; import java.util.Optional; /** * This class models a system application binary interface (ABI). * - * Instances of this class can be obtained by calling {@link Foreign#getSystemABI()} + * Instances of this class can be obtained by calling {@link SystemABI#getSystemABI()} */ public interface SystemABI { /** @@ -100,113 +101,317 @@ default void freeUpcallStub(MemoryAddress address) { */ String name(); - enum Type { + /** + * The {@code _Bool} native type. + */ + ValueLayout C_BOOL = Utils.pick(SysV.C_BOOL, Win64.C_BOOL, AArch64.C_BOOL); + + /** + * The {@code char} native type. + */ + ValueLayout C_CHAR = Utils.pick(SysV.C_CHAR, Win64.C_CHAR, AArch64.C_CHAR); + + /** + * The {@code short} native type. + */ + ValueLayout C_SHORT = Utils.pick(SysV.C_SHORT, Win64.C_SHORT, AArch64.C_SHORT); + + /** + * The {@code int} native type. + */ + ValueLayout C_INT = Utils.pick(SysV.C_INT, Win64.C_INT, AArch64.C_INT); + + /** + * The {@code long} native type. + */ + ValueLayout C_LONG = Utils.pick(SysV.C_LONG, Win64.C_LONG, AArch64.C_LONG); + + /** + * The {@code long long} native type. + */ + ValueLayout C_LONGLONG = Utils.pick(SysV.C_LONGLONG, Win64.C_LONGLONG, AArch64.C_LONGLONG); + + /** + * The {@code float} native type. + */ + ValueLayout C_FLOAT = Utils.pick(SysV.C_FLOAT, Win64.C_FLOAT, AArch64.C_FLOAT); + + /** + * The {@code double} native type. + */ + ValueLayout C_DOUBLE = Utils.pick(SysV.C_DOUBLE, Win64.C_DOUBLE, AArch64.C_DOUBLE); + + /** + * The {@code long double} native type. + */ + ValueLayout C_LONGDOUBLE = Utils.pick(SysV.C_LONGDOUBLE, Win64.C_LONGDOUBLE, AArch64.C_LONGDOUBLE); + + /** + * The {@code T*} native type. + */ + ValueLayout C_POINTER = Utils.pick(SysV.C_POINTER, Win64.C_POINTER, AArch64.C_POINTER); + + /** + * This class defines layout constants modelling standard primitive types supported by the x64 SystemV ABI. + */ + final class SysV { + private SysV() { + //just the one + } + + /** + * The name of the SysV ABI + */ + public static final String NAME = "SysV"; + + public final static String CLASS_ATTRIBUTE_NAME = "abi/sysv/class"; + + public enum ArgumentClass { + INTEGER, + SSE, + X87, + COMPLEX_87, + POINTER; + } + /** * The {@code _Bool} native type. */ - BOOL, + public static final ValueLayout C_BOOL = MemoryLayouts.BITS_8_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code unsigned char} native type. + * The {@code char} native type. */ - UNSIGNED_CHAR, + public static final ValueLayout C_CHAR = MemoryLayouts.BITS_8_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code signed char} native type. + * The {@code short} native type. */ - SIGNED_CHAR, + public static final ValueLayout C_SHORT = MemoryLayouts.BITS_16_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code char} native type. + * The {@code int} native type. */ - CHAR, + public static final ValueLayout C_INT = MemoryLayouts.BITS_32_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code short} native type. + * The {@code long} native type. */ - SHORT, + public static final ValueLayout C_LONG = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code unsigned short} native type. + * The {@code long long} native type. */ - UNSIGNED_SHORT, + public static final ValueLayout C_LONGLONG = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code int} native type. + * The {@code float} native type. */ - INT, + public static final ValueLayout C_FLOAT = MemoryLayouts.BITS_32_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.SSE); /** - * The {@code unsigned int} native type. + * The {@code double} native type. */ - UNSIGNED_INT, + public static final ValueLayout C_DOUBLE = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.SSE); /** - * The {@code long} native type. + * The {@code long double} native type. */ - LONG, + public static final ValueLayout C_LONGDOUBLE = MemoryLayout.ofValueBits(128, ByteOrder.LITTLE_ENDIAN) + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.X87); /** - * The {@code unsigned long} native type. + * The {@code complex long double} native type. */ - UNSIGNED_LONG, + public static final GroupLayout C_COMPLEX_LONGDOUBLE = MemoryLayout.ofStruct(C_LONGDOUBLE, C_LONGDOUBLE) + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.COMPLEX_87); /** - * The {@code long long} native type. + * The {@code T*} native type. */ - LONG_LONG, + public static final ValueLayout C_POINTER = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.POINTER); + } + + /** + * This class defines layout constants modelling standard primitive types supported by the x64 Windows ABI. + */ + final class Win64 { + + private Win64() { + //just the one + } /** - * The {@code unsigned long long} native type. + * The name of the Windows ABI */ - UNSIGNED_LONG_LONG, + public final static String NAME = "Windows"; + + public final static String VARARGS_ATTRIBUTE_NAME = "abi/windows/varargs"; + + public final static String CLASS_ATTRIBUTE_NAME = "abi/windows/class"; + + public enum ArgumentClass { + INTEGER, + FLOAT, + POINTER; + } /** - * The {@code float} native type. + * The {@code _Bool} native type. */ - FLOAT, + public static final ValueLayout C_BOOL = MemoryLayouts.BITS_8_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code double} native type. + * The {@code char} native type. */ - DOUBLE, + public static final ValueLayout C_CHAR = MemoryLayouts.BITS_8_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code long double} native type. + * The {@code short} native type. */ - LONG_DOUBLE, + public static final ValueLayout C_SHORT = MemoryLayouts.BITS_16_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code complex long double} native type. + * The {@code int} native type. */ - COMPLEX_LONG_DOUBLE, + public static final ValueLayout C_INT = MemoryLayouts.BITS_32_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); /** - * The {@code T*} native type. + * The {@code long} native type. + */ + public static final ValueLayout C_LONG = MemoryLayouts.BITS_32_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); + + /** + * The {@code long long} native type. + */ + public static final ValueLayout C_LONGLONG = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); + + /** + * The {@code float} native type. + */ + public static final ValueLayout C_FLOAT = MemoryLayouts.BITS_32_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.FLOAT); + + /** + * The {@code double} native type. + */ + public static final ValueLayout C_DOUBLE = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.FLOAT); + + /** + * The {@code long double} native type. */ - POINTER; + public static final ValueLayout C_LONGDOUBLE = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.FLOAT); /** - * Retrieve the ABI type attached to the given layout, - * or throw an {@code IllegalArgumentException} if there is none - * - * @param ml the layout to retrieve the ABI type of - * @return the retrieved ABI type - * @throws IllegalArgumentException if the given layout does not have an ABI type attribute + * The {@code T*} native type. */ - public static Type fromLayout(MemoryLayout ml) throws IllegalArgumentException { - return ml.attribute(NATIVE_TYPE) - .map(SystemABI.Type.class::cast) - .orElseThrow(() -> new IllegalArgumentException("No ABI attribute present")); + public static final ValueLayout C_POINTER = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.POINTER); + + public static ValueLayout asVarArg(ValueLayout l) { + return l.withAttribute(VARARGS_ATTRIBUTE_NAME, "true"); } } /** - * Returns memory layout for the given native type if supported by the platform ABI. - * @param type the native type for which the layout is to be retrieved. - * @return the layout (if any) associated with {@code type} + * This class defines layout constants modelling standard primitive types supported by the AArch64 ABI. */ - Optional layoutFor(Type type); + final class AArch64 { + + private AArch64() { + //just the one + } + + /** + * The name of the AArch64 ABI + */ + public final static String NAME = "AArch64"; + + public static final String CLASS_ATTRIBUTE_NAME = "abi/aarch64/class"; + + public enum ArgumentClass { + INTEGER, + VECTOR, + POINTER; + } + + /** + * The {@code _Bool} native type. + */ + public static final ValueLayout C_BOOL = MemoryLayouts.BITS_8_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); + + /** + * The {@code char} native type. + */ + public static final ValueLayout C_CHAR = MemoryLayouts.BITS_8_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); + + /** + * The {@code short} native type. + */ + public static final ValueLayout C_SHORT = MemoryLayouts.BITS_16_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); + + /** + * The {@code int} native type. + */ + public static final ValueLayout C_INT = MemoryLayouts.BITS_32_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); + + /** + * The {@code long} native type. + */ + public static final ValueLayout C_LONG = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); + + /** + * The {@code long long} native type. + */ + public static final ValueLayout C_LONGLONG = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.INTEGER); + + /** + * The {@code float} native type. + */ + public static final ValueLayout C_FLOAT = MemoryLayouts.BITS_32_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.VECTOR); + + /** + * The {@code double} native type. + */ + public static final ValueLayout C_DOUBLE = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.VECTOR); + + /** + * The {@code long double} native type. + */ + public static final ValueLayout C_LONGDOUBLE = MemoryLayout.ofValueBits(128, ByteOrder.LITTLE_ENDIAN) + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.VECTOR); + + /** + * The {@code T*} native type. + */ + public static final ValueLayout C_POINTER = MemoryLayouts.BITS_64_LE + .withAttribute(CLASS_ATTRIBUTE_NAME, ArgumentClass.POINTER); + } /** * Obtain an instance of the system ABI. diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/Utils.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/Utils.java index 8ddbb4cca03..534e08163de 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/Utils.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/Utils.java @@ -28,7 +28,10 @@ import jdk.incubator.foreign.MemoryAddress; import jdk.incubator.foreign.MemoryHandles; +import jdk.incubator.foreign.MemoryLayout; +import jdk.incubator.foreign.SystemABI; import jdk.internal.access.foreign.MemoryAddressProxy; +import jdk.internal.foreign.abi.SharedUtils; import jdk.internal.misc.VM; import java.lang.invoke.MethodHandle; @@ -99,4 +102,14 @@ private static void throwIllegalAccessError(String value, String method) { throw new IllegalAccessError("Illegal access to restricted foreign method: " + method + " ; system property 'foreign.restricted' is set to '" + value + "'"); } + + public static Z pick(Z sysv, Z win64, Z aarch64) { + SystemABI abi = SharedUtils.getSystemABI(); + return switch (abi.name()) { + case SystemABI.SysV.NAME -> sysv; + case SystemABI.Win64.NAME -> win64; + case SystemABI.AArch64.NAME -> aarch64; + default -> throw new ExceptionInInitializerError("Unexpected ABI: " + abi.name()); + }; + } } diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/AArch64ABI.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/AArch64ABI.java index 7fd910f25ca..fea3acf0800 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/AArch64ABI.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/AArch64ABI.java @@ -29,15 +29,10 @@ import jdk.incubator.foreign.MemoryAddress; import jdk.incubator.foreign.MemoryLayout; import jdk.incubator.foreign.SystemABI; -import jdk.internal.foreign.MemoryAddressImpl; import jdk.internal.foreign.abi.*; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; -import java.util.Objects; -import java.util.Optional; - -import static jdk.incubator.foreign.MemoryLayouts.AArch64ABI.*; /** * ABI implementation based on ARM document "Procedure Call Standard for @@ -65,40 +60,10 @@ public MemoryAddress upcallStub(MethodHandle target, FunctionDescriptor function @Override public String name() { - return SystemABI.ABI_AARCH64; - } - - @Override - public Optional layoutFor(Type type) { - return switch (Objects.requireNonNull(type)) { - case BOOL -> Optional.of(C_BOOL); - case UNSIGNED_CHAR -> Optional.of(C_UCHAR); - case SIGNED_CHAR -> Optional.of(C_SCHAR); - case CHAR -> Optional.of(C_CHAR); - case SHORT -> Optional.of(C_SHORT); - case UNSIGNED_SHORT -> Optional.of(C_USHORT); - case INT -> Optional.of(C_INT); - case UNSIGNED_INT -> Optional.of(C_UINT); - case LONG -> Optional.of(C_LONG); - case UNSIGNED_LONG -> Optional.of(C_ULONG); - case LONG_LONG -> Optional.of(C_LONGLONG); - case UNSIGNED_LONG_LONG -> Optional.of(C_ULONGLONG); - case FLOAT -> Optional.of(C_FLOAT); - case DOUBLE -> Optional.of(C_DOUBLE); - case LONG_DOUBLE -> Optional.of(C_LONGDOUBLE); - case POINTER -> Optional.of(C_POINTER); - default -> Optional.empty(); - }; + return AArch64.NAME; } - static ArgumentClassImpl argumentClassFor(Type type) { - return switch (Objects.requireNonNull(type)) { - case BOOL, UNSIGNED_CHAR, SIGNED_CHAR, CHAR, SHORT, UNSIGNED_SHORT, - INT, UNSIGNED_INT, LONG, UNSIGNED_LONG, LONG_LONG, UNSIGNED_LONG_LONG -> - ArgumentClassImpl.INTEGER; - case FLOAT, DOUBLE -> ArgumentClassImpl.VECTOR; - case POINTER -> ArgumentClassImpl.POINTER; - default -> null; - }; + static AArch64.ArgumentClass argumentClassFor(MemoryLayout layout) { + return (AArch64.ArgumentClass)layout.attribute(AArch64.CLASS_ATTRIBUTE_NAME).get(); } } diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/ArgumentClassImpl.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/ArgumentClassImpl.java deleted file mode 100644 index cfcdf4bcfb9..00000000000 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/ArgumentClassImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2019, Arm Limited. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package jdk.internal.foreign.abi.aarch64; - -enum ArgumentClassImpl { - POINTER, INTEGER, VECTOR, MEMORY; - - public boolean isIntegral() { - return this == INTEGER || this == POINTER; - } - - public boolean isPointer() { - return this == POINTER; - } - - public boolean isIndirect() { - return this == MEMORY; - } -} diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java index 69023e2a29d..1ba14d3426c 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java @@ -107,7 +107,7 @@ public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, bool boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout()); if (returnInMemory) { - csb.addArgumentBindings(MemoryAddress.class, MemoryLayouts.AArch64ABI.C_POINTER, + csb.addArgumentBindings(MemoryAddress.class, SystemABI.AArch64.C_POINTER, argCalc.getIndirectBindings()); } else if (cDesc.returnLayout().isPresent()) { Class carrier = mt.returnType(); @@ -163,17 +163,17 @@ private enum TypeClass { } private static TypeClass classifyValueType(ValueLayout type) { - ArgumentClassImpl clazz = AArch64ABI.argumentClassFor(SystemABI.Type.fromLayout(type)); + SystemABI.AArch64.ArgumentClass clazz = AArch64ABI.argumentClassFor(type); if (clazz == null) { //padding not allowed here throw new IllegalStateException("Unexpected value layout: could not determine ABI class"); } - if (clazz == ArgumentClassImpl.INTEGER) { + if (clazz == SystemABI.AArch64.ArgumentClass.INTEGER) { return TypeClass.INTEGER; - } else if(clazz == ArgumentClassImpl.POINTER) { + } else if(clazz == SystemABI.AArch64.ArgumentClass.POINTER) { return TypeClass.POINTER; - } else if (clazz == ArgumentClassImpl.VECTOR) { + } else if (clazz == SystemABI.AArch64.ArgumentClass.VECTOR) { return TypeClass.FLOAT; } throw new IllegalArgumentException("Unknown ABI class: " + clazz); @@ -198,15 +198,15 @@ static boolean isHomogeneousFloatAggregate(MemoryLayout type) { if (!(baseType instanceof ValueLayout)) return false; - ArgumentClassImpl baseArgClass = AArch64ABI.argumentClassFor(SystemABI.Type.fromLayout(baseType)); - if (baseArgClass != ArgumentClassImpl.VECTOR) + SystemABI.AArch64.ArgumentClass baseArgClass = AArch64ABI.argumentClassFor(baseType); + if (baseArgClass != SystemABI.AArch64.ArgumentClass.VECTOR) return false; for (MemoryLayout elem : groupLayout.memberLayouts()) { if (!(elem instanceof ValueLayout)) return false; - ArgumentClassImpl argClass = AArch64ABI.argumentClassFor(SystemABI.Type.fromLayout(elem)); + SystemABI.AArch64.ArgumentClass argClass = AArch64ABI.argumentClassFor(elem); if (elem.bitSize() != baseType.bitSize() || elem.bitAlignment() != baseType.bitAlignment() || baseArgClass != argClass) { diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/ArgumentClassImpl.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/ArgumentClassImpl.java similarity index 86% rename from src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/ArgumentClassImpl.java rename to src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/ArgumentClassImpl.java index 22e66099ac5..7bd9dc61786 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/ArgumentClassImpl.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/ArgumentClassImpl.java @@ -1,10 +1,12 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -20,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package jdk.internal.foreign.abi.x64; +package jdk.internal.foreign.abi.x64.sysv; public enum ArgumentClassImpl { POINTER, INTEGER, SSE, SSEUP, X87, X87UP, COMPLEX_X87, NO_CLASS, MEMORY; diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java index b5e285db9b2..93bc4c2f979 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java @@ -29,7 +29,6 @@ import jdk.incubator.foreign.GroupLayout; import jdk.incubator.foreign.MemoryAddress; import jdk.incubator.foreign.MemoryLayout; -import jdk.incubator.foreign.MemoryLayouts; import jdk.incubator.foreign.MemorySegment; import jdk.incubator.foreign.SequenceLayout; import jdk.incubator.foreign.SystemABI; @@ -44,7 +43,6 @@ import jdk.internal.foreign.abi.ProgrammableUpcallHandler; import jdk.internal.foreign.abi.VMStorage; import jdk.internal.foreign.abi.x64.X86_64Architecture; -import jdk.internal.foreign.abi.x64.ArgumentClassImpl; import jdk.internal.foreign.abi.SharedUtils; import java.lang.invoke.MethodHandle; @@ -60,6 +58,7 @@ import static jdk.internal.foreign.abi.x64.X86_64Architecture.*; import static jdk.internal.foreign.abi.x64.sysv.SysVx64ABI.MAX_INTEGER_ARGUMENT_REGISTERS; import static jdk.internal.foreign.abi.x64.sysv.SysVx64ABI.MAX_VECTOR_ARGUMENT_REGISTERS; +import static jdk.internal.foreign.abi.x64.sysv.SysVx64ABI.argumentClassFor; /** * For the SysV x64 C ABI specifically, this class uses the ProgrammableInvoker API, namely CallingSequenceBuilder2 @@ -104,7 +103,7 @@ public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, bool boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout()); if (returnInMemory) { Class carrier = MemoryAddress.class; - MemoryLayout layout = MemoryLayouts.SysV.C_POINTER; + MemoryLayout layout = SystemABI.SysV.C_POINTER; csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout)); } else if (cDesc.returnLayout().isPresent()) { Class carrier = mt.returnType(); @@ -120,7 +119,7 @@ public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, bool if (!forUpcall) { //add extra binding for number of used vector registers (used for variadic calls) - csb.addArgumentBindings(long.class, MemoryLayouts.SysV.C_LONG, + csb.addArgumentBindings(long.class, SystemABI.SysV.C_LONG, List.of(move(rax, long.class))); } @@ -429,11 +428,8 @@ private static List createMemoryClassArray(long size) { private static List classifyValueType(ValueLayout type) { ArrayList classes = new ArrayList<>(); - ArgumentClassImpl clazz = SysVx64ABI.argumentClassFor(SystemABI.Type.fromLayout(type)); - if (clazz == null) { - //padding not allowed here - throw new IllegalStateException("Unexpected value layout: could not determine ABI class"); - } + ArgumentClassImpl clazz = SysVx64ABI.argumentClassFor(type) + .orElseThrow(() -> new IllegalStateException("Unexpected value layout: could not determine ABI class")); classes.add(clazz); if (clazz == ArgumentClassImpl.INTEGER) { // int128 @@ -517,10 +513,8 @@ private static List classifyArrayType(SequenceLayout type) { // TODO: handle zero length arrays // TODO: Handle nested structs (and primitives) private static List classifyStructType(GroupLayout type) { - if (type.attribute(SystemABI.NATIVE_TYPE) - .map(SystemABI.Type.class::cast) - .map(SysVx64ABI::argumentClassFor) - .filter(ArgumentClassImpl.COMPLEX_X87::equals) + if (argumentClassFor(type) + .filter(argClass -> argClass == ArgumentClassImpl.COMPLEX_X87) .isPresent()) { return COMPLEX_X87_CLASSES; } diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64ABI.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64ABI.java index e776a4eb423..102b5249e11 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64ABI.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64ABI.java @@ -28,15 +28,11 @@ import jdk.incubator.foreign.MemoryAddress; import jdk.incubator.foreign.MemoryLayout; import jdk.incubator.foreign.SystemABI; -import jdk.internal.foreign.MemoryAddressImpl; import jdk.internal.foreign.abi.*; -import jdk.internal.foreign.abi.x64.ArgumentClassImpl; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; -import java.util.*; - -import static jdk.incubator.foreign.MemoryLayouts.SysV.*; +import java.util.Optional; /** * ABI implementation based on System V ABI AMD64 supplement v.0.99.6 @@ -69,43 +65,20 @@ public MemoryAddress upcallStub(MethodHandle target, FunctionDescriptor function @Override public String name() { - return SystemABI.ABI_SYSV; - } - - @Override - public Optional layoutFor(Type type) { - return switch (Objects.requireNonNull(type)) { - case BOOL -> Optional.of(C_BOOL); - case UNSIGNED_CHAR -> Optional.of(C_UCHAR); - case SIGNED_CHAR -> Optional.of(C_SCHAR); - case CHAR -> Optional.of(C_CHAR); - case SHORT -> Optional.of(C_SHORT); - case UNSIGNED_SHORT -> Optional.of(C_USHORT); - case INT -> Optional.of(C_INT); - case UNSIGNED_INT -> Optional.of(C_UINT); - case LONG -> Optional.of(C_LONG); - case UNSIGNED_LONG -> Optional.of(C_ULONG); - case LONG_LONG -> Optional.of(C_LONGLONG); - case UNSIGNED_LONG_LONG -> Optional.of(C_ULONGLONG); - case FLOAT -> Optional.of(C_FLOAT); - case DOUBLE -> Optional.of(C_DOUBLE); - case LONG_DOUBLE -> Optional.of(C_LONGDOUBLE); - case COMPLEX_LONG_DOUBLE -> Optional.of(C_COMPLEX_LONGDOUBLE); - case POINTER -> Optional.of(C_POINTER); - default -> Optional.empty(); - }; + return SysV.NAME; } - static ArgumentClassImpl argumentClassFor(Type type) { - return switch (Objects.requireNonNull(type)) { - case BOOL, UNSIGNED_CHAR, SIGNED_CHAR, CHAR, SHORT, UNSIGNED_SHORT, - INT, UNSIGNED_INT, LONG, UNSIGNED_LONG, LONG_LONG, UNSIGNED_LONG_LONG -> - ArgumentClassImpl.INTEGER; - case FLOAT, DOUBLE -> ArgumentClassImpl.SSE; - case LONG_DOUBLE -> ArgumentClassImpl.X87; - case COMPLEX_LONG_DOUBLE -> ArgumentClassImpl.COMPLEX_X87; + static Optional argumentClassFor(MemoryLayout layout) { + @SuppressWarnings({"unchecked", "rawtypes"}) + Optional argClassOpt = + (Optional)(Optional)layout.attribute(SysV.CLASS_ATTRIBUTE_NAME); + return argClassOpt.map(argClass -> switch (argClass) { + case INTEGER -> ArgumentClassImpl.INTEGER; + case SSE -> ArgumentClassImpl.SSE; + case X87 -> ArgumentClassImpl.X87; + case COMPLEX_87 -> ArgumentClassImpl.COMPLEX_X87; case POINTER -> ArgumentClassImpl.POINTER; default -> null; - }; + }); } } diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java index 8e3164759ca..c6be2c46bb1 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java @@ -26,7 +26,6 @@ import jdk.incubator.foreign.GroupLayout; import jdk.incubator.foreign.MemoryAddress; import jdk.incubator.foreign.MemoryLayout; -import jdk.incubator.foreign.MemoryLayouts; import jdk.incubator.foreign.MemorySegment; import jdk.incubator.foreign.SequenceLayout; import jdk.incubator.foreign.SystemABI; @@ -41,17 +40,15 @@ import jdk.internal.foreign.abi.ProgrammableUpcallHandler; import jdk.internal.foreign.abi.VMStorage; import jdk.internal.foreign.abi.x64.X86_64Architecture; -import jdk.internal.foreign.abi.x64.ArgumentClassImpl; import jdk.internal.foreign.abi.SharedUtils; -import jdk.internal.foreign.abi.x64.sysv.SysVx64ABI; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; import java.util.List; import java.util.Optional; +import static jdk.incubator.foreign.SystemABI.Win64.VARARGS_ATTRIBUTE_NAME; import static jdk.internal.foreign.abi.x64.X86_64Architecture.*; -import static jdk.internal.foreign.abi.x64.windows.Windowsx64ABI.VARARGS_ATTRIBUTE_NAME; /** * For the Windowx x64 C ABI specifically, this class uses the ProgrammableInvoker API, namely CallingSequenceBuilder2 @@ -108,7 +105,7 @@ void setReturnBindings(Class carrier, MemoryLayout layout) { boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout()); if (returnInMemory) { Class carrier = MemoryAddress.class; - MemoryLayout layout = MemoryLayouts.WinABI.C_POINTER; + MemoryLayout layout = SystemABI.Win64.C_POINTER; csb.addArgumentBindings(carrier, layout); if (forUpcall) { csb.setReturnBindings(carrier, layout); @@ -163,7 +160,7 @@ private enum TypeClass { } private static TypeClass classifyValueType(ValueLayout type) { - ArgumentClassImpl clazz = Windowsx64ABI.argumentClassFor(SystemABI.Type.fromLayout(type)); + SystemABI.Win64.ArgumentClass clazz = Windowsx64ABI.argumentClassFor(type); if (clazz == null) { //padding not allowed here throw new IllegalStateException("Unexpected value layout: could not determine ABI class"); @@ -178,11 +175,11 @@ private static TypeClass classifyValueType(ValueLayout type) { // but must be considered volatile across function calls." // https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019 - if (clazz == ArgumentClassImpl.INTEGER) { + if (clazz == SystemABI.Win64.ArgumentClass.INTEGER) { return TypeClass.INTEGER; - } else if(clazz == ArgumentClassImpl.POINTER) { + } else if(clazz == SystemABI.Win64.ArgumentClass.POINTER) { return TypeClass.POINTER; - } else if (clazz == ArgumentClassImpl.SSE) { + } else if (clazz == SystemABI.Win64.ArgumentClass.FLOAT) { if (type.attribute(VARARGS_ATTRIBUTE_NAME) .map(String.class::cast) .map(Boolean::parseBoolean).orElse(false)) { diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64ABI.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64ABI.java index caa0d21625d..538a6bc29d0 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64ABI.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64ABI.java @@ -28,16 +28,11 @@ import jdk.incubator.foreign.MemoryAddress; import jdk.incubator.foreign.MemoryLayout; import jdk.incubator.foreign.SystemABI; -import jdk.internal.foreign.MemoryAddressImpl; -import jdk.internal.foreign.abi.x64.ArgumentClassImpl; +import jdk.internal.foreign.abi.x64.sysv.ArgumentClassImpl; import jdk.internal.foreign.abi.*; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; -import java.util.Objects; -import java.util.Optional; - -import static jdk.incubator.foreign.MemoryLayouts.WinABI.*; /** * ABI implementation based on Windows ABI AMD64 supplement v.0.99.6 @@ -51,8 +46,6 @@ public class Windowsx64ABI implements SystemABI { public static final int MAX_REGISTER_ARGUMENTS = 4; public static final int MAX_REGISTER_RETURNS = 1; - public static final String VARARGS_ATTRIBUTE_NAME = "abi/windows/varargs"; - private static Windowsx64ABI instance; public static Windowsx64ABI getInstance() { @@ -74,40 +67,10 @@ public MemoryAddress upcallStub(MethodHandle target, FunctionDescriptor function @Override public String name() { - return SystemABI.ABI_WINDOWS; - } - - @Override - public Optional layoutFor(Type type) { - return switch (Objects.requireNonNull(type)) { - case BOOL -> Optional.of(C_BOOL); - case UNSIGNED_CHAR -> Optional.of(C_UCHAR); - case SIGNED_CHAR -> Optional.of(C_SCHAR); - case CHAR -> Optional.of(C_CHAR); - case SHORT -> Optional.of(C_SHORT); - case UNSIGNED_SHORT -> Optional.of(C_USHORT); - case INT -> Optional.of(C_INT); - case UNSIGNED_INT -> Optional.of(C_UINT); - case LONG -> Optional.of(C_LONG); - case UNSIGNED_LONG -> Optional.of(C_ULONG); - case LONG_LONG -> Optional.of(C_LONGLONG); - case UNSIGNED_LONG_LONG -> Optional.of(C_ULONGLONG); - case FLOAT -> Optional.of(C_FLOAT); - case DOUBLE -> Optional.of(C_DOUBLE); - case LONG_DOUBLE -> Optional.of(C_LONGDOUBLE); - case POINTER -> Optional.of(C_POINTER); - default -> Optional.empty(); - }; + return Win64.NAME; } - static ArgumentClassImpl argumentClassFor(Type type) { - return switch (Objects.requireNonNull(type)) { - case BOOL, UNSIGNED_CHAR, SIGNED_CHAR, CHAR, SHORT, UNSIGNED_SHORT, - INT, UNSIGNED_INT, LONG, UNSIGNED_LONG, LONG_LONG, UNSIGNED_LONG_LONG -> - ArgumentClassImpl.INTEGER; - case FLOAT, DOUBLE -> ArgumentClassImpl.SSE; - case POINTER -> ArgumentClassImpl.POINTER; - default -> null; - }; + static Win64.ArgumentClass argumentClassFor(MemoryLayout layout) { + return (Win64.ArgumentClass)layout.attribute(Win64.CLASS_ATTRIBUTE_NAME).get(); } } diff --git a/test/jdk/java/foreign/CallGeneratorHelper.java b/test/jdk/java/foreign/CallGeneratorHelper.java index a5fc0fb6658..ae0340638e1 100644 --- a/test/jdk/java/foreign/CallGeneratorHelper.java +++ b/test/jdk/java/foreign/CallGeneratorHelper.java @@ -38,7 +38,7 @@ import org.testng.annotations.*; -import static jdk.incubator.foreign.MemoryLayouts.*; +import static jdk.incubator.foreign.SystemABI.*; import static org.testng.Assert.*; public class CallGeneratorHelper extends NativeTestHelper { diff --git a/test/jdk/java/foreign/Cstring.java b/test/jdk/java/foreign/Cstring.java index 6e1931aff65..4a1d9fae396 100644 --- a/test/jdk/java/foreign/Cstring.java +++ b/test/jdk/java/foreign/Cstring.java @@ -27,7 +27,7 @@ import jdk.incubator.foreign.MemoryAddress; import jdk.incubator.foreign.MemoryLayout; import jdk.incubator.foreign.MemorySegment; -import static jdk.incubator.foreign.MemoryLayouts.C_CHAR; +import static jdk.incubator.foreign.SystemABI.C_CHAR; public final class Cstring { // don't create! diff --git a/test/jdk/java/foreign/NativeTestHelper.java b/test/jdk/java/foreign/NativeTestHelper.java index 7874469b076..c49da9731fb 100644 --- a/test/jdk/java/foreign/NativeTestHelper.java +++ b/test/jdk/java/foreign/NativeTestHelper.java @@ -23,32 +23,32 @@ */ import jdk.incubator.foreign.MemoryLayout; -import jdk.incubator.foreign.MemoryLayouts.WinABI; import jdk.incubator.foreign.SystemABI; -import jdk.incubator.foreign.SystemABI.Type; import jdk.incubator.foreign.ValueLayout; -import jdk.internal.foreign.Utils; -import java.util.function.Predicate; - -import static jdk.incubator.foreign.SystemABI.ABI_WINDOWS; public class NativeTestHelper { public static final SystemABI ABI = SystemABI.getSystemABI(); public static boolean isIntegral(MemoryLayout layout) { - return switch(SystemABI.Type.fromLayout(layout)) { - case BOOL, UNSIGNED_CHAR, SIGNED_CHAR, CHAR, SHORT, UNSIGNED_SHORT, - INT, UNSIGNED_INT, LONG, UNSIGNED_LONG, LONG_LONG, UNSIGNED_LONG_LONG -> true; - default -> false; + return switch (ABI.name()) { + case SystemABI.SysV.NAME -> layout.attribute(SystemABI.SysV.CLASS_ATTRIBUTE_NAME).get() == SystemABI.SysV.ArgumentClass.INTEGER; + case SystemABI.Win64.NAME -> layout.attribute(SystemABI.Win64.CLASS_ATTRIBUTE_NAME).get() == SystemABI.Win64.ArgumentClass.INTEGER; + case SystemABI.AArch64.NAME -> layout.attribute(SystemABI.AArch64.CLASS_ATTRIBUTE_NAME).get() == SystemABI.AArch64.ArgumentClass.INTEGER; + default -> throw new AssertionError("unexpected ABI: " + ABI.name()); }; } public static boolean isPointer(MemoryLayout layout) { - return SystemABI.Type.fromLayout(layout) == Type.POINTER; + return switch (ABI.name()) { + case SystemABI.SysV.NAME -> layout.attribute(SystemABI.SysV.CLASS_ATTRIBUTE_NAME).get() == SystemABI.SysV.ArgumentClass.POINTER; + case SystemABI.Win64.NAME -> layout.attribute(SystemABI.Win64.CLASS_ATTRIBUTE_NAME).get() == SystemABI.Win64.ArgumentClass.POINTER; + case SystemABI.AArch64.NAME -> layout.attribute(SystemABI.AArch64.CLASS_ATTRIBUTE_NAME).get() == SystemABI.AArch64.ArgumentClass.POINTER; + default -> throw new AssertionError("unexpected ABI: " + ABI.name()); + }; } public static ValueLayout asVarArg(ValueLayout layout) { - return ABI.name().equals(ABI_WINDOWS) ? WinABI.asVarArg(layout) : layout; + return ABI.name().equals(SystemABI.Win64.NAME) ? SystemABI.Win64.asVarArg(layout) : layout; } } diff --git a/test/jdk/java/foreign/StdLibTest.java b/test/jdk/java/foreign/StdLibTest.java index 67ab04ee264..c525e0ae156 100644 --- a/test/jdk/java/foreign/StdLibTest.java +++ b/test/jdk/java/foreign/StdLibTest.java @@ -61,7 +61,7 @@ import jdk.incubator.foreign.SystemABI; import org.testng.annotations.*; -import static jdk.incubator.foreign.MemoryLayouts.*; +import static jdk.incubator.foreign.SystemABI.*; import static org.testng.Assert.*; @Test @@ -200,7 +200,7 @@ static class StdLibHelper { qsort = abi.downcallHandle(lookup.lookup("qsort"), MethodType.methodType(void.class, MemoryAddress.class, long.class, long.class, MemoryAddress.class), - FunctionDescriptor.ofVoid(C_POINTER, C_ULONG, C_ULONG, C_POINTER)); + FunctionDescriptor.ofVoid(C_POINTER, C_LONG, C_LONG, C_POINTER)); //qsort upcall handle qsortCompar = MethodHandles.lookup().findStatic(StdLibTest.StdLibHelper.class, "qsortCompare", diff --git a/test/jdk/java/foreign/TestCircularInit1.java b/test/jdk/java/foreign/TestCircularInit1.java index d12b85f2955..17724e0e434 100644 --- a/test/jdk/java/foreign/TestCircularInit1.java +++ b/test/jdk/java/foreign/TestCircularInit1.java @@ -27,7 +27,7 @@ * @run testng/othervm TestCircularInit1 */ -import jdk.incubator.foreign.MemoryLayouts; +import jdk.incubator.foreign.SystemABI; import org.testng.annotations.Test; import static org.testng.Assert.assertNotNull; @@ -36,8 +36,8 @@ public class TestCircularInit1 { @Test public void testCircularInit() { - System.out.println(MemoryLayouts.WinABI.C_BOOL); // trigger clinit - assertNotNull(MemoryLayouts.C_BOOL); // should not be null + System.out.println(SystemABI.C_BOOL); // trigger clinit + assertNotNull(SystemABI.C_BOOL); // should not be null } } diff --git a/test/jdk/java/foreign/TestCircularInit2.java b/test/jdk/java/foreign/TestCircularInit2.java index 17f2984f294..eff0883be5e 100644 --- a/test/jdk/java/foreign/TestCircularInit2.java +++ b/test/jdk/java/foreign/TestCircularInit2.java @@ -27,7 +27,7 @@ * @run testng/othervm TestCircularInit2 */ -import jdk.incubator.foreign.MemoryLayouts; +import jdk.incubator.foreign.SystemABI; import org.testng.annotations.Test; import static org.testng.Assert.assertNotNull; @@ -36,10 +36,10 @@ public class TestCircularInit2 { @Test public void testCircularInit() { - System.out.println(MemoryLayouts.C_BOOL); // trigger clinit - assertNotNull(MemoryLayouts.WinABI.C_BOOL); - assertNotNull(MemoryLayouts.SysV.C_BOOL); - assertNotNull(MemoryLayouts.AArch64ABI.C_BOOL); + System.out.println(SystemABI.C_BOOL); // trigger clinit + assertNotNull(SystemABI.C_BOOL); + assertNotNull(SystemABI.C_BOOL); + assertNotNull(SystemABI.C_BOOL); } } diff --git a/test/jdk/java/foreign/TestUpcall.java b/test/jdk/java/foreign/TestUpcall.java index e12e9780448..fa11c398108 100644 --- a/test/jdk/java/foreign/TestUpcall.java +++ b/test/jdk/java/foreign/TestUpcall.java @@ -55,7 +55,7 @@ import java.util.stream.Collectors; import static java.lang.invoke.MethodHandles.insertArguments; -import static jdk.incubator.foreign.MemoryLayouts.C_POINTER; +import static jdk.incubator.foreign.SystemABI.C_POINTER; import static org.testng.Assert.assertEquals; diff --git a/test/jdk/java/foreign/TestVarArgs.java b/test/jdk/java/foreign/TestVarArgs.java index 4fa5edc04f3..ba77d9f3bcc 100644 --- a/test/jdk/java/foreign/TestVarArgs.java +++ b/test/jdk/java/foreign/TestVarArgs.java @@ -51,7 +51,7 @@ import java.util.List; import static jdk.incubator.foreign.MemoryLayout.PathElement.*; -import static jdk.incubator.foreign.MemoryLayouts.*; +import static jdk.incubator.foreign.SystemABI.*; import static org.testng.Assert.assertEquals; public class TestVarArgs extends NativeTestHelper { diff --git a/test/jdk/java/foreign/callarranger/TestAarch64CallArranger.java b/test/jdk/java/foreign/callarranger/TestAarch64CallArranger.java index 33054daaa7c..8e0151fc1ad 100644 --- a/test/jdk/java/foreign/callarranger/TestAarch64CallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestAarch64CallArranger.java @@ -44,7 +44,7 @@ import java.lang.invoke.MethodType; -import static jdk.incubator.foreign.MemoryLayouts.AArch64ABI.*; +import static jdk.incubator.foreign.SystemABI.AArch64.*; import static jdk.internal.foreign.abi.Binding.*; import static jdk.internal.foreign.abi.aarch64.AArch64Architecture.*; import static org.testng.Assert.assertEquals; diff --git a/test/jdk/java/foreign/callarranger/TestSysVCallArranger.java b/test/jdk/java/foreign/callarranger/TestSysVCallArranger.java index 4806655479b..3b6058b58c6 100644 --- a/test/jdk/java/foreign/callarranger/TestSysVCallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestSysVCallArranger.java @@ -45,8 +45,7 @@ import java.lang.invoke.MethodType; -import static jdk.incubator.foreign.MemoryLayouts.SysV.*; -import static jdk.incubator.foreign.MemoryLayouts.WinABI.C_POINTER; +import static jdk.incubator.foreign.SystemABI.SysV.*; import static jdk.internal.foreign.abi.Binding.*; import static jdk.internal.foreign.abi.x64.X86_64Architecture.*; import static org.testng.Assert.assertEquals; @@ -285,17 +284,17 @@ public void testStruct(MemoryLayout struct, Binding[] expectedBindings) { @DataProvider public static Object[][] structs() { return new Object[][]{ - { MemoryLayout.ofStruct(C_ULONG), new Binding[]{ + { MemoryLayout.ofStruct(C_LONG), new Binding[]{ dereference(0, long.class), move(rdi, long.class) } }, - { MemoryLayout.ofStruct(C_ULONG, C_ULONG), new Binding[]{ + { MemoryLayout.ofStruct(C_LONG, C_LONG), new Binding[]{ dup(), dereference(0, long.class), move(rdi, long.class), dereference(8, long.class), move(rsi, long.class) } }, - { MemoryLayout.ofStruct(C_ULONG, C_ULONG, C_ULONG), new Binding[]{ + { MemoryLayout.ofStruct(C_LONG, C_LONG, C_LONG), new Binding[]{ dup(), dereference(0, long.class), move(stackStorage(0), long.class), dup(), @@ -303,7 +302,7 @@ public static Object[][] structs() { dereference(16, long.class), move(stackStorage(2), long.class) } }, - { MemoryLayout.ofStruct(C_ULONG, C_ULONG, C_ULONG, C_ULONG), new Binding[]{ + { MemoryLayout.ofStruct(C_LONG, C_LONG, C_LONG, C_LONG), new Binding[]{ dup(), dereference(0, long.class), move(stackStorage(0), long.class), dup(), @@ -318,7 +317,7 @@ public static Object[][] structs() { @Test public void testReturnRegisterStruct() { - MemoryLayout struct = MemoryLayout.ofStruct(C_ULONG, C_ULONG); + MemoryLayout struct = MemoryLayout.ofStruct(C_LONG, C_LONG); MethodType mt = MethodType.methodType(MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.of(struct); @@ -348,7 +347,7 @@ public void testReturnRegisterStruct() { @Test public void testIMR() { - MemoryLayout struct = MemoryLayout.ofStruct(C_ULONG, C_ULONG, C_ULONG); + MemoryLayout struct = MemoryLayout.ofStruct(C_LONG, C_LONG, C_LONG); MethodType mt = MethodType.methodType(MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.of(struct); diff --git a/test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java b/test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java index 90f7743c65e..6c499356627 100644 --- a/test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java +++ b/test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java @@ -44,8 +44,7 @@ import java.lang.invoke.MethodType; -import static jdk.incubator.foreign.MemoryLayouts.WinABI.*; -import static jdk.incubator.foreign.MemoryLayouts.WinABI.asVarArg; +import static jdk.incubator.foreign.SystemABI.Win64.*; import static jdk.internal.foreign.abi.Binding.*; import static jdk.internal.foreign.abi.Binding.copy; import static jdk.internal.foreign.abi.x64.X86_64Architecture.*; @@ -210,7 +209,7 @@ public void testAbiExampleVarargs() { */ @Test public void testStructRegister() { - MemoryLayout struct = MemoryLayout.ofStruct(C_ULONGLONG); + MemoryLayout struct = MemoryLayout.ofStruct(C_LONGLONG); MethodType mt = MethodType.methodType(void.class, MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct); @@ -239,7 +238,7 @@ public void testStructRegister() { */ @Test public void testStructReference() { - MemoryLayout struct = MemoryLayout.ofStruct(C_ULONGLONG, C_ULONGLONG); + MemoryLayout struct = MemoryLayout.ofStruct(C_LONGLONG, C_LONGLONG); MethodType mt = MethodType.methodType(void.class, MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct); @@ -290,7 +289,7 @@ public void testMemoryAddress() { @Test public void testReturnRegisterStruct() { - MemoryLayout struct = MemoryLayout.ofStruct(C_ULONGLONG); + MemoryLayout struct = MemoryLayout.ofStruct(C_LONGLONG); MethodType mt = MethodType.methodType(MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.of(struct); @@ -312,7 +311,7 @@ public void testReturnRegisterStruct() { @Test public void testIMR() { - MemoryLayout struct = MemoryLayout.ofStruct(C_ULONGLONG, C_ULONGLONG); + MemoryLayout struct = MemoryLayout.ofStruct(C_LONGLONG, C_LONGLONG); MethodType mt = MethodType.methodType(MemorySegment.class); FunctionDescriptor fd = FunctionDescriptor.of(struct); diff --git a/test/micro/org/openjdk/bench/jdk/incubator/foreign/CallOverhead.java b/test/micro/org/openjdk/bench/jdk/incubator/foreign/CallOverhead.java index 465ed9ca6ed..5c5300a1c5f 100644 --- a/test/micro/org/openjdk/bench/jdk/incubator/foreign/CallOverhead.java +++ b/test/micro/org/openjdk/bench/jdk/incubator/foreign/CallOverhead.java @@ -39,7 +39,7 @@ import java.lang.invoke.MethodType; import java.util.concurrent.TimeUnit; -import static jdk.incubator.foreign.MemoryLayouts.C_INT; +import static jdk.incubator.foreign.SystemABI.C_INT; @BenchmarkMode(Mode.AverageTime) @Warmup(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS) diff --git a/test/micro/org/openjdk/bench/jdk/incubator/foreign/points/support/PanamaPoint.java b/test/micro/org/openjdk/bench/jdk/incubator/foreign/points/support/PanamaPoint.java index 48af5960b3d..622d49f395f 100644 --- a/test/micro/org/openjdk/bench/jdk/incubator/foreign/points/support/PanamaPoint.java +++ b/test/micro/org/openjdk/bench/jdk/incubator/foreign/points/support/PanamaPoint.java @@ -36,13 +36,13 @@ import static java.lang.invoke.MethodType.methodType; import static jdk.incubator.foreign.MemoryLayout.PathElement.groupElement; -import static jdk.incubator.foreign.MemoryLayouts.*; +import static jdk.incubator.foreign.SystemABI.*; public class PanamaPoint implements AutoCloseable { public static final MemoryLayout LAYOUT = MemoryLayout.ofStruct( - MemoryLayouts.C_INT.withName("x"), - MemoryLayouts.C_INT.withName("y") + C_INT.withName("x"), + C_INT.withName("y") ); private static final VarHandle VH_x = LAYOUT.varHandle(int.class, groupElement("x"));