Search in sources :

Example 11 with StructuredGraph

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

the class InlineableGraph method parseBytecodes.

/**
 * This method builds the IR nodes for the given <code>method</code> and canonicalizes them.
 * Provided profiling info is mature, the resulting graph is cached. The caller is responsible
 * for cloning before modification.
 * </p>
 */
@SuppressWarnings("try")
private static StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer, StructuredGraph caller, boolean trackNodeSourcePosition) {
    DebugContext debug = caller.getDebug();
    StructuredGraph newGraph = new StructuredGraph.Builder(caller.getOptions(), debug, AllowAssumptions.ifNonNull(caller.getAssumptions())).method(method).trackNodeSourcePosition(trackNodeSourcePosition).build();
    try (DebugContext.Scope s = debug.scope("InlineGraph", newGraph)) {
        if (!caller.isUnsafeAccessTrackingEnabled()) {
            newGraph.disableUnsafeAccessTracking();
        }
        if (context.getGraphBuilderSuite() != null) {
            context.getGraphBuilderSuite().apply(newGraph, context);
        }
        assert newGraph.start().next() != null : "graph needs to be populated by the GraphBuilderSuite " + method + ", " + method.canBeInlined();
        new DeadCodeEliminationPhase(Optional).apply(newGraph);
        canonicalizer.apply(newGraph, context);
        return newGraph;
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugContext(org.graalvm.compiler.debug.DebugContext) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Example 12 with StructuredGraph

use of org.graalvm.compiler.nodes.StructuredGraph 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 13 with StructuredGraph

use of org.graalvm.compiler.nodes.StructuredGraph 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)

Example 14 with StructuredGraph

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

the class HotSpotGraalCompiler method compile.

public CompilationResult compile(ResolvedJavaMethod method, int entryBCI, boolean useProfilingInfo, CompilationIdentifier compilationId, OptionValues options, DebugContext debug) {
    StructuredGraph graph = createGraph(method, entryBCI, useProfilingInfo, compilationId, options, debug);
    CompilationResult result = new CompilationResult(compilationId);
    return compileHelper(CompilationResultBuilderFactory.Default, result, graph, method, entryBCI, useProfilingInfo, options);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 15 with StructuredGraph

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

the class HotSpotGraalCompiler method createGraph.

public StructuredGraph createGraph(ResolvedJavaMethod method, int entryBCI, boolean useProfilingInfo, CompilationIdentifier compilationId, OptionValues options, DebugContext debug) {
    HotSpotBackend backend = graalRuntime.getHostBackend();
    HotSpotProviders providers = backend.getProviders();
    final boolean isOSR = entryBCI != JVMCICompiler.INVOCATION_ENTRY_BCI;
    StructuredGraph graph = method.isNative() || isOSR ? null : getIntrinsicGraph(method, providers, compilationId, options, debug);
    if (graph == null) {
        SpeculationLog speculationLog = method.getSpeculationLog();
        if (speculationLog != null) {
            speculationLog.collectFailedSpeculations();
        }
        graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.ifTrue(OptAssumptions.getValue(options))).method(method).entryBCI(entryBCI).speculationLog(speculationLog).useProfilingInfo(useProfilingInfo).compilationId(compilationId).build();
    }
    return graph;
}
Also used : SpeculationLog(jdk.vm.ci.meta.SpeculationLog) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HotSpotProviders(org.graalvm.compiler.hotspot.meta.HotSpotProviders)

Aggregations

StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)360 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)97 Test (org.junit.Test)96 DebugContext (org.graalvm.compiler.debug.DebugContext)88 ValueNode (org.graalvm.compiler.nodes.ValueNode)70 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)62 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)62 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)57 Node (org.graalvm.compiler.graph.Node)39 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)37 OptionValues (org.graalvm.compiler.options.OptionValues)34 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)28 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)26 FixedNode (org.graalvm.compiler.nodes.FixedNode)26 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)25 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)24 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)24 LogicNode (org.graalvm.compiler.nodes.LogicNode)21 CompilationResult (org.graalvm.compiler.code.CompilationResult)19 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)19