use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class ClassOutput method printFields.
public static void printFields(JavaObject jo, JavaClass jc, JavaRuntime jr, PrintStream out) {
boolean array;
try {
array = jo.isArray();
} catch (CorruptDataException e) {
out.print("\t <cannot determine if above object is array (" + Exceptions.getCorruptDataExceptionString() + "); " + "we will assume it is not an array>\n");
array = false;
}
if (array) {
String componentType;
int arraySize;
try {
componentType = jc.getComponentType().getName();
} catch (CorruptDataException e) {
out.print("\t <cannot determine what type of array this is (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
return;
}
try {
arraySize = jo.getArraySize();
} catch (CorruptDataException e) {
out.print("\t <cannot determine the size of the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
return;
}
Object dst = null;
if (componentType.equals("boolean")) {
dst = new boolean[arraySize];
} else if (componentType.equals("byte")) {
dst = new byte[arraySize];
} else if (componentType.equals("char")) {
dst = new char[arraySize];
} else if (componentType.equals("short")) {
dst = new short[arraySize];
} else if (componentType.equals("int")) {
dst = new int[arraySize];
} else if (componentType.equals("long")) {
dst = new long[arraySize];
} else if (componentType.equals("float")) {
dst = new float[arraySize];
} else if (componentType.equals("double")) {
dst = new double[arraySize];
} else {
dst = new JavaObject[arraySize];
}
try {
jo.arraycopy(0, dst, 0, arraySize);
} catch (CorruptDataException e) {
out.print("\t <cannot copy data from the array (" + Exceptions.getCorruptDataExceptionString() + ")>\n");
return;
} catch (MemoryAccessException e) {
out.print("\t <cannot copy data from the array (" + Exceptions.getMemoryAccessExceptionString() + ")>\n");
return;
} catch (UnsupportedOperationException e) {
// Some artefacts e.g. phd do not support arraycopy so just put out what we can
out.print("\t This is an array of size " + arraySize + " elements\n");
return;
}
for (int i = 0; i < arraySize; i++) {
out.print("\t " + i + ":\t");
if (componentType.equals("boolean")) {
out.print(Utils.getVal(new Boolean(((boolean[]) dst)[i])));
} else if (componentType.equals("byte")) {
out.print(Utils.getVal(new Byte(((byte[]) dst)[i])));
} else if (componentType.equals("char")) {
out.print(Utils.getVal(new Character(((char[]) dst)[i])));
} else if (componentType.equals("short")) {
out.print(Utils.getVal(new Short(((short[]) dst)[i])));
} else if (componentType.equals("int")) {
out.print(Utils.getVal(new Integer(((int[]) dst)[i])));
} else if (componentType.equals("long")) {
out.print(Utils.getVal(new Long(((long[]) dst)[i])));
} else if (componentType.equals("float")) {
out.print(Utils.getVal(new Float(((float[]) dst)[i])));
} else if (componentType.equals("double")) {
out.print(Utils.getVal(new Double(((double[]) dst)[i])));
} else {
out.print(Utils.getVal(((JavaObject[]) dst)[i]));
}
out.print("\n");
}
} else {
JavaClass initialJC = jc;
List<JavaClass> classList = new ArrayList<JavaClass>();
while (jc != null) {
classList.add(jc);
try {
jc = jc.getSuperclass();
} catch (CorruptDataException d) {
jc = null;
}
}
for (int i = (classList.size() - 1); i >= 0; i--) {
jc = classList.get(i);
Iterator itField = jc.getDeclaredFields();
if (itField.hasNext()) {
if (jc.equals(initialJC)) {
out.print("\t declared fields:\n");
} else {
out.print("\t fields inherited from \"");
try {
out.print(jc.getName() + "\":\n");
} catch (CorruptDataException d) {
out.print(Exceptions.getCorruptDataExceptionString());
}
}
}
while (itField.hasNext()) {
JavaField jf = (JavaField) itField.next();
boolean isStatic;
try {
isStatic = Modifier.isStatic(jf.getModifiers());
} catch (CorruptDataException e) {
out.print("\t <error while getting modifier for field \"");
try {
out.print(jf.getName());
} catch (CorruptDataException d) {
out.print(Exceptions.getCorruptDataExceptionString());
}
out.print("\", " + Exceptions.getCorruptDataExceptionString() + ">");
isStatic = true;
}
if (!isStatic) {
printNonStaticFieldData(jo, jf, out);
}
}
}
}
out.print("\n");
}
use of com.ibm.dtfj.java.JavaClass 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.JavaClass 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.JavaClass 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.JavaClass in project openj9 by eclipse.
the class WhatisCommand method checkMethodInRange.
private void checkMethodInRange(Iterator objects, long address) {
while (objects.hasNext()) {
JavaObject jObject = (JavaObject) objects.next();
JavaClass jClass;
try {
jClass = jObject.getJavaClass();
} catch (CorruptDataException cde) {
// go to the next iteration
continue;
}
Iterator methods = jClass.getDeclaredMethods();
while (methods.hasNext()) {
JavaMethod jMethod = (JavaMethod) methods.next();
Iterator bytecodeSections = jMethod.getBytecodeSections();
Iterator compiledSections = jMethod.getCompiledSections();
if (isWithinImageSections(bytecodeSections, jMethod, false, address)) {
// found it, we are done
return;
}
if (isWithinImageSections(compiledSections, jMethod, true, address)) {
// found it, we are done
return;
}
}
}
}
Aggregations