Search in sources :

Example 46 with JavaObject

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

the class JavaAbstractClass method addClassLoaderReference.

protected void addClassLoaderReference(Collection coll) {
    JavaReference jRef = null;
    try {
        JavaClassLoader classLoader = this.getClassLoader();
        if (null != classLoader) {
            JavaObject classLoaderObject = classLoader.getObject();
            if (null != classLoaderObject) {
                jRef = new JavaReference(_javaVM, this, classLoaderObject, "Classloader", JavaReference.REFERENCE_CLASS_LOADER, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
                coll.add(jRef);
            }
        }
    } catch (CorruptDataException e) {
        coll.add(e.getCorruptData());
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 47 with JavaObject

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

the class JavaThread method getName.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaThread#getName()
	 */
public String getName() throws CorruptDataException {
    JavaObject theObject = getObject();
    if (null != theObject) {
        JavaClass threadClass = _javaLangThreadSuperclass();
        Iterator fields = threadClass.getDeclaredFields();
        while (fields.hasNext()) {
            JavaField oneField = (JavaField) fields.next();
            if (oneField.getName().equals("name")) {
                try {
                    return oneField.getString(theObject);
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to read memory for 'name' field", null));
                }
            }
        }
        throw new CorruptDataException(new CorruptData("unable to find 'name' field", null));
    } else {
        return "vmthread @" + _jniEnv.getAddress();
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 48 with JavaObject

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

the class JavaHeapRegion method getObjectAtAddress.

public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException {
    JavaObject object = null;
    if ((null != address) && (0 != address.getAddress())) {
        // try the special objects cache first...
        JavaObject specialObject = _javaVM.getSpecialObject(address);
        if (null != specialObject) {
            return specialObject;
        }
        // CMVC 173262 - check alignment
        if ((address.getAddress() & (_objectAlignment - 1)) != 0) {
            throw new IllegalArgumentException("Invalid alignment for JavaObject should be " + _objectAlignment + " aligned. Address = " + address.toString());
        }
        long arrayletIdentificationBitmask = 0;
        long arrayletIdentificationResult = 0;
        int arrayletIdentificationWidth = 0;
        int arrayletIdentificationOffset = 0;
        int arrayletSpineSize = 0;
        long arrayletLeafSize = 0;
        arrayletIdentificationBitmask = _parentHeap.getArrayletIdentificationBitmask();
        arrayletIdentificationResult = _parentHeap.getArrayletIdentificationResult();
        arrayletIdentificationWidth = _parentHeap.getArrayletIdentificationWidth();
        arrayletIdentificationOffset = _parentHeap.getArrayletIdentificationOffset();
        arrayletSpineSize = getArrayletSpineSize();
        arrayletLeafSize = getArrayletLeafSize();
        boolean isArraylet = false;
        if (0 != arrayletIdentificationResult) {
            // note that this may be an arraylet so we need to do some extra work here
            long maskedFlags = 0;
            if (4 == arrayletIdentificationWidth) {
                try {
                    maskedFlags = 0xFFFFFFFFL & (long) (address.getIntAt(arrayletIdentificationOffset));
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to access object flags", address));
                }
            } else if (8 == arrayletIdentificationWidth) {
                try {
                    maskedFlags = address.getLongAt(arrayletIdentificationOffset);
                } catch (MemoryAccessException e) {
                    throw new CorruptDataException(new CorruptData("unable to access object flags", address));
                }
            } else {
                // this size cannot be read without exposing endian of the underlying core
                System.err.println("Arraylet identification width is invalid: " + arrayletIdentificationWidth + " (should be 4 or 8)");
            }
            isArraylet = arrayletIdentificationResult == (arrayletIdentificationBitmask & maskedFlags);
        }
        object = new com.ibm.dtfj.java.j9.JavaObject(_javaVM, address, _parentHeap, arrayletSpineSize, arrayletLeafSize, isArraylet, _objectAlignment);
    }
    return object;
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 49 with JavaObject

use of com.ibm.dtfj.java.JavaObject 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 JavaObject

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

the class PHDJavaHeap method getCachedObjectAtAddress.

JavaObject getCachedObjectAtAddress(ImagePointer address, boolean withRefs) throws IOException {
    for (CacheHeapSegment seg : cache.values()) {
        SoftReference<Map<AddressKey, JavaObject>> sr = seg.objects;
        Map<AddressKey, JavaObject> map = sr.get();
        if (map == null || withRefs && !seg.withRefs && map.get(AddressKey.getAddress(PHDJavaHeap.this, address.getAddress())) != null) {
            long addr = address.getAddress();
            if (seg.minAddress <= addr && addr <= seg.maxAddress) {
                // Possibly here, so refresh the data
                int[] next = new int[] { seg.index };
                map = getObjects(seg.maxSize, next, withRefs);
                seg.withRefs = withRefs;
                seg.objects = sr = new SoftReference<Map<AddressKey, JavaObject>>(map);
            }
        }
        if (map != null) {
            JavaObject jo = map.get(AddressKey.getAddress(PHDJavaHeap.this, address.getAddress()));
            if (jo != null) {
                // Found object
                return jo;
            }
        }
    }
    return null;
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) SoftReference(java.lang.ref.SoftReference) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

JavaObject (com.ibm.dtfj.java.JavaObject)70 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)47 Iterator (java.util.Iterator)35 JavaClass (com.ibm.dtfj.java.JavaClass)31 CorruptData (com.ibm.dtfj.image.CorruptData)19 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)17 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)14 JavaReference (com.ibm.dtfj.java.JavaReference)9 JavaThread (com.ibm.dtfj.java.JavaThread)9 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)8 JavaField (com.ibm.dtfj.java.JavaField)7 ImagePointer (com.ibm.dtfj.image.ImagePointer)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)6 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)6 CorruptJavaObject (com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.CorruptJavaObject)6 CorruptData (com.ibm.dtfj.image.j9.CorruptData)5 LongEnumeration (com.ibm.dtfj.phd.util.LongEnumeration)5 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)5 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)5 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)5