Skip to content

Commit 3440684

Browse files
committed
Verify off heap entry during update and free offheap array
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]>
1 parent 24f5138 commit 3440684

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

runtime/gc_check/CheckEngine.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,12 @@ GC_CheckEngine::checkJ9Object(J9JavaVM *javaVM, J9Object* objectPtr, J9MM_Iterat
468468
if (extensions->isVirtualLargeObjectHeapEnabled && extensions->objectModel.isIndexable(objectPtr)) {
469469
/* Check that the indexable object has the correct data address pointer */
470470
void *dataAddr = extensions->indexableObjectModel.getDataAddrForIndexableObject((J9IndexableObject *)objectPtr);
471-
bool isValidDataAddr = extensions->largeObjectVirtualMemory->getSparseDataPool()->isValidDataPtr(dataAddr);
472-
if (!isValidDataAddr && !extensions->indexableObjectModel.isValidDataAddr((J9IndexableObject *)objectPtr, dataAddr, isValidDataAddr)) {
471+
bool isDataNonAdjacent = false;
472+
bool isValidDataAddr = extensions->indexableObjectModel.isValidDataAddrForAdjacentData((J9IndexableObject *)objectPtr, dataAddr, &isDataNonAdjacent);
473+
if (isDataNonAdjacent) {
474+
isValidDataAddr = extensions->largeObjectVirtualMemory->getSparseDataPool()->isValidDataPtr(dataAddr, objectPtr, extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)objectPtr));
475+
}
476+
if (!isValidDataAddr) {
473477
return J9MODRON_GCCHK_RC_INVALID_INDEXABLE_DATA_ADDRESS;
474478
}
475479
}

runtime/gc_glue_java/ArrayletObjectModel.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -947,17 +947,17 @@ class GC_ArrayletObjectModel : public GC_ArrayletObjectModelBase
947947
* Checks that the dataAddr field of the indexable object is correct.
948948
* this method is supposed to be called only if offheap is enabled.
949949
*
950-
* @param arrayPtr Pointer to the indexable object
951-
* @param isValidDataAddrForOffHeapObject Boolean to determine whether the given indexable object is off heap
952-
* @return if the dataAddr field of the indexable object is correct
950+
* @param arrayPtr[in] Pointer to the indexable object
951+
* @param isDataNonAdjacent[out] set true if the given indexable object is off heap
952+
* @return if the dataAddr field of the indexable object is correct(not heap object case), return false if indexable object is off heap
953953
*/
954954
MMINLINE bool
955-
isValidDataAddr(J9IndexableObject *arrayPtr, bool isValidDataAddrForOffHeapObject)
955+
isValidDataAddrForAdjacentData(J9IndexableObject *arrayPtr, bool *isDataNonAdjacent)
956956
{
957957
bool isValidDataAddress = true;
958958
if (_isIndexableDataAddrPresent) {
959959
void *dataAddr = getDataAddrForIndexableObject(arrayPtr);
960-
isValidDataAddress = isValidDataAddr(arrayPtr, dataAddr, isValidDataAddrForOffHeapObject);
960+
isValidDataAddress = isValidDataAddrForAdjacentData(arrayPtr, dataAddr, isDataNonAdjacent);
961961
}
962962
return isValidDataAddress;
963963
}
@@ -966,12 +966,12 @@ class GC_ArrayletObjectModel : public GC_ArrayletObjectModelBase
966966
* Checks that the dataAddr field of the indexable object is correct.
967967
* this method is supposed to be called only if offheap is enabled
968968
*
969-
* @param arrayPtr Pointer to the indexable object
970-
* @param isValidDataAddrForOffHeapObject Boolean to determine whether the given indexable object is off heap
971-
* @return if the dataAddr field of the indexable object is correct
969+
* @param arrayPtr Pointer to the indexable object
970+
* @param isDataNonAdjacent[out] set true if the given indexable object is off heap
971+
* @return if the dataAddr field of the indexable object is correct(not heap object case), return false if indexable object is off heap
972972
*/
973973
MMINLINE bool
974-
isValidDataAddr(J9IndexableObject *arrayPtr, void *dataAddr, bool isValidDataAddrForOffHeapObject)
974+
isValidDataAddrForAdjacentData(J9IndexableObject *arrayPtr, void *dataAddr, bool *isDataNonAdjacent)
975975
{
976976
bool isValidDataAddress = false;
977977
uintptr_t dataSizeInBytes = getDataSizeInBytes(arrayPtr);
@@ -981,7 +981,7 @@ class GC_ArrayletObjectModel : public GC_ArrayletObjectModelBase
981981
} else if (dataSizeInBytes < _omrVM->_arrayletLeafSize) {
982982
isValidDataAddress = (dataAddr == (void *)((uintptr_t)arrayPtr + contiguousIndexableHeaderSize()));
983983
} else {
984-
isValidDataAddress = isValidDataAddrForOffHeapObject;
984+
*isDataNonAdjacent = true;
985985
}
986986

