use of com.ibm.dtfj.image.DTFJException in project openj9 by eclipse.
the class InfoThreadCommand method getJavaThreads.
private Map getJavaThreads(String id) {
Map threads = new HashMap();
ManagedRuntime mr = ctx.getRuntime();
if (mr instanceof JavaRuntime) {
JavaRuntime jr = (JavaRuntime) mr;
Iterator itThread = jr.getThreads();
while (itThread.hasNext()) {
Object next = itThread.next();
// skip any corrupt threads
if (next instanceof CorruptData)
continue;
JavaThread jt = (JavaThread) next;
// Obtain the native thread ID for this thread, and for zOS also obtain the TCB
String currentTID = null;
String currentTCB = null;
try {
ImageThread it = jt.getImageThread();
currentTID = it.getID();
if (_is_zOS) {
currentTCB = it.getProperties().getProperty("TCB");
}
} catch (DTFJException e) {
// Continue with what we have obtained so far
}
if (null == id) {
// save all orphaned java threads in a list within the hashmap
if (null == currentTID) {
if (threads.containsKey(null)) {
ArrayList ta = (ArrayList) threads.get(null);
ta.add(new ThreadData(jt, jr));
} else {
ArrayList ta = new ArrayList(1);
ta.add(new ThreadData(jt, jr));
threads.put(null, ta);
}
} else {
threads.put(currentTID, new ThreadData(jt, jr));
}
} else if (id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
// We just want the specific Java thread that matches the native thread ID or zOS TCB
threads.put(currentTID, new ThreadData(jt, jr));
}
}
}
return threads;
}
use of com.ibm.dtfj.image.DTFJException in project openj9 by eclipse.
the class HeapdumpCommand method getClassReferences.
/* Reference code reimplemented (rather than using the DTFJ getReferences() API)
* because we are trying to match the behaviour of the runtime heapdump rather than
* the GC spec. The set of references we're trying to create is different.
*/
/**
* Gets the references for the supplied class
*
* @param thisJavaClass Class being examined
*/
private ReferenceIterator getClassReferences(JavaClass thisJavaClass) {
List references = new LinkedList();
try {
// Class object instance references
addReferences(thisJavaClass.getObject(), references);
// Statics
addStaticReferences(thisJavaClass, references);
addProtectionDomainReference(thisJavaClass, references);
// Constant pool class references
Iterator constantPoolIt = thisJavaClass.getConstantPoolReferences();
while (constantPoolIt.hasNext()) {
Object cpObject = constantPoolIt.next();
if (cpObject instanceof JavaClass) {
// Found a class reference, add it to the list
JavaClass cpJavaClass = (JavaClass) cpObject;
references.add(new Long(cpJavaClass.getObject().getID().getAddress()));
}
}
// Superclass references
JavaClass superClass = thisJavaClass.getSuperclass();
while (null != superClass) {
references.add(new Long(superClass.getObject().getID().getAddress()));
superClass = superClass.getSuperclass();
}
// Classloader
JavaClassLoader loader = thisJavaClass.getClassLoader();
if (loader != null) {
JavaObject loaderObject = loader.getObject();
if (loaderObject != null) {
references.add(new Long(loaderObject.getID().getAddress()));
} else {
reportError("Null loader object returned for class: " + thisJavaClass.getName() + "(" + thisJavaClass.getID() + ")", null);
_numberOfErrors++;
}
} else {
reportError("Null classloader returned for class: " + thisJavaClass.getName() + "(" + thisJavaClass.getID() + ")", null);
_numberOfErrors++;
}
} catch (DTFJException ex) {
reportError(null, ex);
_numberOfErrors++;
}
return new LongListReferenceIterator(references);
}
use of com.ibm.dtfj.image.DTFJException in project openj9 by eclipse.
the class HeapdumpCommand method dumpClasses.
/**
* Walks the runtime classes and passes them through the formatter interface
*/
private void dumpClasses(HeapDumpFormatter formatter, JavaRuntime runtime) throws IOException {
Iterator classLoaderIt = runtime.getJavaClassLoaders();
int numberOfClasses = 0;
ITERATING_LOADERS: while (classLoaderIt.hasNext()) {
Object potential = classLoaderIt.next();
if (potential instanceof CorruptData) {
_numberOfErrors++;
reportError("CorruptData found in classloader list at address: " + ((CorruptData) potential).getAddress(), null);
continue ITERATING_LOADERS;
}
JavaClassLoader thisClassLoader = (JavaClassLoader) potential;
Iterator classesIt = thisClassLoader.getDefinedClasses();
ITERATING_CLASSES: while (classesIt.hasNext()) {
potential = classesIt.next();
numberOfClasses++;
try {
if (potential instanceof CorruptData) {
_numberOfErrors++;
reportError("CorruptData found in class list for classloader " + Long.toHexString(thisClassLoader.getObject().getID().getAddress()) + " at address: " + ((CorruptData) potential).getAddress(), null);
continue ITERATING_CLASSES;
}
JavaClass thisJavaClass = (JavaClass) potential;
JavaClass superClass = thisJavaClass.getSuperclass();
JavaObject classObject = thisJavaClass.getObject();
long instanceSize;
if (thisJavaClass.isArray()) {
instanceSize = 0;
} else {
instanceSize = thisJavaClass.getInstanceSize();
}
int hashcode = 0;
if (_is32BitHash) {
// JVMs from 2.6 on, optional 32-bit hashcodes, if object was hashed
try {
hashcode = classObject != null ? (int) classObject.getPersistentHashcode() : 0;
} 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
hashcode = classObject != null ? (int) classObject.getHashcode() : 0;
}
formatter.addClass(classObject.getID().getAddress(), thisJavaClass.getName(), superClass != null ? superClass.getID().getAddress() : 0, classObject != null ? (int) classObject.getSize() : 0, instanceSize, hashcode, getClassReferences(thisJavaClass));
} catch (DTFJException ex) {
// Handle CorruptDataException and DataUnavailableException the same way
_numberOfErrors++;
reportError(null, ex);
continue ITERATING_CLASSES;
}
}
}
_numberOfClasses = numberOfClasses;
if ((pdSkipCount > 0) && _verbose) {
out.println("Warning : The protection domain information was not available for " + pdSkipCount + " classes");
}
}
Aggregations