use of com.ibm.j9ddr.vm29.pointer.AbstractPointer in project openj9 by eclipse.
the class GCConstantPoolSlotIterator method initializeSlots_V1.
protected void initializeSlots_V1(J9ClassPointer clazz, boolean returnClassSlots, boolean returnObjectSlots) throws CorruptDataException {
U32Pointer cpDescriptionSlots = clazz.romClass().cpShapeDescription();
PointerPointer cpEntry = PointerPointer.cast(clazz.ramConstantPool());
long cpDescription = 0;
long cpEntryCount = clazz.romClass().ramConstantPoolCount().longValue();
long cpDescriptionIndex = 0;
ArrayList<AbstractPointer> slots = new ArrayList<AbstractPointer>();
ArrayList<VoidPointer> addresses = new ArrayList<VoidPointer>();
while (cpEntryCount > 0) {
if (0 == cpDescriptionIndex) {
// Load a new description word
cpDescription = cpDescriptionSlots.at(0).longValue();
cpDescriptionSlots = cpDescriptionSlots.add(1);
cpDescriptionIndex = J9_CP_DESCRIPTIONS_PER_U32;
}
long slotType = cpDescription & J9_CP_DESCRIPTION_MASK;
if ((slotType == J9CPTYPE_STRING) || (slotType == J9CPTYPE_ANNOTATION_UTF8)) {
if (returnObjectSlots) {
J9RAMStringRefPointer ref = J9RAMStringRefPointer.cast(cpEntry);
J9ObjectPointer slot = ref.stringObject();
if (slot.notNull()) {
slots.add(slot);
addresses.add(VoidPointer.cast(ref.stringObjectEA()));
}
}
} else if (slotType == J9CPTYPE_METHOD_TYPE) {
if (returnObjectSlots) {
J9RAMMethodTypeRefPointer ref = J9RAMMethodTypeRefPointer.cast(cpEntry);
J9ObjectPointer slot = ref.type();
if (slot.notNull()) {
slots.add(slot);
addresses.add(VoidPointer.cast(ref.typeEA()));
}
}
} else if (slotType == J9CPTYPE_METHODHANDLE) {
if (returnObjectSlots) {
J9RAMMethodHandleRefPointer ref = J9RAMMethodHandleRefPointer.cast(cpEntry);
J9ObjectPointer slot = ref.methodHandle();
if (slot.notNull()) {
slots.add(slot);
addresses.add(VoidPointer.cast(ref.methodHandleEA()));
}
}
} else if (slotType == J9CPTYPE_CLASS) {
if (returnClassSlots) {
J9RAMClassRefPointer ref = J9RAMClassRefPointer.cast(cpEntry);
J9ClassPointer slot = ref.value();
if (slot.notNull()) {
slots.add(slot);
addresses.add(VoidPointer.cast(ref.valueEA()));
}
}
}
cpEntry = cpEntry.addOffset(J9RAMConstantPoolItem.SIZEOF);
cpEntryCount -= 1;
cpDescription >>= J9_CP_BITS_PER_DESCRIPTION;
cpDescriptionIndex -= 1;
}
slotIterator = slots.iterator();
addressIterator = addresses.iterator();
}
use of com.ibm.j9ddr.vm29.pointer.AbstractPointer in project openj9 by eclipse.
the class LinearDumper method addSlot.
public void addSlot(StructurePointer clazz, SlotType type, AbstractPointer slotPtr, String slotName, String additionalInfo) throws CorruptDataException {
try {
J9ROMNameAndSignaturePointer nas;
long offset;
/* The slots of the type J9_ROM_UTF8 are changed to have 2 slots:
* -J9_SRP_TO_STRING
* -J9_ROM_UTF8
* This is done because we want to print the SRP field and also print
* the UTF8 it is pointing to */
switch(type) {
case J9_ROM_UTF8:
offset = slotPtr.getAddress() - clazz.getAddress();
classRegions.add(new J9ClassRegion(slotPtr, SlotType.J9_SRP_TO_STRING, slotName, additionalInfo, type.getSize(), offset, true));
VoidPointer srp = SelfRelativePointer.cast(slotPtr).get();
addUTF8Region(clazz, slotName, additionalInfo, srp);
break;
case J9_UTF8:
addUTF8Region(clazz, slotName, additionalInfo, slotPtr);
break;
/* The fields of the type J9_SRPNAS or J9_SRP are changed to have 2 J9_ROM_UTF8
* fields for their name and signature separated. */
case J9_SRPNAS:
nas = J9ROMNameAndSignaturePointer.cast(SelfRelativePointer.cast(slotPtr).get());
if (nas.notNull()) {
addSlot(clazz, SlotType.J9_ROM_UTF8, nas.nameEA(), "name");
addSlot(clazz, SlotType.J9_ROM_UTF8, nas.signatureEA(), "signature");
}
/* Since it is a SRP to a NAS, also print the SRP field. */
addSlot(clazz, SlotType.J9_SRP, slotPtr, "cpFieldNAS");
break;
case J9_NAS:
nas = J9ROMNameAndSignaturePointer.cast(slotPtr);
addSlot(clazz, SlotType.J9_ROM_UTF8, nas.nameEA(), "name");
addSlot(clazz, SlotType.J9_ROM_UTF8, nas.signatureEA(), "signature");
break;
case J9_IntermediateClassData:
offset = slotPtr.getAddress() - clazz.getAddress();
classRegions.add(new J9ClassRegion(slotPtr, type, slotName, additionalInfo, ((J9ROMClassPointer) clazz).intermediateClassDataLength().longValue(), offset, true));
break;
default:
offset = slotPtr.getAddress() - clazz.getAddress();
classRegions.add(new J9ClassRegion(slotPtr, type, slotName, additionalInfo, type.getSize(), offset, true));
break;
}
} catch (Exception e) {
}
}
use of com.ibm.j9ddr.vm29.pointer.AbstractPointer in project openj9 by eclipse.
the class LinearDumper method getAllRegions.
/**
* Returns a tree of regions and slots. Each slot is under a region. The
* root element is always null.
* @param classWalker
*
* @return J9ClassRegionNode tree of J9ClassRegion
* @throws CorruptDataException
*/
public J9ClassRegionNode getAllRegions(ClassWalker classWalker) throws CorruptDataException {
classWalker.allSlotsInObjectDo(this);
final StructurePointer clazz = classWalker.getClazz();
/* Add the UTF8 region */
if (firstJ9_ROM_UTF8 != Long.MAX_VALUE) {
addSection(clazz, PointerPointer.cast(firstJ9_ROM_UTF8), lastJ9_ROM_UTF8 - firstJ9_ROM_UTF8, "UTF8", true);
}
groupSectionByName(clazz, "methodDebugInfo", false);
groupSectionByName(clazz, "variableInfo", false);
/*
* the offset is a pointer which points at the end of the current
* region, in the case of a region which have no real size, it points at
* the beginning of the region
*/
AbstractPointer offset = PointerPointer.NULL;
J9ClassRegionNode currentNode = new J9ClassRegionNode(null);
Stack<J9ClassRegionNode> parentStack = new Stack<J9ClassRegionNode>();
J9ClassRegion previousRegion = null;
Collections.sort(classRegions);
for (J9ClassRegion region : classRegions) {
if (isSameRegion(previousRegion, region)) {
previousRegion = region;
continue;
}
previousRegion = region;
if (SlotType.J9_SECTION_START == region.getType()) {
if (region.getComputePadding() && offset.notNull() && !offset.eq(region.getSlotPtr())) {
currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", region.getSlotPtr().getAddress() - offset.getAddress(), 0, true)));
}
if (region.getComputePadding()) {
offset = region.getSlotPtr();
}
parentStack.push(currentNode);
J9ClassRegionNode newChild = new J9ClassRegionNode(region);
currentNode.addChild(newChild);
currentNode = newChild;
} else if (SlotType.J9_SECTION_END == region.getType()) {
if (region.getComputePadding()) {
long paddingSize = (region.getSlotPtr().getAddress() - offset.getAddress());
if (paddingSize != 0) {
currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", paddingSize, 0, true)));
}
offset = region.getSlotPtr();
}
currentNode = parentStack.pop();
} else {
boolean computePadding = false;
if (currentNode.getNodeValue() != null) {
computePadding = currentNode.getNodeValue().getComputePadding();
}
if (computePadding && offset.notNull() && !offset.eq(region.getSlotPtr())) {
currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", region.getSlotPtr().getAddress() - offset.getAddress(), 0, true)));
}
if (computePadding) {
offset = region.getSlotPtr().addOffset(region.length);
}
currentNode.addChild(new J9ClassRegionNode(region));
}
}
// Padding after the class and inside the romSize.
if (clazz instanceof J9ROMClassPointer) {
long size = J9ROMClassPointer.cast(clazz).romSize().longValue();
long paddingSize = (clazz.longValue() + size) - offset.longValue();
if (paddingSize != 0) {
currentNode.addChild(new J9ClassRegionNode(new J9ClassRegion(offset, SlotType.J9_Padding, "Padding", "", paddingSize, 0, true)));
// The class padding might be inserted out of order
Collections.sort(currentNode.getChildren());
}
}
return currentNode;
}
use of com.ibm.j9ddr.vm29.pointer.AbstractPointer in project openj9 by eclipse.
the class WhatIsCommand method walkStructuresFrom.
private boolean walkStructuresFrom(StructurePointer startPoint) throws DDRInteractiveCommandException {
Set<AbstractPointer> walked = new HashSet<AbstractPointer>();
SearchStack searchStack = new SearchStack(maxDepth);
if (UDATA.cast(startPoint).eq(searchValue)) {
out.println("Found " + searchValue.getHexValue() + " as " + startPoint.formatShortInteractive());
return true;
}
/* Seed with startPoint */
searchStack.push(new SearchFrame(startPoint));
walked.add(startPoint);
boolean found = false;
while (!searchStack.isEmpty() && !found) {
SearchFrame current = searchStack.peek();
int fieldIndex = current.fieldIndex++;
if (current.fieldAccessors.length <= fieldIndex) {
// We've walked all the fields on this object
searchStack.pop();
continue;
}
try {
current.fieldName = current.fieldAccessors[fieldIndex].getName();
Object result = current.fieldAccessors[fieldIndex].invoke(current.ptr);
if (result == null) {
continue;
}
fieldCount++;
if (result instanceof StructurePointer) {
StructurePointer ptr = (StructurePointer) result;
found = checkPointer(searchStack, ptr);
if (!searchStack.isFull() && !walked.contains(ptr)) {
walked.add(ptr);
searchStack.push(new SearchFrame(ptr));
}
} else if (result instanceof AbstractPointer) {
AbstractPointer ptr = (AbstractPointer) result;
found = checkPointer(searchStack, ptr);
} else if (result instanceof Scalar) {
Scalar s = (Scalar) result;
found = checkScalar(searchStack, s);
} else {
out.println("Unexpected type walked: " + result.getClass().getName());
continue;
}
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof CorruptDataException || cause instanceof NoSuchFieldError || cause instanceof NoClassDefFoundError) {
// Skip this field
continue;
} else {
throw new DDRInteractiveCommandException("Unexpected exception during walk", cause);
}
} catch (Exception e) {
throw new DDRInteractiveCommandException("Unexpected exception during !whatis walk", e);
}
}
return found;
}
use of com.ibm.j9ddr.vm29.pointer.AbstractPointer in project openj9 by eclipse.
the class WhatIsCommand method checkPointer.
private boolean checkPointer(SearchStack searchStack, AbstractPointer ptr) {
UDATA cmpValue = UDATA.cast(ptr);
if (searchValue.eq(cmpValue)) {
if (++foundCount > skipCount) {
out.print("Found " + searchValue.getHexValue() + " as " + ptr.formatShortInteractive() + ": ");
searchStack.dump(out);
out.println();
return true;
}
} else {
updateClosest(searchStack, cmpValue);
}
return false;
}
Aggregations