use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class ImageStackFrameTest method loadTestObjects.
protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
// Extract stack frames from all threads
List<Object> ddrThreads = new LinkedList<Object>();
List<Object> jextractThreads = new LinkedList<Object>();
Comparator<Object> c = new Comparator<Object>() {
public int compare(Object o1, Object o2) {
if (o1 instanceof ImageThread && o2 instanceof ImageThread) {
ImageThread t1 = (ImageThread) o1;
ImageThread t2 = (ImageThread) o2;
try {
return t1.getID().compareTo(t2.getID());
} catch (CorruptDataException e) {
return 0;
}
} else {
return 0;
}
}
};
fillLists(ddrThreads, ddrProcess.getThreads(), jextractThreads, jextractProcess.getThreads(), c);
assertEquals("Different numbers of threads", jextractThreads.size(), ddrThreads.size());
Collections.sort(ddrThreads, c);
Collections.sort(jextractThreads, c);
for (int i = 0; i != ddrThreads.size(); i++) {
ImageThread ddrThreadObj = (ImageThread) ddrThreads.get(i);
ImageThread jextractThreadObj = (ImageThread) jextractThreads.get(i);
Exception ddrException = null;
Exception jextractException = null;
try {
Iterator<?> it = ddrThreadObj.getStackFrames();
slurpIterator(it, ddrObjects);
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
Iterator<?> it = jextractThreadObj.getStackFrames();
slurpIterator(it, jextractObjects);
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException != null || jextractException != null) {
if (ddrException != null && jextractException != null) {
assertEquals("JExtract and DDR threw different exceptions", 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 DTFJMethod method handleException.
/**
* Handle an exception thrown by the DTFJ API.
*
* @param cmd the command current executing the API. This is required to provide access to context information.
* @param cause exception to be handled
* @return textual data to be written out
*/
public static String handleException(BaseJdmpviewCommand cmd, Throwable cause) {
ctx = cmd.ctx;
StringBuffer sb = new StringBuffer();
// Try and determine the artifact type
StackTraceElement[] myStack = cause.getStackTrace();
ArtifactType artifactType = cmd.getArtifactType();
String artifactTypeName = null;
switch(artifactType) {
case core:
artifactTypeName = "core";
break;
case javacore:
artifactTypeName = "javacore";
break;
case phd:
artifactTypeName = "phd";
break;
default:
artifactTypeName = "Unknown artifact type";
break;
}
// Let's find out which DTFJ Class/Method was being used
DTFJMethod dMethod = getDTFJMethod(myStack, cmd);
if (cause instanceof DataUnavailable) {
if (dMethod == null) {
sb.append("Could not determine DTFJ class/method that caused this exception: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == WORKS) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" should have worked for a ");
sb.append(artifactTypeName);
sb.append(" but returned: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == CAN_FAIL) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" can fail for a ");
sb.append(artifactTypeName);
sb.append(" which is why it returned: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == FAILS) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" is not supported for a ");
sb.append(artifactTypeName);
String s = cause.getLocalizedMessage();
if (s != null) {
sb.append(" causing: ");
sb.append(s);
}
}
} else if (cause instanceof CorruptDataException) {
CorruptData corruptData = ((CorruptDataException) cause).getCorruptData();
ImagePointer ip = corruptData.getAddress();
if (ip == null) {
sb.append("CorruptData found in dump at unknown address executing ");
if (dMethod == null) {
sb.append("an unknown class/method that caused this exception: ");
sb.append(cause.getLocalizedMessage());
} else {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
}
} else {
String addr = cmd.toHexStringAddr(ip.getAddress());
sb.append("CorruptData found in dump at address: ");
sb.append(addr);
sb.append(" causing: ");
sb.append(cause.getLocalizedMessage());
if (dMethod != null) {
sb.append(" executing ");
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
}
}
} else if (cause instanceof MemoryAccessException) {
sb.append(cause.getLocalizedMessage());
} else if (cause instanceof IllegalArgumentException) {
sb.append(cause.getLocalizedMessage());
} else {
// If we are here then something bad has really happened
// This is just debug code to help determine other problems this
// method has to deal with
sb.append("==========> Unexpected exception " + cause.getClass().getName() + " thrown: " + cause.getLocalizedMessage());
StringWriter st = new StringWriter();
cause.printStackTrace(new PrintWriter(st));
sb.append(st.toString());
}
return sb.toString();
}
use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class DDRLibraryAdapter method constructLibraryList.
/**
* Constructs the list of libraries required using the DDR implementation of the DTFJ Image* API.
* This ensures that the correct classloading is used for determining which libraries to collect.
* @param coreFile core file to process
*/
@SuppressWarnings({ "unchecked" })
private void constructLibraryList(final File coreFile) {
moduleNames = new ArrayList<String>();
ImageFactory factory = new J9DDRImageFactory();
final Image image;
final boolean isAIX;
try {
image = factory.getImage(coreFile);
isAIX = image.getSystemType().toLowerCase().startsWith("aix");
} catch (IOException e) {
logger.log(SEVERE, "Could not open core file", e);
errorMessages.add(e.getMessage());
return;
} catch (CorruptDataException e) {
logger.log(SEVERE, "Could not determine system type", e);
errorMessages.add(e.getMessage());
return;
} catch (DataUnavailable e) {
logger.log(SEVERE, "Could not determine system type", e);
errorMessages.add(e.getMessage());
return;
}
for (Iterator spaces = image.getAddressSpaces(); spaces.hasNext(); ) {
ImageAddressSpace space = (ImageAddressSpace) spaces.next();
for (Iterator procs = space.getProcesses(); procs.hasNext(); ) {
ImageProcess proc = (ImageProcess) procs.next();
try {
// add the executable to the list of libraries to be collected
ImageModule exe = proc.getExecutable();
moduleNames.add(exe.getName());
for (Iterator libraries = proc.getLibraries(); libraries.hasNext(); ) {
ImageModule module = (ImageModule) libraries.next();
String key = null;
try {
// handle CDE thrown by getName(), as this is required further on this call needs to succeed
if (isAIX) {
key = module.getName();
// check on AIX if module is the .a file or library
int pos = key.indexOf(".a(");
if ((pos != -1) && (key.lastIndexOf(')') == key.length() - 1)) {
key = key.substring(0, pos + 2);
}
} else {
key = module.getName();
}
logger.fine("Module : " + key);
if (!moduleNames.contains(key)) {
// don't store duplicate libraries
moduleNames.add(key);
}
} catch (Exception e) {
logger.log(WARNING, "Error getting module name", e);
}
}
} catch (DataUnavailable e) {
logger.log(WARNING, "Error getting library list", e);
errorMessages.add(e.getMessage());
} catch (com.ibm.dtfj.image.CorruptDataException e) {
logger.log(WARNING, "Error getting library list", e);
errorMessages.add(e.getMessage());
}
}
}
}
use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class J9DDRImageProcess method getEnvironment.
/**
* This method gets the environment variables.
* First it tries to extract it from RAS structure.
* If not, it tries to get it from loaded modules.
* @return Properties instance of environment variables.
* @throws DataUnavailable
* @throws CorruptDataException
*/
public Properties getEnvironment() throws DataUnavailable, CorruptDataException {
try {
checkFailureInfo();
if (j9rasProcessData != null) {
try {
Properties properties;
long environ = j9rasProcessData.getEnvironment();
if (process.getPlatform() == Platform.WINDOWS && j9rasProcessData.version() > 4) {
// Get the env vars from an environment strings block instead of the environ global
properties = EnvironmentUtils.readEnvironmentStrings(process, environ);
} else {
long stringPointer = process.getPointerAt(environ);
properties = EnvironmentUtils.readEnvironment(process, stringPointer);
}
if ((null == properties) || (0 == properties.size())) {
/* In the case of env vars is null or empty,
* throw exception so that it tries to get env vars from modules
*/
throw new com.ibm.j9ddr.CorruptDataException("");
}
return properties;
} catch (com.ibm.j9ddr.CorruptDataException e1) {
/* Seems like RAS structure is corrupted. Try to get it from modules. */
return process.getEnvironmentVariables();
}
} else {
/* We don't have a J9RAS structure to work with. Try to get it from modules. */
return process.getEnvironmentVariables();
}
} catch (com.ibm.j9ddr.CorruptDataException e) {
throw new DTFJCorruptDataException(process, e);
} catch (DataUnavailableException e) {
throw new DataUnavailable(e.getMessage());
}
}
use of com.ibm.dtfj.image.DataUnavailable in project openj9 by eclipse.
the class J9DDRImageProcess method getCurrentThread.
/**
* This method returns the ImageThread that matches the TID stored in the J9RAS data structure,
* or
* case 1: if no J9RAS structure available return null
* case 2: if J9RAS structure available but no TID field (old JVMs, old jextract behaviour)
* - return the first thread, or null if no threads
* case 3: if J9RAS structure available with TID field but TID is zero (eg dump triggered outside JVM)
* - platform specific code if core readers have identified a current thread, else...
* case 4: if J9RAS structure available with TID field but no match (eg Linux), return a stub ImageThread
*
* @return ImageThread
* @throws {@link CorruptDataException}
*/
public ImageThread getCurrentThread() throws CorruptDataException {
try {
checkFailureInfo();
if (j9rasProcessData != null) {
long currentThreadId;
try {
currentThreadId = j9rasProcessData.tid();
} catch (DataUnavailable e) {
// JExtract currently just takes first thread as we do here
for (IOSThread thread : process.getThreads()) {
return new J9DDRImageThread(process, thread);
}
return null;
}
for (IOSThread thread : process.getThreads()) {
if (thread.getThreadId() == currentThreadId) {
return new J9DDRImageThread(process, thread);
}
}
if (currentThreadId == 0) {
// for a thread with a non-zero Task Completion Code. There may be more we can do here for Win/Linux/AIX
if (process.getPlatform() == Platform.ZOS) {
for (IOSThread thread : process.getThreads()) {
Properties threadProps = thread.getProperties();
String tcc = threadProps.getProperty("Task Completion Code");
if (tcc != null && !tcc.equals("0x0")) {
return new J9DDRImageThread(process, thread);
}
}
}
}
// We cannot match the native thread at this point, so provide a stub based on the information in the RAS structure.
return new J9DDRStubImageThread(process, currentThreadId);
} else {
return null;
}
} catch (com.ibm.j9ddr.CorruptDataException e) {
throw new DTFJCorruptDataException(process, e);
}
}
Aggregations