use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class Utils method getClassGivenName.
public static JavaClass[] getClassGivenName(String className, JavaRuntime jr, PrintStream out) {
Iterator itJavaClassLoader = jr.getJavaClassLoaders();
List classes = new ArrayList();
while (itJavaClassLoader.hasNext()) {
Object nextCl = itJavaClassLoader.next();
if (!(nextCl instanceof JavaClassLoader)) {
continue;
}
JavaClassLoader jcl = (JavaClassLoader) nextCl;
Iterator itJavaClass = jcl.getDefinedClasses();
while (itJavaClass.hasNext()) {
Object next = itJavaClass.next();
if (!(next instanceof JavaClass)) {
continue;
}
JavaClass jc = (JavaClass) next;
String currClassName;
try {
currClassName = jc.getName();
if (currClassName.equals(className)) {
classes.add(jc);
}
} catch (CorruptDataException e) {
out.print("\t <error getting class name while traversing classes: ");
out.print(Exceptions.getCorruptDataExceptionString());
out.print(">\n");
currClassName = null;
}
}
}
if (classes.size() > 0) {
return (JavaClass[]) classes.toArray(new JavaClass[0]);
} else {
return null;
}
}
use of com.ibm.dtfj.java.JavaClass 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.JavaClass in project openj9 by eclipse.
the class Utils method getClassGivenAddress.
public static JavaClass getClassGivenAddress(long address, JavaRuntime jr) {
Iterator itJavaClassLoader = jr.getJavaClassLoaders();
while (itJavaClassLoader.hasNext()) {
Object nextCl = itJavaClassLoader.next();
if (!(nextCl instanceof JavaClassLoader)) {
continue;
}
JavaClassLoader jcl = (JavaClassLoader) nextCl;
Iterator itJavaClass = jcl.getDefinedClasses();
while (itJavaClass.hasNext()) {
Object next = itJavaClass.next();
if (!(next instanceof JavaClass)) {
continue;
}
if (next instanceof JavaClass) {
JavaClass jc = (JavaClass) next;
long currClassAddress = jc.getID().getAddress();
if (currClassAddress == address) {
return jc;
}
}
}
}
return null;
}
use of com.ibm.dtfj.java.JavaClass 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;
}
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class Utils method getThreadNameFromObject.
public static String getThreadNameFromObject(JavaObject lockOwnerObj, JavaRuntime rt, PrintStream out) throws CorruptDataException, MemoryAccessException {
if (lockOwnerObj == null) {
return null;
}
JavaClass[] threadClasses = Utils.getClassGivenName("java/lang/Thread", rt, out);
// We might have got no classes or more than one. Both of which should be pretty hard to manage.
if (threadClasses.length == 1) {
Iterator fields = threadClasses[0].getDeclaredFields();
while (fields.hasNext()) {
Object o = fields.next();
if (!(o instanceof JavaField)) {
continue;
}
JavaField f = (JavaField) o;
if ("name".equalsIgnoreCase(f.getName())) {
return f.getString(lockOwnerObj);
}
}
}
return null;
}
Aggregations