Switch vs if ?

Remi Forax forax at univ-mlv.fr
Wed Jan 17 22:42:15 UTC 2018


> De: "John Rose" <john.r.rose at oracle.com>
> À: "Roland Westrelin" <rwestrel at redhat.com>, "Laurent Bourgès"
> <bourges.laurent at gmail.com>
> Cc: "hotspot compiler" <hotspot-compiler-dev at openjdk.java.net>
> Envoyé: Mercredi 17 Janvier 2018 21:42:15
> Objet: Re: Switch vs if ?

> On Jan 16, 2018, at 6:59 AM, Roland Westrelin < [ mailto:rwestrel at redhat.com |
> rwestrel at redhat.com ] > wrote:

>> I've been working
>> on some profiling support for tableswitch/lookupswitch and that should
>> make it to a future jdk release.

> I'm really glad about that! Here's a relevant bug:
> [ https://bugs.openjdk.java.net/browse/JDK-8143859 |
> https://bugs.openjdk.java.net/browse/JDK-8143859 ]

> Until that stuff is fixed, you might choose to code like this:

> if (…is 80% case…)
> …do 80% stuff…
> else if (…is 10% case …)
> …do 10% stuff…
> else switch (…some key…) {
> …many other cases…
> }

> But…

> What we should be able to write is everything in one
> switch, while the JVM should detect which cases are hot.
> If you think you know what are the hot cases, you could
> emphasize them however you want, e.g., by putting
> them at the top of the switch. So we want to write evenly
> balanced code and get it optimized as if it were written
> as above (unevenly).

i fully agree, 
next we need a method handle combinator for the integer switch for amber. 

> — John

Rémi 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20180117/f4b01d1d/attachment.html>


More information about the hotspot-compiler-dev mailing list