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

Tobias Holenstein duke at openjdk.java.net
Mon Oct 18 06:56:53 UTC 2021


On Wed, 13 Oct 2021 13:40:04 GMT, Roland Westrelin <roland 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
>
> That looks good to me.

@rwestrel and @TobiHartmann thanks for the reviews!

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

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


More information about the hotspot-compiler-dev mailing list