changeset 21462:ac2694c465db

Fix SnippetCounters private location assert
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Wed, 20 May 2015 11:58:51 -0700
parents 2e6ce8d1d067
children b1072d72fa2e
files graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounterNode.java graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java
diffstat 2 files changed, 34 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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);
         }
--- 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");