use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class HeapdumpCommand method heapArgumentsAreValid.
/**
* Checks the list of heaps to dump as specified by the user.
* @param runtime Current java runtime
* @param heapsToDump Set of strings the user passed as heaps to dump
* @return True if all the names are valid heaps, false otherwise
*/
private boolean heapArgumentsAreValid(JavaRuntime runtime, Set heapsToDump) {
if (heapsToDump.size() == 0) {
return true;
}
Set workingSet = new HashSet();
workingSet.addAll(heapsToDump);
Iterator heapIt = runtime.getHeaps();
while (heapIt.hasNext()) {
Object potential = heapIt.next();
if (potential instanceof JavaHeap) {
JavaHeap thisHeap = (JavaHeap) potential;
workingSet.remove(thisHeap.getName());
} else if (potential instanceof CorruptData) {
reportError("Corrupt heap found. Address = " + ((CorruptData) potential).getAddress(), null);
_numberOfErrors++;
} else {
_numberOfErrors++;
reportError("Unexpected type " + potential.getClass().getName() + " found in heap iterator", null);
}
}
if (workingSet.isEmpty()) {
return true;
} else {
StringBuffer buffer = new StringBuffer();
buffer.append("These specified heaps do not exist:\n");
Iterator nameIterator = workingSet.iterator();
while (nameIterator.hasNext()) {
buffer.append("\t\t" + nameIterator.next() + "\n");
}
buffer.append("\tUse \"info heap\" to see list of heap names");
out.println(buffer.toString());
return false;
}
}
use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class HeapdumpCommand method addReferences.
/**
* Extracts the instance references from an object
* @param object Object being walked
* @param references List<Long> to add references to
* @param thisClass Class of object
*/
private void addReferences(JavaObject object, List<Long> references) throws CorruptDataException, MemoryAccessException {
Iterator it = object.getReferences();
Object ref = null;
// discard the first reference which is always to the class
if (it.hasNext()) {
// test hasNext() to be on the safe side.
ref = it.next();
}
while (it.hasNext()) {
ref = it.next();
if (ref instanceof CorruptData) {
// can sometimes get a nasty surprise in the list - e.g. a J9DDRCorruptData
_numberOfErrors++;
reportError("Corrupt data found at address " + ((CorruptData) ref).getAddress() + " getting references from object at address: " + Long.toHexString(object.getID().getAddress()) + " of class " + object.getJavaClass().getName() + "(" + object.getJavaClass().getID() + ")", null);
continue;
}
if (!(ref instanceof JavaReference)) {
_numberOfErrors++;
reportError("Object of unexpected type " + ref.getClass() + " found within references from object at address: " + object.getID().getAddress() + " of class " + object.getJavaClass().getName() + "(" + object.getJavaClass().getID() + ")", null);
continue;
} else {
Object target;
try {
target = ((JavaReference) ref).getTarget();
} catch (DataUnavailable e) {
_numberOfErrors++;
reportError("DataUnavailable thrown from call to getTarget() on reference: " + ref, null);
continue;
}
// the following ugliness is necessary as JavaObject and JavaClass both support getID() but do not inherit from a common parent
if (target instanceof JavaObject) {
references.add(new Long(((JavaObject) target).getID().getAddress()));
} else if (target instanceof JavaClass) {
references.add(new Long(((JavaClass) target).getID().getAddress()));
} else {
_numberOfErrors++;
reportError("Object of unexpected type " + target.getClass() + " returned from call to getTarget() on reference " + ref, null);
}
}
}
}
use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class InfoHeapCommand method printOccupancyInfo.
private void printOccupancyInfo(JavaHeap theHeap, PrintStream out) {
/*
* This method takes a lot of time and hence this information is only included
* when using "info heap <heapname>". If this method was run for every heap
* when using "info heap *" the amount of time it would take would be astronomical.
*/
long size = 0;
long totalObjectSize = 0;
// total number of objects on the heap
long totalObjects = 0;
// total number of corrupt objects
long totalCorruptObjects = 0;
Iterator itSections = theHeap.getSections();
// object returned from various iterators
Object obj = null;
// corrupt data
CorruptData cdata = null;
while (itSections.hasNext()) {
obj = itSections.next();
if (obj instanceof CorruptData) {
// returned section is corrupt
cdata = (CorruptData) obj;
out.print("\t\t Warning - corrupt image section found");
if (cdata.getAddress() != null) {
out.print(" at 0x" + cdata.getAddress().toString());
}
out.print("\n");
} else {
// returned section is valid, so process it
ImageSection theSection = (ImageSection) obj;
size = size + theSection.getSize();
}
}
out.print("\t Size of heap: " + size + " bytes\n");
Iterator itObjects = theHeap.getObjects();
try {
while (itObjects.hasNext()) {
obj = itObjects.next();
totalObjects++;
if (obj instanceof CorruptData) {
totalCorruptObjects++;
cdata = (CorruptData) obj;
out.print("\t\t Warning - corrupt heap object found at position " + totalObjects);
if (cdata.getAddress() != null) {
out.print(" address 0x" + cdata.getAddress().toString());
}
out.print("\n");
} else {
JavaObject theObject = (JavaObject) obj;
totalObjectSize = totalObjectSize + theObject.getSize();
}
}
float percentage = ((float) totalObjectSize / (float) size) * 10000;
// Sending this float through an int gets it down to 2 decimal places.
int trimmedPercent = ((int) percentage);
percentage = ((float) trimmedPercent) / 100;
out.print("\t Occupancy : " + totalObjectSize + " bytes (" + percentage + "%)\n");
out.print("\t Total objects : " + totalObjects + "\n");
out.print("\t Total corrupted objects : " + totalCorruptObjects + "\n");
} catch (CorruptDataException e) {
out.print("\t Occupancy : <unknown>\n");
}
}
use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class InfoSymCommand method printModule.
private void printModule(ImageModule imageModule, boolean printSymbols) {
try {
out.print("\t " + imageModule.getName());
} catch (CorruptDataException cde) {
out.print("\t " + Exceptions.getCorruptDataExceptionString());
}
try {
String addressInHex = String.format("0x%x", imageModule.getLoadAddress());
out.print(" @ " + addressInHex);
} catch (DataUnavailable e) {
// if we do not have the load address, simply omit it
} catch (CorruptDataException e) {
// if we do not have the load address, simply omit it
}
Iterator itSection = imageModule.getSections();
if (itSection.hasNext()) {
out.print(", sections:\n");
} else {
out.print(", <no section information>\n");
}
// iterate through the library sections
while (itSection.hasNext()) {
Object next = itSection.next();
if (next instanceof ImageSection) {
ImageSection is = (ImageSection) next;
out.print("\t 0x" + Long.toHexString(is.getBaseAddress().getAddress()) + " - 0x" + Long.toHexString(is.getBaseAddress().getAddress() + is.getSize()));
out.print(", name: \"");
out.print(is.getName());
out.print("\", size: 0x");
out.print(Long.toHexString(is.getSize()));
out.print("\n");
} else if (next instanceof CorruptData) {
// warn the user that this image section is corrupt
out.print("\t <corrupt section encountered>\n");
} else {
// unexpected type in iterator
out.print("\t <corrupt section encountered>\n");
}
}
if (printSymbols) {
out.print("\t " + "symbols:\n");
Iterator itSymbols = imageModule.getSymbols();
while (itSymbols.hasNext()) {
Object next = itSymbols.next();
if (next instanceof ImageSymbol) {
ImageSymbol is = (ImageSymbol) next;
out.print("\t 0x" + Long.toHexString(is.getAddress().getAddress()));
out.print(", name: \"");
out.print(is.getName());
out.print("\"\n");
} else if (next instanceof CorruptData) {
// warn the user that this image section is corrupt
out.print("\t <corrupt symbol encountered>\n");
} else {
// unexpected type in iterator
out.print("\t <corrupt symbol encountered>\n");
}
}
}
out.print("\n");
}
use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class InfoThreadCommand method printStackFrameInfo.
private void printStackFrameInfo(ImageThread it) {
Iterator itStackFrame;
ImageStackFrame isf;
try {
itStackFrame = it.getStackFrames();
} catch (DataUnavailable d) {
out.print(" native stack frames: " + Exceptions.getDataUnavailableString() + "\n");
return;
}
out.print(" native stack frames:");
out.print("\n");
while (itStackFrame.hasNext()) {
Object o = itStackFrame.next();
if (o instanceof CorruptData) {
out.print(" <corrupt stack frame: " + ((CorruptData) o).toString() + ">\n");
continue;
}
isf = (ImageStackFrame) o;
out.print(" bp: ");
try {
out.print(toAdjustedHex(isf.getBasePointer().getAddress()));
} catch (CorruptDataException e) {
if (getArtifactType() == ArtifactType.javacore) {
// javacore does not provide native stack base pointers, show as unavailable, not corrupt
out.print(Exceptions.getDataUnavailableString());
} else {
out.print(Exceptions.getCorruptDataExceptionString());
}
}
out.print(" pc: ");
try {
out.print(toAdjustedHex(isf.getProcedureAddress().getAddress()));
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
}
out.print(" ");
try {
out.print(isf.getProcedureName());
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
}
out.print("\n");
}
}
Aggregations