use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class PHDImageAddressSpace method getImageSections.
public Iterator<ImageSection> getImageSections() {
List<ImageSection> list = new ArrayList<ImageSection>();
for (Iterator<ImageProcess> ip = getProcesses(); ip.hasNext(); ) {
ImageProcess p = ip.next();
if (p instanceof CorruptData)
continue;
for (Iterator<ManagedRuntime> jr = p.getRuntimes(); jr.hasNext(); ) {
ManagedRuntime mr = jr.next();
if (mr instanceof CorruptData)
continue;
if (mr instanceof JavaRuntime) {
for (Iterator<JavaHeap> jh = ((JavaRuntime) mr).getHeaps(); jh.hasNext(); ) {
JavaHeap hp = jh.next();
if (hp instanceof CorruptData)
continue;
for (Iterator<ImageSection> is = hp.getSections(); is.hasNext(); ) {
// Add the corrupt sections too
list.add(is.next());
}
}
}
}
}
if (metaImageAddressSpace != null) {
for (Iterator it = metaImageAddressSpace.getImageSections(); it.hasNext(); ) {
Object next = it.next();
if (next instanceof ImageSection) {
ImageSection section = (ImageSection) next;
ImageSection newSection = new PHDImageSection(section.getName(), getPointer(section.getBaseAddress().getAddress()), section.getSize());
list.add(newSection);
}
}
}
return list.iterator();
}
use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class InfoClassCommand method countClassInstances.
private void countClassInstances() {
JavaRuntime runtime = ctx.getRuntime();
Map<JavaClass, ClassStatistics> thisRuntimeClasses = classInstanceCounts.get(runtime);
final Collection<JavaClass> javaClasses = getRuntimeClasses(runtime);
long corruptObjectCount = 0;
long corruptClassCount = 0;
long corruptClassNameCount = 0;
Iterator itHeap = runtime.getHeaps();
while (itHeap.hasNext()) {
Object heap = itHeap.next();
if (heap instanceof CorruptData) {
out.println("[skipping corrupt heap]");
continue;
}
JavaHeap jh = (JavaHeap) heap;
Iterator itObject = jh.getObjects();
// Walk through all objects in this heap, accumulating counts and total memory size by class
while (itObject.hasNext()) {
Object next = itObject.next();
// JavaHeap, we don't attempt to count these as instances of known classes).
if (next instanceof JavaObject) {
JavaObject jo = (JavaObject) next;
ClassStatistics stats = null;
try {
// Check whether we found this class in the classloaders walk earlier
JavaClass jc = jo.getJavaClass();
if (javaClasses.contains(jc)) {
stats = thisRuntimeClasses.get(jc);
} else {
// Class not found in the classloaders, create a statistic for it now, and issue a warning message
stats = new ClassStatistics();
thisRuntimeClasses.put(jc, stats);
String classname;
try {
classname = jc.getName();
out.println("Warning, class: " + classname + " found when walking the heap was missing from classloader walk");
} catch (CorruptDataException cde) {
corruptClassNameCount++;
}
}
// Increment the statistic for objects of this class (accumulated count and size)
stats.incrementCount();
try {
stats.addToSize(jo.getSize());
} catch (CorruptDataException cde) {
// bad size, count object as corrupt
corruptObjectCount++;
}
} catch (CorruptDataException cde) {
corruptClassCount++;
}
} else {
corruptObjectCount++;
}
}
}
if (corruptObjectCount != 0) {
out.println("Warning, found " + corruptObjectCount + " corrupt objects during heap walk");
}
if (corruptClassCount != 0) {
out.println("Warning, found " + corruptClassCount + " corrupt class references during heap walk");
}
if (corruptClassNameCount != 0) {
out.println("Warning, found " + corruptClassNameCount + " corrupt class names during heap walk");
}
}
use of com.ibm.dtfj.java.JavaRuntime 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);
}
}
}
use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class OpenCommand method createContexts.
private void createContexts(Image loadedImage, String coreFilePath) {
if (loadedImage == null) {
// cannot create any contexts as an image has not been obtained
return;
}
boolean hasContexts = false;
Iterator<?> spaces = loadedImage.getAddressSpaces();
while (spaces.hasNext()) {
Object o = spaces.next();
if (o instanceof ImageAddressSpace) {
ImageAddressSpace space = (ImageAddressSpace) o;
Iterator<?> procs = space.getProcesses();
if (procs.hasNext()) {
while (procs.hasNext()) {
o = procs.next();
if (o instanceof ImageProcess) {
ImageProcess proc = (ImageProcess) o;
Iterator<?> runtimes = proc.getRuntimes();
if (runtimes.hasNext()) {
while (runtimes.hasNext()) {
o = runtimes.next();
if (o instanceof JavaRuntime) {
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, (JavaRuntime) o, coreFilePath);
hasContexts = true;
} else if (o instanceof CorruptData) {
logger.fine("CorruptData encountered in ImageProcess.getRuntimes(): " + ((CorruptData) o).toString());
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
hasContexts = true;
} else {
logger.fine("Unexpected class encountered in ImageProcess.getRuntimes()");
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
hasContexts = true;
}
}
} else {
// there are no runtimes so create a context for this process
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
hasContexts = true;
}
}
}
} else {
// context with only an address space
createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, null, null, coreFilePath);
hasContexts = true;
}
} else {
// need a representation of a corrupt context
logger.fine("Skipping corrupt ImageAddress space");
}
}
if (!hasContexts) {
if (ctx.hasPropertyBeenSet(VERBOSE_MODE_PROPERTY)) {
out.println("Warning : no contexts were found, is this a valid core file ?");
}
}
}
use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class J9DDRImageProcess method getExecutablePathFromSystemProperties.
private String getExecutablePathFromSystemProperties() {
Iterator<?> runtimeIt = getRuntimes();
while (runtimeIt.hasNext()) {
Object o = runtimeIt.next();
if (o instanceof JavaRuntime) {
JavaRuntime runtime = (JavaRuntime) o;
try {
JavaVMInitArgs args = runtime.getJavaVMInitArgs();
Iterator<?> optionsIt = args.getOptions();
Pattern javaHomePattern = Pattern.compile("-Djava.home=(.*)");
while (optionsIt.hasNext()) {
Object optionObj = optionsIt.next();
if (optionObj instanceof JavaVMOption) {
JavaVMOption option = (JavaVMOption) optionObj;
Matcher m = javaHomePattern.matcher(option.getOptionString());
if (m.find()) {
String javaHome = m.group(1);
// Note this method not used on Windows - don't have to worry about .exe or \
return javaHome + "/bin/java";
}
}
}
} catch (Exception e) {
// Ignore
}
}
}
return null;
}
Aggregations