Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(0.48) Use unsigned indexes for unsafe array access #20157

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions runtime/oti/UnsafeAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class VM_UnsafeAPI
return 0 == ((offset - arrayBase(currentThread)) % ((UDATA)1 << logElementSize));
}

static VMINLINE I_32
static VMINLINE UDATA
convertOffsetToIndex(J9VMThread *currentThread, UDATA offset, UDATA logElementSize)
{
return (I_32)((offset - arrayBase(currentThread)) >> logElementSize);
return (UDATA)((offset - arrayBase(currentThread)) >> logElementSize);
}

static VMINLINE I_32
Expand Down Expand Up @@ -139,7 +139,7 @@ class VM_UnsafeAPI
/* Array access */
if (offsetIsAlignedArrayIndex(currentThread, offset, logElementSize)) {
/* Aligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
switch (logElementSize) {
case 0:
if (isSigned) {
Expand All @@ -165,7 +165,7 @@ class VM_UnsafeAPI
}
} else {
/* Unaligned array access - unreachable for logElementSize == 0 */
I_32 index = convertOffsetToIndex(currentThread, offset, 0);
UDATA index = convertOffsetToIndex(currentThread, offset, 0);
if (1 == logElementSize) {
I_16 temp = 0;
VM_ArrayCopyHelpers::memcpyFromArray(currentThread, object, (UDATA)0, index, (I_32)sizeof(temp), (void*)&temp);
Expand Down Expand Up @@ -210,7 +210,7 @@ class VM_UnsafeAPI
/* Array access */
if (offsetIsAlignedArrayIndex(currentThread, offset, logElementSize)) {
/* Aligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
switch (logElementSize) {
case 0:
if (isSigned) {
Expand All @@ -236,7 +236,7 @@ class VM_UnsafeAPI
}
} else {
/* Unaligned array access - unreachable for logElementSize == 0 */
I_32 index = convertOffsetToIndex(currentThread, offset, 0);
UDATA index = convertOffsetToIndex(currentThread, offset, 0);
if (1 == logElementSize) {
I_16 temp = (I_16)value;
VM_ArrayCopyHelpers::memcpyToArray(currentThread, object, (UDATA)0, index, (I_32)sizeof(temp), (void*)&temp);
Expand Down Expand Up @@ -272,11 +272,11 @@ class VM_UnsafeAPI
/* Array access */
if (offsetIsAlignedArrayIndex(currentThread, offset, logElementSize)) {
/* Aligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
value = objectAccessBarrier->inlineIndexableObjectReadI64(currentThread, object, index, isVolatile);
} else {
/* Unaligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, 0);
UDATA index = convertOffsetToIndex(currentThread, offset, 0);
VM_ArrayCopyHelpers::memcpyFromArray(currentThread, object, (UDATA)0, index, (I_32)sizeof(value), (void*)&value); }
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
/* Static field */
Expand Down Expand Up @@ -305,11 +305,11 @@ class VM_UnsafeAPI
/* Array access */
if (offsetIsAlignedArrayIndex(currentThread, offset, logElementSize)) {
/* Aligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
objectAccessBarrier->inlineIndexableObjectStoreI64(currentThread, object, index, value, isVolatile);
} else {
/* Unaligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, 0);
UDATA index = convertOffsetToIndex(currentThread, offset, 0);
VM_ArrayCopyHelpers::memcpyToArray(currentThread, object, (UDATA)0, index, (I_32)sizeof(value), (void*)&value);
}
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
Expand Down Expand Up @@ -554,7 +554,7 @@ class VM_UnsafeAPI
} else {
if (VM_VMHelpers::objectIsArray(currentThread, object)) {
/* Aligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
result = objectAccessBarrier->inlineIndexableObjectCompareAndSwapU64(currentThread, object, index, compareValue, swapValue, true);
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
/* Static field */
Expand Down Expand Up @@ -583,7 +583,7 @@ class VM_UnsafeAPI
} else {
if (VM_VMHelpers::objectIsArray(currentThread, object)) {
/* Aligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
result = objectAccessBarrier->inlineIndexableObjectCompareAndSwapU32(currentThread, object, index, compareValue, swapValue, true);
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
/* Static field */
Expand Down Expand Up @@ -641,7 +641,7 @@ class VM_UnsafeAPI
} else {
if (VM_VMHelpers::objectIsArray(currentThread, object)) {
/* Aligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
result = objectAccessBarrier->inlineIndexableObjectCompareAndExchangeU32(currentThread, object, index, compareValue, swapValue, true);
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
/* Static field */
Expand Down Expand Up @@ -672,7 +672,7 @@ class VM_UnsafeAPI
} else {
if (VM_VMHelpers::objectIsArray(currentThread, object)) {
/* Aligned array access */
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
result = objectAccessBarrier->inlineIndexableObjectCompareAndExchangeU64(currentThread, object, index, compareValue, swapValue, true);
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
/* Static field */
Expand Down