On Fri, 7 Jul 2023 23:42:51 GMT, 温绍锦 <d...@openjdk.org> wrote:

>> src/java.base/share/classes/java/util/UUID.java line 475:
>> 
>>> 473:         long msb = mostSigBits;
>>> 474:         byte[] buf = new byte[36];
>>> 475:         UNSAFE.putLongUnaligned(
>> 
>> I understood that since UUID was not used during startup, that using 
>> VarHandles is the preferred abstraction.
>
> Using VarHandle will be 10% slower than using Unsafe directly, I haven't 
> found the reason yet

I believe it’s because `VarHandle`s do bounds checking:
https://github.com/openjdk/jdk/blob/581f90e242b8a943215a223189d171b7ede37785/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template#L113-L116
 
https://github.com/openjdk/jdk/blob/581f90e242b8a943215a223189d171b7ede37785/src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template#L144-L161

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14745#discussion_r1257510755

Reply via email to