use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class InfoThreadCommand method printThreadInfo.
private boolean printThreadInfo(String id, Map threads) {
Iterator itThread;
ImageThread it;
boolean found = false;
itThread = ctx.getProcess().getThreads();
while (itThread.hasNext()) {
Object next = itThread.next();
if (next instanceof CorruptData) {
out.print("\n <corrupt data>");
continue;
}
it = (ImageThread) next;
// Obtain the native thread ID for this thread, and for zOS also obtain the TCB
String currentTID = null;
String currentTCB = null;
try {
currentTID = it.getID();
if (_is_zOS) {
currentTCB = it.getProperties().getProperty("TCB");
}
} catch (CorruptDataException e) {
// Continue with what we have obtained so far
}
// the requested native thread ID or zOS TCB, then go ahead and print out this thread.
if (null == id || id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
out.print(" thread id: ");
out.print(currentTID);
out.print("\n");
printRegisters(it);
out.print(" native stack sections:");
out.print("\n");
Iterator itStackSection = it.getStackSections();
while (itStackSection.hasNext()) {
Object nextStackSection = itStackSection.next();
if (nextStackSection instanceof CorruptData) {
out.print(" " + Exceptions.getCorruptDataExceptionString() + "\n");
continue;
}
ImageSection is = (ImageSection) nextStackSection;
printStackSection(is);
}
printStackFrameInfo(it);
out.print(" properties:");
out.print("\n");
printProperties(it);
out.print(" associated Java thread: ");
ThreadData td = (ThreadData) threads.remove(currentTID);
if (null != td) {
out.print("\n");
printJavaThreadInfo(td.getThread(), true);
} else {
out.print("<no associated Java thread>\n");
}
out.print("\n");
found = true;
}
}
return found;
}
use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class JavaLocation method getCompilationLevel.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaLocation#getCompilationLevel()
*/
public int getCompilationLevel() throws CorruptDataException {
/* we can't get accurate information from the JIT, so we will
* consider any JIT section to be 1, and any non-JIT section to
* be 0.
*/
long pointer = getAddress().getAddress();
Iterator iter = getMethod().getBytecodeSections();
while (iter.hasNext()) {
ImageSection section = (ImageSection) iter.next();
if (pointer >= section.getBaseAddress().getAddress() && pointer < section.getBaseAddress().getAddress() + section.getSize()) {
/* the PC is within an interpreted section */
return 0;
}
}
iter = getMethod().getCompiledSections();
while (iter.hasNext()) {
ImageSection section = (ImageSection) iter.next();
if (pointer >= section.getBaseAddress().getAddress() && pointer < section.getBaseAddress().getAddress() + section.getSize()) {
/* the PC is within a compiled section */
return 1;
}
}
// but let's play it safe, since J9 uses some magic PCs which jextract doesn't hide
return 0;
}
use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class ThreadSectionParser method addThread.
/**
* @param javaThreadResults
* @param nativeStacks list of attributes of the native stacks
* @param currentFileLineNumber
* @return java thread
* @throws ParserException if error handler decides to throw it due java thread or image thread error creation
*/
private JavaThread addThread(IAttributeValueMap javaThreadResults, IAttributeValueMap nativeResults, List nativeStacks, IAttributeValueMap blockerInfo, IAttributeValueMap cpuTimes, int currentFileLineNumber) throws ParserException {
long imageThreadID = (nativeResults != null) ? nativeResults.getLongValue(NATIVE_THREAD_ID) : javaThreadResults.getLongValue(NATIVE_THREAD_ID);
long tid = javaThreadResults.getLongValue(VM_THREAD_ID);
if (imageThreadID == IBuilderData.NOT_AVAILABLE) {
imageThreadID = tid;
}
ImageThread imageThread = null;
JavaThread javaThread = null;
// CMVC 158108 : fixed so that if the thread name is not present then it is not subsequently parsed
String threadName = javaThreadResults.getTokenValue(JAVA_THREAD_NAME);
if (threadName != null && threadName.length() >= 2) {
// remove quotes
threadName = threadName.substring(1, threadName.length() - 1);
}
String threadState = javaThreadResults.getTokenValue(JAVA_STATE);
int threadPriority = javaThreadResults.getIntValue(VM_THREAD_PRIORITY);
long abstractThreadID = javaThreadResults.getLongValue(ABSTRACT_THREAD_ID);
Properties properties = new Properties();
if (abstractThreadID != IBuilderData.NOT_AVAILABLE) {
addAsProperty(properties, ABSTRACT_THREAD_ID, "0x" + Long.toHexString(abstractThreadID));
}
if (nativeResults != null) {
addAsProperty(properties, NATIVE_THREAD_PRIORITY, nativeResults.getTokenValue(NATIVE_THREAD_PRIORITY));
addAsProperty(properties, NATIVE_THREAD_POLICY, nativeResults.getTokenValue(NATIVE_THREAD_POLICY));
addAsProperty(properties, SCOPE, nativeResults.getTokenValue(SCOPE));
addAsProperty(properties, VM_STATE, nativeResults.getTokenValue(VM_STATE));
addAsProperty(properties, VM_FLAGS, nativeResults.getTokenValue(VM_FLAGS));
}
if (cpuTimes != null) {
addAsProperty(properties, CPU_TIME_TOTAL, cpuTimes.getTokenValue(CPU_TIME_TOTAL));
addAsProperty(properties, CPU_TIME_USER, cpuTimes.getTokenValue(CPU_TIME_USER));
addAsProperty(properties, CPU_TIME_SYSTEM, cpuTimes.getTokenValue(CPU_TIME_SYSTEM));
}
String blockerObjectClassName = null;
// CMVC 180977 : the parser expects missing data to be represented by a -ve number, so change the default address from 0 to IBuilderData.NOT_AVAILABLE (currently -1)
// this parser check will break on a sufficiently large 64bit number, but fixing that is beyond the scope of this defect.
long blockerObjectAddress = IBuilderData.NOT_AVAILABLE;
if (blockerInfo != null) {
blockerObjectClassName = blockerInfo.getTokenValue(BLOCKER_OBJECT_FULL_JAVA_NAME);
blockerObjectAddress = blockerInfo.getLongValue(BLOCKER_OBJECT_ADDRESS);
}
long javaObjID = javaThreadResults.getLongValue(JAVA_THREAD_OBJ);
if (javaObjID == IBuilderData.NOT_AVAILABLE && nativeResults == null) {
String vmthread = javaThreadResults.getTokenValue(VM_THREAD_ID);
// Java 5.0 vmthreads tend to start with 0x0, and are not Java objects
if (vmthread != null && !vmthread.startsWith("0x0"))
javaObjID = tid;
}
try {
imageThread = fImageProcessBuilder.addImageThread(imageThreadID, abstractThreadID, properties);
if (threadName != null || tid != IBuilderData.NOT_AVAILABLE) {
javaThread = fRuntimeBuilder.addJavaThread(imageThread, threadName, tid, abstractThreadID, javaObjID, IBuilderData.NOT_AVAILABLE, threadState, threadPriority, blockerObjectAddress, blockerObjectClassName);
}
} catch (BuilderFailureException e) {
handleErrorAtLineNumber(currentFileLineNumber, "Failed to add thread: " + threadName + " " + imageThreadID, e);
}
for (Iterator it = nativeStacks.iterator(); it.hasNext(); ) {
IAttributeValueMap stackInfo = (IAttributeValueMap) it.next();
long from = stackInfo.getLongValue(NATIVE_STACK_FROM);
long to = stackInfo.getLongValue(NATIVE_STACK_TO);
long size = stackInfo.getLongValue(NATIVE_STACK_SIZE);
if (from != IBuilderData.NOT_AVAILABLE && size != IBuilderData.NOT_AVAILABLE) {
ImageSection section = fImageAddressSpaceBuilder.addImageSection("Native stack section", from, size);
fImageProcessBuilder.addImageStackSection(imageThread, section);
}
}
return javaThread;
}
use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class FindCommand method doCommand.
public void doCommand(String[] params) {
sb = new StringBuffer();
matches.clear();
if (!isParametersValid(params))
return;
determineModeFromPattern();
if (!parseParams(params))
return;
Iterator imageSections = ctx.getAddressSpace().getImageSections();
while (imageSections.hasNext()) {
if (matches.size() > findAtt.numMatchesToDisplay)
break;
ImageSection imageSection = (ImageSection) imageSections.next();
if (scanImageSection(imageSection))
break;
}
if (matches.size() > 0)
findAtt.lastMatch = ((Long) matches.get(matches.size() - 1)).longValue();
ctx.getProperties().put(Utils.FIND_ATTRIBUTES, findAtt);
doPrint();
if (matches.size() > 0)
printLastMatchContent();
// preppend "0x" back to pattern for findnext command
restoreHexPrefix();
}
use of com.ibm.dtfj.image.ImageSection in project openj9 by eclipse.
the class DTFJJavaRuntimeHelper method getTotalHeapSize.
@SuppressWarnings("rawtypes")
public static long getTotalHeapSize(JavaRuntime runtime, IProcess process) throws CorruptDataException {
if (totalSizeOfAllHeaps > 0) {
// already calculated, never changes
return totalSizeOfAllHeaps;
}
if (runtime == null) {
throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "No Java Runtime present"));
}
Iterator heaps = runtime.getHeaps();
while (heaps.hasNext()) {
Object nextHeap = heaps.next();
Iterator sections;
if (nextHeap instanceof JavaHeap) {
sections = ((JavaHeap) nextHeap).getSections();
} else {
// CorruptData?
throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "Corrupt heap encountered whilst calculating total heap size"));
}
while (sections.hasNext()) {
Object nextSection = sections.next();
if (nextSection instanceof ImageSection) {
long sectionSize = ((ImageSection) nextSection).getSize();
if (Long.MAX_VALUE - sectionSize > totalSizeOfAllHeaps) {
totalSizeOfAllHeaps += sectionSize;
} else {
// no point adding further, the cap is on Long.MAX_VALUE
return Long.MAX_VALUE;
}
} else {
// CorruptData?
throw new com.ibm.dtfj.image.CorruptDataException(J9DDRDTFJUtils.newCorruptData(process, "Corrupt section encountered whilst calculating total heap size"));
}
}
}
return totalSizeOfAllHeaps;
}
Aggregations