Skip to content

Verify off heap entry during update and free offheap array #20985

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

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions runtime/gc_check/CheckEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,12 @@ 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 isDataNonAdjacent = false;
bool isValidDataAddr = extensions->indexableObjectModel.isValidDataAddrForAdjacentData((J9IndexableObject *)objectPtr, dataAddr, &isDataNonAdjacent);
if (isDataNonAdjacent) {
isValidDataAddr = extensions->largeObjectVirtualMemory->getSparseDataPool()->isValidDataPtr(dataAddr, objectPtr, extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)objectPtr));
}
if (!isValidDataAddr) {
return J9MODRON_GCCHK_RC_INVALID_INDEXABLE_DATA_ADDRESS;
}
}
Expand Down
20 changes: 10 additions & 10 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 isDataNonAdjacent[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)
isValidDataAddrForAdjacentData(J9IndexableObject *arrayPtr, bool *isDataNonAdjacent)
{
bool isValidDataAddress = true;
if (_isIndexableDataAddrPresent) {
void *dataAddr = getDataAddrForIndexableObject(arrayPtr);
isValidDataAddress = isValidDataAddr(arrayPtr, dataAddr, isValidDataAddrForOffHeapObject);
isValidDataAddress = isValidDataAddrForAdjacentData(arrayPtr, dataAddr, isDataNonAdjacent);
}
return isValidDataAddress;
}
Expand All @@ -966,12 +966,12 @@ 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 Pointer to the indexable object
* @param isDataNonAdjacent[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)
isValidDataAddrForAdjacentData(J9IndexableObject *arrayPtr, void *dataAddr, bool *isDataNonAdjacent)
{
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;
*isDataNonAdjacent = 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); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LinHu2016 Could you create a follow-up change to put the closing brace back on a line by itself, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have created a PR, which also clean up some others format issues, #21072

}
}
}
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