RFR: 8141678: sun.invoke.util.Wrapper eagerly initializes all integral type caches

Aleksey Shipilev aleksey.shipilev at oracle.com
Mon Nov 9 11:27:53 UTC 2015

On 11/09/2015 02:13 PM, Claes Redestad wrote:
>> Can we avoid shared secrets by doing the following?
>> @HotSpotIntrinsicCandidate
>> public static Byte valueOf(byte b) {
>>      if (b == 0) return ZERO;
>>      final int offset = 128;
>>      return ByteCache.cache[(int)b + offset];
>> }
> I considered this and would like to avoid it since it has potential to
> regress the hot path. It's quite possible it'll have no measurable
> effect on any benchmarks we have, but I'm still more comfortable with
> having somewhat sketchy code warts in initialization code that will only
> run once.

I agree with Claes here: let's not touch the valueOf hotpath.

Granted, valueOf would be intrinsified by most compilers, and that zero
check dropped, but that may lead to other slowdowns during the initial
startup when optimized code is not available yet. Plus, I am
uncomfortable with a potential desync between ByteCache.cache[0 +
offset] value and ZERO.


More information about the core-libs-dev mailing list