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

Tobias Holenstein github.com+71546117+tobiasholenstein at openjdk.java.net
Thu Oct 7 13:31:27 UTC 2021


On Wed, 6 Oct 2021 09:27:15 GMT, Tobias Holenstein <github.com+71546117+tobiasholenstein at openjdk.org> 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

in `do_lookupswitch` the ranges for the defaults values have very accurate value (by taking the average). Whereas the  ranges for the defaults values in `do_tableswitch` are just calculated by taking `profile->default_count() / 2` for the lower and upper default ranges. But this can be very imbalanced if lower and upper range for the default have very different size. Should this be changed?

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

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


More information about the hotspot-compiler-dev mailing list