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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations