tableswitch does not use an array of offsets
Chuck Rasbold
rasbold at google.com
Wed Mar 27 07:16:14 PDT 2013
The behavior is expected, but the rationale behind it may be lost to
history.
There's a HotSpot flag, -XX:MinJumpTableSize=<NN> that controls the minimum
number of consecutive case branches needed to provoke the creation of a
jump table.
As you've discovered, the default is 18. I'm sure that value had some
empirical backing when it was set (at least six) years ago, but perhaps it
could be differently tuned for today's hardware.
-- Chuck
On Wed, Mar 27, 2013 at 1:56 AM, Yann Le Tallec <ylt at letallec.org> wrote:
> The code below is compiled as a tableswitch bytecode instruction as one
> would expect because the case values are contiguous. However, the JIT
> (Hotspot using JDK/JRE 1.7u17 64 bit on x86/Windows in either -server or
> -client mode) compiles it into a succession of cmp/je/jg.
>
> When adding one more case statement (case 17) to reach a total number of
> 18 case statements, the JIT does compile the switch using an array of
> offsets to calculate the jump.
>
> A micro-benchmark (controlled for compilation, inlining (off), gc) shows
> that adding an additional case statement to the method below (case 17) to
> reach a total of 18 improves performance materially (up to 25% depending on
> how the method is exercised).
>
> Is the decision to *not* use an array of offsets for <18 cases derived
> from profiling? Is that the expected behaviour and what is the underlying
> reason?
>
> Many thanks,
> Yann
>
> static double multiplyByPowerOfTen(final double d, final int exponent)
> {
> switch (exponent) {
> case 0:
> return d;
> case 1:
> return d * 10;
> case 2:
> return d * 100;
> case 3:
> return d * 1000;
> case 4:
> return d * 10000;
> case 5:
> return d * 100000;
> case 6:
> return d * 1000000;
> case 7:
> return d * 10000000;
> case 8:
> return d * 100000000;
> case 9:
> return d * 1000000000;
> case 10:
> return d * 10000000000L;
> case 11:
> return d * 100000000000L;
> case 12:
> return d * 1000000000000L;
> case 13:
> return d * 10000000000000L;
> case 14:
> return d * 100000000000000L;
> case 15:
> return d * 1000000000000000L;
> case 16:
> return d * 10000000000000000L;
> default:
> throw new RuntimeException("Unhandled power of ten " +
> exponent);
> }
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20130327/4863bc64/attachment-0001.html
More information about the hotspot-compiler-dev
mailing list