Search in sources :

Example 16 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class BarrierSnippetCountersFeature method postWriteBarrierSnippet.

/**
 * Given an object, dirty the card for the object.
 *
 * @param object The object to which the write has been done.
 */
@Snippet
public static void postWriteBarrierSnippet(Object object) {
    counters().postWriteBarrier.inc();
    // Get the Object to which the write happened.
    final Object fixedObject = FixedValueAnchorNode.getObject(object);
    // Get the ObjectHeader from the Object.
    final UnsignedWord objectHeader = ObjectHeader.readHeaderFromObject(fixedObject);
    // Does the ObjectHeader indicate that I need a barrier?
    final boolean needsBarrier = ObjectHeaderImpl.hasRememberedSet(objectHeader);
    if (BranchProbabilityNode.probability(BranchProbabilityNode.FREQUENT_PROBABILITY, !needsBarrier)) {
        // Most likely (?): expect that no barrier is needed.
        return;
    }
    // The object needs a write-barrier. Is it aligned or unaligned?
    final boolean unaligned = ObjectHeaderImpl.isHeapObjectUnaligned(objectHeader);
    if (BranchProbabilityNode.probability(BranchProbabilityNode.LIKELY_PROBABILITY, !unaligned)) {
        // Next most likely (?): aligned objects.
        counters().postWriteBarrierAligned.inc();
        AlignedHeapChunk.dirtyCardForObjectOfAlignedHeapChunk(fixedObject);
        return;
    }
    // Least likely (?): object needs a write-barrier and is unaligned.
    counters().postWriteBarrierUnaligned.inc();
    UnalignedHeapChunk.dirtyCardForObjectOfUnalignedHeapChunk(fixedObject);
    return;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 17 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class SubstrateReplacements method registerSnippet.

/**
 * Compiles the snippet and stores the graph.
 */
@Platforms(Platform.HOSTED_ONLY.class)
@Override
public void registerSnippet(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
    assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
    assert method.hasBytecodes() : "Snippet must not be abstract or native";
    assert builder.graphs.get(method) == null : "snippet registered twice: " + method.getName();
    try (DebugContext debug = openDebugContext("Snippet_", method)) {
        StructuredGraph graph = makeGraph(debug, defaultBytecodeProvider, method, null, null, trackNodeSourcePosition, null);
        // Check if all methods which should be inlined are really inlined.
        for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod callee = callTarget.targetMethod();
            if (!builder.delayedInvocationPluginMethods.contains(callee)) {
                throw shouldNotReachHere("method " + callee.getName() + " not inlined in snippet " + method.getName() + " (maybe not final?)");
            }
        }
        builder.graphs.put(method, graph);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) Snippet(org.graalvm.compiler.api.replacements.Snippet) DebugContext(org.graalvm.compiler.debug.DebugContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Platforms(org.graalvm.nativeimage.Platforms)

Example 18 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class DefaultJavaLoweringProvider method lowerBinaryMath.

private void lowerBinaryMath(BinaryMathIntrinsicNode math, LoweringTool tool) {
    if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
        return;
    }
    ResolvedJavaMethod method = math.graph().method();
    if (method != null) {
        if (method.getAnnotation(Snippet.class) != null) {
            /*
                 * In the context of the snippet use the LIR lowering instead of the Node lowering.
                 */
            return;
        }
        if (method.getName().equalsIgnoreCase(math.getOperation().name()) && tool.getMetaAccess().lookupJavaType(Math.class).equals(method.getDeclaringClass())) {
            /*
                 * A root compilation of the intrinsic method should emit the full assembly
                 * implementation.
                 */
            return;
        }
    }
    ForeignCallDescriptor foreignCall = toForeignCall(math.getOperation());
    if (foreignCall != null) {
        StructuredGraph graph = math.graph();
        ForeignCallNode call = graph.add(new ForeignCallNode(foreignCalls, toForeignCall(math.getOperation()), math.getX(), math.getY()));
        graph.addAfterFixed(tool.lastFixedNode(), call);
        math.replaceAtUsages(call);
    }
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Snippet(org.graalvm.compiler.api.replacements.Snippet) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 19 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class WordTest method cast.

@Snippet
public static long cast(long input) {
    WordBase base = WordFactory.signed(input);
    UnsignedWord unsigned = (UnsignedWord) base;
    Pointer pointer = (Pointer) unsigned;
    Word word = (Word) pointer;
    return word.rawValue();
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Word(org.graalvm.compiler.word.Word) UnsignedWord(org.graalvm.word.UnsignedWord) WordBase(org.graalvm.word.WordBase) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 20 with Snippet

use of org.graalvm.compiler.api.replacements.Snippet in project graal by oracle.

the class ReplacementsImpl method getSnippet.

@Override
@SuppressWarnings("try")
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
    assert method.hasBytecodes() : "Snippet must not be abstract or native";
    StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(method) : null;
    if (graph == null || (trackNodeSourcePosition && !graph.trackNodeSourcePosition())) {
        try (DebugContext debug = openDebugContext("Snippet_", method);
            DebugCloseable a = SnippetPreparationTime.start(debug)) {
            StructuredGraph newGraph = makeGraph(debug, defaultBytecodeProvider, method, args, recursiveEntry, trackNodeSourcePosition, replaceePosition);
            DebugContext.counter("SnippetNodeCount[%#s]", method).add(newGraph.getDebug(), newGraph.getNodeCount());
            if (!UseSnippetGraphCache.getValue(options) || args != null) {
                return newGraph;
            }
            newGraph.freeze();
            if (graph != null) {
                graphs.replace(method, graph, newGraph);
            } else {
                graphs.putIfAbsent(method, newGraph);
            }
            graph = graphs.get(method);
        }
    }
    assert !trackNodeSourcePosition || graph.trackNodeSourcePosition();
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Snippet(org.graalvm.compiler.api.replacements.Snippet) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Aggregations

Snippet (org.graalvm.compiler.api.replacements.Snippet)47 Word (org.graalvm.compiler.word.Word)22 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)17 Pointer (org.graalvm.word.Pointer)14 UnsignedWord (org.graalvm.word.UnsignedWord)12 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)9 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)6 DynamicHub (com.oracle.svm.core.hub.DynamicHub)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 Safepoint (com.oracle.svm.core.thread.Safepoint)2 ForeignCallDescriptor (org.graalvm.compiler.core.common.spi.ForeignCallDescriptor)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 ForeignCallNode (org.graalvm.compiler.nodes.extended.ForeignCallNode)2 WordBase (org.graalvm.word.WordBase)2 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)1 JavaFrameAnchor (com.oracle.svm.core.stack.JavaFrameAnchor)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 HotSpotReplacementsUtil.arrayPrototypeMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord)1 HotSpotReplacementsUtil.tlabIntArrayMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord)1