Instrumentation with snippets
Chris Atkin-Granville
me at chrisatk.in
Mon Jun 17 12:10:23 PDT 2013
Hi Doug, Mick,
On 17 Jun 2013, at 17:05, Doug Simon <doug.simon at oracle.com> wrote:
> Snippets (as opposed to method substitutions) are currently only used during lowering. So one thing you could do is replace the lowering in HotSpotRuntime.lower() for LoadIndexedNode and StoreIndexedNode to use your snippets instead. However, this means you need to replicate the correct semantics for these operations in your snippet in addition to the instrumentation code. I think a better alternative would be to insert an InvokeNode before/after the array access node that takes the same inputs of the array access and calls a well known (static) instrumentation method.
After that information I agree that inserting an InvokeNode is probably the best idea too. I'd like to avoid modifying the Graal source if possible!
> It might be instructive to look at MonitorSnippets.checkBalancedMonitors() for an example of inserting an invoke node.
Thanks for the pointer. Is the best way to do this to add a phase (at HIGH_LEVEL I presume?) and then call a method that inserts InvokeNodes upon each instance of StoreIndexedNode/LoadIndexedNode? In other words, to use the same mechanism as in the code I posted below, replacing the contents of ArrayAccessSnippets.Templates:lower() with code that adds InvokeNodes? If so, I have already tried this but I'm getting SIGSEGVs from the JVM upon execution (LinkResolver::lookup_method_in_klasses) - I've attached the full report.
At the moment the behaviour in my Templates class is:
private final SnippetInfo methodOnStore = snippet(ArrayAccessSnippets.class, "arrayIndexStore"); // note - arrayIndexStore has been declared static, no args, void return
public void invokeAfter(StoreIndexedNode node, StructuredGraph graph) {
JavaType returnType = methodOnStore.getMethod().getSignature().getReturnType(methodOnStore.getMethod().getDeclaringClass());
MethodCallTargetNode callTarget = graph.add(new MethodCallTargetNode(InvokeKind.Static, methodOnStore.getMethod(), new ValueNode[] {}, returnType));
InvokeNode invoke = graph.add(new InvokeNode(callTarget, 0));
invoke.setStateAfter(node.stateAfter());
graph.addAfterFixed(node, invoke);
}
invokeAfter is called from my HIGH_LEVEL phase [i.e., for(Node node: graph.getNodes()) if (node instanceOf StoreIndexedNode) snippets.invokeAfter((StoreIndexedNode) node, graph); ]
I'm confused as to why I'm getting the LinkResolver error - to me (through a debugger) it looks like everything is "wired up" correctly.
On 17 Jun 2013, at 18:49, Mick Jordan <mick.jordan at oracle.com> wrote:
> I am planning to implement the VMA instrumentation from Maxine in Graal fairly soon which, as Doug suggests, involves inserting Invoke nodes in general. However, depending on the nature of the instrumentation, the inlining may then remove them and inline the instrumentation. This should work with Hotspot also (eventually).
Interesting. Could you perhaps elaborate on the "nature of the instrumentation"? Specifically, would you perform inlining based on the behaviour of the instrumentation or something else?
More information about the graal-dev
mailing list