From 2cc2a9537def1d305717c746c8a0c892a0b6d4af Mon Sep 17 00:00:00 2001 From: lhu Date: Tue, 15 Oct 2024 11:46:51 -0400 Subject: [PATCH] Update test code for off-heap feature 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 --- .../org/openj9/test/unsafe/TestUnsafeCopyMemory.java | 7 ++++++- .../org/openj9/test/unsafe/TestUnsafeCopyMemory.java | 7 ++++++- .../VM_Test/src/j9vm/test/unsafe/UnsafeCopyMemoryTest.java | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) 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);