Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
[FFI] Disable FFI related code in OpenJDK for JDK20
Browse files Browse the repository at this point in the history
The change is to disable all downcall & upcall code
specific to FFI in OpenJDK for the moment to ensure
it gets compiled in JDK20 as we have been working
on the changes in OpenJDK & OpenJ9 to deal with the
latest APIs intended for JEP434.

Signed-off-by: ChengJin01 <jincheng@ca.ibm.com>
  • Loading branch information
ChengJin01 committed Jan 20, 2023
1 parent c4fdc10 commit 7fa5db1
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

Expand Down Expand Up @@ -89,7 +89,7 @@ private static SymbolLookup makeAixLookup() {
long addr = lib.lookup(name);
return (addr == 0) ?
Optional.empty() :
Optional.of(MemorySegment.ofAddress(MemoryAddress.ofLong(addr), 0, MemorySession.global()));
Optional.of(MemorySegment.ofAddress(addr, 0, SegmentScope.global()));
} catch (NoSuchMethodException e) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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

Expand Down Expand Up @@ -307,9 +307,9 @@ public static VaList newVaList(Consumer<VaList.Builder> actions, SegmentScope sc
case SYS_V -> SysVx64Linker.newVaList(actions, scope);
case LINUX_AARCH_64 -> LinuxAArch64Linker.newVaList(actions, scope);
case MAC_OS_AARCH_64 -> MacOsAArch64Linker.newVaList(actions, scope);
case SysVPPC64le -> SysVPPC64leLinker.newVaList(actions, session);
case SysVS390x -> SysVS390xLinker.newVaList(actions, session);
case AIX -> AixPPC64Linker.newVaList(actions, session);
case SysVPPC64le -> SysVPPC64leLinker.newVaList(actions, scope);
case SysVS390x -> SysVS390xLinker.newVaList(actions, scope);
case AIX -> AixPPC64Linker.newVaList(actions, scope);
};
}

Expand All @@ -319,9 +319,9 @@ public static VaList newVaListOfAddress(long address, SegmentScope scope) {
case SYS_V -> SysVx64Linker.newVaListOfAddress(address, scope);
case LINUX_AARCH_64 -> LinuxAArch64Linker.newVaListOfAddress(address, scope);
case MAC_OS_AARCH_64 -> MacOsAArch64Linker.newVaListOfAddress(address, scope);
case SysVPPC64le -> SysVPPC64leLinker.newVaListOfAddress(ma, session);
case SysVS390x -> SysVS390xLinker.newVaListOfAddress(ma, session);
case AIX -> AixPPC64Linker.newVaListOfAddress(ma, session);
case SysVPPC64le -> SysVPPC64leLinker.newVaListOfAddress(address, scope);
case SysVS390x -> SysVS390xLinker.newVaListOfAddress(address, scope);
case AIX -> AixPPC64Linker.newVaListOfAddress(address, scope);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

Expand Down Expand Up @@ -154,15 +154,16 @@ public Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean for
}

/* Replace DowncallLinker in OpenJDK with the implementation of DowncallLinker specific to OpenJ9 */
public MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
MethodHandle handle = DowncallLinker.getBoundMethodHandle(mt, cDesc);
return handle;
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
// MethodHandle handle = DowncallLinker.getBoundMethodHandle(mt, cDesc, options);
// return handle;
return null;
}

/* Replace UpcallLinker in OpenJDK with the implementation of UpcallLinker specific to OpenJ9 */
public MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope session) {
MethodHandle handle = DowncallLinker.getBoundMethodHandle(mt, cDesc);
return handle;
public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope session) {
// return UpcallLinker.make(target, mt, cDesc, session);
return null;
}

private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

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

package jdk.internal.foreign.abi.ppc64;

