use of com.ibm.dtfj.java.JavaObject 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;
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class NodeList method toString.
// Print this list of monitor nodes (ie the owning threads and there object addresses)
public String toString() {
String retval = "";
MonitorNode currNode = tail;
MonitorNode lastNode = null;
boolean firstTime = true;
boolean done = false;
do {
String name = "";
String objAddr = "";
JavaObject object = null;
JavaThread owner = null;
try {
owner = currNode.getOwner();
name = owner.getName();
ImageThread nativeThread = owner.getImageThread();
if (nativeThread != null) {
name = name + " id: " + nativeThread.getID();
}
} catch (CorruptDataException e) {
name = Exceptions.getCorruptDataExceptionString();
} catch (DataUnavailable e) {
name = Exceptions.getDataUnavailableString();
} catch (MemoryAccessException e) {
name = Exceptions.getMemoryAccessExceptionString();
}
object = currNode.getObject();
if (null == object) {
objAddr = " at : " + Utils.toHex(currNode.getMonitorAddress());
} else {
objAddr = " object : " + Utils.toHex(object.getID().getAddress());
}
String lockName = currNode.getType();
retval += "thread: " + name + " (owns " + lockName + objAddr + ") waiting for =>\n\t ";
lastNode = currNode;
currNode = currNode.waitingOn;
if (head == lastNode) {
if (firstTime && head == tail)
done = false;
else
done = true;
}
firstTime = false;
} while (!done);
// removes the tail of the last entry
retval = retval.substring(0, retval.length() - 18);
return retval;
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class WhatisCommand method isStartOfObj.
private boolean isStartOfObj(Iterator objects, long address) {
String className;
long corruptObjectCount = 0;
while (objects.hasNext()) {
Object obj = objects.next();
if (obj instanceof CorruptData) {
corruptObjectCount++;
continue;
}
JavaObject jObject = (JavaObject) obj;
if (address == jObject.getID().getAddress()) {
try {
className = jObject.getJavaClass().getName();
} catch (CorruptDataException cde) {
className = "<corrupt class name>";
}
out.print("\t\t0x" + Long.toHexString(address) + " is the start of an object of type " + className);
return true;
}
}
if (corruptObjectCount > 0) {
out.println("\t\t[skipped " + corruptObjectCount + " corrupt object(s) in heap]");
}
return false;
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class JavaClass method getConstantPoolReferences.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaClass#getConstantPoolReferences()
*/
public Iterator getConstantPoolReferences() {
// first look up all the class IDs and translate them into classes then add the objects
Iterator ids = _constantPoolClassRefs.iterator();
Vector allRefs = new Vector();
while (ids.hasNext()) {
long oneID = ((Long) ids.next()).longValue();
Object toBeAdded = null;
com.ibm.dtfj.java.JavaClass oneClass = _javaVM.getClassForID(oneID);
if (oneClass == null) {
toBeAdded = new CorruptData("Unknown class in constant pool " + oneID, null);
} else {
try {
toBeAdded = oneClass.getObject();
} catch (CorruptDataException e) {
toBeAdded = e.getCorruptData();
} catch (Exception e) {
toBeAdded = new CorruptData(e.getMessage());
}
}
allRefs.add(toBeAdded);
}
// Loop through the list of constant pool objects, instantiating them and adding them to the list
for (int i = 0; i < _constantPoolObjects.size(); i++) {
try {
long objectId = ((Long) (_constantPoolObjects.get(i))).longValue();
if (objectId != 0) {
ImagePointer pointer = _javaVM.pointerInAddressSpace(objectId);
try {
JavaObject instance = _javaVM.getObjectAtAddress(pointer);
allRefs.add(instance);
} catch (IllegalArgumentException e) {
// getObjectAtAddress may throw an IllegalArgumentException if the address is not aligned
allRefs.add(new CorruptData(e.getMessage(), pointer));
}
}
} catch (CorruptDataException e) {
allRefs.add(e.getCorruptData());
}
}
return allRefs.iterator();
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class JavaRuntime method getObjectAtAddress.
// CMVC 173262 - improve validation - throw NPE if address is null, throw IAE if address = 0, throw IAE if address in not correctly aligned
public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException {
if (null == address) {
throw new NullPointerException("The ImagePointer was null");
}
long ptr = address.getAddress();
if (0 == ptr) {
throw new IllegalArgumentException("The object address " + ptr + " is not in any heap");
}
Iterator heaps = getHeaps();
JavaHeapRegion region = null;
JavaHeap heap = null;
while ((null == region) && (heaps.hasNext())) {
heap = (JavaHeap) (heaps.next());
region = heap.regionForPointer(address);
}
if (null == region) {
// We permit off-heap objects to be created, eg for class objects prior to J9 2.4 (default to 8-byte alignment - this won't actually be used since it is only needed for walking arraylet sections)
if ((address.getAddress() & DEFAULT_OBJECT_ALIGNMENT - 1) != 0) {
throw new IllegalArgumentException("Invalid alignment for JavaObject. Address = " + address.toString());
}
return new com.ibm.dtfj.java.j9.JavaObject(this, address, heap, 0, 0, false, DEFAULT_OBJECT_ALIGNMENT);
} else {
return region.getObjectAtAddress(address);
}
}
Aggregations