Skip to content
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 @@ -62,6 +62,7 @@ protected void verify(StructuredGraph graph, CoreProviders context) {
case "jdk.graal.compiler.hotspot.aarch64.AArch64HotSpotMacroAssembler.<init>":
case "jdk.graal.compiler.hotspot.aarch64.AArch64HotSpotBackend.emitCodePrefix":
case "com.oracle.svm.core.aarch64.SubstrateAArch64MacroAssembler.<clinit>":
case "com.oracle.svm.core.graal.aarch64.SubstrateAArch64RegisterConfig.getCallingConvention":
// Exempted cases
return;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ public static AArch64Address createExtendedRegisterOffsetAddress(int bitMemoryTr
* @param bitMemoryTransferSize Memory operation size.
*/
public static AArch64Address createPCLiteralAddress(int bitMemoryTransferSize) {
return new AArch64Address(bitMemoryTransferSize, zr, zr, 0, false, null, AddressingMode.PC_LITERAL);
return createPCLiteralAddress(bitMemoryTransferSize, 0);
}

public static AArch64Address createPCLiteralAddress(int bitMemoryTransferSize, int immediate) {
return new AArch64Address(bitMemoryTransferSize, zr, zr, immediate, false, null, AddressingMode.PC_LITERAL);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,14 @@
"jdk.internal.foreign.abi.x64",
"jdk.internal.foreign.abi.x64.sysv",
"jdk.internal.foreign.abi.x64.windows",
"jdk.internal.foreign.abi.aarch64",
"jdk.internal.foreign.abi.aarch64.macos",
"jdk.internal.foreign.abi.aarch64.linux",
"jdk.internal.loader",
"jdk.internal.reflect",
],
"jdk.internal.vm.ci" : [
"jdk.vm.ci.aarch64",
"jdk.vm.ci.amd64",
"jdk.vm.ci.code",
"jdk.vm.ci.meta"
Expand Down Expand Up @@ -800,9 +804,13 @@
"jdk.internal.foreign.abi",
"jdk.internal.foreign.abi.x64.windows",
"jdk.internal.foreign.abi.x64.sysv",
"jdk.internal.foreign.abi.aarch64",
"jdk.internal.foreign.abi.aarch64.macos",
"jdk.internal.foreign.abi.aarch64.linux",
"jdk.internal.foreign.layout",
],
"jdk.internal.vm.ci" : [
"jdk.vm.ci.aarch64",
"jdk.vm.ci.code",
"jdk.vm.ci.meta",
"jdk.vm.ci.amd64",
Expand Down Expand Up @@ -2430,13 +2438,17 @@
"jdk.vm.ci.meta",
"jdk.vm.ci.code",
"jdk.vm.ci.amd64",
"jdk.vm.ci.aarch64",
],
"java.base": [
"jdk.internal.foreign",
"jdk.internal.foreign.abi",
"jdk.internal.foreign.abi.x64",
"jdk.internal.foreign.abi.x64.sysv",
"jdk.internal.foreign.abi.x64.windows",
"jdk.internal.foreign.abi.aarch64",
"jdk.internal.foreign.abi.aarch64.macos",
"jdk.internal.foreign.abi.aarch64.linux",
],
},
},
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public static SymbolLookup makeSystemLookup() {
}

