Skip to content

Commit

Permalink
Verify off heap entry during update and free offheap array
Browse files Browse the repository at this point in the history
Verify the consistency (dataAddr, size and related proxy array object)
of off heap Entry before freeing the off heap array or updating related
proxy object.

Signed-off-by: lhu <[email protected]>
  • Loading branch information
LinHu2016 committed Jan 27, 2025
1 parent 24f5138 commit 1c5f6bb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
13 changes: 11 additions & 2 deletions runtime/gc_check/CheckEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,19 @@ GC_CheckEngine::checkJ9Object(J9JavaVM *javaVM, J9Object* objectPtr, J9MM_Iterat
if (extensions->isVirtualLargeObjectHeapEnabled && extensions->objectModel.isIndexable(objectPtr)) {
/* Check that the indexable object has the correct data address pointer */
void *dataAddr = extensions->indexableObjectModel.getDataAddrForIndexableObject((J9IndexableObject *)objectPtr);
bool isValidDataAddr = extensions->largeObjectVirtualMemory->getSparseDataPool()->isValidDataPtr(dataAddr);
if (!isValidDataAddr && !extensions->indexableObjectModel.isValidDataAddr((J9IndexableObject *)objectPtr, dataAddr, isValidDataAddr)) {
bool isDataAddrForOffHeapObject = false;
bool isValidDataAddr = extensions->indexableObjectModel.isValidDataAddr((J9IndexableObject *)objectPtr, dataAddr, &isDataAddrForOffHeapObject);
if (isDataAddrForOffHeapObject) {
isValidDataAddr = extensions->largeObjectVirtualMemory->getSparseDataPool()->isValidDataPtr(dataAddr, objectPtr, extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)objectPtr));
}
if (!isValidDataAddr) {
return J9MODRON_GCCHK_RC_INVALID_INDEXABLE_DATA_ADDRESS;
}
//
// bool isValidDataAddr = extensions->largeObjectVirtualMemory->getSparseDataPool()->isValidDataPtr(dataAddr);
// if (!isValidDataAddr && !extensions->indexableObjectModel.isValidDataAddr((J9IndexableObject *)objectPtr, dataAddr, isValidDataAddr)) {
// return J9MODRON_GCCHK_RC_INVALID_INDEXABLE_DATA_ADDRESS;
// }
}
#endif /* defined(J9VM_ENV_DATA64) */

