Skip to content
Permalink
Browse files

Merge foreign-abi

  • Loading branch information
J. Duke authored and JornVernee committed May 6, 2020
2 parents 6f69981 + 50e5acd commit 43032131817ce1f4301d55c159b5e56bc389aab3
Showing with 359 additions and 758 deletions.
  1. +4 −473 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayouts.java
  2. +254 −49 src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SystemABI.java
  3. +13 −0 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/Utils.java
  4. +3 −38 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/AArch64ABI.java
  5. +0 −40 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/ArgumentClassImpl.java
  6. +8 −8 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java
  7. +5 −3 ...jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/{ → sysv}/ArgumentClassImpl.java
  8. +7 −13 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/CallArranger.java
  9. +12 −39 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/sysv/SysVx64ABI.java
  10. +6 −9 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/CallArranger.java
  11. +4 −41 src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/x64/windows/Windowsx64ABI.java
  12. +1 −1 test/jdk/java/foreign/CallGeneratorHelper.java
  13. +1 −1 test/jdk/java/foreign/Cstring.java
  14. +12 −12 test/jdk/java/foreign/NativeTestHelper.java
  15. +2 −2 test/jdk/java/foreign/StdLibTest.java
  16. +3 −3 test/jdk/java/foreign/TestCircularInit1.java
  17. +5 −5 test/jdk/java/foreign/TestCircularInit2.java
  18. +1 −1 test/jdk/java/foreign/TestUpcall.java
  19. +1 −1 test/jdk/java/foreign/TestVarArgs.java
  20. +1 −1 test/jdk/java/foreign/callarranger/TestAarch64CallArranger.java
  21. +7 −8 test/jdk/java/foreign/callarranger/TestSysVCallArranger.java
  22. +5 −6 test/jdk/java/foreign/callarranger/TestWindowsCallArranger.java
  23. +1 −1 test/micro/org/openjdk/bench/jdk/incubator/foreign/CallOverhead.java
  24. +3 −3 test/micro/org/openjdk/bench/jdk/incubator/foreign/points/support/PanamaPoint.java

Large diffs are not rendered by default.

@@ -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<MemoryLayout> 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.

0 comments on commit 4303213

Please sign in to comment.