987987
return isValidDataAddress;

runtime/gc_vlhgc/CopyForwardScheme.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4096,16 +4096,15 @@ class MM_CopyForwardSchemeRootClearer : public MM_RootScanner
40964096
Assert_MM_mustBeClass(_extensions->objectModel.getPreservedClass(&forwardedHeader));
40974097
env->_copyForwardStats._offHeapRegionsCleared += 1;
40984098
void *dataAddr = _extensions->indexableObjectModel.getDataAddrForContiguous((J9IndexableObject *)objectPtr);
4099-
_extensions->largeObjectVirtualMemory->freeSparseRegionAndUnmapFromHeapObject(_env, dataAddr);
4099+
_extensions->largeObjectVirtualMemory->freeSparseRegionAndUnmapFromHeapObject(_env, dataAddr, objectPtr, _extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)objectPtr));
41004100
*sparseHeapAllocation = false;
41014101
} else {
41024102
void *dataAddr = _extensions->indexableObjectModel.getDataAddrForContiguous((J9IndexableObject *)fwdOjectPtr);
41034103
if (NULL != dataAddr) {
41044104
/* There might be the case that GC finds a floating arraylet, which was a result of an allocation
41054105
* failure (reason why this GC cycle is happening).
41064106
*/
4107-
_extensions->largeObjectVirtualMemory->updateSparseDataEntryAfterObjectHasMoved(dataAddr, fwdOjectPtr);
4108-
}
4107+
_extensions->largeObjectVirtualMemory->updateSparseDataEntryAfterObjectHasMoved(dataAddr, objectPtr, _extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)fwdOjectPtr), fwdOjectPtr); }
41094108
}
41104109
}
41114110
}

runtime/gc_vlhgc/GlobalMarkingScheme.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,8 @@ class MM_GlobalMarkingSchemeRootClearer : public MM_RootScanner
13781378
env->_markVLHGCStats._offHeapRegionsCleared += 1;
13791379
void *dataAddr = _extensions->indexableObjectModel.getDataAddrForContiguous((J9IndexableObject *)objectPtr);
13801380
if (NULL != dataAddr) {
1381-
_extensions->largeObjectVirtualMemory->freeSparseRegionAndUnmapFromHeapObject(_env, dataAddr);
1381+
_extensions->largeObjectVirtualMemory->freeSparseRegionAndUnmapFromHeapObject(_env, dataAddr, objectPtr, _extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)objectPtr));
1382+
13821383
*sparseHeapAllocation = false;
13831384
}
13841385
}

runtime/gc_vlhgc/WriteOnceCompactor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ class MM_WriteOnceCompactFixupRoots : public MM_RootScanner {
16971697
/* There might be the case that GC finds a floating arraylet, which was a result of an allocation
16981698
* failure (reason why this GC cycle is happening).
16991699
*/
1700-
_extensions->largeObjectVirtualMemory->updateSparseDataEntryAfterObjectHasMoved(dataAddr, fwdOjectPtr);
1700+
_extensions->largeObjectVirtualMemory->updateSparseDataEntryAfterObjectHasMoved(dataAddr, objectPtr, _extensions->indexableObjectModel.getDataSizeInBytes((J9IndexableObject *)fwdOjectPtr), fwdOjectPtr);
17011701
}
17021702
}
17031703
}

0 commit comments

Comments
 (0)