Skip to content

Commit 3be5a9b

Browse files
authored
Merge pull request #20157 from tajila/pmr
(0.48) Use unsigned indexes for unsafe array access
2 parents f9be535 + 04750a2 commit 3be5a9b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

runtime/oti/UnsafeAPI.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ class VM_UnsafeAPI
9999
return 0 == ((offset - arrayBase(currentThread)) % ((UDATA)1 << logElementSize));
100100
}
101101

102-
static VMINLINE I_32
102+
static VMINLINE UDATA
103103
convertOffsetToIndex(J9VMThread *currentThread, UDATA offset, UDATA logElementSize)
104104
{
105-
return (I_32)((offset - arrayBase(currentThread)) >> logElementSize);
105+
return (UDATA)((offset - arrayBase(currentThread)) >> logElementSize);
106106
}
107107

108108
static VMINLINE I_32
@@ -139,7 +139,7 @@ class VM_UnsafeAPI
139139
/* Array access */
140140
if (offsetIsAlignedArrayIndex(currentThread, offset, logElementSize)) {
141141
/* Aligned array access */
142-
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
142+
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
143143
switch (logElementSize) {
144144
case 0:
145145
if (isSigned) {
@@ -165,7 +165,7 @@ class VM_UnsafeAPI
165165
}
166166
} else {
167167
/* Unaligned array access - unreachable for logElementSize == 0 */
168-
I_32 index = convertOffsetToIndex(currentThread, offset, 0);
168+
UDATA index = convertOffsetToIndex(currentThread, offset, 0);
169169
if (1 == logElementSize) {
170170
I_16 temp = 0;
171171
VM_ArrayCopyHelpers::memcpyFromArray(currentThread, object, (UDATA)0, index, (I_32)sizeof(temp), (void*)&temp);
@@ -210,7 +210,7 @@ class VM_UnsafeAPI
210210
/* Array access */
211211
if (offsetIsAlignedArrayIndex(currentThread, offset, logElementSize)) {
212212
/* Aligned array access */
213-
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
213+
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
214214
switch (logElementSize) {
215215
case 0:
216216
if (isSigned) {
@@ -236,7 +236,7 @@ class VM_UnsafeAPI
236236
}
237237
} else {
238238
/* Unaligned array access - unreachable for logElementSize == 0 */
239-
I_32 index = convertOffsetToIndex(currentThread, offset, 0);
239+
UDATA index = convertOffsetToIndex(currentThread, offset, 0);
240240
if (1 == logElementSize) {
241241
I_16 temp = (I_16)value;
242242
VM_ArrayCopyHelpers::memcpyToArray(currentThread, object, (UDATA)0, index, (I_32)sizeof(temp), (void*)&temp);
@@ -272,11 +272,11 @@ class VM_UnsafeAPI
272272
/* Array access */
273273
if (offsetIsAlignedArrayIndex(currentThread, offset, logElementSize)) {
274274
/* Aligned array access */
275-
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
275+
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
276276
value = objectAccessBarrier->inlineIndexableObjectReadI64(currentThread, object, index, isVolatile);
277277
} else {
278278
/* Unaligned array access */
279-
I_32 index = convertOffsetToIndex(currentThread, offset, 0);
279+
UDATA index = convertOffsetToIndex(currentThread, offset, 0);
280280
VM_ArrayCopyHelpers::memcpyFromArray(currentThread, object, (UDATA)0, index, (I_32)sizeof(value), (void*)&value); }
281281
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
282282
/* Static field */
@@ -305,11 +305,11 @@ class VM_UnsafeAPI
305305
/* Array access */
306306
if (offsetIsAlignedArrayIndex(currentThread, offset, logElementSize)) {
307307
/* Aligned array access */
308-
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
308+
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
309309
objectAccessBarrier->inlineIndexableObjectStoreI64(currentThread, object, index, value, isVolatile);
310310
} else {
311311
/* Unaligned array access */
312-
I_32 index = convertOffsetToIndex(currentThread, offset, 0);
312+
UDATA index = convertOffsetToIndex(currentThread, offset, 0);
313313
VM_ArrayCopyHelpers::memcpyToArray(currentThread, object, (UDATA)0, index, (I_32)sizeof(value), (void*)&value);
314314
}
315315
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
@@ -554,7 +554,7 @@ class VM_UnsafeAPI
554554
} else {
555555
if (VM_VMHelpers::objectIsArray(currentThread, object)) {
556556
/* Aligned array access */
557-
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
557+
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
558558
result = objectAccessBarrier->inlineIndexableObjectCompareAndSwapU64(currentThread, object, index, compareValue, swapValue, true);
559559
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
560560
/* Static field */
@@ -583,7 +583,7 @@ class VM_UnsafeAPI
583583
} else {
584584
if (VM_VMHelpers::objectIsArray(currentThread, object)) {
585585
/* Aligned array access */
586-
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
586+
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
587587
result = objectAccessBarrier->inlineIndexableObjectCompareAndSwapU32(currentThread, object, index, compareValue, swapValue, true);
588588
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
589589
/* Static field */
@@ -641,7 +641,7 @@ class VM_UnsafeAPI
641641
} else {
642642
if (VM_VMHelpers::objectIsArray(currentThread, object)) {
643643
/* Aligned array access */
644-
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
644+
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
645645
result = objectAccessBarrier->inlineIndexableObjectCompareAndExchangeU32(currentThread, object, index, compareValue, swapValue, true);
646646
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
647647
/* Static field */
@@ -672,7 +672,7 @@ class VM_UnsafeAPI
672672
} else {
673673
if (VM_VMHelpers::objectIsArray(currentThread, object)) {
674674
/* Aligned array access */
675-
I_32 index = convertOffsetToIndex(currentThread, offset, logElementSize);
675+
UDATA index = convertOffsetToIndex(currentThread, offset, logElementSize);
676676
result = objectAccessBarrier->inlineIndexableObjectCompareAndExchangeU64(currentThread, object, index, compareValue, swapValue, true);
677677
} else if (offset & J9_SUN_STATIC_FIELD_OFFSET_TAG) {
678678
/* Static field */

0 commit comments

Comments
 (0)