Search in sources :

Example 26 with JavaClass

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

the class JavaFieldTest method loadTestObjects.

protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
    List<Object> ddrClassLoaders = new ArrayList<Object>();
    List<Object> jextractClassLoaders = new ArrayList<Object>();
    fillLists(ddrClassLoaders, ddrRuntime.getJavaClassLoaders(), jextractClassLoaders, jextractRuntime.getJavaClassLoaders(), null);
    List<Object> ddrClasses = new ArrayList<Object>();
    List<Object> jextractClasses = new ArrayList<Object>();
    for (int i = 0; i < ddrClassLoaders.size(); i++) {
        JavaClassLoader ddrClassLoader = (JavaClassLoader) ddrClassLoaders.get(i);
        JavaClassLoader jextractClassLoader = (JavaClassLoader) jextractClassLoaders.get(i);
        fillLists(ddrClasses, ddrClassLoader.getDefinedClasses(), jextractClasses, jextractClassLoader.getDefinedClasses(), null);
    }
    for (int i = 0; i < ddrClasses.size(); i++) {
        JavaClass ddrClass = (JavaClass) ddrClasses.get(i);
        JavaClass jextractClass = (JavaClass) jextractClasses.get(i);
        fillLists(ddrObjects, ddrClass.getDeclaredFields(), jextractObjects, jextractClass.getDeclaredFields(), JavaClassTest.DECLARED_FIELDS_SORT_ORDER);
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) ArrayList(java.util.ArrayList)

Example 27 with JavaClass

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

the class JavaReferenceTest method loadTestObjects.

protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
    List<Object> ddrClassLoaders = new ArrayList<Object>();
    List<Object> jextractClassLoaders = new ArrayList<Object>();
    fillLists(ddrClassLoaders, ddrRuntime.getJavaClassLoaders(), jextractClassLoaders, jextractRuntime.getJavaClassLoaders(), null);
    List<Object> ddrClasses = new ArrayList<Object>();
    List<Object> jextractClasses = new ArrayList<Object>();
    for (int i = 0; i < ddrClassLoaders.size(); i++) {
        JavaClassLoader ddrClassLoader = (JavaClassLoader) ddrClassLoaders.get(i);
        JavaClassLoader jextractClassLoader = (JavaClassLoader) jextractClassLoaders.get(i);
        fillLists(ddrClasses, ddrClassLoader.getDefinedClasses(), jextractClasses, jextractClassLoader.getDefinedClasses(), null);
    }
    for (int i = 0; i < ddrClasses.size(); i++) {
        JavaClass ddrClass = (JavaClass) ddrClasses.get(i);
        JavaClass jextractClass = (JavaClass) jextractClasses.get(i);
        fillLists(ddrObjects, ddrClass.getReferences(), jextractObjects, jextractClass.getReferences(), JavaClassTest.REFERENCES_SORT_ORDER);
    }
}
Also used : JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) ArrayList(java.util.ArrayList)

Example 28 with JavaClass

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

the class JavaObject method getArraySize.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaObject#getArraySize()
	 */
