RFR: 8061472 String.format in DeferredAttr.DeferredTypeMap constructor leads to excessive object creation

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Dec 19 16:10:40 UTC 2014


Looks good to me!

Thanks
Maurizio

On 19/12/14 14:52, Joel Borggrén-Franck wrote:
> Hi Maurizio,
>
>> On 18 dec 2014, at 23:08, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>>
>> The fix looks ok - but it feels a bit odd for the AttrMode (which is a general enum) to be returning the name including the 'deferredTypeMap' string - as that's another class. Maybe a static 'EnumMap<AttrMode, String>' inside the DeferredAttrMap class would more encapsulated?
>>
> You are right, new patch inline.
>
> cheers
> /Joel
>
> diff -r 47926c290355 src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Wed Dec 17 12:48:04 2014 -0800
> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Fri Dec 19 12:11:56 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);
>           }



More information about the compiler-dev mailing list