Search in sources :

Example 6 with OptionValues

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

the class TypedNodeIteratorTest method iteratorBehaviorTest.

@Test
public void iteratorBehaviorTest() {
    OptionValues options = getOptions();
    Graph graph = new Graph(options, getDebug(options));
    graph.add(new TestNode("a"));
    Iterator<TestNode> iterator = graph.getNodes(TestNode.TYPE).iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next().getName());
    assertFalse(iterator.hasNext());
    graph.add(new TestNode("b"));
    assertTrue(iterator.hasNext());
    assertEquals("b", iterator.next().getName());
    assertFalse(iterator.hasNext());
    TestNode c = new TestNode("c");
    graph.add(c);
    assertTrue(iterator.hasNext());
    c.safeDelete();
    assertFalse(iterator.hasNext());
}
Also used : Graph(org.graalvm.compiler.graph.Graph) OptionValues(org.graalvm.compiler.options.OptionValues) Test(org.junit.Test)

Example 7 with OptionValues

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

the class TypedNodeIteratorTest method deletingNodeTest.

@Test
public void deletingNodeTest() {
    TestNode testNode = new TestNode("a");
    OptionValues options = getOptions();
    Graph graph = new Graph(options, getDebug(options));
    graph.add(testNode);
    testNode.safeDelete();
    assertEquals("", toString(graph.getNodes(TestNode.TYPE)));
}
Also used : Graph(org.graalvm.compiler.graph.Graph) OptionValues(org.graalvm.compiler.options.OptionValues) Test(org.junit.Test)

Example 8 with OptionValues

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

the class GraalTruffleRuntime method submitForCompilation.

@SuppressWarnings("try")
public CancellableCompileTask submitForCompilation(OptimizedCallTarget optimizedCallTarget) {
    BackgroundCompileQueue l = getCompileQueue();
    final WeakReference<OptimizedCallTarget> weakCallTarget = new WeakReference<>(optimizedCallTarget);
    final OptionValues optionOverrides = TruffleCompilerOptions.getCurrentOptionOverrides();
    CancellableCompileTask cancellable = new CancellableCompileTask();
    cancellable.setFuture(l.compileQueue.submit(new Runnable() {

        @Override
        public void run() {
            OptimizedCallTarget callTarget = weakCallTarget.get();
            if (callTarget != null) {
                try (TruffleOptionsOverrideScope scope = optionOverrides != null ? overrideOptions(optionOverrides.getMap()) : null) {
                    OptionValues options = TruffleCompilerOptions.getOptions();
                    doCompile(options, callTarget, cancellable);
                } finally {
                    callTarget.resetCompilationTask();
                }
            }
        }
    }));
    // task and future must never diverge from each other
    assert cancellable.future != null;
    return cancellable;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) WeakReference(java.lang.ref.WeakReference) TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope)

Example 9 with OptionValues

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

the class AOTInliningPolicy method isWorthInlining.

@Override
public boolean isWorthInlining(Replacements replacements, MethodInvocation invocation, int inliningDepth, boolean fullyProcessed) {
    final InlineInfo info = invocation.callee();
    for (int i = 0; i < info.numberOfMethods(); ++i) {
        HotSpotResolvedObjectType t = (HotSpotResolvedObjectType) info.methodAt(i).getDeclaringClass();
        if (t.getFingerprint() == 0) {
            return false;
        }
    }
    final double probability = invocation.probability();
    final double relevance = invocation.relevance();
    OptionValues options = info.graph().getOptions();
    if (InlineEverything.getValue(options)) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "inline everything");
        return true;
    }
    if (isIntrinsic(replacements, info)) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "intrinsic");
        return true;
    }
    if (info.shouldInline()) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "forced inlining");
        return true;
    }
    double inliningBonus = getInliningBonus(info);
    int nodes = info.determineNodeCount();
    if (nodes < TrivialInliningSize.getValue(options) * inliningBonus) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "trivial (relevance=%f, probability=%f, bonus=%f, nodes=%d)", relevance, probability, inliningBonus, nodes);
        return true;
    }
    double maximumNodes = computeMaximumSize(relevance, (int) (maxInliningSize(inliningDepth, options) * inliningBonus));
    if (nodes <= maximumNodes) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "relevance-based (relevance=%f, probability=%f, bonus=%f, nodes=%d <= %f)", relevance, probability, inliningBonus, nodes, maximumNodes);
        return true;
    }
    InliningUtil.traceNotInlinedMethod(info, inliningDepth, "relevance-based (relevance=%f, probability=%f, bonus=%f, nodes=%d > %f)", relevance, probability, inliningBonus, nodes, maximumNodes);
    return false;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) InlineInfo(org.graalvm.compiler.phases.common.inlining.info.InlineInfo)

