Skip to content

Commit

Permalink
Update java9above unsafe test for off-heap case
Browse files Browse the repository at this point in the history
In TestUnsafeCopyMemory.testCopyLargeArrayIntoRawMemory(),
arrayBaseOffset has been used to generate the arbitrary arrayOffsets for
copy, the original test assume that arrayBaseOffset is positive number(
array header size), but for off-heap enabled case arrayBaseOffset =0,
which could cause negative offset for testing copy(trigger exceptions),
update the test code to avoid negative offset for copying.

Signed-off-by: lhu <[email protected]>
  • Loading branch information
LinHu2016 committed Dec 2, 2024
1 parent 735ab88 commit 66ecf39
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,12 @@ private void testCopyLargeArrayIntoRawMemory(Class arrayClass) {
Array.setByte(array, i, (byte) (i % Byte.SIZE));
}

for (long arrayOffset = baseOffset; arrayOffset < (baseOffset + maxNumBytes); arrayOffset = arrayOffset * 11 - 1) {
/*
For off-heap eanbled case initial arrayOffset would be 0 (baseOffset=0),
cause the next arrayOffset in loop become to negative (arrayOffset*11-1),
update logic for the next arrayOffset to avoid negative offset test case.
*/
for (long arrayOffset = baseOffset; arrayOffset < (baseOffset + maxNumBytes); arrayOffset = ((arrayOffset==0) ? 16 : arrayOffset) * 11 - 1 ) {
long maxNumBytesLeft = ((baseOffset + maxNumBytes) - arrayOffset);
for (long numBytesToCopy = 1; numBytesToCopy < maxNumBytesLeft; numBytesToCopy = (numBytesToCopy + 1)
* numBytesToCopy) {
Expand Down

0 comments on commit 66ecf39

Please sign in to comment.