Search in sources :

Example 6 with MemoryAccessException

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

the class InfoLockCommand method showJavaUtilConcurrentLocks.

private void showJavaUtilConcurrentLocks() {
    // A map of lock objects and their waiting threads.
    Map locksToThreads = new HashMap();
    JavaRuntime jr = ctx.getRuntime();
    Iterator itThread = jr.getThreads();
    while (itThread.hasNext()) {
        try {
            Object o = itThread.next();
            if (!(o instanceof JavaThread)) {
                continue;
            }
            JavaThread jt = (JavaThread) o;
            if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
                JavaObject lock = jt.getBlockingObject();
                if (lock != null) {
                    List parkedList = (List) locksToThreads.get(lock);
                    if (parkedList == null) {
                        parkedList = new LinkedList();
                        locksToThreads.put(lock, parkedList);
                    }
                    parkedList.add(jt);
                }
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
        }
    }
    out.println("\njava.util.concurrent locks in use...");
    if (locksToThreads.size() == 0) {
        out.println("\t...None.");
        out.println();
    }
    for (Object e : locksToThreads.entrySet()) {
        try {
            Map.Entry entry = (Map.Entry) e;
            JavaObject lock = (JavaObject) entry.getKey();
            List threads = (List) entry.getValue();
            String threadName = "<unowned>";
            JavaThread lockOwnerThread = Utils.getParkBlockerOwner(lock, ctx.getRuntime());
            if (lockOwnerThread != null) {
                threadName = lockOwnerThread.getName();
            } else {
                // If the owning thread has ended we won't find the JavaThread
                // We can still get the owning thread name from the java.lang.Thread object itself.
                JavaObject lockOwnerObj = Utils.getParkBlockerOwnerObject(lock, ctx.getRuntime());
                if (lockOwnerObj != null) {
                    threadName = Utils.getThreadNameFromObject(lockOwnerObj, ctx.getRuntime(), out);
                } else {
                    threadName = "<unknown>";
                }
            }
            if (threads != null && threads.size() > 0) {
                String lockID = Long.toHexString(lock.getID().getAddress());
                ImageThread imageThread = (lockOwnerThread != null ? lockOwnerThread.getImageThread() : null);
                out.println(lock.getJavaClass().getName() + "@0x" + lockID + "\n\tlocked by java thread id: " + ((imageThread != null) ? imageThread.getID() : "<null>") + " name: " + (threadName));
                for (Object t : threads) {
                    JavaThread waiter = (JavaThread) t;
                    out.println("\twaiting thread id: " + waiter.getImageThread().getID() + " name: " + waiter.getName());
                }
            }
        } catch (CorruptDataException cde) {
            out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
        } catch (MemoryAccessException ma) {
            out.println("\nwarning, memory access error encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getMemoryAccessExceptionString(), ma);
        } catch (DataUnavailable du) {
            out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
            logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
        }
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) LinkedList(java.util.LinkedList) List(java.util.List) ImageThread(com.ibm.dtfj.image.ImageThread) HashMap(java.util.HashMap) Map(java.util.Map) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 7 with MemoryAccessException

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

the class JavaThread method getPriority.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaThread#getPriority()
	 */
public int getPriority() throws CorruptDataException {
    JavaObject theObject = getObject();
    if (null != theObject) {
        JavaClass threadClass = _javaLangThreadSuperclass();
        Iterator fields = threadClass.getDeclaredFields();
        while (fields.hasNext()) {
            JavaField oneField = (JavaField) fields.next();
            if (oneField.getName().equals("priority")) {
                try {
                    return oneField.getInt(theObject);
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to read memory for 'priority' field", null));
                }
            }
        }
        throw new CorruptDataException(new CorruptData("unable to find 'priority' field", null));
    } else {
        // TODO:  have a good exception for this sort of thing
        return -1;
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 8 with MemoryAccessException

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

the class Utils method getVal.

// note: this method lets you pass in a null JavaObject, but it _will_ throw a
// NullPointerException if the JavaField is not a static field when you pass it
// a null JavaObject; this is the behavior of jf.get() and jf.getString()
public static String getVal(JavaObject jo, JavaField jf) {
    Object o;
    String s;
    if (null == jf) {
        o = jo;
        s = null;
    } else {
        try {
            o = jf.get(jo);
        } catch (CorruptDataException e) {
            return "<corrupt data>";
        } catch (MemoryAccessException d) {
            return "<invalid memory address>";
        } catch (NumberFormatException nfe) {
            return "<invalid number>";
        }
        try {
            s = jf.getString(jo);
        } catch (CorruptDataException e) {
            s = null;
        } catch (MemoryAccessException e) {
            s = null;
        } catch (IllegalArgumentException e) {
            s = null;
        }
    }
    return getVal(o, s, jf);
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 9 with MemoryAccessException

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

the class HexdumpCommand method doCommand.

public void doCommand(String[] args) {
    StringBuffer stringBuffer = new StringBuffer();
    ImageAddressSpace imageAddressSpace = ctx.getAddressSpace();
    if (null == imageAddressSpace) {
        out.println("Could not find an address space which contains a process in this core file");
        return;
    }
    long addressInDecimal = 0;
    // dump 256 bytes by default
    int numBytesToPrint = 16 * 16;
    int asciiIndex = 0;
    if (args.length != 0) {
        Long address = Utils.longFromString(args[0]);
        if (null == address) {
            out.println("Specified address is invalid");
            return;
        }
        addressInDecimal = address.longValue();
    } else {
        out.println("\"hexdump\" requires at least an address parameter");
        return;
    }
    if (args.length > 1) {
        try {
            numBytesToPrint = Integer.parseInt(args[1]);
        } catch (NumberFormatException nfe) {
            out.println("Specified length is invalid");
            return;
        }
    }
    ImagePointer imagePointerBase = imageAddressSpace.getPointer(addressInDecimal);
    boolean is_zOSdump = false;
    try {
        is_zOSdump = ctx.getImage().getSystemType().toLowerCase().indexOf("z/os") >= 0;
    } catch (DataUnavailable e1) {
    // unable to get the dump OS type, continue without the additional zOS EBCDIC option
    } catch (CorruptDataException e1) {
    // unable to get the dump OS type, continue without the additional zOS EBCDIC option
    }
    String asciiChars = "";
    String ebcdicChars = "";
    long i;
    for (i = 0; i < numBytesToPrint; i++) {
        ImagePointer imagePointer = imagePointerBase.add(i);
        // stringBuffer.append(Long.toHexString(imagePointer.getAddress())+":\t");
        try {
            Byte byteValue = new Byte(imagePointer.getByteAt(0));
            asciiIndex = (int) byteValue.byteValue();
            if (asciiIndex < 0) {
                asciiIndex += 256;
            }
            String rawHexString = Integer.toHexString(byteValue.intValue());
            String fixedHexString = fixHexStringLength(rawHexString);
            String hexText = fixedHexString;
            if (0 == i % 4) {
                hexText = " " + hexText;
            }
            if (0 == i % 16) {
                hexText = "\n" + Long.toHexString(imagePointer.getAddress()) + ":" + hexText;
                asciiChars = "  |";
                ebcdicChars = " |";
            }
            stringBuffer.append(hexText);
            asciiChars += Utils.byteToAscii.substring(asciiIndex, asciiIndex + 1);
            if (15 == i % 16 && i != 0) {
                asciiChars += "|";
                stringBuffer.append(asciiChars);
            }
            if (is_zOSdump) {
                // for zOS dumps, output additional EBCDIC interpretation of the memory byes
                ebcdicChars += Utils.byteToEbcdic.substring(asciiIndex, asciiIndex + 1);
                if (15 == i % 16 && i != 0) {
                    ebcdicChars += "|";
                    stringBuffer.append(ebcdicChars);
                }
            }
        } catch (MemoryAccessException e) {
            out.println("Address not in memory - 0x" + Long.toHexString(imagePointer.getAddress()));
            return;
        } catch (CorruptDataException e) {
            out.println("Dump data is corrupted");
            return;
        }
    }
    long undisplayedBytes = 16 - i % 16;
    if (16 != undisplayedBytes) {
        stringBuffer.append(padSpace(undisplayedBytes, asciiChars));
        if (is_zOSdump) {
            // Add padding and output the remaining EBCDIC characters
            for (int j = 0; j < undisplayedBytes; j++) {
                ebcdicChars = " " + ebcdicChars;
            }
            stringBuffer.append(" " + ebcdicChars);
        }
    }
    stringBuffer.append("\n");
    out.println(new String(stringBuffer));
    /*properties.put(Utils.CURRENT_MEM_ADDRESS, 
				Long.toHexString(addressInDecimal+numBytesToPrint));*/
    ctx.getProperties().put(Utils.CURRENT_MEM_ADDRESS, new Long(addressInDecimal));
    ctx.getProperties().put(Utils.CURRENT_NUM_BYTES_TO_PRINT, new Integer(numBytesToPrint));
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImagePointer(com.ibm.dtfj.image.ImagePointer) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 10 with MemoryAccessException

use of com.ibm.dtfj.image.MemoryAccessException 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)

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