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

Tobias Holenstein duke at openjdk.java.net
Mon Oct 18 07:36:58 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

This pull request has now been integrated.

Changeset: ebb1363e
Author:    Tobias Holenstein <tobias.holenstein at oracle.com>
Committer: Tobias Hartmann <thartmann at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/ebb1363e5d6b47daf1badad93490580fedcb0572
Stats:     38 lines in 2 files changed: 3 ins; 12 del; 23 mod

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

Reviewed-by: roland, thartmann

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

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


More information about the hotspot-compiler-dev mailing list