RFR: JDK-8251513: Code around Parse::do_lookupswitch/do_tableswitch should be cleaned up

Roland Westrelin roland at openjdk.java.net
Wed Oct 13 13:42:48 UTC 2021


On Wed, 6 Oct 2021 09:27:15 GMT, Tobias Holenstein <duke at openjdk.java.net> wrote:

> - `default_cnt` can be computed without using a loop: 
> 
> An example of how `defaults` was computed before at parse2.cpp:521-533 with switch labels `-10`, `0`, `10`, `42` and `200`:
> 
> defaults = 0
> defaults += -10 - (-2147483648)
> defaults += 0 - (-10 + 1)
> defaults += 10 - (0 + 1)
> defaults += 42 - (10 + 1) 
> defaults += 200 - (42 + 1)
> defaults += 2147483647 - (200 + 1) + 1
> 
> => `defaults`  = 
> -10 - (-2147483648) + 0 - (-10 + 1) + 10 - (0 + 1) + 42 - (10 + 1) + 200 - (42 + 1) + 2147483647 - (200 + 1) + 1 = 
> 4294967291 = 2147483648 + 2147483648 - 5
> BUT actually `defaults` was : `defaults` = 2147483648 + 2147483648
> 
> The reason has to do with using floats:
> ((float)match_int - (float)prev) == (-(float)prev) is True
> for match_int=-10, prev=-2147483648
> 
> BUT actually `defaults` (2147483648 + 2147483648 - 5) can also be computed without using a loop with `juint defaults = max_juint - len`
> 
> 
> - also made some casts explicit 
> 
> - A lot of casts could be avoided by making `_cnt` in `SwitchRange` a uint. Unfortunately, the Range for the default values of a switch in `do_lookupswitch` calculates the count by scaling the average cnt/label up to cnt/range which needs a float to store an accurate result

That looks good to me.

-------------

Marked as reviewed by roland (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/5837


More information about the hotspot-compiler-dev mailing list