# HG changeset patch # User Tom Rodriguez # Date 1432148331 25200 # Node ID ac2694c465dbb762ba1b2b665bc882d9d7a4fd3b # Parent 2e6ce8d1d067664c4fb73da8049e181c4027f6ab Fix SnippetCounters private location assert diff -r 2e6ce8d1d067 -r ac2694c465db graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounterNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounterNode.java Mon May 18 16:51:01 2015 -0700 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounterNode.java Wed May 20 11:58:51 2015 -0700 @@ -22,9 +22,12 @@ */ package com.oracle.graal.replacements; +import static com.oracle.graal.compiler.common.GraalOptions.*; import static com.oracle.graal.compiler.common.UnsafeAccess.*; import static com.oracle.graal.replacements.SnippetTemplate.*; +import java.util.*; + import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.replacements.*; @@ -35,6 +38,7 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.util.*; +import com.oracle.graal.replacements.Snippet.ConstantParameter; import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates; import com.oracle.graal.replacements.SnippetTemplate.Arguments; import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo; @@ -85,6 +89,34 @@ } } + /** + * When {@link #SnippetCounters} are enabled make sure {@link #SNIPPET_COUNTER_LOCATION} is part + * of the private locations. + * + * @param privateLocations + * @return a copy of privateLocations with any needed locations added + */ + public static LocationIdentity[] addSnippetCounters(LocationIdentity[] privateLocations) { + if (SnippetCounters.getValue()) { + for (LocationIdentity location : privateLocations) { + if (location.equals(SNIPPET_COUNTER_LOCATION)) { + return privateLocations; + } + } + LocationIdentity[] result = Arrays.copyOf(privateLocations, privateLocations.length + 1); + result[result.length - 1] = SnippetCounterNode.SNIPPET_COUNTER_LOCATION; + return result; + } + return privateLocations; + } + + /** + * We do not want to use the {@link LocationIdentity} of the {@link SnippetCounter#value} field, + * so that the usage in snippets is always possible. If a method accesses the counter via the + * field and the snippet, the result might not be correct though. + */ + public static final LocationIdentity SNIPPET_COUNTER_LOCATION = NamedLocationIdentity.mutable("SnippetCounter"); + static class SnippetCounterSnippets implements Snippets { @Fold @@ -96,15 +128,8 @@ } } - /** - * We do not want to use the {@link LocationIdentity} of the {@link SnippetCounter#value} - * field, so that the usage in snippets is always possible. If a method accesses the counter - * via the field and the snippet, the result might not be correct though. - */ - protected static final LocationIdentity SNIPPET_COUNTER_LOCATION = NamedLocationIdentity.mutable("SnippetCounter"); - @Snippet - public static void add(SnippetCounter counter, int increment) { + public static void add(@ConstantParameter SnippetCounter counter, int increment) { long loadedValue = ObjectAccess.readLong(counter, countOffset(), SNIPPET_COUNTER_LOCATION); ObjectAccess.writeLong(counter, countOffset(), loadedValue + increment, SNIPPET_COUNTER_LOCATION); } diff -r 2e6ce8d1d067 -r ac2694c465db graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Mon May 18 16:51:01 2015 -0700 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Wed May 20 11:58:51 2015 -0700 @@ -151,7 +151,7 @@ protected SnippetInfo(ResolvedJavaMethod method, LocationIdentity[] privateLocations) { this.method = method; - this.privateLocations = privateLocations; + this.privateLocations = SnippetCounterNode.addSnippetCounters(privateLocations); instantiationCounter = Debug.metric("SnippetInstantiationCount[%s]", method.getName()); instantiationTimer = Debug.timer("SnippetInstantiationTime[%s]", method.getName()); assert method.isStatic() : "snippet method must be static: " + method.format("%H.%n");