use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class ClassOutput method printFields.
public static void printFields(JavaObject jo, JavaClass jc, JavaRuntime jr, PrintStream out) {
boolean array;
try {
array = jo.isArray();
} catch (CorruptDataException e) {
out.print("\t <cannot determine if above object is array (" + Exceptions.getCorruptDataExceptionString() + "); " + "we will assume it is not an array>\n");
array = false;
}
if (array) {
String componentType;
int arraySize;
try {
componentType = jc.getComponentType().getName();
} catch (CorruptDataException e) {
out.print("\t <cannot determine what type of array this is (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
return;
}
try {
arraySize = jo.getArraySize();
} catch (CorruptDataException e) {
out.print("\t <cannot determine the size of the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
return;
}
Object dst = null;
if (componentType.equals("boolean")) {
dst = new boolean[arraySize];
} else if (componentType.equals("byte")) {
dst = new byte[arraySize];
} else if (componentType.equals("char")) {
dst = new char[arraySize];
} else if (componentType.equals("short")) {
dst = new short[arraySize];
} else if (componentType.equals("int")) {
dst = new int[arraySize];
} else if (componentType.equals("long")) {
dst = new long[arraySize];
} else if (componentType.equals("float")) {
dst = new float[arraySize];
} else if (componentType.equals("double")) {
dst = new double[arraySize];
} else {
dst = new JavaObject[arraySize];
}
try {
jo.arraycopy(0, dst, 0, arraySize);
} catch (CorruptDataException e) {
out.print("\t <cannot copy data from the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
return;
} catch (MemoryAccessException e) {
out.print("\t <cannot copy data from the array (" + Exceptions.getMemoryAccessExceptionString() + ")>\n");
return;
} catch (UnsupportedOperationException e) {
// Some artefacts e.g. phd do not support arraycopy so just put out what we can
out.print("\t This is an array of size " + arraySize + " elements\n");
return;
}
for (int i = 0; i < arraySize; i++) {
out.print("\t " + i + ":\t");
if (componentType.equals("boolean")) {
out.print(Utils.getVal(new Boolean(((boolean[]) dst)[i])));
} else if (componentType.equals("byte")) {
out.print(Utils.getVal(new Byte(((byte[]) dst)[i])));
} else if (componentType.equals("char")) {
out.print(Utils.getVal(new Character(((char[]) dst)[i])));
} else if (componentType.equals("short")) {
out.print(Utils.getVal(new Short(((short[]) dst)[i])));
} else if (componentType.equals("int")) {
out.print(Utils.getVal(new Integer(((int[]) dst)[i])));
} else if (componentType.equals("long")) {
out.print(Utils.getVal(new Long(((long[]) dst)[i])));
} else if (componentType.equals("float")) {
out.print(Utils.getVal(new Float(((float[]) dst)[i])));
} else if (componentType.equals("double")) {
out.print(Utils.getVal(new Double(((double[]) dst)[i])));
} else {
out.print(Utils.getVal(((JavaObject[]) dst)[i]));
}
out.print("\n");
}
} else {
JavaClass initialJC = jc;
List<JavaClass> classList = new ArrayList<JavaClass>();
while (jc != null) {
classList.add(jc);
try {
jc = jc.getSuperclass();
} catch (CorruptDataException d) {
jc = null;
}
}
for (int i = (classList.size() - 1); i >= 0; i--) {
jc = classList.get(i);
Iterator itField = jc.getDeclaredFields();
if (itField.hasNext()) {
if (jc.equals(initialJC)) {
out.print("\t declared fields:\n");
} else {
out.print("\t fields inherited from \"");
try {
out.print(jc.getName() + "\":\n");
} catch (CorruptDataException d) {
out.print(Exceptions.getCorruptDataExceptionString());
}
}
}
while (itField.hasNext()) {
JavaField jf = (JavaField) itField.next();
boolean isStatic;
try {
isStatic = Modifier.isStatic(jf.getModifiers());
} catch (CorruptDataException e) {
out.print("\t <error while getting modifier for field \"");
try {
out.print(jf.getName());
} catch (CorruptDataException d) {
out.print(Exceptions.getCorruptDataExceptionString());
}
out.print("\", " + Exceptions.getCorruptDataExceptionString() + ">");
isStatic = true;
}
if (!isStatic) {
printNonStaticFieldData(jo, jf, out);
}
}
}
}
out.print("\n");
}
use of com.ibm.dtfj.java.JavaObject 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.java.JavaObject in project openj9 by eclipse.
the class WhatisCommand method isWithinObjectRange.
private boolean isWithinObjectRange(Iterator objects, long address) {
long startAddress, endAddress;
String className;
while (objects.hasNext()) {
JavaObject jObject = (JavaObject) objects.next();
try {
className = jObject.getJavaClass().getName();
startAddress = jObject.getID().getAddress();
endAddress = startAddress + jObject.getSize();
} catch (CorruptDataException cde) {
// TODO exception handling
continue;
}
if (isWithinRange(startAddress, endAddress, address)) {
out.print("\t\t0x" + Long.toHexString(address) + " is within an object on the heap:\n" + "\t\t\toffset " + (address - startAddress) + " within " + className + " instance @ 0x" + Long.toHexString(startAddress) + "\n");
return true;
}
}
return false;
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class JUCMonitorNode method getEnterWaiters.
public Iterator getEnterWaiters() {
List waiters = new LinkedList();
Iterator itThread = jr.getThreads();
while (itThread.hasNext()) {
Object o = itThread.next();
try {
if (!(o instanceof JavaThread)) {
continue;
}
JavaThread jt = (JavaThread) o;
if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
JavaObject blocker = jt.getBlockingObject();
if (blocker != null && blocker.equals(lock)) {
waiters.add(jt);
}
}
} catch (CorruptDataException cde) {
// out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
} catch (DataUnavailable du) {
// out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
}
}
return waiters.iterator();
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class WhatisCommand method checkMethodInRange.
private void checkMethodInRange(Iterator objects, long address) {
while (objects.hasNext()) {
JavaObject jObject = (JavaObject) objects.next();
JavaClass jClass;
try {
jClass = jObject.getJavaClass();
} catch (CorruptDataException cde) {
// go to the next iteration
continue;
}
Iterator methods = jClass.getDeclaredMethods();
while (methods.hasNext()) {
JavaMethod jMethod = (JavaMethod) methods.next();
Iterator bytecodeSections = jMethod.getBytecodeSections();
Iterator compiledSections = jMethod.getCompiledSections();
if (isWithinImageSections(bytecodeSections, jMethod, false, address)) {
// found it, we are done
return;
}
if (isWithinImageSections(compiledSections, jMethod, true, address)) {
// found it, we are done
return;
}
}
}
}
Aggregations