RFR: 8310843: Reimplement ByteArray and ByteArrayLittleEndian with Unsafe [v2]
Shaojin Wen
duke at openjdk.org
Mon Jun 10 13:58:13 UTC 2024
On Mon, 10 Jun 2024 03:51:40 GMT, Glavo <duke at openjdk.org> wrote:
>> Things have changed since https://github.com/openjdk/jdk/pull/14636 was closed, so let me reopen it.
>>
>> https://github.com/openjdk/jdk/pull/15386 confirmed that `VarHandle` in BALE caused a startup regression. In order to not have any more revert patches, it makes sense to optimize BALE.
>>
>> The optimization of https://github.com/openjdk/jdk/pull/16245 allows the traditional expression to have good performance, but BA and BALE save us from having to copy these lengthy expressions everywhere. So it makes sense to keep them.
>>
>> Now here's the question, should I rewrite this PR without `Unsafe`? I'll do some research (e.g. does `Unsafe` have better performance during warmup?), but I'd also like to take some advice.
>
> Glavo has updated the pull request incrementally with one additional commit since the last revision:
>
> update copyright
#16245 combining values into larger store, Instead of using Unsafe, can we implement it as follows, similar to the early versions of java.nio.Bits?
class ByteArrayLittleEndian {
// ...
public static void setInt(byte[] array, int offset, int value) {
array[offset ] = (byte) value;
array[offset + 1] = (byte) (value >> 8);
array[offset + 2] = (byte) (value >> 16);
array[offset + 3] = (byte) (value >> 24);
}
public static void setLong(byte[] bytes, int off, long value) {
array[offset] = (byte) value;
array[offset + 1] = (byte) (value >> 8);
array[offset + 2] = (byte) (value >> 16);
array[offset + 3] = (byte) (value >> 24);
array[offset + 4] = (byte) (value >> 32);
array[offset + 5] = (byte) (value >> 40);
array[offset + 6] = (byte) (value >> 48);
array[offset + 7] = (byte) (value >> 56);
}
// ...
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19616#issuecomment-2158447800
More information about the core-libs-dev
mailing list