Example 10 with OptionValues

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

the class GreedyInliningPolicy method isWorthInlining.

@Override
public boolean isWorthInlining(Replacements replacements, MethodInvocation invocation, int inliningDepth, boolean fullyProcessed) {
    final InlineInfo info = invocation.callee();
    OptionValues options = info.graph().getOptions();
    final double probability = invocation.probability();
    final double relevance = invocation.relevance();
    if (InlineEverything.getValue(options)) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "inline everything");
        return true;
    }
    if (isIntrinsic(replacements, info)) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "intrinsic");
        return true;
    }
    if (info.shouldInline()) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "forced inlining");
        return true;
    }
    double inliningBonus = getInliningBonus(info);
    int nodes = info.determineNodeCount();
    int lowLevelGraphSize = previousLowLevelGraphSize(info);
    if (SmallCompiledLowLevelGraphSize.getValue(options) > 0 && lowLevelGraphSize > SmallCompiledLowLevelGraphSize.getValue(options) * inliningBonus) {
        InliningUtil.traceNotInlinedMethod(info, inliningDepth, "too large previous low-level graph (low-level-nodes: %d, relevance=%f, probability=%f, bonus=%f, nodes=%d)", lowLevelGraphSize, relevance, probability, inliningBonus, nodes);
        return false;
    }
    if (nodes < TrivialInliningSize.getValue(options) * inliningBonus) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "trivial (relevance=%f, probability=%f, bonus=%f, nodes=%d)", relevance, probability, inliningBonus, nodes);
        return true;
    }
    /*
         * TODO (chaeubl): invoked methods that are on important paths but not yet compiled -> will
         * be compiled anyways and it is likely that we are the only caller... might be useful to
         * inline those methods but increases bootstrap time (maybe those methods are also getting
         * queued in the compilation queue concurrently)
         */
    double invokes = determineInvokeProbability(info);
    if (LimitInlinedInvokes.getValue(options) > 0 && fullyProcessed && invokes > LimitInlinedInvokes.getValue(options) * inliningBonus) {
        InliningUtil.traceNotInlinedMethod(info, inliningDepth, "callee invoke probability is too high (invokeP=%f, relevance=%f, probability=%f, bonus=%f, nodes=%d)", invokes, relevance, probability, inliningBonus, nodes);
        return false;
    }
    double maximumNodes = computeMaximumSize(relevance, (int) (MaximumInliningSize.getValue(options) * inliningBonus));
    if (nodes <= maximumNodes) {
        InliningUtil.traceInlinedMethod(info, inliningDepth, fullyProcessed, "relevance-based (relevance=%f, probability=%f, bonus=%f, nodes=%d <= %f)", relevance, probability, inliningBonus, nodes, maximumNodes);
        return true;
    }
    InliningUtil.traceNotInlinedMethod(info, inliningDepth, "relevance-based (relevance=%f, probability=%f, bonus=%f, nodes=%d > %f)", relevance, probability, inliningBonus, nodes, maximumNodes);
    return false;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) InlineInfo(org.graalvm.compiler.phases.common.inlining.info.InlineInfo)

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