Expand Down
18 changes: 9 additions & 9 deletions runtime/gc_glue_java/ArrayletObjectModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,17 +947,17 @@ class GC_ArrayletObjectModel : public GC_ArrayletObjectModelBase
* Checks that the dataAddr field of the indexable object is correct.
* this method is supposed to be called only if offheap is enabled.
*
* @param arrayPtr Pointer to the indexable object
* @param isValidDataAddrForOffHeapObject Boolean to determine whether the given indexable object is off heap
* @return if the dataAddr field of the indexable object is correct
* @param arrayPtr[in] Pointer to the indexable object
* @param isDataAddrForOffHeapObject[out] set true if the given indexable object is off heap
* @return if the dataAddr field of the indexable object is correct((not heap object case), return false if indexable object is off heap
*/
MMINLINE bool
isValidDataAddr(J9IndexableObject *arrayPtr, bool isValidDataAddrForOffHeapObject)
isValidDataAddr(J9IndexableObject *arrayPtr, bool *isDataAddrForOffHeapObject)
{
bool isValidDataAddress = true;
if (_isIndexableDataAddrPresent) {
void *dataAddr = getDataAddrForIndexableObject(arrayPtr);
isValidDataAddress = isValidDataAddr(arrayPtr, dataAddr, isValidDataAddrForOffHeapObject);
isValidDataAddress = isValidDataAddr(arrayPtr, dataAddr, isDataAddrForOffHeapObject);
}
return isValidDataAddress;
}
Expand All @@ -967,11 +967,11 @@ class GC_ArrayletObjectModel : public GC_ArrayletObjectModelBase
* this method is supposed to be called only if offheap is enabled
*
* @param arrayPtr Pointer to the indexable object
* @param isValidDataAddrForOffHeapObject Boolean to determine whether the given indexable object is off heap
* @return if the dataAddr field of the indexable object is correct
* @param isDataAddrForOffHeapObject[out] set true if the given indexable object is off heap
* @return if the dataAddr field of the indexable object is correct(not heap object case), return false if indexable object is off heap
*/
MMINLINE bool
isValidDataAddr(J9IndexableObject *arrayPtr, void *dataAddr, bool isValidDataAddrForOffHeapObject)
isValidDataAddr(J9IndexableObject *arrayPtr, void *dataAddr, bool *isDataAddrForOffHeapObject)
{
bool isValidDataAddress = false;
uintptr_t dataSizeInBytes = getDataSizeInBytes(arrayPtr);
Expand All @@ -981,7 +981,7 @@ class GC_ArrayletObjectModel : public GC_ArrayletObjectModelBase
} else if (dataSizeInBytes < _omrVM->_arrayletLeafSize) {
isValidDataAddress = (dataAddr == (void *)((uintptr_t)arrayPtr + contiguousIndexableHeaderSize()));
} else {
isValidDataAddress = isValidDataAddrForOffHeapObject;
*isDataAddrForOffHeapObject = true;
}

return isValidDataAddress;
Expand Down
5 changes: 2 additions & 3 deletions runtime/gc_vlhgc/CopyForwardScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4096,16 +4096,15 @@ class MM_CopyForwardSchemeRootClearer : public MM_RootScanner
Assert_MM_mustBeClass(_extensions->objectModel.getPreservedClass(&forwardedHeader));
env->_copyForwardStats._offHeapRegionsCleared += 1;
void *dataAddr = _extensions->indexableObjectModel.getDataAddrForContiguous((J9IndexableObject *)objectPtr);
_extensions->largeObjectVirtualMemory->freeSparseRegionAndUnmapFromHeapObject(_env, dataAddr);
_extensions->largeObjectVirtualMemory->freeSparseRegionAndUnmapFromHeapObject(_env, dataAddr, objectPtr, _extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)objectPtr));
*sparseHeapAllocation = false;
} else {
void *dataAddr = _extensions->indexableObjectModel.getDataAddrForContiguous((J9IndexableObject *)fwdOjectPtr);
if (NULL != dataAddr) {
/* There might be the case that GC finds a floating arraylet, which was a result of an allocation
* failure (reason why this GC cycle is happening).
*/
_extensions->largeObjectVirtualMemory->updateSparseDataEntryAfterObjectHasMoved(dataAddr, fwdOjectPtr);
}
_extensions->largeObjectVirtualMemory->updateSparseDataEntryAfterObjectHasMoved(dataAddr, objectPtr, _extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)fwdOjectPtr), fwdOjectPtr); }
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/gc_vlhgc/GlobalMarkingScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,8 @@ class MM_GlobalMarkingSchemeRootClearer : public MM_RootScanner
env->_markVLHGCStats._offHeapRegionsCleared += 1;
void *dataAddr = _extensions->indexableObjectModel.getDataAddrForContiguous((J9IndexableObject *)objectPtr);
if (NULL != dataAddr) {
_extensions->largeObjectVirtualMemory->freeSparseRegionAndUnmapFromHeapObject(_env, dataAddr);
_extensions->largeObjectVirtualMemory->freeSparseRegionAndUnmapFromHeapObject(_env, dataAddr, objectPtr, _extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)objectPtr));

*sparseHeapAllocation = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/gc_vlhgc/WriteOnceCompactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ class MM_WriteOnceCompactFixupRoots : public MM_RootScanner {
/* There might be the case that GC finds a floating arraylet, which was a result of an allocation
* failure (reason why this GC cycle is happening).
*/
_extensions->largeObjectVirtualMemory->updateSparseDataEntryAfterObjectHasMoved(dataAddr, fwdOjectPtr);
_extensions->largeObjectVirtualMemory->updateSparseDataEntryAfterObjectHasMoved(dataAddr, objectPtr, _extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)fwdOjectPtr), fwdOjectPtr);
}
}
}
Expand Down

0 comments on commit 1c5f6bb

Please sign in to comment.