Search in sources :

Example 1 with ForeignCallNode

use of org.graalvm.compiler.nodes.extended.ForeignCallNode in project graal by oracle.

the class StubAVXTest method editGraphBuilderConfiguration.

@Override
protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) {
    InvocationPlugins invocationPlugins = conf.getPlugins().getInvocationPlugins();
    InvocationPlugins.Registration r = new InvocationPlugins.Registration(invocationPlugins, TestStub.class);
    r.register0("testStub", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, InvocationPlugin.Receiver receiver) {
            b.add(new ForeignCallNode(getProviders().getForeignCalls(), TEST_STUB));
            return true;
        }
    });
    return super.editGraphBuilderConfiguration(conf);
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with ForeignCallNode

use of org.graalvm.compiler.nodes.extended.ForeignCallNode in project graal by oracle.

the class ArrayCopyCallNode method lower.

@Override
public void lower(LoweringTool tool) {
    if (graph().getGuardsStage().areFrameStatesAtDeopts()) {
        updateAlignedDisjoint();
        ForeignCallDescriptor desc = HotSpotHostForeignCallsProvider.lookupArraycopyDescriptor(elementKind, isAligned(), isDisjoint(), isUninitialized(), locationIdentity.equals(LocationIdentity.any()));
        StructuredGraph graph = graph();
        ValueNode srcAddr = computeBase(getSource(), getSourcePosition());
        ValueNode destAddr = computeBase(getDestination(), getDestinationPosition());
        ValueNode len = getLength();
        if (len.stamp(NodeView.DEFAULT).getStackKind() != JavaKind.Long) {
            len = IntegerConvertNode.convert(len, StampFactory.forKind(JavaKind.Long), graph(), NodeView.DEFAULT);
        }
        ForeignCallNode call = graph.add(new ForeignCallNode(runtime.getHostBackend().getForeignCalls(), desc, srcAddr, destAddr, len));
        call.setStateAfter(stateAfter());
        graph.replaceFixedWithFixed(this, call);
    }
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 3 with ForeignCallNode

use of org.graalvm.compiler.nodes.extended.ForeignCallNode in project graal by oracle.

the class CheckcastArrayCopyCallNode method lower.

@Override
public void lower(LoweringTool tool) {
    if (graph().getGuardsStage().areFrameStatesAtDeopts()) {
        ForeignCallDescriptor desc = HotSpotHostForeignCallsProvider.lookupCheckcastArraycopyDescriptor(isUninit());
        StructuredGraph graph = graph();
        ValueNode srcAddr = computeBase(getSource(), getSourcePosition());
        ValueNode destAddr = computeBase(getDestination(), getDestinationPosition());
        ValueNode len = getLength();
        if (len.stamp(NodeView.DEFAULT).getStackKind() != runtime.getTarget().wordJavaKind) {
            len = IntegerConvertNode.convert(len, StampFactory.forKind(runtime.getTarget().wordJavaKind), graph(), NodeView.DEFAULT);
        }
        ForeignCallNode call = graph.add(new ForeignCallNode(runtime.getHostBackend().getForeignCalls(), desc, srcAddr, destAddr, len, superCheckOffset, destElemKlass));
        call.setStateAfter(stateAfter());
        graph.replaceFixedWithFixed(this, call);
    }
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 4 with ForeignCallNode

use of org.graalvm.compiler.nodes.extended.ForeignCallNode in project graal by oracle.

the class DefaultHotSpotLoweringProvider method lowerBytecodeExceptionNode.

private void lowerBytecodeExceptionNode(BytecodeExceptionNode node) {
    if (OmitHotExceptionStacktrace.getValue(node.getOptions())) {
        if (throwCachedException(node)) {
            return;
        }
    }
    ForeignCallDescriptor descriptor;
    if (node.getExceptionClass() == NullPointerException.class) {
        descriptor = RuntimeCalls.CREATE_NULL_POINTER_EXCEPTION;
    } else if (node.getExceptionClass() == ArrayIndexOutOfBoundsException.class) {
        descriptor = RuntimeCalls.CREATE_OUT_OF_BOUNDS_EXCEPTION;
    } else if (node.getExceptionClass() == ArrayStoreException.class) {
        descriptor = RuntimeCalls.CREATE_ARRAY_STORE_EXCEPTION;
    } else if (node.getExceptionClass() == ClassCastException.class) {
        descriptor = RuntimeCalls.CREATE_CLASS_CAST_EXCEPTION;
    } else {
        throw GraalError.shouldNotReachHere();
    }
    StructuredGraph graph = node.graph();
    ForeignCallNode foreignCallNode = graph.add(new ForeignCallNode(foreignCalls, descriptor, node.stamp(NodeView.DEFAULT), node.getArguments()));
    graph.replaceFixedWithFixed(node, foreignCallNode);
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Example 5 with ForeignCallNode

use of org.graalvm.compiler.nodes.extended.ForeignCallNode in project graal by oracle.

the class DefaultHotSpotLoweringProvider method lowerOSRStartNode.

private void lowerOSRStartNode(OSRStartNode osrStart) {
    StructuredGraph graph = osrStart.graph();
    if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
        StartNode newStart = graph.add(new StartNode());
        ParameterNode buffer = graph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(StampFactory.forKind(runtime.getTarget().wordJavaKind))));
        ForeignCallNode migrationEnd = graph.add(new ForeignCallNode(foreignCalls, OSR_MIGRATION_END, buffer));
        migrationEnd.setStateAfter(osrStart.stateAfter());
        newStart.setNext(migrationEnd);
        FixedNode next = osrStart.next();
        osrStart.setNext(null);
        migrationEnd.setNext(next);
        graph.setStart(newStart);
        final int wordSize = target.wordSize;
        // @formatter:off
        // taken from c2 locals_addr = osr_buf + (max_locals-1)*wordSize)
        // @formatter:on
        int localsOffset = (graph.method().getMaxLocals() - 1) * wordSize;
        for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.TYPE)) {
            int size = osrLocal.getStackKind().getSlotCount();
            int offset = localsOffset - (osrLocal.index() + size - 1) * wordSize;
            AddressNode address = createOffsetAddress(graph, buffer, offset);
            ReadNode load = graph.add(new ReadNode(address, any(), osrLocal.stamp(NodeView.DEFAULT), BarrierType.NONE));
            osrLocal.replaceAndDelete(load);
            graph.addBeforeFixed(migrationEnd, load);
        }
        // @formatter:off
        // taken from c2 monitors_addr = osr_buf + (max_locals+mcnt*2-1)*wordSize);
        // @formatter:on
        final int lockCount = osrStart.stateAfter().locksSize();
        final int locksOffset = (graph.method().getMaxLocals() + lockCount * 2 - 1) * wordSize;
        // buffer
        for (OSRMonitorEnterNode osrMonitorEnter : graph.getNodes(OSRMonitorEnterNode.TYPE)) {
            MonitorIdNode monitorID = osrMonitorEnter.getMonitorId();
            OSRLockNode lock = (OSRLockNode) osrMonitorEnter.object();
            final int index = lock.index();
            final int offsetDisplacedHeader = locksOffset - ((index * 2) + 1) * wordSize;
            final int offsetLockObject = locksOffset - index * 2 * wordSize;
            // load the displaced mark from the osr buffer
            AddressNode addressDisplacedHeader = createOffsetAddress(graph, buffer, offsetDisplacedHeader);
            ReadNode loadDisplacedHeader = graph.add(new ReadNode(addressDisplacedHeader, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
            graph.addBeforeFixed(migrationEnd, loadDisplacedHeader);
            // we need to initialize the stack slot for the lock
            BeginLockScopeNode beginLockScope = graph.add(new BeginLockScopeNode(lock.getStackKind(), monitorID.getLockDepth()));
            graph.addBeforeFixed(migrationEnd, beginLockScope);
            // write the displaced mark to the correct stack slot
            AddressNode addressDisplacedMark = createOffsetAddress(graph, beginLockScope, runtime.getVMConfig().basicLockDisplacedHeaderOffset);
            WriteNode writeStackSlot = graph.add(new WriteNode(addressDisplacedMark, DISPLACED_MARK_WORD_LOCATION, loadDisplacedHeader, BarrierType.NONE));
            graph.addBeforeFixed(migrationEnd, writeStackSlot);
            // load the lock object from the osr buffer
            AddressNode addressLockObject = createOffsetAddress(graph, buffer, offsetLockObject);
            ReadNode loadObject = graph.add(new ReadNode(addressLockObject, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
            lock.replaceAndDelete(loadObject);
            graph.addBeforeFixed(migrationEnd, loadObject);
        }
        osrStart.replaceAtUsagesAndDelete(newStart);
    }
}
Also used : MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) OSRStartNode(org.graalvm.compiler.nodes.extended.OSRStartNode) StartNode(org.graalvm.compiler.nodes.StartNode) OSRLocalNode(org.graalvm.compiler.nodes.extended.OSRLocalNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) OSRLockNode(org.graalvm.compiler.nodes.extended.OSRLockNode) OSRMonitorEnterNode(org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) BeginLockScopeNode(org.graalvm.compiler.hotspot.nodes.BeginLockScopeNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode) ComputeObjectAddressNode(org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode)

Aggregations

ForeignCallNode (org.graalvm.compiler.nodes.extended.ForeignCallNode)18 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)7 ForeignCallDescriptor (org.graalvm.compiler.core.common.spi.ForeignCallDescriptor)5 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)4 Node (org.graalvm.compiler.graph.Node)3 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)3 StartNode (org.graalvm.compiler.nodes.StartNode)3 Snippet (org.graalvm.compiler.api.replacements.Snippet)2 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)2 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)2 BeginNode (org.graalvm.compiler.nodes.BeginNode)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 EndNode (org.graalvm.compiler.nodes.EndNode)2 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)2