Search in sources :

Example 36 with JavaClass

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

the class JavaClassComparator method testEquals.

// getClassLoader()
// getComponentType()
// getConstantPoolReferences()
// getDeclaredFields()
// getDeclaredMethods()
// getID()
// getInterfaces()
// getModifiers()
// getName()
// getObject()
// getReferences()
// getSuperclass()
// isArray()
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    JavaClass ddrJavaClass = (JavaClass) ddrObject;
    JavaClass jextractJavaClass = (JavaClass) jextractObject;
    JavaObjectComparator javaObjectComparator = new JavaObjectComparator();
    // getClassLoader()
    if ((CLASS_LOADER & members) != 0)
        new JavaClassLoaderComparator().testComparatorEquals(ddrJavaClass, jextractJavaClass, "getClassLoader");
    // isArray()
    if ((IS_ARRAY & members) != 0)
        testJavaEquals(ddrJavaClass, jextractJavaClass, "isArray");
    // getComponentType()
    if ((COMPONENT_TYPE & members) != 0) {
        try {
            if (ddrJavaClass.isArray()) {
                new JavaClassComparator().testComparatorEquals(ddrJavaClass, jextractJavaClass, "getComponentType");
            }
        } catch (CorruptDataException e) {
            fail("Problem comparing JavaClass");
        }
    }
    // getConstantPoolReferences()
    if ((CONSTANT_POOL_REFERENCES & members) != 0)
        javaObjectComparator.testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getConstantPoolReferences", JavaObject.class);
    // getDeclaredFields
    if ((DECLARED_FIELDS & members) != 0)
        new JavaFieldComparator().testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getDeclaredFields", JavaField.class);
    // getDeclaredMethods
    if ((DECLARED_METHODS & members) != 0)
        new JavaMethodComparator().testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getDeclaredMethods", JavaMethod.class);
    // getID()
    if ((ID & members) != 0)
        new ImagePointerComparator().testComparatorEquals(ddrJavaClass, jextractJavaClass, "getID");
    // getInterfaces()
    if ((INTERFACES & members) != 0)
        testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getInterfaces", String.class);
    // getModifiers()
    if ((MODIFIERS & members) != 0)
        testJavaEquals(ddrJavaClass, jextractJavaClass, "getModifiers");
    // getName()
    if ((NAME & members) != 0) {
        testJavaEquals(ddrJavaClass, jextractJavaClass, "getName");
    }
    // getObject()
    if ((OBJECT & members) != 0)
        javaObjectComparator.testJavaEquals(ddrJavaClass, jextractJavaClass, "getObject");
    // getReferneces()
    if ((REFERENCES & members) != 0)
        new JavaReferenceComparator().testComparatorIteratorEquals(ddrJavaClass, jextractJavaClass, "getReferneces", JavaReference.class);
    // getSuperclass()
    if ((SUPERCLASS & members) != 0)
        testComparatorEquals(ddrJavaClass, jextractJavaClass, "getSuperclass");
}
Also used : CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaReference(com.ibm.dtfj.java.JavaReference) JavaField(com.ibm.dtfj.java.JavaField) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) JavaMethod(com.ibm.dtfj.java.JavaMethod)

Example 37 with JavaClass

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

the class JavaClassLoaderTest method findClassTest.

@SuppressWarnings("unchecked")
@Test
public void findClassTest() throws Exception {
    JavaClassComparator comparator = new JavaClassComparator();
    assertEquals(jextractTestObjects.size(), ddrTestObjects.size());
    for (int i = 0; i < ddrTestObjects.size(); i++) {
        JavaClassLoader ddrLoader = (JavaClassLoader) ddrTestObjects.get(i);
        JavaClassLoader jextractLoader = (JavaClassLoader) jextractTestObjects.get(i);
        Iterator ddrClasses = ddrLoader.getDefinedClasses();
        // loop the defined classes trying to find each one
        Iterator jextractClasses = jextractLoader.getDefinedClasses();
        while (ddrClasses.hasNext() || jextractClasses.hasNext()) {
            assertTrue("DDR classloader has less items than the jextract equivalent : " + ddrLoader.toString(), ddrClasses.hasNext());
            assertTrue("Jextract classloader has less items than the jextract equivalent : " + jextractLoader.toString(), jextractClasses.hasNext());
            JavaClass ddrClass = (JavaClass) ddrClasses.next();
            JavaClass jextractClass = (JavaClass) jextractClasses.next();
            assertEquals("Different class names : ddr = " + ddrClass.getName() + " jx = " + jextractClass.getName(), jextractClass.getName(), ddrClass.getName());
            String name = ddrClass.getName();
            JavaClass ddrFound = ddrLoader.findClass(name);
            assertNotNull("DDR loader could not find class : " + name, ddrFound);
            JavaClass jextractFound = jextractLoader.findClass(name);
            assertNotNull("JX loader could not find class : " + name, jextractFound);
            comparator.testEquals(ddrFound, jextractFound, javaClassComparator.getDefaultMask());
        }
    }
}
Also used : JavaClassComparator(com.ibm.j9ddr.view.dtfj.comparators.JavaClassComparator) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 38 with JavaClass

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

