Search in sources :

Example 36 with Snippet

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

the class PosixCEntryPointSnippets method detachThreadSnippet.

@Snippet
public static int detachThreadSnippet() {
    int result = Errors.NO_ERROR;
    if (MultiThreaded.getValue()) {
        IsolateThread thread = CEntryPointContext.getCurrentIsolateThread();
        result = runtimeCall(DETACH_THREAD_MT, thread);
    }
    if (UseHeapBaseRegister.getValue()) {
        writeCurrentVMHeapBase(WordFactory.nullPointer());
    }
    return result;
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Safepoint(com.oracle.svm.core.thread.Safepoint) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 37 with Snippet

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

the class ExceptionStateNode method unwindSnippet.

@Snippet
protected static void unwindSnippet(Throwable exception) {
    Pointer callerSP = readCallerStackPointer();
    CodePointer callerIP = readReturnAddress();
    runtimeCall(UNWIND_EXCEPTION, exception, callerSP, callerIP);
    throw unreachable();
}
Also used : CodePointer(org.graalvm.nativeimage.c.function.CodePointer) KnownIntrinsics.readCallerStackPointer(com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer) Pointer(org.graalvm.word.Pointer) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 38 with Snippet

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

the class TypeSnippets method instanceOfDynamicSnippet.

@Snippet
protected static Any instanceOfDynamicSnippet(DynamicHub type, Object object, Any trueValue, Any falseValue, @ConstantParameter boolean allowsNull) {
    if (object == null) {
        return allowsNull ? trueValue : falseValue;
    }
    Object objectNonNull = PiNode.piCastNonNull(object, SnippetAnchorNode.anchor());
    /*
         * We could use instanceOfMatches here instead of assignableFromMatches, but currently we do
         * not preserve these at run time to keep the native image heap small.
         */
    int[] matches = type.getAssignableFromMatches();
    DynamicHub objectHub = loadHub(objectNonNull);
    int le = DynamicHub.fromClass(matches.getClass()).getLayoutEncoding();
    for (int i = 0; i < matches.length; i += 2) {
        /*
             * We cannot use regular array accesses like match[i] because we need to provide a
             * custom LocationIdentity for the read.
             */
        int matchTypeID = ObjectAccess.readInt(matches, LayoutEncoding.getArrayElementOffset(le, i), NamedLocationIdentity.FINAL_LOCATION);
        int matchLength = ObjectAccess.readInt(matches, LayoutEncoding.getArrayElementOffset(le, i + 1), NamedLocationIdentity.FINAL_LOCATION);
        if (UnsignedMath.belowThan(objectHub.getTypeID() - matchTypeID, matchLength)) {
            return trueValue;
        }
    }
    return falseValue;
}
Also used : DynamicHub(com.oracle.svm.core.hub.DynamicHub) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 39 with Snippet

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

the class InstanceOfSnippets method instanceofExact.

/**
 * A test against a final type.
 */
@Snippet
public static Object instanceofExact(Object object, KlassPointer exactHub, Object trueValue, Object falseValue, @ConstantParameter Counters counters) {
    if (probability(NOT_FREQUENT_PROBABILITY, object == null)) {
        counters.isNull.inc();
        return falseValue;
    }
    GuardingNode anchorNode = SnippetAnchorNode.anchor();
    KlassPointer objectHub = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
    if (probability(LIKELY_PROBABILITY, objectHub.notEqual(exactHub))) {
        counters.exactMiss.inc();
        return falseValue;
    }
    counters.exactHit.inc();
    return trueValue;
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 40 with Snippet

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

the class InstanceOfSnippets method instanceofWithProfile.

/**
 * A test against a set of hints derived from a profile with 100% precise coverage of seen
 * types. This snippet deoptimizes on hint miss paths.
 */
@Snippet
public static Object instanceofWithProfile(Object object, @VarargsParameter KlassPointer[] hints, @VarargsParameter boolean[] hintIsPositive, Object trueValue, Object falseValue, @ConstantParameter boolean nullSeen, @ConstantParameter Counters counters) {
    if (probability(NOT_FREQUENT_PROBABILITY, object == null)) {
        counters.isNull.inc();
        if (!nullSeen) {
            // See comment below for other deoptimization path; the
            // same reasoning applies here.
            DeoptimizeNode.deopt(InvalidateReprofile, OptimizedTypeCheckViolated);
        }
        return falseValue;
    }
    GuardingNode anchorNode = SnippetAnchorNode.anchor();
    KlassPointer objectHub = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
    // if we get an exact match: succeed immediately
    ExplodeLoopNode.explodeLoop();
    for (int i = 0; i < hints.length; i++) {
        KlassPointer hintHub = hints[i];
        boolean positive = hintIsPositive[i];
        if (probability(LIKELY_PROBABILITY, hintHub.equal(objectHub))) {
            counters.hintsHit.inc();
            return positive ? trueValue : falseValue;
        }
        counters.hintsMiss.inc();
    }
    // This maybe just be a rare event but it might also indicate a phase change
    // in the application. Ideally we want to use DeoptimizationAction.None for
    // the former but the cost is too high if indeed it is the latter. As such,
    // we defensively opt for InvalidateReprofile.
    DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, OptimizedTypeCheckViolated);
    return falseValue;
}
Also used : KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) Snippet(org.graalvm.compiler.api.replacements.Snippet)

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