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 @@ -45,6 +45,7 @@
import java.util.function.BiConsumer;

import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.Pair;
import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.CPUFeatureAccess;
Expand All @@ -54,7 +55,6 @@
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.amd64.AMD64CPUFeatureAccess;
import com.oracle.svm.core.code.BaseLayerMethodAccessor;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.cpufeature.Stubs;
import com.oracle.svm.core.deopt.Deoptimizer;
Expand Down Expand Up @@ -84,6 +84,7 @@
import com.oracle.svm.core.graal.nodes.ComputedIndirectCallTargetNode.FieldLoadIfZero;
import com.oracle.svm.core.heap.ReferenceAccess;
import com.oracle.svm.core.heap.SubstrateReferenceMapBuilder;
import com.oracle.svm.core.imagelayer.DynamicImageLayerInfo;
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 @@ -673,14 +674,14 @@ protected Value emitIndirectForeignCallAddress(ForeignCallLinkage linkage) {
SharedMethod targetMethod = (SharedMethod) callTarget.getMethod();
if (SubstrateUtil.HOSTED && targetMethod.forceIndirectCall()) {
/*
* Load the absolute address of the target method from the method entry stored in
* the data section.
* Load the address for the start of the text section and then add in the offset for
* this specific method.
*/
CGlobalDataInfo methodDataInfo = BaseLayerMethodAccessor.singleton().getMethodData(targetMethod);
AllocatableValue methodPointerAddress = newVariable(getLIRKindTool().getWordKind());
append(new AMD64CGlobalDataLoadAddressOp(methodDataInfo, methodPointerAddress));
AMD64AddressValue methodTableEntryAddress = new AMD64AddressValue(getLIRKindTool().getWordKind(), methodPointerAddress, Value.ILLEGAL, Stride.S1, 0);
return getArithmetic().emitLoad(getLIRKindTool().getWordKind(), methodTableEntryAddress, null, MemoryOrderMode.PLAIN, MemoryExtendKind.DEFAULT);
Pair<CGlobalDataInfo, Integer> methodLocation = DynamicImageLayerInfo.singleton().getPriorLayerMethodLocation(targetMethod);
AllocatableValue basePointerAddress = newVariable(getLIRKindTool().getWordKind());
append(new AMD64CGlobalDataLoadAddressOp(methodLocation.getLeft(), basePointerAddress));
Value codeOffsetInSection = emitConstant(getLIRKindTool().getWordKind(), JavaConstant.forLong(methodLocation.getRight()));
return getArithmetic().emitAdd(basePointerAddress, codeOffsetInSection, false);
}
if (!shouldEmitOnlyIndirectCalls()) {
return null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
import java.util.Map;
import java.util.function.Predicate;

import org.graalvm.collections.Pair;
import org.graalvm.word.LocationIdentity;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateUtil;
import com.oracle.svm.core.c.BoxedRelocatedPointer;
import com.oracle.svm.core.code.BaseLayerMethodAccessor;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
import com.oracle.svm.core.graal.code.SubstrateBackend;
Expand All @@ -49,6 +49,7 @@
import com.oracle.svm.core.graal.nodes.LoadOpenTypeWorldDispatchTableStartingOffset;
import com.oracle.svm.core.graal.nodes.LoweredDeadEndNode;
import com.oracle.svm.core.graal.nodes.ThrowBytecodeExceptionNode;
import com.oracle.svm.core.imagelayer.DynamicImageLayerInfo;
import com.oracle.svm.core.meta.SharedMethod;
import com.oracle.svm.core.meta.SubstrateObjectConstant;
import com.oracle.svm.core.snippets.ImplicitExceptions;
Expand Down Expand Up @@ -369,7 +370,7 @@ public void lower(FixedNode node, LoweringTool tool) {
SharedMethod targetMethod = method;
if (!invokeKind.isDirect()) {
/*
* We only have one possible implementation for a indirect call, so we can
* We only have one possible implementation for an indirect call, so we can
* emit a direct call to the unique implementation.
*/
targetMethod = implementations[0];
Expand All @@ -378,19 +379,14 @@ public void lower(FixedNode node, LoweringTool tool) {
if (SubstrateUtil.HOSTED && targetMethod.forceIndirectCall()) {
/*
* Lower cross layer boundary direct calls to indirect calls. First load the
* target method absolute address from the method entry stored in the data
* section. Then call that address indirectly.
* address offset of the text section start and then add in the offset for
* this specific method.
*/
CGlobalDataInfo methodDataInfo = BaseLayerMethodAccessor.singleton().getMethodData(targetMethod);
AddressNode methodPointerAddress = graph.addOrUniqueWithInputs(OffsetAddressNode.create(new CGlobalDataLoadAddressNode(methodDataInfo)));

/*
* Use the ANY location identity to prevent ReadNode.canonicalizeRead() to
* try to constant fold the method address.
*/
ReadNode entry = graph.add(new ReadNode(methodPointerAddress, LocationIdentity.any(), FrameAccess.getWordStamp(), BarrierType.NONE, MemoryOrderMode.PLAIN));
loweredCallTarget = createIndirectCall(graph, callTarget, parameters, method, signature, callType, invokeKind, entry);
graph.addBeforeFixed(node, entry);
Pair<CGlobalDataInfo, Integer> methodLocation = DynamicImageLayerInfo.singleton().getPriorLayerMethodLocation(targetMethod);
AddressNode methodPointerAddress = graph.addOrUniqueWithInputs(
new OffsetAddressNode(new CGlobalDataLoadAddressNode(methodLocation.getLeft()),
ConstantNode.forIntegerKind(ConfigurationValues.getWordKind(), methodLocation.getRight())));
loweredCallTarget = createIndirectCall(graph, callTarget, parameters, method, signature, callType, invokeKind, methodPointerAddress);
} else if (!SubstrateBackend.shouldEmitOnlyIndirectCalls()) {
loweredCallTarget = createDirectCall(graph, callTarget, parameters, signature, callType, invokeKind, targetMethod, node);
} else if (!targetMethod.hasImageCodeOffset()) {
Expand Down Expand Up @@ -494,7 +490,7 @@ protected LoweredCallTargetNode createDirectCall(StructuredGraph graph, MethodCa
}

protected IndirectCallTargetNode createIndirectCall(StructuredGraph graph, MethodCallTargetNode callTarget, NodeInputList<ValueNode> parameters, SharedMethod method, JavaType[] signature,
CallingConvention.Type callType, InvokeKind invokeKind, ReadNode entry) {
CallingConvention.Type callType, InvokeKind invokeKind, ValueNode entry) {
return graph.add(new IndirectCallTargetNode(entry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, method, callType, invokeKind));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,18 @@
*/
package com.oracle.svm.core.imagelayer;

import java.util.EnumSet;

import org.graalvm.collections.Pair;
import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.ImageSingletonLoader;
import com.oracle.svm.core.layeredimagesingleton.ImageSingletonWriter;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingleton;
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonBuilderFlags;
import com.oracle.svm.core.graal.code.CGlobalDataInfo;
import com.oracle.svm.core.meta.SharedMethod;

@AutomaticallyRegisteredImageSingleton(onlyWith = BuildingImageLayerPredicate.class)
public class DynamicImageLayerInfo implements LayeredImageSingleton {
public abstract class DynamicImageLayerInfo {
public final int layerNumber;
public final int nextLayerNumber;
public final int numLayers;

public DynamicImageLayerInfo() {
this(0);
}

private DynamicImageLayerInfo(int layerNumber) {
protected DynamicImageLayerInfo(int layerNumber) {
this.layerNumber = layerNumber;
this.nextLayerNumber = layerNumber + 1;
this.numLayers = nextLayerNumber;
Expand All @@ -54,19 +45,8 @@ public static DynamicImageLayerInfo singleton() {
return ImageSingletons.lookup(DynamicImageLayerInfo.class);
}

@Override
public EnumSet<LayeredImageSingletonBuilderFlags> getImageBuilderFlags() {
return LayeredImageSingletonBuilderFlags.BUILDTIME_ACCESS_ONLY;
}

@Override
public PersistFlags preparePersist(ImageSingletonWriter writer) {
writer.writeInt("nextLayerNumber", nextLayerNumber);
return PersistFlags.CREATE;
}

@SuppressWarnings("unused")
public static Object createFromLoader(ImageSingletonLoader loader) {
return new DynamicImageLayerInfo(loader.readInt("nextLayerNumber"));
}
/**
* Returns a (Base, Offset) pair which can be used to call a method defined in a prior layer.
*/
public abstract Pair<CGlobalDataInfo, Integer> getPriorLayerMethodLocation(SharedMethod method);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface ImageSingletonLoader {
int readInt(String keyName);

List<Integer> readIntList(String keyName);

String readString(String keyName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface ImageSingletonWriter {
void writeInt(String keyName, int value);

void writeIntList(String keyName, List<Integer> value);

void writeString(String keyName, String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,15 @@ public int readInt(String keyName) {
public List<Integer> readIntList(String keyName) {
List<Object> value = cast(keyStore.get(keyName));
String type = cast(value.get(0));
assert type.equals("I[]") : type;
assert type.equals("I(") : type;
return cast(value.get(1));
}

@Override
public String readString(String keyName) {
List<Object> value = cast(keyStore.get(keyName));
String type = cast(value.get(0));
assert type.equals("S") : type;
return cast(value.get(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ public void writeInt(String keyName, int value) {

@Override
public void writeIntList(String keyName, List<Integer> value) {
keyValueStore.put(keyName, List.of("I[]", value));
keyValueStore.put(keyName, List.of("I(", value));
}

@Override
public void writeString(String keyName, String value) {
keyValueStore.put(keyName, List.of("S", value));
}
}

This file was deleted.

Loading