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


- `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

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

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

Changes: https://git.openjdk.java.net/jdk/pull/5837/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=5837&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8251513
  Stats: 38 lines in 2 files changed: 3 ins; 12 del; 23 mod
  Patch: https://git.openjdk.java.net/jdk/pull/5837.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/5837/head:pull/5837

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


More information about the hotspot-compiler-dev mailing list