Search in sources :

Example 91 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class GraalOSRTestBase method getBackedgeBCI.

/**
 * Returns the target BCI of the first bytecode backedge. This is where HotSpot triggers
 * on-stack-replacement in case the backedge counter overflows.
 */
private static int getBackedgeBCI(DebugContext debug, ResolvedJavaMethod method) {
    Bytecode code = new ResolvedJavaMethodBytecode(method);
    BytecodeStream stream = new BytecodeStream(code.getCode());
    OptionValues options = debug.getOptions();
    BciBlockMapping bciBlockMapping = BciBlockMapping.create(stream, code, options, debug);
    for (BciBlock block : bciBlockMapping.getBlocks()) {
        if (block.startBci != -1) {
            int bci = block.startBci;
            for (BciBlock succ : block.getSuccessors()) {
                if (succ.startBci != -1) {
                    int succBci = succ.startBci;
                    if (succBci < bci) {
                        // back edge
                        return succBci;
                    }
                }
            }
        }
    }
    TTY.println("Cannot find loop back edge with bytecode loops at:%s", Arrays.toString(bciBlockMapping.getLoopHeaders()));
    TTY.println(new BytecodeDisassembler().disassemble(code));
    return -1;
}
Also used : BytecodeDisassembler(org.graalvm.compiler.bytecode.BytecodeDisassembler) OptionValues(org.graalvm.compiler.options.OptionValues) BciBlockMapping(org.graalvm.compiler.java.BciBlockMapping) BytecodeStream(org.graalvm.compiler.bytecode.BytecodeStream) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock)

Example 92 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class GraalOSRTestBase method compileOSR.

private void compileOSR(OptionValues options, ResolvedJavaMethod method) {
    OptionValues goptions = options;
    // are expected for some OSR tests.
    if (!GraalCompilerOptions.CompilationBailoutAction.hasBeenSet(options)) {
        goptions = new OptionValues(options, GraalCompilerOptions.CompilationBailoutAction, ExceptionAction.Silent);
    }
    // ensure eager resolving
    StructuredGraph graph = parseEager(method, AllowAssumptions.YES, goptions);
    DebugContext debug = graph.getDebug();
    int bci = getBackedgeBCI(debug, method);
    assert bci != -1;
    compile(debug, method, bci);
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 93 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class AMD64HotSpotBackend method newCompilationResultBuilder.

@Override
public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenRen, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory) {
    // Omit the frame if the method:
    // - has no spill slots or other slots allocated during register allocation
    // - has no callee-saved registers
    // - has no incoming arguments passed on the stack
    // - has no deoptimization points
    // - makes no foreign calls (which require an aligned stack)
    HotSpotLIRGenerationResult gen = (HotSpotLIRGenerationResult) lirGenRen;
    LIR lir = gen.getLIR();
    assert gen.getDeoptimizationRescueSlot() == null || frameMap.frameNeedsAllocating() : "method that can deoptimize must have a frame";
    OptionValues options = lir.getOptions();
    DebugContext debug = lir.getDebug();
    boolean omitFrame = CanOmitFrame.getValue(options) && !frameMap.frameNeedsAllocating() && !lir.hasArgInCallerFrame() && !gen.hasForeignCall();
    Stub stub = gen.getStub();
    Assembler masm = createAssembler(frameMap);
    HotSpotFrameContext frameContext = new HotSpotFrameContext(stub != null, omitFrame);
    DataBuilder dataBuilder = new HotSpotDataBuilder(getCodeCache().getTarget());
    CompilationResultBuilder crb = factory.createBuilder(getCodeCache(), getForeignCalls(), frameMap, masm, dataBuilder, frameContext, options, debug, compilationResult);
    crb.setTotalFrameSize(frameMap.totalFrameSize());
    crb.setMaxInterpreterFrameSize(gen.getMaxInterpreterFrameSize());
    StackSlot deoptimizationRescueSlot = gen.getDeoptimizationRescueSlot();
    if (deoptimizationRescueSlot != null && stub == null) {
        crb.compilationResult.setCustomStackAreaOffset(deoptimizationRescueSlot);
    }
    if (stub != null) {
        EconomicSet<Register> destroyedCallerRegisters = gatherDestroyedCallerRegisters(lir);
        updateStub(stub, destroyedCallerRegisters, gen.getCalleeSaveInfo(), frameMap);
    }
    return crb;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotLIRGenerationResult(org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult) HotSpotDataBuilder(org.graalvm.compiler.hotspot.HotSpotDataBuilder) Stub(org.graalvm.compiler.hotspot.stubs.Stub) StackSlot(jdk.vm.ci.code.StackSlot) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) LIR(org.graalvm.compiler.lir.LIR) HotSpotDataBuilder(org.graalvm.compiler.hotspot.HotSpotDataBuilder) DataBuilder(org.graalvm.compiler.lir.asm.DataBuilder) Register(jdk.vm.ci.code.Register) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) Assembler(org.graalvm.compiler.asm.Assembler) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler)

Example 94 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class EffectsClosure method processBlock.

