use of com.ibm.dtfj.java.JavaField in project openj9 by eclipse.
the class DTFJJavaObject method getAssociatedClass.
private JavaClass getAssociatedClass() {
// Retrieve the class loader for this class for using introspection to speed up
// lookup when lots of classes are loaded by lots of class loaders.
JavaObject targetClassLoaderObject = null;
try {
JavaClass javaLangClass = this.getJavaClass();
Iterator<?> fields = javaLangClass.getDeclaredFields();
while (fields.hasNext()) {
Object o = fields.next();
if (o instanceof JavaField) {
JavaField field = (JavaField) o;
if ("classLoader".equals(field.getName())) {
targetClassLoaderObject = (JavaObject) field.get(this);
break;
}
}
}
} catch (CorruptDataException e) {
// This is only an optimisation to save us walking all class loaders. Continue
} catch (MemoryAccessException e) {
// This is only an optimisation to save us walking all class loaders. Continue
}
return getAssociatedClass(targetClassLoaderObject);
}
use of com.ibm.dtfj.java.JavaField in project openj9 by eclipse.
the class DTFJJavaField method equals.
public boolean equals(Object obj) {
boolean isEqual = false;
if (obj instanceof JavaField) {
JavaField field = (JavaField) obj;
boolean hasSameName;
try {
hasSameName = name.equals(field.getName());
} catch (CorruptDataException cde) {
hasSameName = false;
}
try {
isEqual = hasSameName && (getClass().equals(field.getClass())) && clazz.equals(field.getDeclaringClass());
} catch (Throwable t) {
J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
}
}
return isEqual;
}
use of com.ibm.dtfj.java.JavaField in project openj9 by eclipse.
the class InfoThreadCommand method printJavaThreadInfo.
private void printJavaThreadInfo(JavaThread jt, boolean idPrinted) {
out.print(" name: ");
try {
out.print(jt.getName());
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
}
out.print("\n");
if (!idPrinted) {
try {
if (jt.getImageThread() != null) {
out.print(" id: ");
out.print(jt.getImageThread().getID());
}
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
} catch (DataUnavailable e) {
out.print(Exceptions.getDataUnavailableString());
logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), e);
} finally {
out.print("\n");
}
}
out.print(" Thread object: ");
try {
JavaObject threadObj = jt.getObject();
if (null == threadObj) {
out.print("<no associated Thread object>");
} else {
String threadClassName = null;
try {
JavaClass threadClass = threadObj.getJavaClass();
threadClassName = threadClass.getName();
if (threadClassName != null) {
out.print(threadClassName + " @ ");
}
out.print(Utils.toHex(threadObj.getID().getAddress()));
// Navigate to the parent java/lang.Thread class to get the 'tid' and 'isDaemon' fields
while (!JAVA_LANG_THREAD_CLASS.equals(threadClass.getName()) && threadClass != null) {
threadClass = threadClass.getSuperclass();
}
if (threadClass != null) {
Iterator itField = threadClass.getDeclaredFields();
boolean foundThreadId = false;
while (itField.hasNext()) {
JavaField jf = (JavaField) itField.next();
/* "uniqueId" field in java.lang.Thread is renamed to "tid". The old field name is
* checked to preserve functionality of DDR command with old core files that reference
* the "uniqueId" field.
*/
if (!foundThreadId && (jf.getName().equals("uniqueId") || jf.getName().equals("tid"))) {
foundThreadId = true;
out.print("\n ID: " + Utils.getVal(threadObj, jf));
} else if (jf.getName().equals("isDaemon")) {
out.print("\n Daemon: " + Utils.getVal(threadObj, jf));
}
}
}
} catch (CorruptDataException cde) {
out.print(" <in-flight or corrupt data encountered>");
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
}
}
} catch (CorruptDataException cde) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
}
out.print("\n");
out.print(" Priority: ");
try {
Integer pri = new Integer(jt.getPriority());
out.print(pri.toString());
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
}
out.print("\n");
out.print(" Thread.State: ");
try {
out.print(StateToString.getThreadStateString(jt.getState()));
} catch (CorruptDataException cde) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
}
out.print("\n");
out.print(" JVMTI state: ");
try {
out.print(StateToString.getJVMTIStateString(jt.getState()));
} catch (CorruptDataException cde) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), cde);
}
out.print("\n");
printThreadBlocker(jt);
out.print(" Java stack frames: ");
printJavaStackFrameInfo(jt);
out.print("\n");
}
use of com.ibm.dtfj.java.JavaField in project openj9 by eclipse.
the class Utils method getStringVal.
private static String getStringVal(JavaObject jo) {
JavaClass jc;
try {
jc = jo.getJavaClass();
} catch (CorruptDataException e) {
return "<cannot get String class from String object (" + Exceptions.getCorruptDataExceptionString() + ")>";
}
Iterator itJavaField = jc.getDeclaredFields();
JavaField jf = null;
while (itJavaField.hasNext()) {
jf = (JavaField) itJavaField.next();
try {
if (jf.getSignature().equals("[C") && !Modifier.isStatic(jf.getModifiers()))
break;
} catch (CorruptDataException e) {
// if we have an exception, do nothing and go onto the next field
}
}
if (jf == null) {
// empty field iterator (occurs e.g. when reading PHD heapdumps), can't get the char array
return "<cannot get char array out of String>";
}
JavaObject charArray = null;
try {
charArray = (JavaObject) jf.get(jo);
} catch (CorruptDataException e) {
return "<cannot get char array out of String (" + Exceptions.getCorruptDataExceptionString() + ")>";
} catch (MemoryAccessException e) {
return "<cannot get char array out of String (" + Exceptions.getMemoryAccessExceptionString() + ")>";
}
int arraySize;
try {
arraySize = charArray.getArraySize();
} catch (CorruptDataException e) {
return "<cannot determine the size of the array (" + Exceptions.getCorruptDataExceptionString() + ")>";
}
char[] dst = new char[arraySize];
try {
charArray.arraycopy(0, dst, 0, arraySize);
} catch (CorruptDataException e) {
return "<cannot copy data from the array (" + Exceptions.getCorruptDataExceptionString() + ")>";
} catch (MemoryAccessException e) {
return "<cannot copy data from the array (" + Exceptions.getMemoryAccessExceptionString() + ")>";
}
return "\"" + Utils.getPrintable(new String(dst)) + "\"";
}
use of com.ibm.dtfj.java.JavaField 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