Unsafe.{get,put}-X-Unaligned; Efficient array comparison intrinsics

Remi Forax forax at univ-mlv.fr
Sun Mar 8 23:57:45 UTC 2015


On 03/09/2015 12:32 AM, David Holmes wrote:
> On 9/03/2015 9:21 AM, Remi Forax wrote:
>>
>> On 03/09/2015 12:11 AM, David Holmes wrote:
>>> On 7/03/2015 4:50 AM, Andrew Haley wrote:
>>>> I've tried to so everything I've been asked.  If this version passes
>>>> muster with everyone I'll Javadoc all the public methods and fields
>>>> and put it up for RFA next week.
>>>>
>>>> I guess it's going to need a lot of testing and security analysis.
>>>>
>>>> I added versions of all {put,get} methods with the boolean bigEndian
>>>> argument.  This makes HeapByteBuffer much cleaner, and it does not
>>>> need to know the machine endianness at all.  I hope that's OK.
>>>>
>>>> Andrew.
>>>>
>>>>
>>>> http://cr.openjdk.java.net/~aph/unaligned.hotspot.4/
>>>> http://cr.openjdk.java.net/~aph/unaligned.jdk.4/
>>>
>>> I think it is cleaner and more efficient if Unsafe maintains BE as an
>>> instance variable (initialized at construction) and that isBigEndian()
>>> simply returns that. The native check should only need to be called
>>> once in the lifetime of the VM.
>>>
>>> David
>>>
>>
>> BE doesn't need to be an instance, method of Unsafe are instance methods
>> just to enforce security,
>> you can not call them if you don"t have an instance of Unsafe (and
>> getUnsafe() does the security check).
>>
>> BE is private so it doesn't have to be an instance field it can be
>> static field.
>
> Yes it could but why should it be? You have a singleton instance with 
> all instance methods, so cached state should be in an instance field 
> not a static one.

because the instance of Unsafe is a kind of security token (you get the 
instance once you have pass the security check) and starting to add 
instance field to it will obscure its meaning.

>
>> And I agree with you that the native isBigEndian() should be called once
>> in the lifetime of the VM.
>>
>> so the idea is to write:
>>
>> public boolean isBigEndian() {
>>    return BE;
>> }
>> private static final boolean BE = isBigEndian0();
>>
>> private static native boolean isBigEndian0();
>
> Other than the static parts that is what I was suggesting :)
>
> Cheers,
> David

cheers,
Rémi




More information about the core-libs-dev mailing list