@Override
protected BlockT processBlock(Block block, BlockT state) {
    if (!state.isDead()) {
        GraphEffectList effects = blockEffects.get(block);
        /*
             * If we enter an if branch that is known to be unreachable, we mark it as dead and
             * cease to do any more analysis on it. At merges, these dead branches will be ignored.
             */
        if (block.getBeginNode().predecessor() instanceof IfNode) {
            IfNode ifNode = (IfNode) block.getBeginNode().predecessor();
            LogicNode condition = ifNode.condition();
            Node alias = getScalarAlias(condition);
            if (alias instanceof LogicConstantNode) {
                LogicConstantNode constant = (LogicConstantNode) alias;
                boolean isTrueSuccessor = block.getBeginNode() == ifNode.trueSuccessor();
                if (constant.getValue() != isTrueSuccessor) {
                    state.markAsDead();
                    effects.killIfBranch(ifNode, constant.getValue());
                    return state;
                }
            }
        }
        OptionValues options = block.getBeginNode().getOptions();
        VirtualUtil.trace(options, debug, "\nBlock: %s, preds: %s, succ: %s (", block, block.getPredecessors(), block.getSuccessors());
        // a lastFixedNode is needed in case we want to insert fixed nodes
        FixedWithNextNode lastFixedNode = null;
        Iterable<? extends Node> nodes = schedule != null ? schedule.getBlockToNodesMap().get(block) : block.getNodes();
        for (Node node : nodes) {
            // reset the aliases (may be non-null due to iterative loop processing)
            aliases.set(node, null);
            if (node instanceof LoopExitNode) {
                LoopExitNode loopExit = (LoopExitNode) node;
                for (ProxyNode proxy : loopExit.proxies()) {
                    aliases.set(proxy, null);
                    changed |= processNode(proxy, state, effects, lastFixedNode) && isSignificantNode(node);
                }
                processLoopExit(loopExit, loopEntryStates.get(loopExit.loopBegin()), state, blockEffects.get(block));
            }
            changed |= processNode(node, state, effects, lastFixedNode) && isSignificantNode(node);
            if (node instanceof FixedWithNextNode) {
                lastFixedNode = (FixedWithNextNode) node;
            }
            if (state.isDead()) {
                break;
            }
        }
        VirtualUtil.trace(options, debug, ")\n    end state: %s\n", state);
    }
    return state;
}
Also used : ProxyNode(org.graalvm.compiler.nodes.ProxyNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) OptionValues(org.graalvm.compiler.options.OptionValues) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) IfNode(org.graalvm.compiler.nodes.IfNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Example 95 with OptionValues

use of org.graalvm.compiler.options.OptionValues in project graal by oracle.

the class PEReadEliminationClosure method processKilledLoopLocations.

@Override
protected void processKilledLoopLocations(Loop<Block> loop, PEReadEliminationBlockState initialState, PEReadEliminationBlockState mergedStates) {
    assert initialState != null;
    assert mergedStates != null;
    if (initialState.readCache.size() > 0) {
        LoopKillCache loopKilledLocations = loopLocationKillCache.get(loop);
        // it is visited
        if (loopKilledLocations == null) {
            loopKilledLocations = new LoopKillCache(1);
            loopLocationKillCache.put(loop, loopKilledLocations);
        } else {
            AbstractBeginNode beginNode = loop.getHeader().getBeginNode();
            OptionValues options = beginNode.getOptions();
            if (loopKilledLocations.visits() > ReadEliminationMaxLoopVisits.getValue(options)) {
                // we have processed the loop too many times, kill all locations so the inner
                // loop will never be processed more than once again on visit
                loopKilledLocations.setKillsAll();
            } else {
                // we have fully processed this loop >1 times, update the killed locations
                EconomicSet<LocationIdentity> forwardEndLiveLocations = EconomicSet.create(Equivalence.DEFAULT);
                for (ReadCacheEntry entry : initialState.readCache.getKeys()) {
                    forwardEndLiveLocations.add(entry.identity);
                }
                for (ReadCacheEntry entry : mergedStates.readCache.getKeys()) {
                    forwardEndLiveLocations.remove(entry.identity);
                }
                // loop
                for (LocationIdentity location : forwardEndLiveLocations) {
                    loopKilledLocations.rememberLoopKilledLocation(location);
                }
                if (debug.isLogEnabled() && loopKilledLocations != null) {
                    debug.log("[Early Read Elimination] Setting loop killed locations of loop at node %s with %s", beginNode, forwardEndLiveLocations);
                }
            }
            // remember the loop visit
            loopKilledLocations.visited();
        }
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) ReadCacheEntry(org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

OptionValues (org.graalvm.compiler.options.OptionValues)158 Test (org.junit.Test)65 DebugContext (org.graalvm.compiler.debug.DebugContext)50 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)36 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)30 Graph (org.graalvm.compiler.graph.Graph)22 OptionKey (org.graalvm.compiler.options.OptionKey)16 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)13 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)11 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)10 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)10 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)10 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)9 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)9 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)9 Providers (org.graalvm.compiler.phases.util.Providers)9 IOException (java.io.IOException)8 Method (java.lang.reflect.Method)8 CompilationResult (org.graalvm.compiler.code.CompilationResult)7 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)7