Skip to content

Commit

Permalink
Fix stackwalker calculation of object displacement for Offheap
Browse files Browse the repository at this point in the history
In walkJITFrameSlotsForInternalPointers(), a displacement of data is
calculated between an array object before and after it is moved.
Currently, when offheap is enabled, this displacement is calculated as the
difference between the dataAddr pointers of the new and old locations.
However, because the src object may be overwritten during sliding object
movement, it is not safe to read its contents, such as the dataAddr
pointer.

Thus, this contribution modifies how the stackwalker calculates
displacement when offheap allocation is enabled such that:
- if the array data is adjacent to the array header (i.e.: dataAddr ==
  pinningArrayAddr + sizeofHeader), calculate the displacement as dst -
  src
- otherwise, set displacement to 0

Signed-off-by: midronij <[email protected]>
  • Loading branch information
midronij committed Nov 18, 2024
1 parent 3d719d4 commit bdc9592
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions runtime/compiler/runtime/MethodMetaData.c
Original file line number Diff line number Diff line change
Expand Up @@ -1403,24 +1403,19 @@ void walkJITFrameSlotsForInternalPointers(J9StackWalkState * walkState, U_8 **
J9Object ** currPinningArrayCursor = (J9Object **) (((U_8 *) walkState->bp) + (offsetOfFirstInternalPtr + (((U_16) currPinningArrayIndex * sizeof(UDATA)))));
J9Object *oldPinningArrayAddress = *((J9Object **) currPinningArrayCursor);
J9Object * newPinningArrayAddress;
void *oldDataAddr = 0, *newDataAddr = 0;
if (offHeapAllocationEnabled && oldPinningArrayAddress)
oldDataAddr = walkState->walkThread->javaVM->memoryManagerFunctions->j9gc_objaccess_getArrayObjectDataAddress(walkState->walkThread, (J9IndexableObject*)oldPinningArrayAddress);
IDATA displacement = 0;


#ifdef J9VM_INTERP_STACKWALK_TRACING
swPrintf(walkState, 6, "Before object slot walk &address : %p address : %p bp %p offset of first internal ptr %d\n", currPinningArrayCursor, oldPinningArrayAddress, walkState->bp, offsetOfFirstInternalPtr);
#endif
walkState->objectSlotWalkFunction(walkState->walkThread, walkState, currPinningArrayCursor, currPinningArrayCursor);
newPinningArrayAddress = *((J9Object **) currPinningArrayCursor);
if (offHeapAllocationEnabled && newPinningArrayAddress)
{
newDataAddr = walkState->walkThread->javaVM->memoryManagerFunctions->j9gc_objaccess_getArrayObjectDataAddress(walkState->walkThread, (J9IndexableObject*)newPinningArrayAddress);
displacement = (IDATA) (((UDATA)newDataAddr) - ((UDATA)oldDataAddr));
}
else
displacement = (IDATA) (((UDATA)newPinningArrayAddress) - ((UDATA)oldPinningArrayAddress));

IDATA displacement = 0;

if (newPinningArrayAddress)
displacement = walkState->walkThread->javaVM->memoryManagerFunctions->j9gc_objaccess_indexableDataDisplacement(walkState->walkThread, (J9IndexableObject*)oldPinningArrayAddress, (J9IndexableObject*)newPinningArrayAddress);

++(walkState->slotIndex);

#ifdef J9VM_INTERP_STACKWALK_TRACING
Expand Down

0 comments on commit bdc9592

Please sign in to comment.