on javac flags

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Sep 26 15:34:14 UTC 2018


> Three years ago, i've done the opposite transformation Set<Flat> to long for a compiler far less complex than javac,
> the main issues when you have a Set<Flags> are:
> - the JumboEnumSet (more than 64 flags) is quite slow because it uses an array internally,
> - it's very easy to have more than two representations for a callsite, and at that point your flag check code goes megamorphic.
> - even using an interface makes the code slow because an invokevirtual means there is a check in the assembly code, each additional checks in a tight loop is visible in term of perf.
>
> The last two points can be easily hidden when doing JMH tests.
>
> For dealing with the fact that there are more than 64 flags, i've used 2 longs, one for the public API, one for the internal code, but since another developer change the code to go back to use a 64 bits by reusing the bits (because of the memory consumption).
>
> What you are describing is the kind of perfect use case for a value type. So we know the perfect solution, it's just that you can not using it yet.
+1 on that front. And thanks for sharing your thoughts. As I said in a 
previous email, these are some ideas that we discussed internally but 
never committed to too seriously (in part for the reasons you describe).

Regarding your performance notes, for (1) I think I'm not too worried 
about JumboEnumSet being slow. Of course (2) is a much bigger problem, 
thanks for reminding me of that. As for (3) I would suspect that in case 
of a tight loop the JIT should be able to hoist the check out of the 
loop - but maybe you refer to cases that are not 'hot' enough to trigger 
the JIT (which I agree are problematic, given a compiler rarely takes 
advantage of advanced JIT opts, as its too short lived).

Maurizio
>
>> Maurizio
> Rémi
>
>> [1] -
>> http://mail.openjdk.java.net/pipermail/compiler-dev/2018-September/012470.html
>> [2] -
>> http://hg.openjdk.java.net/jdk/jdk/file/tip/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java#l314
>> [3] -
>> http://hg.openjdk.java.net/jdk/jdk/file/tip/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java#l320



More information about the compiler-dev mailing list