diff --git a/test/functional/UnsafeTest/src_80/org/openj9/test/unsafe/TestUnsafeCopyMemory.java b/test/functional/UnsafeTest/src_80/org/openj9/test/unsafe/TestUnsafeCopyMemory.java index 4b2153e385a..fde780c103d 100644 --- a/test/functional/UnsafeTest/src_80/org/openj9/test/unsafe/TestUnsafeCopyMemory.java +++ b/test/functional/UnsafeTest/src_80/org/openj9/test/unsafe/TestUnsafeCopyMemory.java @@ -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) { diff --git a/test/functional/UnsafeTest/src_90/org/openj9/test/unsafe/TestUnsafeCopyMemory.java b/test/functional/UnsafeTest/src_90/org/openj9/test/unsafe/TestUnsafeCopyMemory.java index 2dcca9d5ce6..60c0e5801ce 100644 --- a/test/functional/UnsafeTest/src_90/org/openj9/test/unsafe/TestUnsafeCopyMemory.java +++ b/test/functional/UnsafeTest/src_90/org/openj9/test/unsafe/TestUnsafeCopyMemory.java @@ -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) { diff --git a/test/functional/VM_Test/src/j9vm/test/unsafe/UnsafeCopyMemoryTest.java b/test/functional/VM_Test/src/j9vm/test/unsafe/UnsafeCopyMemoryTest.java index a3ad48b1e27..54e110e8c12 100644 --- a/test/functional/VM_Test/src/j9vm/test/unsafe/UnsafeCopyMemoryTest.java +++ b/test/functional/VM_Test/src/j9vm/test/unsafe/UnsafeCopyMemoryTest.java @@ -390,7 +390,12 @@ public 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) { long memoryPointer = myUnsafe.allocateMemory(maxNumBytes);