changeset 2767:20475c78a0a6

8061472: String.format in DeferredAttr.DeferredTypeMap constructor leads to excessive object creation Reviewed-by: mcimadamore, vromero
author jfranck
date Fri, 19 Dec 2014 21:07:53 +0100
parents c402b2856ed1
children d442757afcdd
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Dec 18 13:21:44 2014 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Fri Dec 19 21:07:53 2014 +0100
@@ -41,6 +41,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.EnumMap;
 import java.util.EnumSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -838,6 +839,14 @@
     /** an empty deferred attribution context - all methods throw exceptions */
     final DeferredAttrContext emptyDeferredAttrContext;
 
+    /** The AttrMode to descriptive name mapping */
+    private static final EnumMap<AttrMode, String> deferredTypeMapDescriptions;
+    static {
+        deferredTypeMapDescriptions = new EnumMap<>(AttrMode.class);
+        deferredTypeMapDescriptions.put(AttrMode.CHECK, "deferredTypeMap[CHECK]");
+        deferredTypeMapDescriptions.put(AttrMode.SPECULATIVE, "deferredTypeMap[SPECULATIVE]");
+    }
+
     /**
      * Map a list of types possibly containing one or more deferred types
      * into a list of ordinary types. Each deferred type D is mapped into a type T,
@@ -845,11 +854,10 @@
      * computed for D during a previous deferred attribution round of the given kind.
      */
     class DeferredTypeMap extends Type.Mapping {
-
         DeferredAttrContext deferredAttrContext;
 
         protected DeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) {
-            super(String.format("deferredTypeMap[%s]", mode));
+            super(deferredTypeMapDescriptions.get(mode));
             this.deferredAttrContext = new DeferredAttrContext(mode, msym, phase,
                     infer.emptyContext, emptyDeferredAttrContext, types.noWarnings);
         }