Search in sources :

Example 46 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class JavaClassLoader method getCachedClasses.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaClassLoader#getCachedClasses()
	 */
public Iterator getCachedClasses() {
    if (null == _cached) {
        // a cached class is any class known to the loader
        Iterator ids = _classIDs.iterator();
        _cached = new ArrayList();
        while (ids.hasNext()) {
            long oneID = ((Long) ids.next()).longValue();
            JavaClass oneClass = _javaVM.getClassForID(oneID);
            if (null == oneClass) {
                _cached.add(new CorruptData("Cache reference to unknown class " + oneID, null));
            } else {
                _cached.add(oneClass);
            }
        }
    }
    return _cached.iterator();
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) CorruptData(com.ibm.dtfj.image.j9.CorruptData)

Example 47 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class JavaClassLoader method findClass.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaClassLoader#findClass(java.lang.String)
	 */
public JavaClass findClass(String name) throws CorruptDataException {
    Iterator classes = getDefinedClasses();
    JavaClass found = null;
    while (classes.hasNext() && (null == found)) {
        JavaClass one = (JavaClass) classes.next();
        if (one.getName().equals(name)) {
            found = one;
        }
    }
    return found;
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator)

Example 48 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class JCJavaClassLoader method findClass.

/**
 */
public JavaClass findClass(String className) {
    JavaClass foundClass = null;
    if (fClassNames.containsKey(className)) {
        ImagePointer ip = (ImagePointer) fClassNames.get(className);
        if (ip != null) {
            // By class ID
            long id = ip.getAddress();
            foundClass = fRuntime.findJavaClass(id);
        } else {
            // By class name
            foundClass = fRuntime.findJavaClass(className);
        }
    }
    return foundClass;
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaClass(com.ibm.dtfj.java.JavaClass)

Example 49 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class PHDJavaClass method getReferences.

public Iterator<JavaReference> getReferences() {
    final JavaClass source = this;
    return new Iterator<JavaReference>() {

        int count;

        JavaClass sup;

        JavaObject load;

        {
            try {
                sup = getSuperclass();
                if (sup != null)
                    count = -1;
            } catch (CorruptDataException e) {
            }
            try {
                load = loader.getObject();
                if (load != null)
                    count = -2;
            } catch (CorruptDataException e) {
            }
        }

        public boolean hasNext() {
            if (count < 0) {
                return true;
            } else if (refs instanceof LongEnumeration) {
                LongEnumeration le = (LongEnumeration) refs;
                return le.hasMoreElements();
            } else if (refs instanceof long[]) {
                long[] arefs = (long[]) refs;
                return count < arefs.length;
            } else if (refs instanceof int[]) {
                int[] arefs = (int[]) refs;
                return count < arefs.length;
            } else {
                return false;
            }
        }

        public JavaReference next() {
            if (!hasNext())
                throw new NoSuchElementException("" + count++);
            long ref;
            int refType = PHDJavaReference.REFERENCE_UNKNOWN;
            Object cls = null;
            if (count == -2) {
                cls = load;
                ++count;
                // Skip over the superclass if not present
                if (sup == null)
                    ++count;
                ref = 0;
                refType = PHDJavaReference.REFERENCE_CLASS_LOADER;
            } else if (count == -1) {
                cls = sup;
                ++count;
                ref = 0;
                refType = PHDJavaReference.REFERENCE_SUPERCLASS;
            } else {
                if (refs instanceof LongEnumeration) {
                    LongEnumeration le = (LongEnumeration) refs;
                    ref = le.nextLong();
                    ++count;
                } else if (refs instanceof int[]) {
                    int[] arefs = (int[]) refs;
                    ref = runtime.expandAddress(arefs[count++]);
                } else {
                    long[] arefs = (long[]) refs;
                    ref = arefs[count++];
                }
                cls = runtime.findClass(ref);
            }
            if (cls != null) {
                return new PHDJavaReference(cls, source, PHDJavaReference.REACHABILITY_STRONG, refType, PHDJavaReference.HEAP_ROOT_UNKNOWN, "?");
            } else {
                return new PHDJavaReference(new PHDJavaObject.Builder((PHDJavaHeap) (runtime.getHeaps().next()), ref, null, PHDJavaObject.NO_HASHCODE, -1).build(), source, PHDJavaReference.REACHABILITY_STRONG, refType, PHDJavaReference.HEAP_ROOT_UNKNOWN, "?");
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LongEnumeration(com.ibm.dtfj.phd.util.LongEnumeration) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) NoSuchElementException(java.util.NoSuchElementException)

Example 50 with JavaClass

use of com.ibm.dtfj.java.JavaClass in project openj9 by eclipse.

the class PHDJavaClass method getObject.

public JavaObject getObject() throws CorruptDataException {
    if (addr == 0)
        return null;
    if (classObject != null)
        return classObject;
    JavaClass jlc = runtime.findClass("java/lang/Class");
    // Early in initialization the runtime might not know about classes
    if (jlc == null)
        jlc = loader.findClass("java/lang/Class");
    // If the object isn't in the heap at this address then we can't get refs for the object
    // Here we presume there won't be any extra references, then in PHDJavaRuntime we look for a real object on the heap.
    classObject = new PHDJavaObject.Builder((PHDJavaHeap) (runtime.getHeaps().next()), addr, jlc, flags, hashCode).refsAsArray(new long[0], 0).length(PHDJavaObject.SIMPLE_OBJECT).build();
    return classObject;
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass)

Aggregations

JavaClass (com.ibm.dtfj.java.JavaClass)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)40 JavaObject (com.ibm.dtfj.java.JavaObject)39 Iterator (java.util.Iterator)33 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)23 CorruptData (com.ibm.dtfj.image.CorruptData)11 ArrayList (java.util.ArrayList)10 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 ImagePointer (com.ibm.dtfj.image.ImagePointer)9 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)9 CorruptData (com.ibm.dtfj.image.j9.CorruptData)8 JavaReference (com.ibm.dtfj.java.JavaReference)8 JavaField (com.ibm.dtfj.java.JavaField)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 JavaMethod (com.ibm.dtfj.java.JavaMethod)4 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)4 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)4 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)4 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)4