use of com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator in project openj9 by eclipse.
the class RootScanner method scanNonCollectableObjectsInternal.
private void scanNonCollectableObjectsInternal(long memoryType) throws CorruptDataException {
GCHeapRegionIterator regionIterator = GCHeapRegionIterator.from();
while (regionIterator.hasNext()) {
GCHeapRegionDescriptor region = regionIterator.next();
if (new UDATA(region.getTypeFlags()).allBitsIn(memoryType)) {
GCObjectHeapIterator objectIterator = GCObjectHeapIterator.fromHeapRegionDescriptor(region, true, false);
while (objectIterator.hasNext()) {
J9ObjectPointer object = objectIterator.next();
doClassSlot(J9ObjectHelper.clazz(object));
GCObjectIterator fieldIterator = GCObjectIterator.fromJ9Object(object, true);
GCObjectIterator fieldAddressIterator = GCObjectIterator.fromJ9Object(object, true);
while (fieldIterator.hasNext()) {
doNonCollectableObjectSlot(fieldIterator.next(), fieldAddressIterator.nextAddress());
}
}
}
}
}
use of com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator in project openj9 by eclipse.
the class LiveSetWalker method scanObject.
private static void scanObject(HashSet<J9ObjectPointer> visitedObjects, ObjectVisitor visitor, J9ObjectPointer object, VoidPointer address) {
if (visitedObjects.contains(object)) {
return;
}
if (!visitor.visit(object, address)) {
return;
}
visitedObjects.add(object);
try {
GCObjectIterator objectIterator = GCObjectIterator.fromJ9Object(object, true);
GCObjectIterator addressIterator = GCObjectIterator.fromJ9Object(object, true);
while (objectIterator.hasNext()) {
J9ObjectPointer slot = objectIterator.next();
VoidPointer addr = addressIterator.nextAddress();
if (slot.notNull()) {
scanObject(visitedObjects, visitor, slot, addr);
}
}
if (J9ObjectHelper.getClassName(object).equals("java/lang/Class")) {
J9ClassPointer clazz = ConstantPoolHelpers.J9VM_J9CLASS_FROM_HEAPCLASS(object);
// Iterate the Object slots
GCClassIterator classIterator = GCClassIterator.fromJ9Class(clazz);
GCClassIterator classAddressIterator = GCClassIterator.fromJ9Class(clazz);
while (classIterator.hasNext()) {
J9ObjectPointer slot = classIterator.next();
VoidPointer addr = classAddressIterator.nextAddress();
if (slot.notNull()) {
scanObject(visitedObjects, visitor, slot, addr);
}
}
// Iterate the Class slots
GCClassIteratorClassSlots classSlotIterator = GCClassIteratorClassSlots.fromJ9Class(clazz);
GCClassIteratorClassSlots classSlotAddressIterator = GCClassIteratorClassSlots.fromJ9Class(clazz);
while (classSlotIterator.hasNext()) {
J9ClassPointer slot = classSlotIterator.next();
VoidPointer addr = classSlotAddressIterator.nextAddress();
J9ObjectPointer classObject = ConstantPoolHelpers.J9VM_J9CLASS_TO_HEAPCLASS(slot);
if (classObject.notNull()) {
scanObject(visitedObjects, visitor, classObject, addr);
}
}
}
} catch (CorruptDataException e) {
EventManager.raiseCorruptDataEvent("Corruption found while walking the live set, object: " + object.getHexAddress(), e, false);
}
visitor.finishVisit(object, address);
}
use of com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator in project openj9 by eclipse.
the class ObjectRefsCommand method dumpHeapReferences.
/**
* Write the on heap references stanza to the output stream.
* @param vm
* @param targetObject
* @param out
* @throws CorruptDataException
*/
private void dumpHeapReferences(J9JavaVMPointer vm, J9ObjectPointer targetObject, PrintStream out) throws CorruptDataException {
if (GCExtensions.isVLHGC()) {
Table table = new Table("On Heap References");
table.row("object (!j9object)", "field (!j9object)", "!mm_heapregiondescriptorvlhgc", "AC (type)");
/* iterate over all heap regions */
GCHeapRegionIterator regionIterator = GCHeapRegionIterator.from();
while (regionIterator.hasNext()) {
GCHeapRegionDescriptor region = regionIterator.next();
if (region.containsObjects()) {
MM_HeapRegionDescriptorVLHGCPointer vlhgcRegion = MM_HeapRegionDescriptorVLHGCPointer.cast(region.getHeapRegionDescriptorPointer());
MM_AllocationContextTarokPointer currentAllocationContextTarok = vlhgcRegion._allocateData()._owningContext();
/* iterate over all objects in region */
GCObjectHeapIterator heapObjectIterator = region.objectIterator(true, false);
while (heapObjectIterator.hasNext()) {
J9ObjectPointer currentObject = heapObjectIterator.next();
/* Iterate over the object's fields and list any that point at @ref targetObject */
GCObjectIterator fieldIterator = GCObjectIterator.fromJ9Object(currentObject, false);
while (fieldIterator.hasNext()) {
J9ObjectPointer currentTargetObject = fieldIterator.next();
if (currentTargetObject.eq(targetObject)) {
/* found a reference to our targetObject, add it to the table */
J9ClassPointer objectClass = J9ObjectHelper.clazz(currentObject);
String objectClassString = J9ClassHelper.getJavaName(objectClass);
table.row(currentObject.getHexAddress() + " //" + objectClassString, currentTargetObject.getHexAddress(), vlhgcRegion.getHexAddress(), currentAllocationContextTarok.getHexAddress() + " (" + currentAllocationContextTarok._allocationContextType() + ")");
}
}
}
}
}
table.render(out);
}
}
use of com.ibm.j9ddr.vm29.j9.gc.GCObjectIterator in project openj9 by eclipse.
the class CheckEngine method checkObjectHeap.
public int checkObjectHeap(J9ObjectPointer object, GCHeapRegionDescriptor regionDesc) {
int result = J9MODRON_SLOT_ITERATOR_OK;
boolean isDead = false;
boolean isIndexable = false;
J9ClassPointer clazz = null;
try {
if (ObjectModel.isDeadObject(object)) {
/* this is a hole */
result = checkJ9LinkedFreeHeader(GCHeapLinkedFreeHeader.fromJ9Object(object), regionDesc, _cycle.getCheckFlags());
if (J9MODRON_GCCHK_RC_OK != result) {
CheckError error = new CheckError(object, _cycle, _currentCheck, "Object", result, _cycle.nextErrorCount());
_reporter.report(error);
/* There are some error cases would not prevent further iteration */
if (!((J9MODRON_GCCHK_RC_DEAD_OBJECT_NEXT_IS_NOT_HOLE == result) || (J9MODRON_GCCHK_RC_DEAD_OBJECT_NEXT_IS_NOT_IN_REGION == result) || (J9MODRON_GCCHK_RC_DEAD_OBJECT_NEXT_IS_POINTED_INSIDE == result))) {
_reporter.reportHeapWalkError(error, _lastHeapObject1, _lastHeapObject2, _lastHeapObject3);
return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
}
}
return J9MODRON_SLOT_ITERATOR_OK;
}
} catch (CorruptDataException e) {
// TODO : cde should be part of the error
CheckError error = new CheckError(object, _cycle, _currentCheck, "Object ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
_reporter.report(error);
return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
}
try {
// Prefetch this data to make CDE handling easy
isIndexable = ObjectModel.isIndexable(object);
clazz = J9ObjectHelper.clazz(object);
result = checkJ9Object(object, regionDesc, _cycle.getCheckFlags());
} catch (CorruptDataException cde) {
// TODO : cde should be part of the error
CheckError error = new CheckError(object, _cycle, _currentCheck, "Object ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
_reporter.report(error);
return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
}
if (J9MODRON_GCCHK_RC_OK != result) {
String elementName = isIndexable ? "IObject " : "Object ";
CheckError error = new CheckError(object, _cycle, _currentCheck, elementName, result, _cycle.nextErrorCount());
_reporter.report(error);
/* There are some error cases would not prevent further iteration */
if (!(J9MODRON_GCCHK_RC_CLASS_IS_UNLOADED == result)) {
_reporter.reportHeapWalkError(error, _lastHeapObject1, _lastHeapObject2, _lastHeapObject3);
return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
} else {
return J9MODRON_SLOT_ITERATOR_OK;
}
}
try {
/* check Ownable Synchronizer Object consistency */
if (needVerifyOwnableSynchronizerConsistency()) {
if (J9Object.OBJECT_HEADER_SHAPE_MIXED == ObjectModel.getClassShape(clazz).intValue() && !J9ClassHelper.classFlags(clazz).bitAnd(J9AccClassOwnableSynchronizer).eq(0)) {
if (ObjectAccessBarrier.isObjectInOwnableSynchronizerList(object).isNull()) {
CheckError error = new CheckError(object, _cycle, _currentCheck, "Object ", J9MODRON_GCCHK_OWNABLE_SYNCHRONIZER_OBJECT_IS_NOT_ATTACHED_TO_THE_LIST, _cycle.nextErrorCount());
_reporter.report(error);
} else {
_ownableSynchronizerObjectCountOnHeap += 1;
}
}
}
} catch (CorruptDataException cde) {
// TODO : cde should be part of the error
CheckError error = new CheckError(object, _cycle, _currentCheck, "Object ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
_reporter.report(error);
return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
}
if (J9MODRON_GCCHK_RC_OK == result) {
GCObjectIterator fieldIterator;
GCObjectIterator addressIterator;
try {
fieldIterator = GCObjectIterator.fromJ9Object(object, true);
addressIterator = GCObjectIterator.fromJ9Object(object, true);
} catch (CorruptDataException e) {
// TODO : cde should be part of the error
CheckError error = new CheckError(object, _cycle, _currentCheck, "Object ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
_reporter.report(error);
return J9MODRON_SLOT_ITERATOR_UNRECOVERABLE_ERROR;
}
while (fieldIterator.hasNext()) {
J9ObjectPointer field = fieldIterator.next();
VoidPointer address = addressIterator.nextAddress();
result = checkSlotObjectHeap(field, ObjectReferencePointer.cast(address), regionDesc, object);
if (J9MODRON_SLOT_ITERATOR_OK != result) {
break;
}
}
}
if (J9MODRON_GCCHK_RC_OK == result) {
/* this heap object is OK. Record it in the cache in case we find a pointer to it soon */
int cacheIndex = (int) (object.getAddress() % OBJECT_CACHE_SIZE);
_checkedObjectCache[cacheIndex] = object;
}
return result;
}
Aggregations