Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JDK18] Implement the CLinker downcall handle of JEP389/419 on PPC64/S390 #3

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@
* questions.
*
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2022 All Rights Reserved
* ===========================================================================
*/

package jdk.incubator.foreign;

import jdk.internal.foreign.SystemLookup;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.aarch64.linux.LinuxAArch64Linker;
import jdk.internal.foreign.abi.aarch64.macos.MacOsAArch64Linker;
import jdk.internal.foreign.abi.ppc64.aix.AixPPC64Linker;
import jdk.internal.foreign.abi.ppc64.sysv.SysVPPC64leLinker;
import jdk.internal.foreign.abi.s390x.sysv.SysVS390xLinker;
import jdk.internal.foreign.abi.x64.sysv.SysVx64Linker;
import jdk.internal.foreign.abi.x64.windows.Windowsx64Linker;
import jdk.internal.reflect.CallerSensitive;
Expand Down Expand Up @@ -142,7 +152,7 @@
* @implSpec
* Implementations of this interface are immutable, thread-safe and <a href="{@docRoot}/java.base/java/lang/doc-files/ValueBased.html">value-based</a>.
*/
public sealed interface CLinker extends SymbolLookup permits Windowsx64Linker, SysVx64Linker, LinuxAArch64Linker, MacOsAArch64Linker {
public sealed interface CLinker extends SymbolLookup permits Windowsx64Linker, SysVx64Linker, LinuxAArch64Linker, MacOsAArch64Linker, SysVPPC64leLinker, SysVS390xLinker, AixPPC64Linker {

/**
* Returns the C linker for the current platform.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@
* questions.
*
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2022 All Rights Reserved
* ===========================================================================
*/

package jdk.incubator.foreign;

import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.aarch64.linux.LinuxAArch64VaList;
import jdk.internal.foreign.abi.aarch64.macos.MacOsAArch64VaList;
import jdk.internal.foreign.abi.ppc64.aix.AixPPC64VaList;
import jdk.internal.foreign.abi.ppc64.sysv.SysVPPC64leVaList;
import jdk.internal.foreign.abi.s390x.sysv.SysVS390xVaList;
import jdk.internal.foreign.abi.x64.sysv.SysVVaList;
import jdk.internal.foreign.abi.x64.windows.WinVaList;
import jdk.internal.reflect.CallerSensitive;
Expand Down Expand Up @@ -56,7 +66,7 @@
* <p> Unless otherwise specified, passing a {@code null} argument, or an array argument containing one or more {@code null}
* elements to a method in this class causes a {@link NullPointerException NullPointerException} to be thrown. </p>
*/
sealed public interface VaList extends Addressable permits WinVaList, SysVVaList, LinuxAArch64VaList, MacOsAArch64VaList, SharedUtils.EmptyVaList {
sealed public interface VaList extends Addressable permits WinVaList, SysVVaList, LinuxAArch64VaList, MacOsAArch64VaList, SysVPPC64leVaList, SysVS390xVaList, AixPPC64VaList, SharedUtils.EmptyVaList {

/**
* Reads the next value as an {@code int} and advances this variable argument list's position. The behavior of this
Expand Down Expand Up @@ -223,7 +233,7 @@ static VaList empty() {
* <p> Unless otherwise specified, passing a {@code null} argument, or an array argument containing one or more {@code null}
* elements to a method in this class causes a {@link NullPointerException NullPointerException} to be thrown. </p>
*/
sealed interface Builder permits WinVaList.Builder, SysVVaList.Builder, LinuxAArch64VaList.Builder, MacOsAArch64VaList.Builder {
sealed interface Builder permits WinVaList.Builder, SysVVaList.Builder, LinuxAArch64VaList.Builder, MacOsAArch64VaList.Builder, SysVPPC64leVaList.Builder, SysVS390xVaList.Builder, AixPPC64VaList.Builder {

/**
* Writes an {@code int} value to the variable argument list being constructed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
* questions.
*
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2022 All Rights Reserved
* ===========================================================================
*/

package jdk.internal.foreign;

import static jdk.incubator.foreign.ValueLayout.ADDRESS;
Expand All @@ -32,7 +39,10 @@ public enum CABI {
SysV,
Win64,
LinuxAArch64,
MacOsAArch64;
MacOsAArch64,
SysVPPC64le,
SysVS390x,
AIX;

private static final CABI current;

Expand All @@ -55,7 +65,15 @@ public enum CABI {
// The Linux ABI follows the standard AAPCS ABI
current = LinuxAArch64;
}
} else {
} else if (arch.startsWith("ppc64")) {
if (os.startsWith("Linux")) {
current = SysVPPC64le;
} else {
current = AIX;
}
} else if (arch.equals("s390x") && os.startsWith("Linux")) {
current = SysVS390x;
} else {
throw new ExceptionInInitializerError(
"Unsupported os, arch, or address size: " + os + ", " + arch + ", " + addressSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,27 @@
* questions.
*
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2022 All Rights Reserved
* ===========================================================================
*/

package jdk.internal.foreign;

import jdk.incubator.foreign.MemoryLayout;
import jdk.incubator.foreign.ValueLayout;

public class PlatformLayouts {
public static <Z extends MemoryLayout> Z pick(Z sysv, Z win64, Z aarch64) {
public static <Z extends MemoryLayout> Z pick(Z sysv, Z win64, Z aarch64, Z sysvppc64le, Z sysvs390x, Z aix) {
return switch (CABI.current()) {
case SysV -> sysv;
case Win64 -> win64;
case LinuxAArch64, MacOsAArch64 -> aarch64;
case SysVPPC64le -> sysvppc64le;
case SysVS390x -> sysvs390x;
case AIX -> aix;
};
}

Expand Down Expand Up @@ -214,4 +224,181 @@ private AArch64() {
*/
public static final ValueLayout.OfAddress C_VA_LIST = AArch64.C_POINTER;
}

/**
* This class defines layout constants modelling standard primitive types supported by the PPC64LE SystemV ABI.
*/
public static final class SysVPPC64le {
private SysVPPC64le() {
//just the one
}

/**
* The {@code bool} native type.
*/
public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN;

/**
* The {@code char} native type.
*/
public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE;

/**
* The {@code short} native type.
*/
public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT.withBitAlignment(16);

/**
* The {@code int} native type.
*/
public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT.withBitAlignment(32);

/**
* The {@code long} native type.
*/
public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG.withBitAlignment(64);

/**
* The {@code long long} native type.
*/
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG.withBitAlignment(64);

/**
* The {@code float} native type.
*/
public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT.withBitAlignment(32);

/**
* The {@code double} native type.
*/
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE.withBitAlignment(64);

/**
* The {@code T*} native type.
*/
public static final ValueLayout.OfAddress C_POINTER = ValueLayout.ADDRESS.withBitAlignment(64);

/**
* The {@code va_list} native type, as it is passed to a function.
*/
public static final ValueLayout.OfAddress C_VA_LIST = SysVPPC64le.C_POINTER;
}

/**
* This class defines layout constants modelling standard primitive types supported by the s390x SystemV ABI.
*/
public static final class SysVS390x {
private SysVS390x() {
//just the one
}

/**
* The {@code bool} native type.
*/
public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN;

/**
* The {@code char} native type.
*/
public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE;

/**
* The {@code short} native type.
*/
public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT.withBitAlignment(16);

/**
* The {@code int} native type.
*/
public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT.withBitAlignment(32);

/**
* The {@code long} native type.
*/
public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG.withBitAlignment(64);

/**
* The {@code long long} native type.
*/
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG.withBitAlignment(64);

/**
* The {@code float} native type.
*/
public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT.withBitAlignment(32);

/**
* The {@code double} native type.
*/
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE.withBitAlignment(64);

/**
* The {@code T*} native type.
*/
public static final ValueLayout.OfAddress C_POINTER = ValueLayout.ADDRESS.withBitAlignment(64);

/**
* The {@code va_list} native type, as it is passed to a function.
*/
public static final ValueLayout.OfAddress C_VA_LIST = SysVS390x.C_POINTER;
}

/**
* This class defines layout constants modelling standard primitive types supported by the AIX PPC64 ABI.
*/
public static final class AIX {
private AIX() {
//just the one
}

/**
* The {@code bool} native type.
*/
public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN;

/**
* The {@code char} native type.
*/
public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE;

/**
* The {@code short} native type.
*/
public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT.withBitAlignment(16);

/**
* The {@code int} native type.
*/
public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT.withBitAlignment(32);

/**
* The {@code long} native type.
*/
public static final ValueLayout.OfInt C_LONG = ValueLayout.JAVA_INT.withBitAlignment(32);

/**
* The {@code long long} native type.
*/
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG.withBitAlignment(64);

/**
* The {@code float} native type.
*/
public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT.withBitAlignment(32);

/**
* The {@code double} native type.
*/
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE.withBitAlignment(64);

/**
* The {@code T*} native type.
*/
public static final ValueLayout.OfAddress C_POINTER = ValueLayout.ADDRESS.withBitAlignment(64);

/**
* The {@code va_list} native type, as it is passed to a function.
*/
public static final ValueLayout.OfAddress C_VA_LIST = AIX.C_POINTER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2021, 2022 All Rights Reserved
* ===========================================================================
*/

package jdk.internal.foreign;

import jdk.incubator.foreign.MemorySegment;
Expand Down Expand Up @@ -52,10 +58,15 @@ private SystemLookup() { }
* on Windows. For this reason, on Windows we do not generate any side-library, and load msvcrt.dll directly instead.
*/
private static final SymbolLookup syslookup = switch (CABI.current()) {
case SysV, LinuxAArch64, MacOsAArch64 -> libLookup(libs -> libs.loadLibrary("syslookup"));
case SysV, LinuxAArch64, MacOsAArch64, SysVPPC64le, SysVS390x -> libLookup(libs -> libs.loadLibrary("syslookup"));
case AIX -> makeAixLookup();
case Win64 -> makeWindowsLookup(); // out of line to workaround javac crash
};

private static SymbolLookup makeAixLookup() { // Intended for libc.a on AIX
throw new InternalError("Default library loading is not yet implemented on AIX"); //$NON-NLS-1$
}

private static SymbolLookup makeWindowsLookup() {
Path system32 = Path.of(System.getenv("SystemRoot"), "System32");
Path ucrtbase = system32.resolve("ucrtbase.dll");
Expand Down
Loading