use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class InfoClassCommand method printAllRuntimeClasses.
private void printAllRuntimeClasses(Comparator<JavaClass> sortOrder) {
JavaRuntime jr = ctx.getRuntime();
Collection<JavaClass> javaClasses = getRuntimeClasses(jr);
long objCount = 0;
long totalSize = 0;
Iterator<JavaClass> itClass;
if (sortOrder == null) {
itClass = javaClasses.iterator();
} else {
List<JavaClass> sortedList = new LinkedList<JavaClass>();
Iterator<JavaClass> itr = javaClasses.iterator();
while (itr.hasNext()) {
sortedList.add(itr.next());
}
Collections.sort(sortedList, sortOrder);
itClass = sortedList.iterator();
}
if (itClass.hasNext()) {
printClassListHeader();
} else {
out.print("\n\t No information found for loaded classes\n");
}
while (itClass.hasNext()) {
JavaClass jc = itClass.next();
ClassStatistics d = getClassStatisticsFor(jr, jc);
totalSize += d.getSize();
objCount += d.getCount();
printOneClass(jc, d);
}
out.print("\n");
out.print("\t Total number of objects: " + objCount + "\n");
out.print("\t Total size of objects: " + totalSize + "\n");
}
use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class InfoClassCommand method cacheRuntimeClasses.
/**
* Pre-populates the classInstanceCounts map with just classes, and empty ClassStatistics objects.
* The key-set of classInstanceCounts.get(someRuntime) can be then treated as a cache of all classes for that runtime,
* eliminating the need to iterate over all class loaders (see getRuntimeClasses()).
* @param jr
* @param errOut
* @return
*/
private void cacheRuntimeClasses() {
classInstanceCounts = new HashMap<JavaRuntime, Map<JavaClass, ClassStatistics>>();
long corruptClassCount = 0;
Map<JavaClass, ClassStatistics> classesOfThisRuntime = new HashMap<JavaClass, ClassStatistics>();
JavaRuntime runtime = ctx.getRuntime();
classInstanceCounts.put(runtime, classesOfThisRuntime);
Iterator itClassLoader = runtime.getJavaClassLoaders();
while (itClassLoader.hasNext()) {
JavaClassLoader jcl = (JavaClassLoader) itClassLoader.next();
Iterator itClass = jcl.getDefinedClasses();
while (itClass.hasNext()) {
Object obj = itClass.next();
if (obj instanceof JavaClass) {
// check that a cast can be made to JavaClass
classesOfThisRuntime.put((JavaClass) obj, new ClassStatistics());
} else {
corruptClassCount++;
}
}
}
if (corruptClassCount > 0) {
out.print("Warning, found " + corruptClassCount + " corrupt classes during classloader walk\n");
}
}
use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class InfoClassCommand method printSingleRuntimeClassInfo.
private void printSingleRuntimeClassInfo(String className) {
JavaRuntime jr = ctx.getRuntime();
Long objAddress = Utils.longFromStringWithPrefix(className);
JavaClass[] classes = null;
if (objAddress != null) {
JavaClass jc = Utils.getClassGivenAddress(objAddress.longValue(), jr);
if (jc != null) {
classes = new JavaClass[1];
classes[0] = jc;
}
} else {
classes = Utils.getClassGivenName(className, jr, out);
}
// still be an array type or it might not exist
if (null == classes || classes.length == 0) {
out.print("\t could not find class with name \"" + className + "\"\n\n");
} else if (classes.length == 1) {
JavaClass jc = classes[0];
printClassDetails(jr, className, jc);
} else {
out.println("name = " + className + " found " + classes.length + " on different class loaders");
for (int i = 0; i < classes.length; i++) {
JavaClass jc = classes[i];
ClassOutput.printRuntimeClassAndLoader(jc, out);
}
out.println("Use info class with the class ID to print out information on a specific class.");
out.println("For example: info class 0x" + Long.toHexString(classes[0].getID().getAddress()));
}
}
use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class InfoJitmCommand method showJITdMethods.
private void showJITdMethods() {
JavaRuntime jr = ctx.getRuntime();
Iterator itJavaClassLoader = jr.getJavaClassLoaders();
while (itJavaClassLoader.hasNext()) {
JavaClassLoader jcl = (JavaClassLoader) itJavaClassLoader.next();
Iterator itJavaClass = jcl.getDefinedClasses();
while (itJavaClass.hasNext()) {
JavaClass jc = (JavaClass) itJavaClass.next();
Iterator itJavaMethod = jc.getDeclaredMethods();
String jcName;
try {
jcName = jc.getName();
} catch (CorruptDataException e) {
jcName = Exceptions.getCorruptDataExceptionString();
}
while (itJavaMethod.hasNext()) {
JavaMethod jm = (JavaMethod) itJavaMethod.next();
String name;
String sig;
try {
name = jm.getName();
} catch (CorruptDataException e) {
name = Exceptions.getCorruptDataExceptionString();
}
try {
sig = jm.getSignature();
} catch (CorruptDataException e) {
sig = Exceptions.getCorruptDataExceptionString();
}
if (jm.getCompiledSections().hasNext()) {
Iterator itImageSection = jm.getCompiledSections();
while (itImageSection.hasNext()) {
ImageSection is = (ImageSection) itImageSection.next();
long startAddr = is.getBaseAddress().getAddress();
long size = is.getSize();
long endAddr = startAddr + size;
out.print("\n\t" + "start=" + Utils.toHex(startAddr) + " " + "end=" + Utils.toHex(endAddr) + " " + jcName + "::" + name + sig);
}
}
}
}
}
out.print("\n");
}
use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.
the class InfoLockCommand method showSystemLocks.
private void showSystemLocks() {
Vector vMonitorsWithLockedObjects = new Vector();
JavaRuntime jRuntime = ctx.getRuntime();
Iterator monitors = jRuntime.getMonitors();
out.println("\nSystem locks...");
while (monitors.hasNext()) {
JavaMonitor jMonitor = (JavaMonitor) monitors.next();
JavaObject jObject = jMonitor.getObject();
try {
String monitorName = jMonitor.getName().trim();
if (monitorName.equalsIgnoreCase("")) {
monitorName = "<un-named monitor>";
}
out.println("id: 0x" + jMonitor.getID() + " name: " + jMonitor.getName());
JavaThread owner = jMonitor.getOwner();
if (null != owner) {
try {
out.println("\towner thread id: " + owner.getImageThread().getID() + " name: " + owner.getName());
} catch (DataUnavailable e) {
out.println("\towner thread id: " + Exceptions.getDataUnavailableString());
logger.log(Level.FINE, Exceptions.getDataUnavailableString(), e);
}
}
showWaiters(jMonitor);
} catch (CorruptDataException cde) {
out.println("\nwarning, corrupt data encountered during scan for system locks...");
}
if (null != jObject) {
// Remember object monitors (flat or inflated) for later
vMonitorsWithLockedObjects.add(jMonitor);
}
}
showLockedObjects(vMonitorsWithLockedObjects);
}
Aggregations