use of com.ibm.dtfj.java.JavaObject 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.JavaObject 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.JavaObject in project openj9 by eclipse.
the class InfoLockCommand method showJavaUtilConcurrentLocks.
private void showJavaUtilConcurrentLocks() {
// A map of lock objects and their waiting threads.
Map locksToThreads = new HashMap();
JavaRuntime jr = ctx.getRuntime();
Iterator itThread = jr.getThreads();
while (itThread.hasNext()) {
try {
Object o = itThread.next();
if (!(o instanceof JavaThread)) {
continue;
}
JavaThread jt = (JavaThread) o;
if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
JavaObject lock = jt.getBlockingObject();
if (lock != null) {
List parkedList = (List) locksToThreads.get(lock);
if (parkedList == null) {
parkedList = new LinkedList();
locksToThreads.put(lock, parkedList);
}
parkedList.add(jt);
}
}
} catch (CorruptDataException cde) {
out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
} catch (DataUnavailable du) {
out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
}
}
out.println("\njava.util.concurrent locks in use...");
if (locksToThreads.size() == 0) {
out.println("\t...None.");
out.println();
}
for (Object e : locksToThreads.entrySet()) {
try {
Map.Entry entry = (Map.Entry) e;
JavaObject lock = (JavaObject) entry.getKey();
List threads = (List) entry.getValue();
String threadName = "<unowned>";
JavaThread lockOwnerThread = Utils.getParkBlockerOwner(lock, ctx.getRuntime());
if (lockOwnerThread != null) {
threadName = lockOwnerThread.getName();
} else {
// If the owning thread has ended we won't find the JavaThread
// We can still get the owning thread name from the java.lang.Thread object itself.
JavaObject lockOwnerObj = Utils.getParkBlockerOwnerObject(lock, ctx.getRuntime());
if (lockOwnerObj != null) {
threadName = Utils.getThreadNameFromObject(lockOwnerObj, ctx.getRuntime(), out);
} else {
threadName = "<unknown>";
}
}
if (threads != null && threads.size() > 0) {
String lockID = Long.toHexString(lock.getID().getAddress());
ImageThread imageThread = (lockOwnerThread != null ? lockOwnerThread.getImageThread() : null);
out.println(lock.getJavaClass().getName() + "@0x" + lockID + "\n\tlocked by java thread id: " + ((imageThread != null) ? imageThread.getID() : "<null>") + " name: " + (threadName));
for (Object t : threads) {
JavaThread waiter = (JavaThread) t;
out.println("\twaiting thread id: " + waiter.getImageThread().getID() + " name: " + waiter.getName());
}
}
} catch (CorruptDataException cde) {
out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
} catch (MemoryAccessException ma) {
out.println("\nwarning, memory access error encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getMemoryAccessExceptionString(), ma);
} catch (DataUnavailable du) {
out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
}
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class JavaRuntimeBuilder method addJavaStackFrame.
/**
*/
public JavaStackFrame addJavaStackFrame(JavaThread javaThread, String className, String classFileName, String methodName, String methodType, String compilationLevel, int lineNumber) throws BuilderFailureException {
try {
JCJavaThread jThread = (JCJavaThread) javaThread;
JCJavaClass jclass = getJavaRuntime().findJavaClass(className);
if (jclass == null) {
jclass = new JCJavaClass(getJavaRuntime(), className);
}
JCJavaMethod method = new JCJavaMethod(methodName, jclass);
JCJavaLocation location = new JCJavaLocation(method);
location.setFilename(classFileName);
location.setCompilation(compilationLevel);
location.setLineNumber(lineNumber);
JCJavaStackFrame stackFrame = new JCJavaStackFrame(jThread, location);
if ("run".equals(methodName)) {
/*
* Perhaps the type of the thread is the type of the last run() method.
* Not strictly accurate if the class was extended without overriding run().
* Add the object only if the object ID is valid.
*/
try {
JavaObject jo = jThread.getObject();
if (jo != null) {
ImagePointer tid = jo.getID();
if (fAddressSpace.isValidAddressID(tid.getAddress())) {
JCJavaObject jobject = new JCJavaObject(tid, jclass);
jThread.setObject(jobject);
}
}
} catch (CorruptDataException e) {
// Ignore
}
}
return stackFrame;
} catch (JCInvalidArgumentsException e) {
throw new BuilderFailureException(e);
}
}
use of com.ibm.dtfj.java.JavaObject 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;
}
}
Aggregations