RFR: 8310335 JFR: Modernize collections and switch statements

Erik Gahlin egahlin at openjdk.org
Tue Jun 20 14:39:04 UTC 2023


On Tue, 20 Jun 2023 06:47:58 GMT, Hannes Greule <duke at openjdk.org> wrote:

>> Could I have a review of an update to the jfr modules to use more recent APIs and language constructs.
>> 
>> Testing: test/jdk/jdk/jfr
>> 
>> Thanks
>> Erik
>
> src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordedObject.java line 505:
> 
>> 503:             return b;
>> 504:         }
>> 505:         if (o instanceof UnsignedValue unsigned) {
> 
> I think this can be further simplified, e.g.,
> 
>     return switch(o) {
>         case Short s -> s;
>         case Byte b -> b;
>         case UnsignedValue(Short s) -> s;
>         case UnsignedValue(Byte b) -> (short) Byte.toUnsignedInt(b);
>         case null, default -> throw newIllegalArgumentException(name, "short");
>     };
> 
> What do you think?

I thought about having everything in a switch statements, not just for this method, but I wasn't sure about performance. 99% of the calls will probably be trapped in the first instanceof check. Users are likely to use the method matching the datatype. A fast path might pay off.

I did some measurements and I couldn't spot a difference, so I will change to one  switch statement. Thanks.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14547#discussion_r1235367302


More information about the hotspot-jfr-dev mailing list