Unsafe for array access
Andrew Haley
aph at redhat.com
Fri May 9 08:29:31 UTC 2014
On 05/07/2014 05:15 PM, Vladimir Kozlov wrote:
> Note, we do convert some user's bound check to array's range check. The example is Integer::valueOf():
>
> public static Integer valueOf(int i) {
> if (i >= IntegerCache.low && i <= IntegerCache.high)
> return IntegerCache.cache[i + (-IntegerCache.low)];
> return new Integer(i);
> }
>
> The check is converted to ((i-IntegerCache.low) u< IntegerCache.length)
Did you mean
((i-IntegerCache.low) u< IntegerCache.high)
?
and removed as duplicate of the generated range
> check for the following load.
>
> length = (high - low) + 1
>
> Vladimir
>
> On 5/7/14 8:56 AM, John Rose wrote:
>>> On May 7, 2014, at 4:30 AM, Doug Lea <dl at cs.oswego.edu> wrote:
>>
>>>
>>> Relatedly, it might be be nice to have an intrinsic boundsCheck(array, index)
>>> that could be used in such cases that implemented using the more efficient
>>> (using C): (unsigned)index >= (unsigned)array.length, plus relied on more
>>> efficient VM throw mechanics on failure.
>>
>> We need an intrinsic like this for Arrays 2.0. Might as well do it now, since we have an immediate application.
>>
>> Counterpoint: optimizer can and should generate similar code for plain user written range tests.
>>
>> Advice: Do both, and the intrinsic will give everybody a clearer target to aim for. Unit test the intrinsic optimization, and several similar formulations.
>>
>> – John
>>
More information about the hotspot-compiler-dev
mailing list