use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class J9DDRDTFJUtils method handleAsDataUnavailable.
/**
* Handle the supplied error condition and ultimately surface it as a
* data unavailable exception. This is required as not all API calls
* allow a CorruptDataException to be thrown
*
* @param t error condition to handle
* @throws CorruptDataException ultimately throw an CDE
*/
public static DataUnavailable handleAsDataUnavailable(Throwable t) {
if (t instanceof DataUnavailable) {
// prevent repeated logging of this error by ignoring DTFJ DataUnavailable
return (DataUnavailable) t;
}
if (isErrorNotToBeIntercepted(t)) {
if (t instanceof Error) {
// rethrow unhandled errors
throw (Error) t;
}
// should not hit this as we handle run time exceptions
throw new RuntimeException(t);
}
if (t instanceof DataUnavailable) {
logger.log(Level.FINE, "Data unavailable", t);
//
return (DataUnavailable) t;
}
String message = logError(t);
DataUnavailable du = new DataUnavailable(message);
du.initCause(t);
return du;
}
use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class DTFJJavaObject method addFieldReferences.
private void addFieldReferences(JavaClass jClass, int referentReachabilityType) throws CorruptDataException, MemoryAccessException {
Iterator<?> fieldIt = jClass.getDeclaredFields();
while (fieldIt.hasNext()) {
Object fieldObj = fieldIt.next();
if (fieldObj instanceof JavaField) {
JavaField thisField = (JavaField) fieldObj;
if ((thisField.getModifiers() & Modifier.STATIC) == 0) {
String signature = thisField.getSignature();
// From a reference point of view, only objects are interesting
if (signature.startsWith("L") || signature.startsWith("[")) {
Object targetObj = thisField.get(this);
if (targetObj == null) {
continue;
}
if (targetObj instanceof JavaObject) {
String fieldName = thisField.getName();
String declaringClassName = null;
try {
declaringClassName = thisField.getDeclaringClass().getName();
} catch (DataUnavailable e) {
// declaringClassName will be null, we will add this as a strong ref.
}
String description = "Object Reference [field name:" + fieldName + "]";
// (Not any referent field declared in subclasses.)
if (fieldName.equals("referent") && "java/lang/ref/Reference".equals(declaringClassName)) {
references.add(new DTFJJavaReference(this, targetObj, description, JavaReference.REFERENCE_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, referentReachabilityType));
} else {
references.add(new DTFJJavaReference(this, targetObj, description, JavaReference.REFERENCE_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG));
}
} else if (targetObj instanceof CorruptData) {
references.add(targetObj);
} else {
references.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Unexpected type from field get: " + targetObj + ", class=" + targetObj.getClass().getName()));
}
}
}
} else if (fieldObj instanceof CorruptData) {
references.add(fieldObj);
} else {
references.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Unexpected type from field iteration: " + fieldObj + ", class=" + fieldObj.getClass().getName()));
}
}
}
use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class ImageComparator method testEquals.
/* (non-Javadoc)
* @see com.ibm.j9ddr.view.dtfj.test.DTFJComparator#testEquals(java.lang.Object, java.lang.Object, int)
*/
@Override
public void testEquals(Object ddrObject, Object jextractObject, int members) {
Image ddrImg = (Image) ddrObject;
Image jextractImg = (Image) jextractObject;
if ((members & ADDRESS_SPACES) != 0) {
new ImageAddressSpaceComparator().testComparatorIteratorEquals(ddrImg.getAddressSpaces(), jextractImg.getAddressSpaces(), "getAddressSpaces", ImageAddressSpace.class);
}
if ((members & CREATION_TIME) != 0) {
long ddrCreationTime = -1;
long jextractCreationTime = -1;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrCreationTime = ddrImg.getCreationTime();
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractCreationTime = jextractImg.getCreationTime();
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractCreationTime, ddrCreationTime);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & HOST_NAME) != 0) {
String ddrHostname = null;
String jextractHostname = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrHostname = ddrImg.getHostName();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractHostname = jextractImg.getHostName();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractHostname, ddrHostname);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & INSTALLED_MEMORY) != 0) {
long ddrInstalledMemory = -1;
long jextractInstalledMemory = -1;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrInstalledMemory = ddrImg.getInstalledMemory();
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractInstalledMemory = jextractImg.getInstalledMemory();
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractInstalledMemory, ddrInstalledMemory);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & IP_ADDRESSES) != 0) {
Iterator<?> ddrIt = null;
Iterator<?> jextractIt = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrIt = ddrImg.getIPAddresses();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractIt = jextractImg.getIPAddresses();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
// Slurp iterators into lists, sort lists, compare contents
List<?> ddrList = slurpIterator(ddrIt);
List<?> jextractList = slurpIterator(jextractIt);
assertEquals("IP address lists different lengths", jextractList.size(), ddrList.size());
Comparator<Object> inetAddressComp = new Comparator<Object>() {
public int compare(Object o1, Object o2) {
InetAddress i1 = (InetAddress) o1;
InetAddress i2 = (InetAddress) o2;
return i1.getHostAddress().compareTo(i2.getHostAddress());
}
};
Collections.sort(ddrList, inetAddressComp);
Collections.sort(jextractList, inetAddressComp);
assertEquals(jextractList, ddrList);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & PROCESSOR_COUNT) != 0) {
int ddrProcessorCount = -1;
int jextractProcessorCount = -1;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrProcessorCount = ddrImg.getProcessorCount();
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractProcessorCount = jextractImg.getProcessorCount();
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractProcessorCount, ddrProcessorCount);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & PROCESSOR_SUB_TYPE) != 0) {
String ddrSubType = null;
String jextractSubType = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrSubType = ddrImg.getProcessorSubType();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractSubType = jextractImg.getProcessorSubType();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractSubType, ddrSubType);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & PROCESSOR_TYPE) != 0) {
String ddrType = null;
String jextractType = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrType = ddrImg.getProcessorType();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractType = jextractImg.getProcessorType();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractType, ddrType);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & SYSTEM_TYPE) != 0) {
String ddrType = null;
String jextractType = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrType = ddrImg.getSystemType();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractType = jextractImg.getSystemType();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractType, ddrType);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
if ((members & SYSTEM_SUB_TYPE) != 0) {
String ddrType = null;
String jextractType = null;
Exception ddrException = null;
Exception jextractException = null;
try {
ddrType = ddrImg.getSystemSubType();
} catch (Exception e) {
e.printStackTrace();
ddrException = e;
}
try {
jextractType = jextractImg.getSystemSubType();
} catch (Exception e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException == null && jextractException == null) {
assertEquals(jextractType, ddrType);
} else if (ddrException != null && jextractException != null) {
assertEquals(jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception, and jextract didn't");
} else {
fail("jextract threw an exception, and ddr didn't");
}
}
}
}
use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class JavaRuntimeTest method getHeapRootsTest.
@SuppressWarnings("unchecked")
@Test
public void getHeapRootsTest() {
boolean result = true;
String version = ((J9DDRImageProcess) ddrProcess).getVersion();
IteratorFilter ddrFilter = null;
if (version.equals("26")) {
ddrFilter = new IteratorFilter() {
// vm26 has a StringTable Cache that the root scanner scans but jextract(HeapIteratorAPI) does not
public boolean accept(Object obj) {
JavaReference ref = (JavaReference) obj;
if (ref.getDescription().equals("StringCacheTable")) {
return false;
}
return true;
}
};
}
if (version.equals("23")) {
ddrFilter = new IteratorFilter() {
boolean foundFirstContrivedThread = false;
public boolean accept(Object obj) {
try {
JavaReference ref = (JavaReference) obj;
Object ddrHeapRoot = ref.getTarget();
if (ref.getRootType() == JavaReference.HEAP_ROOT_THREAD) {
if (ddrHeapRoot instanceof JavaObject) {
JavaObject javaObject = (JavaObject) ddrHeapRoot;
String name = javaObject.getJavaClass().getName();
if (name.endsWith("Error") || name.endsWith("Exception") || name.equals("com/ibm/dtfj/tck/tests/javaruntime/TestJavaMonitor_ObjectMonitors$MonitorClass") || name.equals("com/ibm/dtfj/tck/harness/Configure$DumpThread")) {
// Ignore these since JExtract can't find them.
return false;
}
if (name.equals("com/ibm/dtfj/tck/tests/javaruntime/TestJavaThread_getStackFrames$ContrivedThread")) {
if (foundFirstContrivedThread) {
return false;
} else {
foundFirstContrivedThread = true;
}
}
}
}
return true;
} catch (DataUnavailable e) {
fail("bail");
return false;
} catch (CorruptDataException e) {
fail("bail");
return false;
}
}
};
}
for (int i = 0; i < ddrTestObjects.size(); i++) {
JavaRuntime localDDRRuntime = (JavaRuntime) ddrTestObjects.get(i);
JavaRuntime localJextractRuntime = (JavaRuntime) jextractTestObjects.get(i);
Object[] ddrHeapRootsArray = null;
Object[] jextractHeapRootsArray = null;
int threadCount = 0;
Iterator titer = localDDRRuntime.getThreads();
while (titer.hasNext()) {
threadCount++;
titer.next();
}
System.out.println("Thread count: " + threadCount);
try {
ddrHeapRootsArray = DTFJComparator.getList(Object.class, localDDRRuntime.getHeapRoots(), ddrFilter).toArray();
jextractHeapRootsArray = DTFJComparator.getList(Object.class, localJextractRuntime.getHeapRoots(), null).toArray();
} catch (InvalidObjectException e1) {
fail("Test setup failure");
}
Map<Long, List<Object>> map = new HashMap<Long, List<Object>>();
for (int j = 0; j < ddrHeapRootsArray.length; j++) {
long key = 0;
JavaReference ref = (JavaReference) ddrHeapRootsArray[j];
Object ddrHeapRoot = null;
try {
ddrHeapRoot = ref.getTarget();
} catch (DataUnavailable e) {
fail("bail");
} catch (CorruptDataException e) {
fail("bail");
}
if (ddrHeapRoot instanceof JavaObject) {
key = ((JavaObject) ddrHeapRoot).getID().getAddress();
} else if (ddrHeapRoot instanceof JavaClass) {
key = ((JavaClass) ddrHeapRoot).getID().getAddress();
} else {
fail("bail");
}
List bucket = map.get(key);
if (bucket == null) {
bucket = new ArrayList<Object>();
map.put(key, bucket);
}
bucket.add(ddrHeapRoot);
}
for (int j = 0; j < jextractHeapRootsArray.length; j++) {
JavaReference ref = (JavaReference) jextractHeapRootsArray[j];
Object heapRoot = null;
String name = null;
long key = 0;
try {
heapRoot = ref.getTarget();
if (heapRoot instanceof JavaObject) {
key = ((JavaObject) heapRoot).getID().getAddress();
name = "Instance of " + ((JavaObject) heapRoot).getJavaClass().getName();
} else if (heapRoot instanceof JavaClass) {
key = ((JavaClass) heapRoot).getID().getAddress();
name = ((JavaClass) heapRoot).getName();
} else {
fail("bail");
}
} catch (DataUnavailable e) {
fail("bail");
} catch (CorruptDataException e) {
fail("bail");
}
List bucket = map.get(key);
if (bucket == null) {
System.out.println(String.format("Jextract found %s at address: %s. Element #: %s that ddr does not know about", name, Long.toHexString(key), j));
result = false;
continue;
}
if (bucket.isEmpty()) {
fail("bail");
}
bucket.remove(0);
if (bucket.isEmpty()) {
map.remove(key);
}
}
// Whats left.
int count = 0;
Collection<List<Object>> remains = map.values();
if (remains.size() > 0) {
System.out.println("");
System.out.println("DDR found the following that JExtract did not know about");
}
Iterator<List<Object>> bucketIter = remains.iterator();
while (bucketIter.hasNext()) {
List<Object> bucket = bucketIter.next();
Iterator<Object> contentsIter = bucket.iterator();
while (contentsIter.hasNext()) {
Object obj = contentsIter.next();
System.out.println(String.format("%s) %s", ++count, obj));
}
}
}
assertTrue(result);
}
use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class JavaStackFrameTest method printStackTrace.
private void printStackTrace(JavaThread thread) throws CorruptDataException {
Iterator<?> frames = thread.getStackFrames();
int count = 0;
while (frames.hasNext()) {
Object o = frames.next();
System.err.print(count + ":");
if (o instanceof JavaStackFrame) {
JavaStackFrame frame = (JavaStackFrame) o;
JavaLocation location = frame.getLocation();
int lineNumber = -1;
String fileName = "<unknown>";
try {
lineNumber = location.getLineNumber();
} catch (DataUnavailable e) {
// deliberately do nothing
}
try {
fileName = location.getFilename();
} catch (DataUnavailable e) {
// Deliberately do nothing
}
System.err.println(location.getMethod().getClass().getName() + "." + location.getMethod().getName() + "(" + fileName + ":" + lineNumber + ")");
} else if (o instanceof CorruptData) {
System.err.println("<Corrupt Data: " + o + " >");
} else {
System.err.println("<Unexpected type: " + o.getClass().getName() + ": " + o + " >");
}
count++;
}
}
Aggregations