RFR(S): 8067471: Use private static final char[0] for empty Strings
Aleksey Shipilev
aleksey.shipilev at oracle.com
Wed Dec 17 18:10:34 UTC 2014
On 17.12.2014 18:58, Claes Redestad wrote:
> On 2014-12-17 11:22, Lev Priima wrote:
>> Please review space optimization in no args String constructor.
>> Originally, it was already rejected once by suggestion in
>> http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-May/010300.html
>> w/o formal justification of pros and contras. And enhancement was
>> requested again by Nathan Reynolds.
>>
>> Issue: https://bugs.openjdk.java.net/browse/JDK-8067471
>> Patch: http://cr.openjdk.java.net/~lpriima/8067471/webrev.00/
I am OK with this change pending we understand the performance impact a
little better. Please do benchmarks.
> Could this have some obscure security implications, such as the ability
> to lock up some subsystem via retrieving and synchronizing on the shared
> new String().value? I guess not, for practical purposes.
This would be an issue if we published String.value directly, but we don't.
> I guess it could also be written:
>
> public String() {
> this.value = "".value;
> }
>
> ... which would saves some byte code and should avoid having to allocate
> a distinct object for this.
Oh, I like this trick, given "" is probably already in constant pool for
some other reason. However, there is an additional dereference. We need
a targeted nanobenchmark to properly quantify the costs for either variant.
-Aleksey.
More information about the core-libs-dev
mailing list