Search in sources :

Example 6 with GCClassLoaderIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator in project openj9 by eclipse.

the class RootScanner method scanClassLoaders.

protected void scanClassLoaders() throws CorruptDataException {
    J9ClassLoaderPointer sysClassLoader = _vm.systemClassLoader();
    J9ClassLoaderPointer appClassLoader = J9ClassLoaderPointer.cast(_vm.applicationClassLoader());
    GCClassLoaderIterator classLoaderIterator = GCClassLoaderIterator.from();
    while (classLoaderIterator.hasNext()) {
        J9ClassLoaderPointer loader = classLoaderIterator.next();
        Reachability reachability;
        if (J9BuildFlags.gc_dynamicClassUnloading) {
            long dynamicClassUnloadingFlag = _extensions.dynamicClassUnloading();
            if (MM_GCExtensions$DynamicClassUnloading.DYNAMIC_CLASS_UNLOADING_NEVER == dynamicClassUnloadingFlag) {
                reachability = Reachability.STRONG;
            } else {
                if (loader.eq(sysClassLoader) || loader.eq(appClassLoader)) {
                    reachability = Reachability.STRONG;
                } else {
                    reachability = Reachability.WEAK;
                }
            }
        } else {
            reachability = Reachability.STRONG;
        }
        setReachability(reachability);
        doClassLoader(loader);
    }
}
Also used : J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator)

Example 7 with GCClassLoaderIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator in project openj9 by eclipse.

the class J9JavaVMHelper method getMethodFromPC.

/*
	 * Returns a program space pointer to the matching J9Method for the
	 * specified PC.
	 */
public static J9MethodPointer getMethodFromPC(J9JavaVMPointer vmPtr, U8Pointer pc) throws CorruptDataException {
    GCClassLoaderIterator it = GCClassLoaderIterator.from();
    while (it.hasNext()) {
        J9ClassLoaderPointer loader = it.next();
        Iterator<J9ClassPointer> classIt = ClassIterator.fromJ9Classloader(loader);
        while (classIt.hasNext()) {
            J9ClassPointer clazz = classIt.next();
            J9MethodPointer result = J9ClassHelper.getMethodFromPCAndClass(clazz, pc);
            if (!result.isNull()) {
                return result;
            }
        }
    }
    return J9MethodPointer.NULL;
}
Also used : J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer)

Example 8 with GCClassLoaderIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator in project openj9 by eclipse.

the class WhatIsCommand method runWhatIs.

private void runWhatIs(String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length == 0) {
        badOrMissingSearchValue(out);
        return;
    }
    long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
    UDATA localSearchValue = new UDATA(address);
    if (localSearchValue.eq(0)) {
        badOrMissingSearchValue(out);
        return;
    }
    if (searchValue == null || !searchValue.eq(localSearchValue)) {
        searchValue = localSearchValue;
    } else {
        out.println("Skip count now " + (++skipCount) + ". Run !whatis 0 to reset it.");
    }
    resetFieldData();
    long startTime = System.currentTimeMillis();
    // Walk from the VM
    J9JavaVMPointer vm = null;
    try {
        vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException("Couldn't get VM", e);
    }
    boolean found = walkStructuresFrom(vm);
    // Walk from each VM thread
    if (!found) {
        try {
            J9VMThreadPointer mainThread = vm.mainThread();
            List<J9VMThreadPointer> threads = new LinkedList<J9VMThreadPointer>();
            if (mainThread.notNull()) {
                J9VMThreadPointer threadCursor = vm.mainThread();
                do {
                    threads.add(threadCursor);
                    threadCursor = threadCursor.linkNext();
                } while (!threadCursor.eq(mainThread) && !found);
                /* Walk the thread list backwards so we will find the match next to the closest thread (prevents walkStructures from doing anything useful with the linkNext list) */
                Collections.reverse(threads);
                for (J9VMThreadPointer thisThread : threads) {
                    found = walkStructuresFrom(thisThread);
                    if (found) {
                        break;
                    }
                }
            }
        } catch (CorruptDataException e) {
            out.println("CDE walking thread list.");
            e.printStackTrace(out);
        }
    }
    // Walk from each class
    if (!found) {
        try {
            GCClassLoaderIterator it = GCClassLoaderIterator.from();
            OUTER: while (it.hasNext()) {
                J9ClassLoaderPointer loader = it.next();
                Iterator<J9ClassPointer> classIt = ClassIterator.fromJ9Classloader(loader);
                while (classIt.hasNext()) {
                    J9ClassPointer clazz = classIt.next();
                    found = walkStructuresFrom(clazz);
                    if (found) {
                        break OUTER;
                    }
                }
            }
        } catch (CorruptDataException e) {
            out.println("CDE walking classes.");
            e.printStackTrace(out);
        }
    }
    long stopTime = System.currentTimeMillis();
    if (found) {
        out.println("Match found");
    } else {
        out.println("No match found");
        if (closestAboveStack != null) {
            out.print("Closest above was: ");
            closestAboveStack.dump(out);
            out.print(" at " + closestAbove.getHexValue());
            out.println();
        } else {
            out.println("No values found above search value");
        }
        if (closestBelowStack != null) {
            out.print("Closest below was: ");
            closestBelowStack.dump(out);
            out.print(" at " + closestBelow.getHexValue());
            out.println();
        } else {
            out.println("No values found below search value");
        }
        if (shortestHammingDistanceStack != null) {
            out.print("Value with shortest hamming distance (fewest single-bit changes required) was: ");
            shortestHammingDistanceStack.dump(out);
            out.print(" at " + shortestHammingDistance.getHexValue());
            out.print(". Hamming distance = " + hammingDistance);
            out.println();
        }
        /* Reset search value - so if someone reruns the same (unsuccessful) search again it won't set skipCount to 1 */
        searchValue = null;
    }
    out.println("Searched " + fieldCount + " fields to a depth of " + maxDepth + " in " + (stopTime - startTime) + " ms");
    resetFieldData();
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException) LinkedList(java.util.LinkedList) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9VMThreadPointer(com.ibm.j9ddr.vm29.pointer.generated.J9VMThreadPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) Iterator(java.util.Iterator) ClassIterator(com.ibm.j9ddr.vm29.j9.walkers.ClassIterator) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)