return lookup;
} else if (OS.DARWIN.isCurrent()) {
return Util_java_lang_foreign_SymbolLookup.libraryLookup(LookupNativeLibraries::loadLibraryPlatformSpecific, List.of("/usr/lib/libSystem.B.dylib"));
} else {
/*
* This list of libraries was obtained by examining the dependencies of libsystemlookup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import jdk.internal.foreign.abi.AbstractLinker;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.aarch64.linux.LinuxAArch64Linker;
import jdk.internal.foreign.abi.aarch64.macos.MacOsAArch64Linker;
import jdk.internal.foreign.abi.x64.sysv.SysVx64Linker;
import jdk.internal.foreign.abi.x64.windows.Windowsx64Linker;

Expand Down Expand Up @@ -108,7 +110,20 @@ UpcallStubFactory arrangeUpcall(MethodType targetType, FunctionDescriptor functi
}
}

/*
* GR-58659, GR-58660: add substitutions for LinuxAArch64Linker and MacOsAArch64Linker here once we
* support them.
*/
@TargetClass(value = MacOsAArch64Linker.class, onlyWith = ForeignFunctionsEnabled.class)
final class Target_jdk_internal_foreign_abi_aarch64_macos_MacOsAArch64Linker {

@Substitute
UpcallStubFactory arrangeUpcall(MethodType targetType, FunctionDescriptor function, LinkerOptions options) {
return new UpcallStubFactoryDecorator(jdk.internal.foreign.abi.aarch64.CallArranger.MACOS.arrangeUpcall(targetType, function, options));
}
}

@TargetClass(value = LinuxAArch64Linker.class, onlyWith = ForeignFunctionsEnabled.class)
final class Target_jdk_internal_foreign_abi_aarch64_linux_LinuxAArch64Linker {

@Substitute
UpcallStubFactory arrangeUpcall(MethodType targetType, FunctionDescriptor function, LinkerOptions options) {
return new UpcallStubFactoryDecorator(jdk.internal.foreign.abi.aarch64.CallArranger.LINUX.arrangeUpcall(targetType, function, options));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static com.oracle.svm.core.graal.code.SubstrateBackend.SubstrateMarkId.PROLOGUE_DECD_RSP;
import static com.oracle.svm.core.graal.code.SubstrateBackend.SubstrateMarkId.PROLOGUE_END;
import static com.oracle.svm.core.util.VMError.shouldNotReachHere;
import static com.oracle.svm.core.util.VMError.unsupportedFeature;
import static jdk.graal.compiler.core.common.GraalOptions.ZapStackOnMethodEntry;
import static jdk.graal.compiler.lir.LIRInstruction.OperandFlag.REG;
import static jdk.graal.compiler.lir.LIRValueUtil.asConstantValue;
Expand All @@ -36,18 +37,20 @@
import static jdk.vm.ci.aarch64.AArch64.sp;
import static jdk.vm.ci.code.ValueUtil.asRegister;

import java.util.Arrays;
import java.util.Collection;
import java.util.function.BiConsumer;

import com.oracle.svm.core.interpreter.InterpreterSupport;
import com.oracle.svm.core.aarch64.SubstrateAArch64MacroAssembler;
import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.ReservedRegisters;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.aarch64.SubstrateAArch64MacroAssembler;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.deopt.Deoptimizer;
import com.oracle.svm.core.graal.code.AssignedLocation;
import com.oracle.svm.core.graal.code.PatchConsumerFactory;
import com.oracle.svm.core.graal.code.SubstrateBackend;
import com.oracle.svm.core.graal.code.SubstrateCallingConvention;
Expand All @@ -68,6 +71,7 @@
import com.oracle.svm.core.heap.ReferenceAccess;
import com.oracle.svm.core.heap.SubstrateReferenceMapBuilder;
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
import com.oracle.svm.core.interpreter.InterpreterSupport;
import com.oracle.svm.core.meta.CompressedNullConstant;
import com.oracle.svm.core.meta.SharedField;
import com.oracle.svm.core.meta.SharedMethod;
Expand Down Expand Up @@ -243,16 +247,19 @@ public static class SubstrateAArch64IndirectCallOp extends AArch64Call.IndirectC
@Temp({REG}) private Value linkReg;
private final BiConsumer<CompilationResultBuilder, Integer> offsetRecorder;

@Def({REG}) private Value[] multipleResults;

public SubstrateAArch64IndirectCallOp(ResolvedJavaMethod callTarget, Value result, Value[] parameters, Value[] temps, Value targetAddress,
LIRFrameState state, Value javaFrameAnchor, int newThreadStatus, boolean destroysCallerSavedRegisters, Value exceptionTemp,
BiConsumer<CompilationResultBuilder, Integer> offsetRecorder) {
BiConsumer<CompilationResultBuilder, Integer> offsetRecorder, Value[] multipleResults) {
super(TYPE, callTarget, result, parameters, temps, targetAddress, state);
this.javaFrameAnchor = javaFrameAnchor;
this.newThreadStatus = newThreadStatus;
this.destroysCallerSavedRegisters = destroysCallerSavedRegisters;
this.exceptionTemp = exceptionTemp;
this.linkReg = lr.asValue(LIRKind.value(AArch64Kind.QWORD));
this.offsetRecorder = offsetRecorder;
this.multipleResults = multipleResults;
}

@Override
Expand Down Expand Up @@ -561,8 +568,9 @@ protected void emitForeignCallOp(ForeignCallLinkage linkage, Value targetAddress
if (shouldEmitOnlyIndirectCalls()) {
RegisterValue targetRegister = AArch64.lr.asValue(FrameAccess.getWordStamp().getLIRKind(getLIRKindTool()));
emitMove(targetRegister, targetAddress);
Value[] multipleResults = new Value[0];
append(new SubstrateAArch64IndirectCallOp(targetMethod, result, arguments, temps, targetRegister, info, Value.ILLEGAL, StatusSupport.STATUS_ILLEGAL,
getDestroysCallerSavedRegisters(targetMethod), exceptionTemp, null));
getDestroysCallerSavedRegisters(targetMethod), exceptionTemp, null, multipleResults));
} else {
assert targetAddress == null;
append(new SubstrateAArch64DirectCallOp(targetMethod, result, arguments, temps, info, Value.ILLEGAL, StatusSupport.STATUS_ILLEGAL,
Expand Down Expand Up @@ -714,6 +722,25 @@ protected DebugInfoBuilder createDebugInfoBuilder(StructuredGraph graph, NodeVal
return new SubstrateDebugInfoBuilder(graph, gen.getProviders().getMetaAccessExtensionProvider(), nodeValueMap);
}

@Override
public Value[] visitInvokeArguments(CallingConvention invokeCc, Collection<ValueNode> arguments) {
Value[] values = super.visitInvokeArguments(invokeCc, arguments);
SubstrateCallingConventionType type = (SubstrateCallingConventionType) ((SubstrateCallingConvention) invokeCc).getType();

if (type.usesReturnBuffer()) {
/*
* We save the return buffer so that it can be accessed after the call.
*/
assert values.length > 0;
Value returnBuffer = values[0];
Variable saved = gen.newVariable(returnBuffer.getValueKind());
gen.append(gen.getSpillMoveFactory().createMove(saved, returnBuffer));
values[0] = saved;
}

return values;
}

private boolean getDestroysCallerSavedRegisters(ResolvedJavaMethod targetMethod) {
return ((SubstrateAArch64LIRGenerator) gen).getDestroysCallerSavedRegisters(targetMethod);
}
Expand Down Expand Up @@ -761,14 +788,44 @@ public BiConsumer<CompilationResultBuilder, Integer> getOffsetRecorder(@Suppress
return null;
}

private static AllocatableValue asReturnedValue(AssignedLocation assignedLocation) {
assert assignedLocation.assignsToRegister();
Register.RegisterCategory category = assignedLocation.register().getRegisterCategory();
LIRKind kind;
if (category.equals(AArch64.CPU)) {
kind = LIRKind.value(AArch64Kind.QWORD);
} else if (category.equals(AArch64.SIMD)) {
kind = LIRKind.value(AArch64Kind.V128_QWORD);
} else {
throw unsupportedFeature("Register category " + category + " should not be used for returns spanning multiple registers.");
}
return assignedLocation.register().asValue(kind);
}

@Override
protected void emitInvoke(LoweredCallTargetNode callTarget, Value[] parameters, LIRFrameState callState, Value result) {
var cc = (SubstrateCallingConventionType) callTarget.callType();
verifyCallTarget(callTarget);
if (callTarget instanceof ComputedIndirectCallTargetNode) {
assert !cc.customABI();
emitComputedIndirectCall((ComputedIndirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
} else {
super.emitInvoke(callTarget, parameters, callState, result);
}
if (cc.usesReturnBuffer()) {
/*
* The buffer argument was saved in visitInvokeArguments, so that the value was not
* killed by the call.
*/
Value returnBuffer = parameters[0];
long offset = 0;
for (AssignedLocation ret : cc.returnSaving) {
Value saveLocation = gen.getArithmetic().emitAdd(returnBuffer, gen.emitJavaConstant(JavaConstant.forLong(offset)), false);
AllocatableValue returnedValue = asReturnedValue(ret);
gen.getArithmetic().emitStore(returnedValue.getValueKind(), saveLocation, returnedValue, callState, MemoryOrderMode.PLAIN);
offset += returnedValue.getPlatformKind().getSizeInBytes();
}
}
}

@Override
Expand All @@ -785,8 +842,17 @@ protected void emitIndirectCall(IndirectCallTargetNode callTarget, Value result,
AllocatableValue targetAddress = targetRegister.asValue(FrameAccess.getWordStamp().getLIRKind(getLIRGeneratorTool().getLIRKindTool()));
gen.emitMove(targetAddress, operand(callTarget.computedAddress()));
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
SubstrateCallingConventionType cc = (SubstrateCallingConventionType) callTarget.callType();

Value[] multipleResults = new Value[0];
if (cc.customABI() && cc.usesReturnBuffer()) {
multipleResults = Arrays.stream(cc.returnSaving)
.map(SubstrateAArch64NodeLIRBuilder::asReturnedValue)
.toList().toArray(new Value[0]);
}

append(new SubstrateAArch64IndirectCallOp(targetMethod, result, parameters, temps, targetAddress, callState, setupJavaFrameAnchor(callTarget),
getNewThreadStatus(callTarget), getDestroysCallerSavedRegisters(targetMethod), getExceptionTemp(callTarget), getOffsetRecorder(callTarget)));
getNewThreadStatus(callTarget), getDestroysCallerSavedRegisters(targetMethod), getExceptionTemp(callTarget), getOffsetRecorder(callTarget), multipleResults));
}

protected void emitComputedIndirectCall(ComputedIndirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) {
Expand Down Expand Up @@ -1380,7 +1446,9 @@ protected void resetForEmittingCode(CompilationResultBuilder crb) {
@Override
public LIRGenerationResult newLIRGenerationResult(CompilationIdentifier compilationId, LIR lir, RegisterAllocationConfig registerAllocationConfig, StructuredGraph graph, Object stub) {
SharedMethod method = (SharedMethod) graph.method();
CallingConvention callingConvention = CodeUtil.getCallingConvention(getCodeCache(), method.getCallingConventionKind().toType(false), method, this);
SubstrateCallingConventionKind ccKind = method.getCallingConventionKind();
SubstrateCallingConventionType ccType = ccKind.isCustom() ? method.getCustomCallingConventionType() : ccKind.toType(false);
CallingConvention callingConvention = CodeUtil.getCallingConvention(getCodeCache(), ccType, method, this);
LIRGenerationResult lirGenerationResult = new SubstrateLIRGenerationResult(compilationId, lir, newFrameMapBuilder(registerAllocationConfig.getRegisterConfig()), registerAllocationConfig,
callingConvention, method);

Expand Down
Loading
Loading