Search in sources :

Example 21 with MemoryAccessException

use of com.ibm.dtfj.image.MemoryAccessException in project openj9 by eclipse.

the class DeadlockCommand method doCommand.

public void doCommand() {
    SortedMap monitorNodes = new TreeMap();
    JavaRuntime jr = ctx.getRuntime();
    Iterator itMonitor = jr.getMonitors();
    int nodeListNum = 0;
    out.print("\n  deadlocks for runtime \n");
    // JVM dumps on Linux don't have all the image threads, so we now use JavaThreads
    while (itMonitor.hasNext()) {
        JavaMonitor monitor = (JavaMonitor) itMonitor.next();
        MonitorNode node = new MonitorNode(monitor);
        JavaThread owner = null;
        Long id = null;
        try {
            owner = monitor.getOwner();
        } catch (CorruptDataException e) {
            out.println("exception encountered while getting monitor owner: " + Exceptions.getCorruptDataExceptionString());
            return;
        }
        if (null == owner) {
            // the monitor's owner or the next monitor in a potential deadlock chain.
            continue;
        } else {
            JavaObject threadObject;
            try {
                threadObject = owner.getObject();
            } catch (CorruptDataException e) {
                out.println("exception encountered while getting owner's JavaObject: " + Exceptions.getCorruptDataExceptionString());
                return;
            }
            id = new Long(threadObject.getID().getAddress());
        }
        // Note: defect 133638, we used to give up here with an error if there was already
        // a monitor node in the table with the same key (thread). This is very common (a
        // thread owning multiple monitors). Longer term the intention is to replace this
        // algorithm with the one used in javacore, but for now we carry on to see if we can
        // still find a deadlock, with some node(s) discarded.
        monitorNodes.put(id, node);
    }
    // Step 1.b
    // Add the JUC locks, technically to find all of them you need to walk the whole
    // heap. But the active ones can be found by walking the thread list and looking
    // at the blocking objects. (Any others aren't blocking any threads anyway so aren't
    // interesting.
    Iterator itThread = jr.getThreads();
    while (itThread.hasNext()) {
        try {
            Object o = itThread.next();
            if (!(o instanceof JavaThread)) {
                continue;
            }
            JavaThread jt = (JavaThread) o;
            JavaThread owner = null;
            Long id = null;
            if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
                JavaObject lock = jt.getBlockingObject();
                MonitorNode node = new JUCMonitorNode(lock, jr);
                try {
                    owner = Utils.getParkBlockerOwner(lock, jr);
                    if (owner == null) {
                        continue;
                    }
                } catch (MemoryAccessException e) {
                    out.println("exception encountered while getting monitor owner: " + Exceptions.getCorruptDataExceptionString());
                    return;
                }
                JavaObject threadObject;
                try {
                    threadObject = owner.getObject();
                } catch (CorruptDataException e) {
                    out.println("exception encountered while getting owner's JavaObject: " + Exceptions.getCorruptDataExceptionString());
                    return;
                }
                id = new Long(threadObject.getID().getAddress());
                monitorNodes.put(id, node);
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
        }
    }
    Iterator values = monitorNodes.values().iterator();
    // enter waiter, set that waiter's MonitorNode's waitingOn to m1.
    while (values.hasNext()) {
        MonitorNode currNode = (MonitorNode) values.next();
        Iterator itWaiters = currNode.getEnterWaiters();
        while (itWaiters.hasNext()) {
            Object o = itWaiters.next();
            if (!(o instanceof JavaThread)) {
                continue;
            }
            JavaThread waiter = (JavaThread) o;
            JavaObject threadObject;
            Long id = null;
            try {
                threadObject = waiter.getObject();
            } catch (CorruptDataException e) {
                out.println("exception encountered while getting waiter's ImageThread: " + Exceptions.getCorruptDataExceptionString());
                return;
            }
            id = new Long(threadObject.getID().getAddress());
            MonitorNode waiterNode = (MonitorNode) monitorNodes.get(id);
            if (null != waiterNode) {
                waiterNode.waitingOn = currNode;
            }
        }
    }
    values = monitorNodes.values().iterator();
    int visit = 1;
    Vector lists = new Vector();
    while (values.hasNext()) {
        MonitorNode startNode = (MonitorNode) values.next();
        MonitorNode currNode = startNode;
        MonitorNode endNode;
        if (0 != startNode.visit) {
            continue;
        }
        while (true) {
            currNode.visit = visit;
            if (null == currNode.waitingOn) {
                currNode.deadlock = MonitorNode.NO_DEADLOCK;
                break;
            }
            if (isDeadlocked(currNode.waitingOn)) {
                // we've encountered a deadlocked node in the chain;
                // set branch deadlock for all nodes between startNode
                // and currNode
                endNode = currNode.waitingOn;
                currNode = startNode;
                NodeList branchList = null;
                while (currNode != endNode) {
                    if (null == branchList) {
                        branchList = new NodeList(currNode, nodeListNum++);
                    }
                    currNode.deadlock = MonitorNode.BRANCH_DEADLOCK;
                    currNode = currNode.waitingOn;
                    branchList.add(currNode);
                    if (currNode != endNode)
                        currNode.inList = branchList;
                }
                if (endNode.inList.isLoop()) {
                    lists.insertElementAt(branchList, lists.indexOf(endNode.inList));
                } else {
                    NodeList oldList = endNode.inList;
                    // FIXME: the below line will cause problems with at least
                    // one case that was not considered when attachOrSplit was
                    // coded: if a NodeList n1 has already been split and another
                    // NodeList n2 tries to attach to the end of n1, then n1 will
                    // allow n2 to attach to n1, while what n1 should really do is
                    // just return n2 and not allow n2 to attach to itself
                    NodeList split = endNode.inList.attachOrSplit(branchList, nodeListNum++);
                    if (null != split) {
                        lists.insertElementAt(split, lists.indexOf(oldList));
                        lists.insertElementAt(branchList, lists.indexOf(oldList));
                    }
                }
                break;
            }
            if (currNode.waitingOn.visit == visit) {
                // we've encountered a node in the same visit as the current
                // visit, ie. we've found a loop; first flag the whole loop
                // with a loop deadlock flag, then flag the rest of the nodes
                // in the chain with a branch deadlock
                endNode = currNode.waitingOn;
                currNode = endNode;
                NodeList loopList = new NodeList(currNode, nodeListNum++);
                lists.insertElementAt(loopList, 0);
                do {
                    currNode.deadlock = MonitorNode.LOOP_DEADLOCK;
                    currNode = currNode.waitingOn;
                    loopList.add(currNode);
                    currNode.inList = loopList;
                } while (currNode != endNode);
                currNode = startNode;
                NodeList branchList = null;
                while (currNode != endNode) {
                    if (null == branchList) {
                        branchList = new NodeList(currNode, nodeListNum++);
                        lists.insertElementAt(branchList, 0);
                    }
                    currNode.deadlock = MonitorNode.BRANCH_DEADLOCK;
                    currNode = currNode.waitingOn;
                    branchList.add(currNode);
                    if (currNode != endNode)
                        currNode.inList = branchList;
                }
                break;
            }
            currNode = currNode.waitingOn;
        }
        visit++;
    }
    if (lists.isEmpty()) {
        out.print("\n");
        out.print("\t no deadlocks detected");
        out.print("\n");
        return;
    }
    boolean lastListWasLoop = true;
    Iterator itList = lists.iterator();
    // Step 5. print the lists
    while (itList.hasNext()) {
        NodeList list = (NodeList) itList.next();
        if (list.isLoop()) {
            out.print("\n    deadlock loop:\n");
            lastListWasLoop = true;
        } else if (lastListWasLoop) {
            // && !list.isLoop()
            out.print("\n\n    deadlock branch(es):\n");
            lastListWasLoop = false;
        }
        out.print("\t  " + list.toString());
        out.print("\n");
    }
    out.print("\n");
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) NodeList(com.ibm.jvm.dtfjview.commands.helpers.NodeList) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) TreeMap(java.util.TreeMap) JUCMonitorNode(com.ibm.jvm.dtfjview.commands.helpers.JUCMonitorNode) JavaMonitor(com.ibm.dtfj.java.JavaMonitor) JUCMonitorNode(com.ibm.jvm.dtfjview.commands.helpers.JUCMonitorNode) MonitorNode(com.ibm.jvm.dtfjview.commands.helpers.MonitorNode) JavaObject(com.ibm.dtfj.java.JavaObject) SortedMap(java.util.SortedMap) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException) Vector(java.util.Vector)