the class JavaClassTest method anyClassIsArray.

@Test
public void anyClassIsArray() {
    boolean foundArray = false;
    for (int i = 0; i < ddrTestObjects.size(); i++) {
        JavaClass ddrClass = (JavaClass) ddrTestObjects.get(i);
        try {
            if (ddrClass.isArray()) {
                foundArray = true;
                break;
            }
        } catch (CorruptDataException e) {
        // Do nothing ... not testing this aspect
        }
    }
    assertTrue("No class under test was an array", foundArray);
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Test(org.junit.Test)

Example 39 with JavaClass

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

the class JavaClassTest method getComponentTypeTest.

@Test
public void getComponentTypeTest() {
    for (int i = 0; i < ddrTestObjects.size(); i++) {
        JavaClass ddrClass = (JavaClass) ddrTestObjects.get(i);
        JavaClass jextractClass = (JavaClass) jextractTestObjects.get(i);
        boolean isArray = false;
        try {
            assertEquals(jextractClass.isArray(), ddrClass.isArray());
            isArray = ddrClass.isArray();
        } catch (CorruptDataException e1) {
            fail("Problem with test setup");
        }
        if (isArray) {
            javaClassComparator.testComparatorEquals(ddrClass, jextractClass, "getComponentType");
        } else {
            JavaClass result = null;
            try {
                result = ddrClass.getComponentType();
            } catch (IllegalArgumentException e) {
            // Expected exception
            } catch (CorruptDataException e) {
                fail("getcComponentType threw unexpected CorruptDataException");
            }
            try {
                assertNull(String.format("%s is not an array and should have thrown an IllegalArgumentException", ddrClass.getName()), result);
            } catch (CorruptDataException e) {
                fail("getcComponentType threw unexpected CorruptDataException");
            }
        }
    }
}
Also used : JavaClass(com.ibm.dtfj.java.JavaClass) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Test(org.junit.Test)

Example 40 with JavaClass

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

the class JavaRuntimeTest method getHeapRootsTest.

@SuppressWarnings("unchecked")
@Test
public void getHeapRootsTest() {
    boolean result = true;
    String version = ((J9DDRImageProcess) ddrProcess).getVersion();
    IteratorFilter ddrFilter = null;
    if (version.equals("26")) {
        ddrFilter = new IteratorFilter() {

            // vm26 has a StringTable Cache that the root scanner scans but jextract(HeapIteratorAPI) does not
            public boolean accept(Object obj) {
                JavaReference ref = (JavaReference) obj;
                if (ref.getDescription().equals("StringCacheTable")) {
                    return false;
                }
                return true;
            }
        };
    }
    if (version.equals("23")) {
        ddrFilter = new IteratorFilter() {

            boolean foundFirstContrivedThread = false;

            public boolean accept(Object obj) {
                try {
                    JavaReference ref = (JavaReference) obj;
                    Object ddrHeapRoot = ref.getTarget();
                    if (ref.getRootType() == JavaReference.HEAP_ROOT_THREAD) {
                        if (ddrHeapRoot instanceof JavaObject) {
                            JavaObject javaObject = (JavaObject) ddrHeapRoot;
                            String name = javaObject.getJavaClass().getName();
                            if (name.endsWith("Error") || name.endsWith("Exception") || name.equals("com/ibm/dtfj/tck/tests/javaruntime/TestJavaMonitor_ObjectMonitors$MonitorClass") || name.equals("com/ibm/dtfj/tck/harness/Configure$DumpThread")) {
                                // Ignore these since JExtract can't find them.
                                return false;
                            }
                            if (name.equals("com/ibm/dtfj/tck/tests/javaruntime/TestJavaThread_getStackFrames$ContrivedThread")) {
                                if (foundFirstContrivedThread) {
                                    return false;
                                } else {
                                    foundFirstContrivedThread = true;
                                }
                            }
                        }
                    }
                    return true;
                } catch (DataUnavailable e) {
                    fail("bail");
                    return false;
                } catch (CorruptDataException e) {
                    fail("bail");
                    return false;
                }
            }
        };
    }
    for (int i = 0; i < ddrTestObjects.size(); i++) {
        JavaRuntime localDDRRuntime = (JavaRuntime) ddrTestObjects.get(i);
        JavaRuntime localJextractRuntime = (JavaRuntime) jextractTestObjects.get(i);
        Object[] ddrHeapRootsArray = null;
        Object[] jextractHeapRootsArray = null;
        int threadCount = 0;
        Iterator titer = localDDRRuntime.getThreads();
        while (titer.hasNext()) {
            threadCount++;
            titer.next();
        }
        System.out.println("Thread count: " + threadCount);
        try {
            ddrHeapRootsArray = DTFJComparator.getList(Object.class, localDDRRuntime.getHeapRoots(), ddrFilter).toArray();
            jextractHeapRootsArray = DTFJComparator.getList(Object.class, localJextractRuntime.getHeapRoots(), null).toArray();
        } catch (InvalidObjectException e1) {
            fail("Test setup failure");
        }
        Map<Long, List<Object>> map = new HashMap<Long, List<Object>>();
        for (int j = 0; j < ddrHeapRootsArray.length; j++) {
            long key = 0;
            JavaReference ref = (JavaReference) ddrHeapRootsArray[j];
            Object ddrHeapRoot = null;
            try {
                ddrHeapRoot = ref.getTarget();
            } catch (DataUnavailable e) {
                fail("bail");
            } catch (CorruptDataException e) {
                fail("bail");
            }
            if (ddrHeapRoot instanceof JavaObject) {
                key = ((JavaObject) ddrHeapRoot).getID().getAddress();
            } else if (ddrHeapRoot instanceof JavaClass) {
                key = ((JavaClass) ddrHeapRoot).getID().getAddress();
            } else {
                fail("bail");
            }
            List bucket = map.get(key);
            if (bucket == null) {
                bucket = new ArrayList<Object>();
                map.put(key, bucket);
            }
            bucket.add(ddrHeapRoot);
        }
        for (int j = 0; j < jextractHeapRootsArray.length; j++) {
            JavaReference ref = (JavaReference) jextractHeapRootsArray[j];
            Object heapRoot = null;
            String name = null;
            long key = 0;
            try {
                heapRoot = ref.getTarget();
                if (heapRoot instanceof JavaObject) {
                    key = ((JavaObject) heapRoot).getID().getAddress();
                    name = "Instance of " + ((JavaObject) heapRoot).getJavaClass().getName();
                } else if (heapRoot instanceof JavaClass) {
                    key = ((JavaClass) heapRoot).getID().getAddress();
                    name = ((JavaClass) heapRoot).getName();
                } else {
                    fail("bail");
                }
            } catch (DataUnavailable e) {
                fail("bail");
            } catch (CorruptDataException e) {
                fail("bail");
            }
            List bucket = map.get(key);
            if (bucket == null) {
                System.out.println(String.format("Jextract found %s at address: %s.  Element #: %s that ddr does not know about", name, Long.toHexString(key), j));
                result = false;
                continue;
            }
            if (bucket.isEmpty()) {
                fail("bail");
            }
            bucket.remove(0);
            if (bucket.isEmpty()) {
                map.remove(key);
            }
        }
        // Whats left.
        int count = 0;
        Collection<List<Object>> remains = map.values();
        if (remains.size() > 0) {
            System.out.println("");
            System.out.println("DDR found the following that JExtract did not know about");
        }
        Iterator<List<Object>> bucketIter = remains.iterator();
        while (bucketIter.hasNext()) {
            List<Object> bucket = bucketIter.next();
            Iterator<Object> contentsIter = bucket.iterator();
            while (contentsIter.hasNext()) {
                Object obj = contentsIter.next();
                System.out.println(String.format("%s) %s", ++count, obj));
            }
        }
    }
    assertTrue(result);
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) J9DDRImageProcess(com.ibm.j9ddr.view.dtfj.image.J9DDRImageProcess) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaReference(com.ibm.dtfj.java.JavaReference) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ArrayList(java.util.ArrayList) List(java.util.List) IteratorFilter(com.ibm.j9ddr.util.IteratorHelpers.IteratorFilter) JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) Test(org.junit.Test)

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