graal icon indicating copy to clipboard operation
graal copied to clipboard

[GR-50774] `ByteArrayAccessCloneBenchmark#unsafeCopyMemory` does not use `ARRAY_BYTE_BASE_OFFSET`

Open Marcono1234 opened this issue 1 year ago • 1 comments

Describe the issue The class ByteArrayAccessCloneBenchmark#unsafeCopyMemory uses 0 as offset values for the Unsafe#copyMemory call: https://github.com/oracle/graal/blob/0808c625f86cddea58e24aa925ff615d1f6a4a8f/truffle/src/com.oracle.truffle.api.benchmark/src/com/oracle/truffle/api/benchmark/ByteArrayAccessCloneBenchmark.java#L90

I think this is incorrect; it should instead use Unsafe#ARRAY_BYTE_BASE_OFFSET[^1]. Otherwise the current code actually also copies the array header and misses the last elements. This is not only incorrect behavior, but it might also distort the benchmark since it is accessing a slightly different memory section than all other methods (?).

[^1]: And technically it should maybe also multiply array.length by ARRAY_BYTE_INDEX_SCALE? But since that value is 1 it might not matter much.

Marcono1234 avatar Apr 12 '24 22:04 Marcono1234

Hi @Marcono1234, thank you for sharing this with us! I will share this with our dev team and I will keep you updated.

selhagani avatar Apr 15 '24 15:04 selhagani