RFR: 8216403: Allocate fewer EnumSets in JavacFileManager#list

Claes Redestad claes.redestad at oracle.com
Wed Jan 9 17:04:50 UTC 2019



On 2019-01-09 17:50, Liam Miller-Cushon wrote:
> On Wed, Jan 9, 2019 at 1:42 AM Claes Redestad <claes.redestad at oracle.com 
> <mailto:claes.redestad at oracle.com>> wrote:
> 
>     not really a langtools reviewer, but I generally avoid using raw
>     static EnumSets due their mutable nature (not saying there's a bug
>     here - just that we should consider all possible futures and treat them
>     kindly).
> 
>     Set.of() / Set.of(FOLLOW_LINKS) is a compact, performant and safer
>     alternative.
> 
> 
> Done, thanks: http://cr.openjdk.java.net/~cushon/8216403/webrev.01/ (I 
> also gave 'sourceOrClass' the same treatment.)

Looks good!

> I used EnumSet initially because it usually performs better than 
> general-purpose sets, but I suppose it doesn't have much of an advantage 
> over Set.of for a one-element set.

Right, EnumSet is hard to beat in the general case, but the Set/List.of
implementations with 0-2 elements should behave similarly on artificial
microbenchmarks. As an added bonus their immutability (and @Stable:ness)
means they will be amenable to constant folding by the JIT.

Thanks!

/Claes


More information about the compiler-dev mailing list