use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class PHDJavaRuntime method prepClassLoaders.
/**
* Remember objects associated with class loaders
* Performance optimization - we can then find these objects on a scan through the heap
* and remember them, saving a fruitless search of the heap if they only exist in a javacore.
*/
private void prepClassLoaders() {
if (metaJavaRuntime != null) {
final PHDJavaClassLoader boot = loaders.get(null);
for (Iterator it = metaJavaRuntime.getJavaClassLoaders(); it.hasNext(); ) {
Object next = it.next();
if (next instanceof CorruptData)
continue;
JavaClassLoader load = (JavaClassLoader) next;
try {
JavaObject jo = load.getObject();
saveExtraObject(boot, jo);
} catch (CorruptDataException e) {
}
}
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class PHDJavaRuntime method saveExtraObject.
private void saveExtraObject(final PHDJavaClassLoader boot, JavaObject jo) {
if (jo != null) {
long addr = jo.getID().getAddress();
JavaClass cls;
try {
cls = boot.findClassUnique(jo.getJavaClass().getName());
} catch (CorruptDataException e) {
cls = null;
}
// Construct a dummy object with little information in case the object is not in the heap
JavaObject jo2 = new PHDJavaObject.Builder(heaps.get(0), addr, cls, PHDJavaObject.NO_HASHCODE, -1).refsAsArray(NOREFS, 0).length(PHDJavaObject.UNKNOWN_TYPE).build();
extraObjectsCache.put(addr, jo2);
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class Utils method getVal.
// note: this method lets you pass in a null JavaObject, but it _will_ throw a
// NullPointerException if the JavaField is not a static field when you pass it
// a null JavaObject; this is the behavior of jf.get() and jf.getString()
public static String getVal(JavaObject jo, JavaField jf) {
Object o;
String s;
if (null == jf) {
o = jo;
s = null;
} else {
try {
o = jf.get(jo);
} catch (CorruptDataException e) {
return "<corrupt data>";
} catch (MemoryAccessException d) {
return "<invalid memory address>";
} catch (NumberFormatException nfe) {
return "<invalid number>";
}
try {
s = jf.getString(jo);
} catch (CorruptDataException e) {
s = null;
} catch (MemoryAccessException e) {
s = null;
} catch (IllegalArgumentException e) {
s = null;
}
}
return getVal(o, s, jf);
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class Utils method getVal.
public static String getVal(Object o, String str, JavaField jf) {
String val = "";
Long value = null;
boolean object = false;
if (null == o) {
val += "null";
} else {
if (o instanceof Boolean) {
val += ((Boolean) o).toString();
} else if (o instanceof Byte) {
byte b = ((Byte) o).byteValue();
val += String.valueOf(b);
value = new Long((new Byte(b)).longValue());
} else if (o instanceof Character) {
char c = ((Character) o).charValue();
val += Utils.getPrintableWithQuotes(c);
value = new Long((new Integer((int) c).longValue()));
} else if (o instanceof Double) {
double d = ((Double) o).doubleValue();
val += String.valueOf(d);
value = new Long(Double.doubleToRawLongBits(d));
} else if (o instanceof Float) {
float f = ((Float) o).floatValue();
val += String.valueOf(f);
value = new Long(Float.floatToRawIntBits(f));
} else if (o instanceof Integer) {
int i = ((Integer) o).intValue();
val += String.valueOf(i);
value = new Long((new Integer(i)).longValue());
} else if (o instanceof Long) {
long l = ((Long) o).longValue();
val += String.valueOf(l);
value = new Long(l);
} else if (o instanceof Short) {
short s = ((Short) o).shortValue();
val += String.valueOf(s);
value = new Long((new Short(s)).longValue());
} else if (o instanceof String) {
val += (String) o;
} else if (o instanceof JavaObject) {
if (Utils.isNull((JavaObject) o)) {
val += "null";
} else {
object = true;
}
} else {
// FIXME
}
// because we want control over the exceptions that are thrown
if (object) {
JavaObject joField = (JavaObject) o;
JavaClass jcField;
String jcName;
try {
jcField = joField.getJavaClass();
} catch (CorruptDataException e) {
jcField = null;
}
try {
if (null != jcField) {
jcName = jcField.getName();
} else {
jcName = null;
}
} catch (CorruptDataException e) {
jcName = null;
}
if (null != jcName && jcName.equals("java/lang/String")) {
if (null == str) {
val += getStringVal(joField);
} else {
val += "\"" + Utils.getPrintable(str) + "\"";
}
val += " @ ";
val += Utils.toHex(joField.getID().getAddress());
} else {
val += "<object>" + " @ " + Utils.toHex(joField.getID().getAddress());
}
}
}
if (null != value) {
val += " (";
val += Utils.toHex(value.longValue());
val += ")";
}
return val;
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class HeapdumpCommand method dumpHeap.
/**
* Walks the supplied heap and passes the artifacts through the formatter
*/
private void dumpHeap(HeapDumpFormatter formatter, JavaHeap thisHeap) throws IOException {
Iterator objectIterator = thisHeap.getObjects();
while (objectIterator.hasNext()) {
Object next = objectIterator.next();
_numberOfObjects++;
if (next instanceof CorruptData) {
_numberOfErrors++;
reportError("Corrupt object data found at " + ((CorruptData) next).getAddress() + " while walking heap " + thisHeap.getName(), null);
continue;
}
try {
JavaObject thisObject = (JavaObject) next;
if (thisObject.getJavaClass().getName().equals("java/lang/Class")) {
// heap classes are handled separately, in dumpClasses()
continue;
}
JavaClass thisClass = thisObject.getJavaClass();
JavaObject thisClassObject = thisClass.getObject();
int hashcode = 0;
if (_is32BitHash) {
// JVMs from 2.6 on, optional 32-bit hashcodes, if object was hashed
try {
hashcode = (int) thisObject.getPersistentHashcode();
} catch (DataUnavailable ex) {
// no persistent hashcode for this object, pass hashcode=0 to the heapdump formatter
}
} else {
// JVMs prior to 2.6, all objects should have a 16-bit hashcode
try {
hashcode = (int) thisObject.getHashcode();
} catch (DataUnavailable ex) {
_numberOfErrors++;
reportError("Failed to get hashcode for object: " + thisObject.getID(), ex);
}
}
if (thisObject.isArray()) {
if (isPrimitive(thisClass.getComponentType())) {
formatter.addPrimitiveArray(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), getPrimitiveTypeCode(thisClass.getComponentType()), thisObject.getSize(), hashcode, thisObject.getArraySize());
} else {
formatter.addObjectArray(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), thisClass.getName(), thisClass.getComponentType().getObject().getID().getAddress(), thisClass.getComponentType().getName(), thisObject.getSize(), thisObject.getArraySize(), hashcode, getObjectReferences(thisObject));
}
} else {
formatter.addObject(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), thisClass.getName(), (int) thisObject.getSize(), hashcode, getObjectReferences(thisObject));
}
} catch (CorruptDataException ex) {
_numberOfErrors++;
reportError(null, ex);
continue;
}
}
}
Aggregations