Search in sources :

Example 66 with JavaObject

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;
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 67 with JavaObject

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);
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Vector(java.util.Vector) JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Example 68 with JavaObject

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);
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Example 69 with JavaObject

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");
            }
        }
    }
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 70 with JavaObject

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");
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Aggregations

JavaObject (com.ibm.dtfj.java.JavaObject)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)47 Iterator (java.util.Iterator)35 JavaClass (com.ibm.dtfj.java.JavaClass)31 CorruptData (com.ibm.dtfj.image.CorruptData)19 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)17 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)14 JavaReference (com.ibm.dtfj.java.JavaReference)9 JavaThread (com.ibm.dtfj.java.JavaThread)9 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)8 JavaField (com.ibm.dtfj.java.JavaField)7 ImagePointer (com.ibm.dtfj.image.ImagePointer)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)6 CorruptJavaObject (com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)6 CorruptData (com.ibm.dtfj.image.j9.CorruptData)5 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)5 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)5 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)5