Remove the assert in Integer.valueOf()
Rémi Forax
forax at univ-mlv.fr
Fri Apr 27 22:42:48 UTC 2012
On 04/27/2012 02:14 PM, Ulf Zibis wrote:
> Am 23.04.2012 19:35, schrieb Rémi Forax:
>> Hi guys,
>> I've found a case where assert is harmful because it doesn't
>> play well with Hotspot inlining heuristic.
>> [...]
>> I think it's a good idea to comment this assert.
>
Hi Ulf,
> While you are there:
> IntegerCache.cache/high/low are static final, so should be named
> _upper case_.
Not done because the system property is also spelled in lower case.
>
> Another optimization:
> public static Integer valueOf(int i) {
> if (i >= 0) {
> if (i <= IntegerCache.HIGH)
> return IntegerCache.POS[i];
> } else {
> if (i >= IntegerCache.LOW)
> return IntegerCache.NEG[~i];
> }
> return new Integer(i);
> }
>
Can you explain a little bit more why it's more efficient ?
Given that low and high are constant for the JIT, I'm not sure the
current code
do bounds checking at all.
>
> -Ulf
>
Rémi
More information about the core-libs-dev
mailing list