public int getArraySize() throws CorruptDataException {
    JavaClass isa = getJavaClass();
    if (isa instanceof JavaArrayClass) {
        JavaArrayClass blueprint = (JavaArrayClass) isa;
        int offset = blueprint.getSizeOffset();
        int numberOfSizeBytes = blueprint.getNumberOfSizeBytes();
        try {
            int numberOfElements = 0;
            if (4 == numberOfSizeBytes) {
                // read an int
                numberOfElements = _basePointer.getIntAt(offset);
            } else if (8 == numberOfSizeBytes) {
                // read a long
                long longCount = _basePointer.getLongAt(offset);
                // the spec says to return an int here so we just truncate, for now
                numberOfElements = (int) longCount;
                if (((long) numberOfElements) != longCount) {
                    System.err.println("Error:  Array element count overflow or underflow.");
                }
            } else {
                // not sure what this is (this could be done generically but that would require exposing endian-conversion differently.  Besides, stopping this at a strange number is probably a good idea since it is more likely an error)
                System.err.println("Error:  unable to read array size as we weren't expecting to read " + numberOfSizeBytes + " bytes.");
            }
            return numberOfElements;
        } catch (MemoryAccessException e) {
            throw new CorruptDataException(new CorruptData("unable to read the number of elements", _basePointer.add(offset)));
        }
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 29 with JavaClass

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

the class JavaObject method getJavaClass.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaObject#getJavaClass()
	 */
public JavaClass getJavaClass() throws CorruptDataException {
    if (0 != _basePointer.getAddress()) {
        ImagePointer classPointer;
        if (_containingHeap == null)
            throw new CorruptDataException(new CorruptData("unable to access class pointer as containing heap is null", _basePointer));
        try {
            classPointer = _containingHeap.readClassPointerRelativeTo(_basePointer);
        } catch (MemoryAccessException e) {
            throw new CorruptDataException(new CorruptData("unable to access class pointer", _basePointer));
        }
        long classID = classPointer.getAddress();
        /* CMVC 167379: Lowest few bits of the class id are used as flags, and should be 
			 * masked with ~(J9_REQUIRED_CLASS_ALIGNMENT - 1) to find real class id. 
			 */
        long classAlignment = _containingHeap.getClassAlignment();
        long alignedClassID = classID;
        if (classAlignment > 0) {
            alignedClassID &= (~(classAlignment - 1L));
        }
        JavaClass ret = _javaVM.getClassForID(alignedClassID);
        if (ret == null) {
            throw new CorruptDataException(new CorruptData("Unknown class ID " + Long.toHexString(alignedClassID) + " for object " + Long.toHexString(_basePointer.getAddress()) + " (read class ID from " + Long.toHexString(classPointer.getAddress()) + ", in memory value was " + Long.toHexString(classID) + ")", _basePointer));
        }
        return ret;
    } else {
        throw new NullPointerException();
    }
}
Also used : ImagePointer(com.ibm.dtfj.image.ImagePointer) JavaClass(com.ibm.dtfj.java.JavaClass) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) MemoryAccessException(com.ibm.dtfj.image.MemoryAccessException)

Example 30 with JavaClass

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

the class JavaArrayClass method getName.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.java.JavaClass#getName()
	 */
public String getName() throws CorruptDataException {
    String name = "";
    // Note that validation in JavaObject.arraycopy is dependent on type name constructed here
    for (int x = 0; x < _dimension; x++) {
        name += JavaObject.ARRAY_PREFIX_SIGNATURE;
    }
    JavaClass leafClass = getLeafClass();
    if (null == leafClass) {
        CorruptData data = new CorruptData("unable to retrieve leaf class", null);
        throw new CorruptDataException(data);
    }
    String elementClassName = leafClass.getName();
    if (elementClassName.equals("boolean")) {
        name += JavaObject.BOOLEAN_SIGNATURE;
    } else if (elementClassName.equals("byte")) {
        name += JavaObject.BYTE_SIGNATURE;
    } else if (elementClassName.equals("char")) {
        name += JavaObject.CHAR_SIGNATURE;
    } else if (elementClassName.equals("short")) {
        name += JavaObject.SHORT_SIGNATURE;
    } else if (elementClassName.equals("int")) {
        name += JavaObject.INTEGER_SIGNATURE;
    } else if (elementClassName.equals("long")) {
        name += JavaObject.LONG_SIGNATURE;
    } else if (elementClassName.equals("float")) {
        name += JavaObject.FLOAT_SIGNATURE;
    } else if (elementClassName.equals("double")) {
        name += JavaObject.DOUBLE_SIGNATURE;
    } else {
        // reference type
        name += JavaObject.OBJECT_PREFIX_SIGNATURE;
        name += elementClassName;
        name += ';';
    }
    return name;
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) CorruptData(com.ibm.dtfj.image.j9.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

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