NullPointerException in HotSpotRuntime:lower when using Snippets

Doug Simon doug.simon at oracle.com
Wed Jul 3 06:53:47 PDT 2013


On Jul 2, 2013, at 9:36 PM, ATKIN-GRANVILLE Chris <s1255753 at sms.ed.ac.uk> wrote:

> Hi there,
> 
> I'm trying add arbitrary behaviour to array accesses - the end goal being to create traces of all memory operations within a program. What I've done so far was suggested to me in a previous thread on this list, but in short, I've got phases that add my own custom nodes to each LoadIndexedNode/StoreIndexedNode. These are then lowered to the desired behaviour via snippets:
> 
> public class InstrumentationSnippets implements Snippets {
> 	@Snippet
> 	public static void store(final ArrayStoreBehaviourNode<?> node) {
> 		Instrument.arrayStores.add(node.getInfo());
> 	}
> 	
> 	@Snippet
> 	public static void load(final ArrayLoadBehaviourNode<?> node) {
> 		Instrument.arrayLoads.add(node.getInfo());
> 	}

This doesn't look right, having compiler nodes as parameter types of snippets. The value of a snippet parameter may come from a compiler node when the snippet is instantiated (during lowering) but the snippet sees the "raw" Java type of the value. Assuming ArrayLoadInfo is the type returned by node.getInfo(), you probably want something like this:

@Snippet
public static void load(ArrayLoadInfo info) {
    Instrument.arrayLoads.add(info);
}


> 	public static class Templates extends AbstractTemplates {
> 		private final SnippetInfo store = snippet(InstrumentationSnippets.class, "store");
> 		private final SnippetInfo load = snippet(InstrumentationSnippets.class, "load");
> 
> 		public Templates(MetaAccessProvider runtime, Replacements replacements, TargetDescription target) {
> 			super(runtime, replacements, target);
> 		}
> 		
> 		public void lower(final ArrayStoreBehaviourNode<?> node) {
> 			Arguments args = new Arguments(store);
> 			args.add("node", node);

and replace the above with:

args.add("info", node.getInfo());

-Doug


More information about the graal-dev mailing list