[10] RFR: 8184665: Skip name and alias checks for standard Charsets
forax at univ-mlv.fr
forax at univ-mlv.fr
Fri Jul 14 19:30:04 UTC 2017
----- Mail original -----
> De: "Claes Redestad" <claes.redestad at oracle.com>
> À: "Roger Riggs" <Roger.Riggs at oracle.com>, "Remi Forax" <forax at univ-mlv.fr>
> Cc: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Vendredi 14 Juillet 2017 20:40:25
> Objet: Re: [10] RFR: 8184665: Skip name and alias checks for standard Charsets
> Hi,
>
> in this case the code isn't really fragile, since two equal but not
> identical Strings will end up with the same Charset, so there's no
> *real* surprises to be had (only a tiny performance loss that isn't
> really consequential except for startup).
>
> So: I did use == mostly to be consistent with StandardCharsets, although
> it is also a gain by a few bytecodes less executed on startup. We could
> change to equals in both places as well if consistency is all that
> matters, but since this is established behavior I'd rather use ==
> in the new place, and add a comment about why it's valid. Reasonable?
yes,
i agree with Roger that this 'optimization' usually bites you in the back when you start to update some parts of the code and not others.
The fact that the Charset code uses == is a kind of historical glitch and it's not that awful if tested,
nevertheless if in the future someone what to change == by equals in these two codes, my gut feeling is that there are other Charset related codes that uses ==, so an audit should be done to change all the codes at once.
>
> I'll add a regression test to test these standard Charsets are kept
> well-behaved, as per Sherman's comment.
>
> Thanks!
>
> /Claes
cheers,
Rémi
>
> On 2017-07-14 20:08, Roger Riggs wrote:
>> Hi Remi,
>>
>> Point taken about consistency.
>> I'm concerned about code that is unnecessarily fragile due to
>> unnecessary and unexpected optimizations.
>>
>> $.02, Roger
>>
>>
>> On 7/14/2017 2:01 PM, Remi Forax wrote:
>>> I do not like the equals in the constructor of Charset given that in
>>> StandardCharsets, == is used.
>>>
>>> I think the constructor of Charset should use == and a comment should
>>> be added explaining why it's valid to use == like in StandardCharsets.
>>>
>>> cheers,
>>> Rémi
>>>
>>> ----- Mail original -----
>>>> De: "Roger Riggs" <Roger.Riggs at Oracle.com>
>>>> À: "core-libs-dev" <core-libs-dev at openjdk.java.net>
>>>> Envoyé: Vendredi 14 Juillet 2017 19:12:09
>>>> Objet: Re: [10] RFR: 8184665: Skip name and alias checks for
>>>> standard Charsets
>>>> +1,
>>>>
>>>> Thanks, Roger
>>>>
>>>> On 7/14/2017 1:03 PM, Claes Redestad wrote:
>>>>> Hi Roger,
>>>>>
>>>>> On 2017-07-14 18:25, Roger Riggs wrote:
>>>>>> Hi Claes,
>>>>>>
>>>>>> Using == with references always looks a bit suspicious in the source
>>>>>> code, especially strings.
>>>>>> Since the first thing in equals() is the identity check, I'd suggest
>>>>>> using .equals for the comparisons.
>>>>> Sure, there's no significant performance difference, even in
>>>>> interpreted mode:
>>>>>
>>>>> http://cr.openjdk.java.net/~redestad/8184665/jdk.01/
>>>>>
>>>>> /Claes
More information about the core-libs-dev
mailing list