use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class JExtractXMLGenerator method generateClassloaders.
@SuppressWarnings("unchecked")
private void generateClassloaders(JavaRuntime rt) throws Exception {
for (Iterator loaders = rt.getJavaClassLoaders(); loaders.hasNext(); ) {
JavaClassLoader loader = (JavaClassLoader) loaders.next();
xml.append("<classloader id=\"");
// xml.append(loader.getID());
xml.append("\" obj=\"0x");
xml.append(Long.toHexString(loader.getObject().getID().getAddress()));
xml.append("\">\n");
for (Iterator classes = loader.getCachedClasses(); classes.hasNext(); ) {
JavaClass clazz = (JavaClass) classes.next();
xml.append("<class id=\"0x");
xml.append(Long.toHexString(clazz.getID().getAddress()));
xml.append("\" />\n");
}
xml.append("</classloader>\n");
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class NodeJavaVM method didFinishParsing.
public void didFinishParsing() {
Iterator classLoaders = _runtime.getJavaClassLoaders();
while (classLoaders.hasNext()) {
Object potentialClassLoader = classLoaders.next();
if (potentialClassLoader instanceof JavaClassLoader) {
JavaClassLoader loader = (JavaClassLoader) potentialClassLoader;
// sets the associated object
try {
Object potentialLoaderObject = loader.getObject();
if (null != potentialLoaderObject && potentialLoaderObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
JavaObject loaderObject = (com.ibm.dtfj.java.j9.JavaObject) potentialLoaderObject;
loaderObject.setAssociatedClassLoader(loader);
_runtime.addSpecialObject(loaderObject);
Iterator classes = loader.getDefinedClasses();
while (classes.hasNext()) {
Object potentialClass = classes.next();
if (potentialClass instanceof JavaClass) {
JavaClass theClass = (JavaClass) potentialClass;
try {
Object potentialClassObject = theClass.getObject();
if (null != potentialClassObject && potentialClassObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
JavaObject classObject = (com.ibm.dtfj.java.j9.JavaObject) potentialClassObject;
classObject.setAssociatedClass(theClass);
_runtime.addSpecialObject(classObject);
}
} catch (CorruptDataException e) {
// no reason to skip the other classloaders/classes just because an exception is thrown on one class
} catch (IllegalArgumentException e) {
// CMVC 173262 : JavaClass.getObject() uses JavaHeap.getObjectAtAddress() which can throw this exception
}
}
}
}
} catch (CorruptDataException e) {
// associated object not set
}
}
}
Iterator monitors = _runtime.getMonitors();
while (monitors.hasNext()) {
Object potentialMonitor = monitors.next();
if (potentialMonitor instanceof JavaMonitor) {
JavaMonitor monitor = (JavaMonitor) potentialMonitor;
// sets the associated object
Object potentialMonitorObject = monitor.getObject();
if (null != potentialMonitorObject && potentialMonitorObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
JavaObject monitorObject = (com.ibm.dtfj.java.j9.JavaObject) potentialMonitorObject;
monitorObject.setAssociatedMonitor(monitor);
_runtime.addSpecialObject(monitorObject);
}
}
}
Iterator threads = _runtime.getThreads();
while (threads.hasNext()) {
Object potentialThread = threads.next();
if (potentialThread instanceof JavaThread) {
JavaThread thread = (JavaThread) potentialThread;
// sets the associated object
try {
Object potentialThreadObject = thread.getObject();
if (null != potentialThreadObject && potentialThreadObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
JavaObject threadObject = (com.ibm.dtfj.java.j9.JavaObject) potentialThreadObject;
threadObject.setAssociatedThread(thread);
_runtime.addSpecialObject(threadObject);
}
} catch (CorruptDataException e) {
// associated object not set
}
}
}
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class XJCommand method printReferences.
/**
* Print the references from the given object. Omit the first reference: this is always a reference to the
* object's class.
*/
public static void printReferences(JavaObject jo, PrintStream out) {
Iterator<?> references = jo.getReferences();
if (references.hasNext()) {
// reference to the class, ignore this one
references.next();
}
if (!references.hasNext()) {
out.print("\t references: <none>\n ");
out.print("\t ");
} else {
out.print("\t references:\n ");
out.print("\t ");
while (references.hasNext()) {
Object potential_reference = references.next();
if (potential_reference instanceof JavaReference) {
JavaReference reference = (JavaReference) potential_reference;
try {
Object target = reference.getTarget();
if (target instanceof JavaObject) {
out.print(" 0x" + Long.toHexString(((JavaObject) target).getID().getAddress()));
} else if (target instanceof JavaClass) {
out.print(" 0x" + Long.toHexString(((JavaClass) target).getID().getAddress()));
}
} catch (DataUnavailable e) {
// don't print anything
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
}
}
}
}
out.print("\n\n");
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class DTFJJavaObject method getAssociatedClass.
private JavaClass getAssociatedClass() {
// Retrieve the class loader for this class for using introspection to speed up
// lookup when lots of classes are loaded by lots of class loaders.
JavaObject targetClassLoaderObject = null;
try {
JavaClass javaLangClass = this.getJavaClass();
Iterator<?> fields = javaLangClass.getDeclaredFields();
while (fields.hasNext()) {
Object o = fields.next();
if (o instanceof JavaField) {
JavaField field = (JavaField) o;
if ("classLoader".equals(field.getName())) {
targetClassLoaderObject = (JavaObject) field.get(this);
break;
}
}
}
} catch (CorruptDataException e) {
// This is only an optimisation to save us walking all class loaders. Continue
} catch (MemoryAccessException e) {
// This is only an optimisation to save us walking all class loaders. Continue
}
return getAssociatedClass(targetClassLoaderObject);
}
use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.
the class DTFJJavaFieldInstance method _findClassForName.
/**
* private method to search all classloaders for a given class
*/
private JavaClass _findClassForName(String candidateClass) throws CorruptDataException {
DTFJJavaRuntime rt = DTFJContext.getRuntime();
Iterator allLoaders = rt.getJavaClassLoaders();
JavaClass subclass = null;
while (allLoaders.hasNext() && (null == subclass)) {
JavaClassLoader loader = (JavaClassLoader) allLoaders.next();
Iterator classes = loader.getDefinedClasses();
while (classes.hasNext() && (null == subclass)) {
JavaClass oneClass = (JavaClass) classes.next();
if (oneClass.getName().equals(candidateClass)) {
subclass = oneClass;
break;
}
}
}
return subclass;
}
Aggregations