use of com.ibm.dtfj.java.JavaClass 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.JavaClass in project openj9 by eclipse.
the class InfoClassCommand method printClassDetails.
private void printClassDetails(JavaRuntime jr, String className, JavaClass jc) {
String spaces = " ";
String cdeInfo = "N/A (CorruptDataException occurred)";
try {
out.print("name = " + jc.getName());
} catch (CorruptDataException dce) {
out.print("name = " + cdeInfo);
}
out.print("\n\n\t");
out.print("ID = " + Utils.toHex(jc.getID()));
String superClassId;
try {
JavaClass superClass = jc.getSuperclass();
if (null == superClass) {
superClassId = "<no superclass>";
} else {
superClassId = Utils.toHex(superClass.getID());
}
} catch (CorruptDataException dce) {
superClassId = cdeInfo;
}
out.print(spaces);
out.print("superID = " + superClassId);
// Omitting size of class because that might differ between instances (i.e. arrays)
String classLoaderId;
try {
JavaClassLoader jClassLoader = jc.getClassLoader();
JavaObject jo = jClassLoader.getObject();
if (jo != null) {
classLoaderId = Utils.toHex(jo.getID());
} else {
classLoaderId = "<data unavailable>";
}
} catch (CorruptDataException cde) {
classLoaderId = cdeInfo;
}
out.print(spaces);
out.print("\n\t");
out.print("classLoader = " + classLoaderId);
String modifiersInfo;
try {
modifiersInfo = Utils.getClassModifierString(jc);
} catch (CorruptDataException cde) {
modifiersInfo = cdeInfo;
}
out.print(spaces);
out.print("modifiers: " + modifiersInfo);
out.print("\n\n");
ClassStatistics d = getClassStatisticsFor(jr, jc);
out.print("\tnumber of instances: " + d.getCount() + "\n");
out.print("\ttotal size of instances on the heap: " + d.getSize() + " bytes");
out.print("\n\n");
printClassHierarchy(jc);
out.print("\n");
printFields(jc);
out.print("\n");
printMethods(jc);
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class InfoClassCommand method countClassInstances.
private void countClassInstances() {
JavaRuntime runtime = ctx.getRuntime();
Map<JavaClass, ClassStatistics> thisRuntimeClasses = classInstanceCounts.get(runtime);
final Collection<JavaClass> javaClasses = getRuntimeClasses(runtime);
long corruptObjectCount = 0;
long corruptClassCount = 0;
long corruptClassNameCount = 0;
Iterator itHeap = runtime.getHeaps();
while (itHeap.hasNext()) {
Object heap = itHeap.next();
if (heap instanceof CorruptData) {
out.println("[skipping corrupt heap]");
continue;
}
JavaHeap jh = (JavaHeap) heap;
Iterator itObject = jh.getObjects();
// Walk through all objects in this heap, accumulating counts and total memory size by class
while (itObject.hasNext()) {
Object next = itObject.next();
// JavaHeap, we don't attempt to count these as instances of known classes).
if (next instanceof JavaObject) {
JavaObject jo = (JavaObject) next;
ClassStatistics stats = null;
try {
// Check whether we found this class in the classloaders walk earlier
JavaClass jc = jo.getJavaClass();
if (javaClasses.contains(jc)) {
stats = thisRuntimeClasses.get(jc);
} else {
// Class not found in the classloaders, create a statistic for it now, and issue a warning message
stats = new ClassStatistics();
thisRuntimeClasses.put(jc, stats);
String classname;
try {
classname = jc.getName();
out.println("Warning, class: " + classname + " found when walking the heap was missing from classloader walk");
} catch (CorruptDataException cde) {
corruptClassNameCount++;
}
}
// Increment the statistic for objects of this class (accumulated count and size)
stats.incrementCount();
try {
stats.addToSize(jo.getSize());
} catch (CorruptDataException cde) {
// bad size, count object as corrupt
corruptObjectCount++;
}
} catch (CorruptDataException cde) {
corruptClassCount++;
}
} else {
corruptObjectCount++;
}
}
}
if (corruptObjectCount != 0) {
out.println("Warning, found " + corruptObjectCount + " corrupt objects during heap walk");
}
if (corruptClassCount != 0) {
out.println("Warning, found " + corruptClassCount + " corrupt class references during heap walk");
}
if (corruptClassNameCount != 0) {
out.println("Warning, found " + corruptClassNameCount + " corrupt class names during heap walk");
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class JavaThread method getPriority.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaThread#getPriority()
*/
public int getPriority() throws CorruptDataException {
JavaObject theObject = getObject();
if (null != theObject) {
JavaClass threadClass = _javaLangThreadSuperclass();
Iterator fields = threadClass.getDeclaredFields();
while (fields.hasNext()) {
JavaField oneField = (JavaField) fields.next();
if (oneField.getName().equals("priority")) {
try {
return oneField.getInt(theObject);
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to read memory for 'priority' field", null));
}
}
}
throw new CorruptDataException(new CorruptData("unable to find 'priority' field", null));
} else {
// TODO: have a good exception for this sort of thing
return -1;
}
}
use of com.ibm.dtfj.java.JavaClass 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);
}
}
Aggregations