RFR: 8332522: SwitchBootstraps::mappedEnumLookup constructs unused array
Claes Redestad
redestad at openjdk.org
Wed Jun 26 18:45:11 UTC 2024
On Wed, 26 Jun 2024 13:02:51 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> test/micro/org/openjdk/bench/java/lang/runtime/SwitchEnum.java line 57:
>>
>>> 55: for (E e : inputs) {
>>> 56: sum += switch (e) {
>>> 57: case null -> -1;
>>
>> As this `null` case adds a case relative to the `-Traditional` test then maybe removing one of the `E0, E1, ...` cases would make the test a little bit more apples-to-apples?
>
> Using `case null -> ` will push javac to use the new code, but all switches do some kind of null check for the selector value. The difference is that if there's no `case null`, there will be `Objects.requireNonNull` generated for the selector value (which will throw an NPE if the value is `null`), while here it will jump to the given case.
>
> So, `case null` does not have the same weight as a normal case, so I don't think it would be fair to remove a full case to compensate for it.
Fair enough, and I guess ~1.6ns/op is reasonable overhead for the added semantics.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19906#discussion_r1655364063
More information about the core-libs-dev
mailing list