Example 9 with GCClassLoaderIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator in project openj9 by eclipse.

the class DumpAllClassloadersCommand method run.

/**
 * Run method for !dumpallclassloaders extension.
 *
 * @param command  !dumpallclassloaders
 * @param args	!dumpallclassloaders extension accepts no args
 * @param context Context
 * @param out PrintStream
 * @throws DDRInteractiveCommandException
 */
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    if (args.length != 0) {
        printUsage(out);
        return;
    }
    try {
        if (J9BuildFlags.env_data64) {
            out.append("+------------------------------------------------------------------------- \n");
            out.append("|    ClassLoader    | SharedLibraries | ClassHashTable  |   jniIDs Pool   |\n");
            out.append("|                   |      Pool       |                 |                 |\n");
            out.append("|                   |-----------------+-----------------+-----------------| \n");
            out.append("|      Address      | used | capacity | used | capacity | used | capacity |\n");
            out.append("+-------------------+-----------------+-----------------+----------------- \n");
        } else {
            out.append("+----------------------------------------------------------------- \n");
            out.append("|ClassLoader| SharedLibraries | ClassHashTable  |   jniIDs Pool   |\n");
            out.append("|           |      Pool       |                 |                 |\n");
            out.append("|           |-----------------+-----------------+-----------------| \n");
            out.append("| Address   | used | capacity | used | capacity | used | capacity |\n");
            out.append("+-----------+-----------------+-----------------+----------------- \n");
        }
        GCClassLoaderIterator iterator = GCClassLoaderIterator.from();
        J9ClassLoaderPointer classLoaderPointer;
        String classLoaderAddress;
        long sharedLibPoolNumOfelements;
        long sharedLibPoolCapacity;
        long classHashTableNumOfelements;
        long classHashTableCapacity;
        long jniIDsPoolNumOfelements;
        long jniIDsPoolCapacity;
        while (iterator.hasNext()) {
            classLoaderPointer = iterator.next();
            classLoaderAddress = classLoaderPointer.getHexAddress();
            J9PoolPointer sharedLibraries = classLoaderPointer.sharedLibraries();
            if (!sharedLibraries.isNull()) {
                Pool<J9PoolPuddlePointer> pool = Pool.fromJ9Pool(sharedLibraries, J9PoolPuddlePointer.class);
                sharedLibPoolNumOfelements = pool.numElements();
                sharedLibPoolCapacity = pool.capacity();
            } else {
                sharedLibPoolNumOfelements = 0;
                sharedLibPoolCapacity = 0;
            }
            J9HashTablePointer classHashTable = classLoaderPointer.classHashTable();
            if (!classHashTable.isNull()) {
                if (!classHashTable.listNodePool().isNull()) {
                    J9PoolPointer listNodePool = classHashTable.listNodePool();
                    Pool<J9PoolPuddlePointer> pool = Pool.fromJ9Pool(listNodePool, J9PoolPuddlePointer.class);
                    classHashTableNumOfelements = pool.numElements();
                    classHashTableCapacity = pool.capacity();
                } else {
                    classHashTableNumOfelements = classHashTable.numberOfNodes().longValue();
                    classHashTableCapacity = classHashTable.tableSize().longValue();
                }
            } else {
                classHashTableNumOfelements = 0;
                classHashTableCapacity = 0;
            }
            J9PoolPointer jniIDs = classLoaderPointer.jniIDs();
            if (!jniIDs.isNull()) {
                Pool<J9PoolPuddlePointer> pool = Pool.fromJ9Pool(jniIDs, J9PoolPuddlePointer.class);
                jniIDsPoolNumOfelements = pool.numElements();
                jniIDsPoolCapacity = pool.capacity();
            } else {
                jniIDsPoolNumOfelements = 0;
                jniIDsPoolCapacity = 0;
            }
            String output = format(classLoaderAddress, sharedLibPoolNumOfelements, sharedLibPoolCapacity, classHashTableNumOfelements, classHashTableCapacity, jniIDsPoolNumOfelements, jniIDsPoolCapacity);
            out.println(output);
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : J9PoolPointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) CorruptDataException(com.ibm.j9ddr.CorruptDataException) J9HashTablePointer(com.ibm.j9ddr.vm29.pointer.generated.J9HashTablePointer) J9PoolPuddlePointer(com.ibm.j9ddr.vm29.pointer.generated.J9PoolPuddlePointer)

Example 10 with GCClassLoaderIterator

use of com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator in project openj9 by eclipse.

the class VmCheckCommand method checkJ9ROMClassSanity.

/*
	 *  Based on vmchk/checkromclasses.c r1.5
	 * 
	 *	J9ROMClass sanity:
	 *		SRP check:
	 *			Ensure J9ROMClass->interfaces SRP is in the same segment if J9ROMClass->interfaceCount != 0.
	 *			Ensure J9ROMClass->romMethods SRP is in the same segment if J9ROMClass->romMethodCount != 0.
	 *			Ensure J9ROMClass->romFields SRP is in the same segment if J9ROMClass->romFieldCount != 0.
	 *			Ensure J9ROMClass->innerClasses SRP is in the same segment if J9ROMClass->innerClasseCount != 0.
	 *			Ensure cpShapeDescription in the same segment.
	 *			Ensure all SRPs are in range on 64 bit platforms (including className, superclassName, and outerClassName).
	 *
	 *		ConstantPool count check:
	 *			Ensure ramConstantPoolCount <= romConstantPoolCount
	 */
private void checkJ9ROMClassSanity(J9JavaVMPointer vm, PrintStream out) throws CorruptDataException {
    reportMessage(out, "Checking ROM classes");
    // Stolen from RootScaner.scanClasses()
    // GCClassLoaderIterator gcClassLoaderIterator =
    // GCClassLoaderIterator.from();
    GCSegmentIterator segmentIterator = GCSegmentIterator.fromJ9MemorySegmentList(vm.classMemorySegments(), J9MemorySegment.MEMORY_TYPE_RAM_CLASS);
    int count = 0;
    while (segmentIterator.hasNext()) {
        J9MemorySegmentPointer segment = segmentIterator.next();
        GCClassHeapIterator classHeapIterator = GCClassHeapIterator.fromJ9MemorySegment(segment);
        while (classHeapIterator.hasNext()) {
            J9ClassPointer clazz = classHeapIterator.next();
            verifyJ9ROMClass(out, vm, clazz);
            count++;
        }
    }
    reportMessage(out, "Checking %d ROM classes done", count);
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9MemorySegmentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer) GCClassHeapIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassHeapIterator) GCSegmentIterator(com.ibm.j9ddr.vm29.j9.gc.GCSegmentIterator)

Aggregations

GCClassLoaderIterator (com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator)8 J9ClassLoaderPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer)8 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)7 J9MemorySegmentPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer)4 CorruptDataException (com.ibm.j9ddr.CorruptDataException)3 GCClassHeapIterator (com.ibm.j9ddr.vm29.j9.gc.GCClassHeapIterator)3 GCSegmentIterator (com.ibm.j9ddr.vm29.j9.gc.GCSegmentIterator)3 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)2 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)2 J9MethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)2 UDATA (com.ibm.j9ddr.vm29.types.UDATA)2 CorruptData (com.ibm.dtfj.image.CorruptData)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)1 ClassIterator (com.ibm.j9ddr.vm29.j9.walkers.ClassIterator)1 ClassSegmentIterator (com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator)1 J9HashTablePointer (com.ibm.j9ddr.vm29.pointer.generated.J9HashTablePointer)1 J9ObjectPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer)1 J9PoolPointer (com.ibm.j9ddr.vm29.pointer.generated.J9PoolPointer)1 J9PoolPuddlePointer (com.ibm.j9ddr.vm29.pointer.generated.J9PoolPuddlePointer)1