use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class PHDJavaRuntime method initClassCache.
private void initClassCache() {
for (PHDJavaClassLoader ldr : loaders.values()) {
for (Iterator<JavaClass> it = ldr.getDefinedClasses(); it.hasNext(); ) {
JavaClass cls = it.next();
ImagePointer ip = cls.getID();
if (ip != null) {
classIdCache.put(ip.getAddress(), cls);
} else {
// Some classes have pseudo ids
for (long l = 1; l <= lastDummyClassAddr(); ++l) {
if (cls.equals(ldr.findClass(l))) {
classIdCache.put(l, cls);
}
}
}
}
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class PHDJavaRuntime method getObjectAtAddress.
public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException, MemoryAccessException, DataUnavailable {
// Is it a class object?
final long addr = address.getAddress();
JavaClass cls = findClass(addr);
JavaObject jo;
if (cls != null) {
jo = cls.getObject();
if (jo != null && address.equals(jo.getID()))
return jo;
}
if ((jo = extraObjectsCache.get(addr)) != null) {
return jo;
} else {
// See if we already have this object
for (PHDJavaHeap heap : heaps) {
try {
jo = heap.getCachedObjectAtAddress(address, false);
} catch (IOException e) {
throw new DataUnavailable("The requested object could not be read from the PHD file");
}
if (jo != null)
return jo;
}
// Return a place holder object, may return corrupt data later
jo = new PHDJavaObject.Builder(heaps.get(0), addr, null, PHDJavaObject.NO_HASHCODE, -1).build();
}
return jo;
}
use of com.ibm.dtfj.java.JavaClass 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.java.JavaClass 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");
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class HeapdumpCommand method addReferences.
/**
* Extracts the instance references from an object
* @param object Object being walked
* @param references List<Long> to add references to
* @param thisClass Class of object
*/
private void addReferences(JavaObject object, List<Long> references) throws CorruptDataException, MemoryAccessException {
Iterator it = object.getReferences();
Object ref = null;
// discard the first reference which is always to the class
if (it.hasNext()) {
// test hasNext() to be on the safe side.
ref = it.next();
}
while (it.hasNext()) {
ref = it.next();
if (ref instanceof CorruptData) {
// can sometimes get a nasty surprise in the list - e.g. a J9DDRCorruptData
_numberOfErrors++;
reportError("Corrupt data found at address " + ((CorruptData) ref).getAddress() + " getting references from object at address: " + Long.toHexString(object.getID().getAddress()) + " of class " + object.getJavaClass().getName() + "(" + object.getJavaClass().getID() + ")", null);
continue;
}
if (!(ref instanceof JavaReference)) {
_numberOfErrors++;
reportError("Object of unexpected type " + ref.getClass() + " found within references from object at address: " + object.getID().getAddress() + " of class " + object.getJavaClass().getName() + "(" + object.getJavaClass().getID() + ")", null);
continue;
} else {
Object target;
try {
target = ((JavaReference) ref).getTarget();
} catch (DataUnavailable e) {
_numberOfErrors++;
reportError("DataUnavailable thrown from call to getTarget() on reference: " + ref, null);
continue;
}
// the following ugliness is necessary as JavaObject and JavaClass both support getID() but do not inherit from a common parent
if (target instanceof JavaObject) {
references.add(new Long(((JavaObject) target).getID().getAddress()));
} else if (target instanceof JavaClass) {
references.add(new Long(((JavaClass) target).getID().getAddress()));
} else {
_numberOfErrors++;
reportError("Object of unexpected type " + target.getClass() + " returned from call to getTarget() on reference " + ref, null);
}
}
}
}
Aggregations