import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.ValueLayout;
import static java.lang.foreign.ValueLayout.*;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static VarHandle classifyVarHandle(ValueLayout layout) {
argHandle = JAVA_DOUBLE.varHandle();
} else if ((carrier == long.class)
|| (carrier == double.class)
|| (carrier == MemoryAddress.class)
|| (carrier == MemorySegment.class)
) {
argHandle = layout.varHandle();
} else {
Expand Down Expand Up @@ -104,7 +104,7 @@ private static TypeClass classifyValueType(ValueLayout layout) {
|| (carrier == double.class)
) {
layoutType = PRIMITIVE;
} else if (carrier == MemoryAddress.class) {
} else if (carrier == MemorySegment.class) {
layoutType = POINTER;
} else {
throw new IllegalStateException("Unspported carrier: " + carrier.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@

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

package jdk.internal.foreign.abi.ppc64.aix;

import jdk.internal.foreign.abi.AbstractLinker;
import jdk.internal.foreign.abi.LinkerOptions;

import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentScope;
import java.lang.foreign.VaList;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
Expand All @@ -57,23 +59,23 @@ public static AixPPC64Linker getInstance() {
}

@Override
protected MethodHandle arrangeDowncall(MethodType inferredMethodType, FunctionDescriptor function) {
return CallArranger.arrangeDowncall(inferredMethodType, function);
protected MethodHandle arrangeDowncall(MethodType inferredMethodType, FunctionDescriptor function, LinkerOptions options) {
return CallArranger.arrangeDowncall(inferredMethodType, function, options);
}

@Override
protected MemorySegment arrangeUpcall(MethodHandle target, MethodType targetType, FunctionDescriptor function, MemorySession session) {
return CallArranger.arrangeUpcall(target, targetType, function, session);
protected MemorySegment arrangeUpcall(MethodHandle target, MethodType targetType, FunctionDescriptor function, SegmentScope scope) {
return CallArranger.arrangeUpcall(target, targetType, function, scope);
}

public static VaList newVaList(Consumer<VaList.Builder> actions, MemorySession session) {
AixPPC64VaList.Builder builder = AixPPC64VaList.builder(session);
public static VaList newVaList(Consumer<VaList.Builder> actions, SegmentScope scope) {
AixPPC64VaList.Builder builder = AixPPC64VaList.builder(scope);
actions.accept(builder);
return builder.build();
}

public static VaList newVaListOfAddress(MemoryAddress ma, MemorySession session) {
return AixPPC64VaList.ofAddress(ma, session);
public static VaList newVaListOfAddress(long addr, SegmentScope scope) {
return AixPPC64VaList.ofAddress(addr, scope);
}

public static VaList emptyVaList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

Expand All @@ -43,7 +43,6 @@
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.SharedUtils.SimpleVaArg;
import jdk.internal.foreign.MemorySessionImpl;
import jdk.internal.foreign.Scoped;
import static jdk.internal.foreign.PlatformLayouts.AIX;

/**
Expand All @@ -58,19 +57,18 @@
* with all supportted types of arugments, including struct (passed by value), pointer and
* primitive types, which are aligned with 8 bytes.
*/
public non-sealed class AixPPC64VaList implements VaList, Scoped {
public static final Class<?> CARRIER = MemoryAddress.class;
public non-sealed class AixPPC64VaList implements VaList {

/* Every primitive/pointer occupies 8 bytes and structs are aligned
* with 8 bytes in the total size when stacking the va_list buffer.
*/
private static final long VA_LIST_SLOT_BYTES = 8;
private static final VaList EMPTY = new SharedUtils.EmptyVaList(MemoryAddress.NULL);
private static final VaList EMPTY = new SharedUtils.EmptyVaList(MemorySegment.NULL);

private MemorySegment segment;
private final MemorySession session;
private final SegmentScope session;

private AixPPC64VaList(MemorySegment segment, MemorySession session) {
private AixPPC64VaList(MemorySegment segment, SegmentScope session) {
this.segment = segment;
this.session = session;
}
Expand All @@ -95,8 +93,8 @@ public double nextVarg(ValueLayout.OfDouble layout) {
}

@Override
public MemoryAddress nextVarg(ValueLayout.OfAddress layout) {
return (MemoryAddress)readArg(layout);
public MemorySegment nextVarg(ValueLayout.OfAddress layout) {
return (MemorySegment)readArg(layout);
}

@Override
Expand Down Expand Up @@ -167,7 +165,7 @@ private static long getSmallerStructArgSize(MemorySegment structSegment, MemoryL
@Override
public void skip(MemoryLayout... layouts) {
Objects.requireNonNull(layouts);
sessionImpl().checkValidState();
((MemorySessionImpl)session).checkValidState();

for (MemoryLayout layout : layouts) {
Objects.requireNonNull(layout);
Expand All @@ -178,42 +176,38 @@ public void skip(MemoryLayout... layouts) {
}
}

public static VaList ofAddress(MemoryAddress addr, MemorySession session) {
public static VaList ofAddress(long addr, SegmentScope session) {
MemorySegment segment = MemorySegment.ofAddress(addr, Long.MAX_VALUE, session);
return new AixPPC64VaList(segment, session);
}

@Override
public MemorySession session() {
return session;
}

@Override
public VaList copy() {
sessionImpl().checkValidState();
((MemorySessionImpl)session).checkValidState();
return new AixPPC64VaList(segment, session);
}

@Override
public MemoryAddress address() {
return segment.address();
public MemorySegment segment() {
/* The returned segment cannot be accessed. */
return segment.asSlice(0, 0);
}

@Override
public String toString() {
return "AixPPC64VaList{" + segment.address() + '}';
return "AixPPC64VaList{" + segment.asSlice(0, 0) + '}';
}

static Builder builder(MemorySession session) {
static Builder builder(SegmentScope session) {
return new Builder(session);
}

public static non-sealed class Builder implements VaList.Builder {
private final MemorySession session;
private final SegmentScope session;
private final List<SimpleVaArg> stackArgs = new ArrayList<>();

public Builder(MemorySession session) {
MemorySessionImpl.toSessionImpl(session).checkValidState();
public Builder(SegmentScope session) {
((MemorySessionImpl)session).checkValidState();
this.session = session;
}

Expand All @@ -240,8 +234,8 @@ public Builder addVarg(ValueLayout.OfDouble layout, double value) {
}

@Override
public Builder addVarg(ValueLayout.OfAddress layout, Addressable value) {
return setArg(layout, value.address());
public Builder addVarg(ValueLayout.OfAddress layout, MemorySegment value) {
return setArg(layout, value);
}

@Override
Expand All @@ -261,7 +255,7 @@ public VaList build() {
*/
long totalArgsSize = stackArgs.stream().reduce(0L,
(accum, arg) -> accum + getAlignedArgSize(arg.layout), Long::sum);
SegmentAllocator allocator = SegmentAllocator.newNativeArena(session);
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(session);
MemorySegment segment = allocator.allocate(totalArgsSize);
MemorySegment cursorSegment = segment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

Expand All @@ -36,25 +36,28 @@
import java.lang.invoke.MethodType;

import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.UpcallLinker;

import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
import java.lang.foreign.SegmentScope;

/**
* PPC64 CallArranger specialized for AIX C ABI
*/
public class CallArranger {

/* Replace DowncallLinker in OpenJDK with the implementation of DowncallLinker specific to OpenJ9 */
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc) {
MethodHandle handle = DowncallLinker.getBoundMethodHandle(mt, cDesc);
return handle;
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
// MethodHandle handle = DowncallLinker.getBoundMethodHandle(mt, cDesc, options);
// return handle;
return null;
}

/* Replace UpcallLinker in OpenJDK with the implementation of UpcallLinker specific to OpenJ9 */
public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, MemorySession session) {
return UpcallLinker.make(target, mt, cDesc, session);
public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope session) {
// return UpcallLinker.make(target, mt, cDesc, session);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

Expand All @@ -36,25 +36,28 @@
import java.lang.invoke.MethodType;

import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.UpcallLinker;

import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
import java.lang.foreign.SegmentScope;

/**
* PPC64LE CallArranger specialized for SysV C ABI
*/
public class CallArranger {

/* Replace DowncallLinker in OpenJDK with the implementation of DowncallLinker specific to OpenJ9 */
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc) {
MethodHandle handle = DowncallLinker.getBoundMethodHandle(mt, cDesc);
return handle;
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
// MethodHandle handle = DowncallLinker.getBoundMethodHandle(mt, cDesc, options);
// return handle;
return null;
}

/* Replace UpcallLinker in OpenJDK with the implementation of UpcallLinker specific to OpenJ9 */
public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, MemorySession session) {
return UpcallLinker.make(target, mt, cDesc, session);
public static MemorySegment arrangeUpcall(MethodHandle target, MethodType mt, FunctionDescriptor cDesc, SegmentScope session) {
// return UpcallLinker.make(target, mt, cDesc, session);
return null;
}
}
Loading

0 comments on commit 7fa5db1

Please sign in to comment.