Example 22 with MemoryAccessException

use of com.ibm.dtfj.image.MemoryAccessException in project openj9 by eclipse.

the class FindCommand method scanRegion.

private boolean scanRegion(long start, long end, ImageSection imageSection) {
    ImagePointer imagePointer = imageSection.getBaseAddress();
    long i;
    if (0 != start % findAtt.boundary) {
        i = start - start % findAtt.boundary + findAtt.boundary;
    } else {
        i = start;
    }
    int patternLength = findAtt.length();
    byte[] bytes = findAtt.getBytes();
    for (; i <= end; i += findAtt.boundary) {
        int j;
        for (j = 0; j < patternLength; j++) {
            byte oneByte = bytes[j];
            try {
                if (getByteFromImage(imagePointer, i + j) == oneByte) {
                    continue;
                } else {
                    break;
                }
            } catch (MemoryAccessException mae) {
                return false;
            }
        }
        if (j >= patternLength) {
            matches.add(new Long(i));
            if (matches.size() == findAtt.numMatchesToDisplay)
                return true;
        }
    }
    return false;
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 23 with MemoryAccessException

use of com.ibm.dtfj.image.MemoryAccessException in project openj9 by eclipse.

the class ClassOutput method printFields.

public static void printFields(JavaObject jo, JavaClass jc, JavaRuntime jr, PrintStream out) {
    boolean array;
    try {
        array = jo.isArray();
    } catch (CorruptDataException e) {
        out.print("\t   <cannot determine if above object is array (" + Exceptions.getCorruptDataExceptionString() + "); " + "we will assume it is not an array>\n");
        array = false;
    }
    if (array) {
        String componentType;
        int arraySize;
        try {
            componentType = jc.getComponentType().getName();
        } catch (CorruptDataException e) {
            out.print("\t   <cannot determine what type of array this is (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        }
        try {
            arraySize = jo.getArraySize();
        } catch (CorruptDataException e) {
            out.print("\t   <cannot determine the size of the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        }
        Object dst = null;
        if (componentType.equals("boolean")) {
            dst = new boolean[arraySize];
        } else if (componentType.equals("byte")) {
            dst = new byte[arraySize];
        } else if (componentType.equals("char")) {
            dst = new char[arraySize];
        } else if (componentType.equals("short")) {
            dst = new short[arraySize];
        } else if (componentType.equals("int")) {
            dst = new int[arraySize];
        } else if (componentType.equals("long")) {
            dst = new long[arraySize];
        } else if (componentType.equals("float")) {
            dst = new float[arraySize];
        } else if (componentType.equals("double")) {
            dst = new double[arraySize];
        } else {
            dst = new JavaObject[arraySize];
        }
        try {
            jo.arraycopy(0, dst, 0, arraySize);
        } catch (CorruptDataException e) {
            out.print("\t   <cannot copy data from the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
            return;
        } catch (MemoryAccessException e) {
            out.print("\t   <cannot copy data from the array (" + Exceptions.getMemoryAccessExceptionString() + ")>\n");
            return;
        } catch (UnsupportedOperationException e) {
            // Some artefacts e.g. phd do not support arraycopy so just put out what we can
            out.print("\t    This is an array of size " + arraySize + " elements\n");
            return;
        }
        for (int i = 0; i < arraySize; i++) {
            out.print("\t   " + i + ":\t");
            if (componentType.equals("boolean")) {
                out.print(Utils.getVal(new Boolean(((boolean[]) dst)[i])));
            } else if (componentType.equals("byte")) {
                out.print(Utils.getVal(new Byte(((byte[]) dst)[i])));
            } else if (componentType.equals("char")) {
                out.print(Utils.getVal(new Character(((char[]) dst)[i])));
            } else if (componentType.equals("short")) {
                out.print(Utils.getVal(new Short(((short[]) dst)[i])));
            } else if (componentType.equals("int")) {
                out.print(Utils.getVal(new Integer(((int[]) dst)[i])));
            } else if (componentType.equals("long")) {
                out.print(Utils.getVal(new Long(((long[]) dst)[i])));
            } else if (componentType.equals("float")) {
                out.print(Utils.getVal(new Float(((float[]) dst)[i])));
            } else if (componentType.equals("double")) {
                out.print(Utils.getVal(new Double(((double[]) dst)[i])));
            } else {
                out.print(Utils.getVal(((JavaObject[]) dst)[i]));
            }
            out.print("\n");
        }
    } else {
        JavaClass initialJC = jc;
        List<JavaClass> classList = new ArrayList<JavaClass>();
        while (jc != null) {
            classList.add(jc);
            try {
                jc = jc.getSuperclass();
            } catch (CorruptDataException d) {
                jc = null;
            }
        }
        for (int i = (classList.size() - 1); i >= 0; i--) {
            jc = classList.get(i);
            Iterator itField = jc.getDeclaredFields();
            if (itField.hasNext()) {
                if (jc.equals(initialJC)) {
                    out.print("\t   declared fields:\n");
                } else {
                    out.print("\t   fields inherited from \"");
                    try {
                        out.print(jc.getName() + "\":\n");
                    } catch (CorruptDataException d) {
                        out.print(Exceptions.getCorruptDataExceptionString());
                    }
                }
            }
            while (itField.hasNext()) {
                JavaField jf = (JavaField) itField.next();
                boolean isStatic;
                try {
                    isStatic = Modifier.isStatic(jf.getModifiers());
                } catch (CorruptDataException e) {
                    out.print("\t   <error while getting modifier for field \"");
                    try {
                        out.print(jf.getName());
                    } catch (CorruptDataException d) {
                        out.print(Exceptions.getCorruptDataExceptionString());
                    }
                    out.print("\", " + Exceptions.getCorruptDataExceptionString() + ">");
                    isStatic = true;
                }
                if (!isStatic) {
                    printNonStaticFieldData(jo, jf, out);
                }
            }
        }
    }
    out.print("\n");
}
Also used : ArrayList(java.util.ArrayList) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 24 with MemoryAccessException

use of com.ibm.dtfj.image.MemoryAccessException in project openj9 by eclipse.

the class XDCommand method doCommand.

public void doCommand(String[] args) {
    String param = args[0];
    Long address;
    address = Utils.longFromStringWithPrefix(param);
    if (null == address) {
        out.println("invalid hex address specified; address must be specified as " + "\"0x<hex_address>\"");
        return;
    }
    out.print("\n");
    boolean found = false;
    for (int index = 0; index < argUnitNumber; index++) {
        long currAddr = address.longValue() + (index * argUnitSize);
        out.print("\t");
        out.print(Utils.toHex(currAddr));
        out.print(": ");
        ImageAddressSpace ias = ctx.getAddressSpace();
        ImagePointer ip = ias.getPointer(currAddr);
        byte b = 0;
        short s = 0;
        int i = 0;
        long l = 0;
        try {
            switch(argUnitSize) {
                case 1:
                    b = ip.getByteAt(0);
                    break;
                case 2:
                    s = ip.getShortAt(0);
                    break;
                case 4:
                    i = ip.getIntAt(0);
                    break;
                case 8:
                    l = ip.getLongAt(0);
                    break;
            }
            found = true;
        } catch (CorruptDataException e) {
            found = false;
        } catch (MemoryAccessException e) {
            found = false;
        }
        if (found) {
            switch(argUnitSize) {
                case 1:
                    out.print(Byte.toString(b));
                    break;
                case 2:
                    out.print(Short.toString(s));
                    break;
                case 4:
                    out.print(Integer.toString(i));
                    break;
                case 8:
                    out.print(Long.toString(l));
                    break;
            }
        }
        out.print("\n");
    }
    if (!found) {
        out.print("<address not found in any address space>");
    }
    out.print("\n");
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImagePointer(com.ibm.dtfj.image.ImagePointer) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 25 with MemoryAccessException

use of com.ibm.dtfj.image.MemoryAccessException in project openj9 by eclipse.

the class XKCommand method doCommand.

public void doCommand(String[] args) {
    String param = args[0];
    Long address = Utils.longFromStringWithPrefix(param);
    if (null == address) {
        out.println("invalid hex address specified; address must be specified as " + "\"0x<hex_address>\"");
        return;
    }
    ImageAddressSpace ias = ctx.getAddressSpace();
    int pointerSize = getIASPointerSize(ias);
    int unitSize;
    if (pointerSize > 32)
        unitSize = 8;
    else
        unitSize = 4;
    out.print("\n");
    for (int index = 0; index < argUnitNumber; index++) {
        boolean found = false;
        long currAddr = address.longValue() + (index * unitSize);
        ImagePointer ip = ias.getPointer(currAddr);
        out.print("\t");
        out.print(Utils.toHex(currAddr));
        out.print("   ");
        long l = 0;
        try {
            l = ip.getPointerAt(0).getAddress();
            found = true;
        } catch (CorruptDataException e) {
            found = false;
        } catch (MemoryAccessException e) {
            found = false;
        }
        if (found) {
            long pointer = l;
            out.print(toAdjustedHex(l, pointerSize));
            out.print("   ");
            if (31 == pointerSize) {
                pointer = (int) (pointer & (((long) 1) << pointerSize) - 1);
            }
            if (printSymbol(pointer, l - currAddr, pointerSize)) {
            } else if (printStackPointer(pointer, l - currAddr, pointerSize, ias)) {
            }
            out.print("\n");
        } else {
            out.print("<address not found in any address space or exception occurred>\n");
        }
    }
    out.print("\n");
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImagePointer(com.ibm.dtfj.image.ImagePointer) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Aggregations

MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)25 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)24 JavaObject (com.ibm.dtfj.java.JavaObject)13 ImagePointer (com.ibm.dtfj.image.ImagePointer)11 CorruptData (com.ibm.dtfj.image.j9.CorruptData)9 JavaClass (com.ibm.dtfj.java.JavaClass)9 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)8 Iterator (java.util.Iterator)8 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)4 JavaThread (com.ibm.dtfj.java.JavaThread)4 JavaField (com.ibm.dtfj.java.JavaField)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Vector (java.util.Vector)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 ImageThread (com.ibm.dtfj.image.ImageThread)2 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)2 HashMap (java.util.HashMap)2 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)1 JavaMethod (com.ibm.dtfj.java.JavaMethod)1