use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class PHDJavaObject method arraycopy.
public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
if (dst == null)
throw new NullPointerException("destination null");
fillInDetails(true);
if (!isArray())
throw new IllegalArgumentException(this + " is not an array");
JavaClass jc = getJavaClass();
String type;
try {
type = jc.getName();
} catch (CorruptDataException e) {
// Presume all primitive arrays will have a real name
type = "[L";
}
// System.out.println("array "+srcStart+" "+dst+" "+dstStart+" "+length);
if (srcStart < 0 || length < 0 || dstStart < 0 || srcStart + length < 0 || dstStart + length < 0)
throw new IndexOutOfBoundsException(srcStart + "," + dstStart + "," + length);
if (srcStart + length > getArraySize())
throw new IndexOutOfBoundsException(srcStart + "+" + length + ">" + getArraySize() + jc);
if (dst instanceof JavaObject[]) {
if (!type.startsWith("[[") && !type.startsWith("[L"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
JavaObject[] dst1 = (JavaObject[]) dst;
// Get to the right point in the refs
int count;
if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
count = le.numberOfElements();
// Skip over the elements before the required start
for (int idx = 0; idx < srcStart && idx < count; ++idx) {
le.nextLong();
}
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
count = arefs.length;
} else if (refs instanceof long[]) {
long[] arefs = (long[]) refs;
count = arefs.length;
} else {
throw new CorruptDataException(new PHDCorruptData("Unknown array contents", getID()));
}
// Copy the data to the destination
for (int idx = srcStart; idx < srcStart + length; ++idx) {
JavaObject target;
if (idx < count) {
long ref;
if (refs instanceof LongEnumeration) {
LongEnumeration le = (LongEnumeration) refs;
ref = le.nextLong();
} else if (refs instanceof int[]) {
int[] arefs = (int[]) refs;
ref = heap.getJavaRuntime().expandAddress(arefs[idx]);
} else {
long[] arefs = (long[]) refs;
ref = arefs[idx];
}
target = new PHDJavaObject.Builder(heap, ref, null, PHDJavaObject.NO_HASHCODE, -1).build();
} else {
target = null;
}
int dstIndex = dstStart + (idx - srcStart);
if (dstIndex >= dst1.length) {
throw new IndexOutOfBoundsException("Array " + jc + " 0x" + Long.toHexString(address) + "[" + getArraySize() + "]" + "," + srcStart + "," + dst1 + "[" + dst1.length + "]" + "," + dstStart + "," + length + " at " + idx);
}
dst1[dstIndex] = target;
}
} else if (dst instanceof byte[]) {
if (!type.startsWith("[B"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
byte[] dst1 = (byte[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof short[]) {
if (!type.startsWith("[S"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
short[] dst1 = (short[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof int[]) {
if (!type.startsWith("[I"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
int[] dst1 = (int[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof long[]) {
if (!type.startsWith("[J"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
long[] dst1 = (long[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof boolean[]) {
if (!type.startsWith("[Z"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
boolean[] dst1 = (boolean[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof char[]) {
if (!type.startsWith("[C"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
char[] dst1 = (char[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof float[]) {
if (!type.startsWith("[F"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
float[] dst1 = (float[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else if (dst instanceof double[]) {
if (!type.startsWith("[D"))
throw new IllegalArgumentException("Expected " + type + " not " + dst);
double[] dst1 = (double[]) dst;
if (dstStart + length > dst1.length)
throw new IndexOutOfBoundsException();
} else {
throw new IllegalArgumentException("Expected " + type + " not " + dst);
}
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class PHDJavaRuntime method prepThreads.
/**
* Remember objects associated with threads.
* Performance optimization - we can then find these objects on a scan through the heap
* and remember them, saving a fruitless search of the heap if they only exist in a javacore.
*/
private void prepThreads() {
if (metaJavaRuntime != null) {
final PHDJavaClassLoader boot = loaders.get(null);
for (Iterator it = metaJavaRuntime.getThreads(); it.hasNext(); ) {
Object next = it.next();
if (next instanceof CorruptData)
continue;
JavaThread thr = (JavaThread) next;
try {
JavaObject jo = thr.getObject();
saveExtraObject(boot, jo);
} catch (CorruptDataException e) {
}
}
}
}
use of com.ibm.dtfj.image.CorruptDataException 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");
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class HeapdumpCommand method doCommand.
public void doCommand(String[] args) {
Set heapsToDump = new HashSet();
_numberOfObjects = 0;
_numberOfErrors = 0;
_numberOfClasses = 0;
if (ctx.hasPropertyBeenSet(VERBOSE_MODE_PROPERTY)) {
_verbose = true;
}
JavaRuntime runtime = ctx.getRuntime();
while (runtime != null) {
ImageAddressSpace addressSpace = null;
try {
addressSpace = runtime.getJavaVM().getAddressSpace();
} catch (CorruptDataException e) {
}
if (addressSpace == null) {
out.println("Couldn't get handle on address space");
break;
}
if (!heapArgumentsAreValid(runtime, heapsToDump)) {
break;
}
String version = getVersionString(runtime);
if (version.contains("IBM J9 2.3") || version.contains("IBM J9 2.4") || version.contains("IBM J9 2.5")) {
// J9 JVMs versions prior to 2.6 have 16-bit hashcodes, later JVMs have 32-bit hashcodes
_is32BitHash = false;
} else {
_is32BitHash = true;
}
boolean is64Bit = addressSpace.getCurrentProcess().getPointerSize() == 64;
String filename = HeapDumpSettings.getFileName(ctx.getProperties());
boolean phdFormat = HeapDumpSettings.areHeapDumpsPHD(ctx.getProperties());
try {
if (HeapDumpSettings.multipleHeapsInMultipleFiles(ctx.getProperties())) {
dumpMultipleHeapsInSeparateFiles(runtime, version, is64Bit, phdFormat, filename, heapsToDump);
} else {
dumpMultipleHeapsInOneFile(runtime, version, is64Bit, phdFormat, filename, heapsToDump);
}
if (_numberOfErrors == 0) {
out.print("\nSuccessfully wrote " + _numberOfObjects + " objects and " + _numberOfClasses + " classes\n");
} else {
out.print("\nWrote " + _numberOfObjects + " objects and " + _numberOfClasses + " classes and encountered " + _numberOfErrors + " errors." + "\n");
}
} catch (IOException ex) {
out.println("I/O error writing dump:\n");
StringWriter writer = new StringWriter();
ex.printStackTrace(new PrintWriter(writer));
out.println(writer.toString());
}
runtime = null;
}
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class ClassOutput method printMethods.
public static void printMethods(Iterator methods, PrintStream out) {
while (methods.hasNext()) {
JavaMethod jMethod = (JavaMethod) methods.next();
try {
out.print("Bytecode range(s): ");
Iterator imageSections = jMethod.getBytecodeSections();
boolean firstSectionPassed = false;
while (imageSections.hasNext()) {
ImageSection is = (ImageSection) imageSections.next();
long baseAddress = is.getBaseAddress().getAddress();
long endAddress = baseAddress + is.getSize();
if (firstSectionPassed) {
out.print(", ");
}
out.print(Long.toHexString(baseAddress) + " -- " + Long.toHexString(endAddress));
firstSectionPassed = true;
}
out.print(": ");
String signature;
try {
out.print(Utils.getMethodModifierString(jMethod));
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
}
try {
signature = jMethod.getSignature();
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
signature = null;
}
if (null != signature) {
String name = Utils.getReturnValueName(signature);
if (null == name) {
out.print("<unknown>");
} else {
out.print(name);
}
}
out.print(" ");
out.print(jMethod.getName());
if (null != signature) {
String name = Utils.getMethodSignatureName(signature);
if (null == name) {
out.print("<unknown>");
} else {
out.print(name);
}
}
out.print("\n");
} catch (CorruptDataException cde) {
out.print("N/A (CorruptDataException occurred)");
}
}
}
Aggregations