Search in sources :

Example 31 with JavaObject

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

Example 32 with JavaObject

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

Example 33 with JavaObject

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;
}
Also used : 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 34 with JavaObject

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();
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.j9.CorruptData) Vector(java.util.Vector)

Example 35 with JavaObject

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

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