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