changeset 12734:2caa21ef52bb

Merge.
author Doug Simon <doug.simon@oracle.com>
date Fri, 08 Nov 2013 18:34:57 +0100
parents 8d8d9d0b04bb (diff) 0646713243fb (current diff)
children bb85b81258a0
files
diffstat 2 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java	Fri Nov 08 17:07:50 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java	Fri Nov 08 18:34:57 2013 +0100
@@ -23,7 +23,9 @@
 package com.oracle.graal.hotspot.replacements;
 
 import static com.oracle.graal.api.code.UnsignedMath.*;
+import static com.oracle.graal.api.meta.MetaUtil.*;
 import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*;
+import static com.oracle.graal.hotspot.replacements.NewObjectSnippets.Options.*;
 import static com.oracle.graal.nodes.PiArrayNode.*;
 import static com.oracle.graal.nodes.PiNode.*;
 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*;
@@ -64,11 +66,11 @@
 
     public static final LocationIdentity INIT_LOCATION = new NamedLocationIdentity("Initialization");
 
-    public static class Options {
+    static class Options {
 
         //@formatter:off
         @Option(help = "")
-        private static final OptionValue<Boolean> ProfileAllocations = new OptionValue<>(false);
+        static final OptionValue<Boolean> ProfileAllocations = new OptionValue<>(false);
         //@formatter:on
     }
 
@@ -114,7 +116,7 @@
 
     @Fold
     private static boolean doProfile() {
-        return Options.ProfileAllocations.getValue();
+        return ProfileAllocations.getValue();
     }
 
     private static void profileAllocation(String path, long size, String typeContext) {
@@ -315,7 +317,7 @@
             args.add("hub", hub);
             args.add("prototypeMarkWord", type.prototypeMarkWord());
             args.addConst("fillContents", newInstanceNode.fillContents());
-            args.addConst("typeContext", MetaUtil.toJavaName(type, false));
+            args.addConst("typeContext", ProfileAllocations.getValue() ? toJavaName(type, false) : "");
 
             SnippetTemplate template = template(args);
             Debug.log("Lowering allocateInstance in %s: node=%s, template=%s, arguments=%s", graph, newInstanceNode, template, args);
@@ -342,7 +344,7 @@
             args.addConst("headerSize", headerSize);
             args.addConst("log2ElementSize", log2ElementSize);
             args.addConst("fillContents", newArrayNode.fillContents());
-            args.addConst("typeContext", MetaUtil.toJavaName(arrayType, false));
+            args.addConst("typeContext", ProfileAllocations.getValue() ? toJavaName(arrayType, false) : "");
 
             SnippetTemplate template = template(args);
             Debug.log("Lowering allocateArray in %s: node=%s, template=%s, arguments=%s", graph, newArrayNode, template, args);
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Fri Nov 08 17:07:50 2013 +0100
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Fri Nov 08 18:34:57 2013 +0100
@@ -23,7 +23,9 @@
 package com.oracle.graal.replacements;
 
 import static com.oracle.graal.api.meta.LocationIdentity.*;
+import static com.oracle.graal.api.meta.MetaUtil.*;
 
+import java.io.*;
 import java.lang.reflect.*;
 import java.util.*;
 import java.util.concurrent.*;
@@ -114,6 +116,17 @@
             assert initNames();
         }
 
+        private int templateCount;
+
+        void notifyNewTemplate() {
+            templateCount++;
+            if (UseSnippetTemplateCache && templateCount > MaxTemplatesPerSnippet) {
+                PrintStream err = System.err;
+                err.printf("WARNING: Exceeded %d templates for snippet %s%n" + "         Adjust maximum with %s system property%n", MaxTemplatesPerSnippet, format("%h.%n(%p)", method),
+                                MAX_TEMPLATES_PER_SNIPPET_PROPERTY_NAME);
+            }
+        }
+
         private boolean initNames() {
             int slotIdx = 0;
             for (int i = 0; i < names.length; i++) {
@@ -350,7 +363,9 @@
     private static final DebugMetric SnippetTemplatesNodeCount = Debug.metric("SnippetTemplatesNodeCount");
     private static final DebugMetric SnippetGraphsNodeCount = Debug.metric("SnippetGraphsNodeCount");
 
+    private static final String MAX_TEMPLATES_PER_SNIPPET_PROPERTY_NAME = "graal.maxTemplatesPerSnippet";
     private static final boolean UseSnippetTemplateCache = Boolean.parseBoolean(System.getProperty("graal.useSnippetTemplateCache", "true"));
+    private static final int MaxTemplatesPerSnippet = Integer.getInteger(MAX_TEMPLATES_PER_SNIPPET_PROPERTY_NAME, 50);
 
     /**
      * Base class for snippet classes. It provides a cache for {@link SnippetTemplate}s.
@@ -427,7 +442,7 @@
         return false;
     }
 
-    private static String debugValueName(SnippetTemplate template, String category, Arguments args) {
+    private static String debugValueName(String category, Arguments args) {
         if (Debug.isEnabled()) {
             StringBuilder result = new StringBuilder(category).append('[');
             SnippetInfo info = args.info;
@@ -445,7 +460,7 @@
                     sep = ", ";
                 }
             }
-            result.append(")]@").append(template.hashCode());
+            result.append(")]");
             return result.toString();
 
         }
@@ -458,8 +473,8 @@
     protected SnippetTemplate(final Providers providers, Arguments args) {
         StructuredGraph snippetGraph = providers.getReplacements().getSnippet(args.info.method);
         SnippetGraphsNodeCount.add(snippetGraph.getNodeCount());
-        instantiationTimer = Debug.timer(debugValueName(this, "SnippetTemplateInstantiationTime", args));
-        instantiationCounter = Debug.metric(debugValueName(this, "SnippetTemplateInstantiationCount", args));
+        instantiationTimer = Debug.timer(debugValueName("SnippetTemplateInstantiationTime", args));
+        instantiationCounter = Debug.metric(debugValueName("SnippetTemplateInstantiationCount", args));
 
         ResolvedJavaMethod method = snippetGraph.method();
         Signature signature = method.getSignature();
@@ -648,6 +663,7 @@
         this.returnNode = retNode;
 
         SnippetTemplatesNodeCount.add(nodes.size());
+        args.info.notifyNewTemplate();
     }
 
     private static boolean checkAllVarargPlaceholdersAreDeleted(int parameterCount, VarargsPlaceholderNode[] placeholders) {