use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class WhatisCommand method checkClassInRange.
/* TODO: need to implement some output for this method and use it
private void checkMonitorInRange(Iterator monitors){
while(monitors.hasNext()){
JavaMonitor jMonitor = (JavaMonitor)monitors.next();
//TODO: need API for retrieving monitor ID (address)
//sb.append("\n" + "monitor object id: " + jMonitor.getObject().getID().getAddress());
}
}
*/
private void checkClassInRange(Iterator objects, long bound, long address) {
long startAddress, endAddress;
while (objects.hasNext()) {
JavaObject jObject = (JavaObject) objects.next();
JavaClass jClass;
String className;
try {
jClass = jObject.getJavaClass();
className = jClass.getName();
} catch (CorruptDataException cde) {
// TODO exception handling
continue;
}
startAddress = jClass.getID().getAddress();
endAddress = startAddress + bound;
if (address == startAddress) {
out.print("\t0x" + Long.toHexString(address) + " is the address of the java/lang/Class object for " + className);
return;
}
if (isWithinRange(startAddress, endAddress, address)) {
out.print("0x" + Long.toHexString(address) + " is within the java/lang/Class object for " + className);
return;
}
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class InfoLockCommand method showSystemLocks.
private void showSystemLocks() {
Vector vMonitorsWithLockedObjects = new Vector();
JavaRuntime jRuntime = ctx.getRuntime();
Iterator monitors = jRuntime.getMonitors();
out.println("\nSystem locks...");
while (monitors.hasNext()) {
JavaMonitor jMonitor = (JavaMonitor) monitors.next();
JavaObject jObject = jMonitor.getObject();
try {
String monitorName = jMonitor.getName().trim();
if (monitorName.equalsIgnoreCase("")) {
monitorName = "<un-named monitor>";
}
out.println("id: 0x" + jMonitor.getID() + " name: " + jMonitor.getName());
JavaThread owner = jMonitor.getOwner();
if (null != owner) {
try {
out.println("\towner thread id: " + owner.getImageThread().getID() + " name: " + owner.getName());
} catch (DataUnavailable e) {
out.println("\towner thread id: " + Exceptions.getDataUnavailableString());
logger.log(Level.FINE, Exceptions.getDataUnavailableString(), e);
}
}
showWaiters(jMonitor);
} catch (CorruptDataException cde) {
out.println("\nwarning, corrupt data encountered during scan for system locks...");
}
if (null != jObject) {
// Remember object monitors (flat or inflated) for later
vMonitorsWithLockedObjects.add(jMonitor);
}
}
showLockedObjects(vMonitorsWithLockedObjects);
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class InfoLockCommand method showLockedObjects.
private void showLockedObjects(Vector vMonitorsWithLockedObjects) {
out.println("\nObject Locks in use...");
if (0 == vMonitorsWithLockedObjects.size()) {
out.println("\t...None.");
return;
}
Iterator lockedObjects = vMonitorsWithLockedObjects.iterator();
while (lockedObjects.hasNext()) {
JavaMonitor jMonitor = (JavaMonitor) lockedObjects.next();
JavaObject jObject = jMonitor.getObject();
try {
JavaThread owner = jMonitor.getOwner();
String className = "<unknown class>";
JavaClass jClass = jObject.getJavaClass();
if (null != jClass) {
className = jClass.getName();
}
String jObjectID = Long.toHexString(jObject.getID().getAddress());
if (null == owner) {
out.println(className + "@0x" + jObjectID);
} else {
String owningThreadID = null;
try {
owningThreadID = owner.getImageThread().getID();
} catch (DataUnavailable e) {
owningThreadID = Exceptions.getDataUnavailableString();
}
out.println(className + "@0x" + jObjectID);
out.println("\towner thread id: " + owningThreadID + " name: " + owner.getName());
}
showWaiters(jMonitor);
} catch (CorruptDataException cde) {
logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
}
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class XJCommand method printObjectsFromName.
private void printObjectsFromName(JavaHeap jh, String objName, PrintStream out, boolean supers, JavaRuntime jr) {
if (objName != null) {
JavaClass[] classes = Utils.getClassGivenName(objName, jr, out);
// still be an array type or it might not exist
if (classes == null || classes.length == 0) {
out.print("\t could not find class with name \"" + objName + "\"\n\n");
return;
}
for (int i = 0; i < classes.length; i++) {
boolean foundInstance = false;
JavaClass objClass = classes[i];
if (classes.length > 1) {
ClassOutput.printRuntimeClassAndLoader(objClass, out);
}
ClassOutput.printStaticFields(objClass, out);
Iterator<?> itObject = jh.getObjects();
int corruptObjectCount = 0;
while (itObject.hasNext()) {
Object obj = itObject.next();
if (obj instanceof CorruptData) {
// skip the corrupt object
corruptObjectCount++;
continue;
}
JavaObject jo = (JavaObject) obj;
String hierarchy = "";
JavaClass jc;
try {
jc = jo.getJavaClass();
} catch (CorruptDataException e) {
out.print("\t <error getting class while traversing objects: ");
out.print(Exceptions.getCorruptDataExceptionString());
out.print(">\n");
jc = null;
}
boolean foundSuperclass = false;
while (jc != null && !foundSuperclass) {
String className;
try {
className = jc.getName();
} catch (CorruptDataException e) {
out.print("\t <error getting class name while traversing objects: ");
out.print(Exceptions.getCorruptDataExceptionString());
out.print(">\n");
jc = null;
continue;
}
if (hierarchy.equals("")) {
hierarchy = className;
} else {
hierarchy = className + " => " + hierarchy;
}
if (jc.equals(objClass)) {
foundInstance = true;
foundSuperclass = true;
out.print("\t ");
out.print(hierarchy);
out.print(" @ ");
out.print(Utils.toHex(jo.getID().getAddress()));
out.print("\n");
ClassOutput.printFields(jo, jc, jr, out);
printReferences(jo, out);
} else {
if (supers) {
try {
jc = jc.getSuperclass();
} catch (CorruptDataException e) {
out.print("\t <error getting superclass while traversing objects: ");
out.print(Exceptions.getCorruptDataExceptionString());
out.print(">\n");
jc = null;
}
} else {
jc = null;
}
}
}
}
if (!foundInstance) {
out.print("\t <no object of class \"");
out.print(objName);
out.print("\" exists>\n\n");
}
if (corruptObjectCount != 0) {
out.println("\t Warning : " + corruptObjectCount + " corrupt objects were skipped\n");
}
}
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class XJCommand method printObjectsFromAddress.
private void printObjectsFromAddress(JavaHeap jh, Long objAddress, PrintStream out, JavaRuntime jr) {
JavaObject jo;
Iterator<?> itObject = jh.getObjects();
boolean found = false;
boolean done = false;
int corruptObjectCount = 0;
while (itObject.hasNext() && !done) {
Object obj = itObject.next();
if (obj instanceof CorruptData) {
// skip the corrupt object
corruptObjectCount++;
continue;
}
jo = (JavaObject) obj;
if (jo.getID().getAddress() == objAddress.longValue()) {
JavaClass jc;
found = true;
out.print("\t ");
try {
jc = jo.getJavaClass();
} catch (CorruptDataException e) {
out.print("\t <error getting class while traversing objects: ");
out.print(Exceptions.getCorruptDataExceptionString());
out.print(">");
jc = null;
}
if (null != jc) {
try {
out.print(jc.getName());
} catch (CorruptDataException e) {
out.print("\t <error getting class name while traversing objects: ");
out.print(Exceptions.getCorruptDataExceptionString());
out.print(">");
}
out.print(" @ ");
out.print(Utils.toHex(objAddress.longValue()));
out.print("\n");
ClassOutput.printFields(jo, jc, jr, out);
printReferences(jo, out);
// assumes only one object can exist at a specific memory address
done = true;
}
}
}
if (!found) {
out.print("\t <no object found at address ");
out.print(Utils.toHex(objAddress.longValue()));
out.print(">\n\n");
}
if (corruptObjectCount != 0) {
out.println("\t Warning : " + corruptObjectCount + " corrupt objects were skipped\n");
}
}
Aggregations