Search in sources :

Example 1 with GCClassLoaderIterator

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

the class ClassloadersSummaryCommand method getStat.

public Collection<ClassloadersSummaryNode> getStat() throws CorruptDataException {
    Map<J9ClassLoaderPointer, Counter> classloadersCount = new HashMap<J9ClassLoaderPointer, Counter>();
    J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
    GCClassLoaderIterator iterator = GCClassLoaderIterator.from();
    while (iterator.hasNext()) {
        J9ClassLoaderPointer classLoader = iterator.next();
        classloadersCount.put(classLoader, new Counter(0));
    }
    /* Iterate through all classes and count how many were loaded by each classLoader */
    ClassSegmentIterator classSegmentIterator = new ClassSegmentIterator(vm.classMemorySegments());
    while (classSegmentIterator.hasNext()) {
        J9ClassPointer classPointer = (J9ClassPointer) classSegmentIterator.next();
        Counter counter = classloadersCount.get(classPointer.classLoader());
        if (counter != null) {
            counter.addOne();
        } else {
            classloadersCount.put(classPointer.classLoader(), new Counter(1));
        }
    }
    J9ObjectPointer sys = vm.systemClassLoader().classLoaderObject();
    final UDATA valueROM = new UDATA(J9MemorySegment.MEMORY_TYPE_ROM_CLASS);
    final UDATA valueRAM = new UDATA(J9MemorySegment.MEMORY_TYPE_RAM_CLASS);
    Map<String, ClassloadersSummaryNode> classloaders = new LinkedHashMap<String, ClassloadersSummaryNode>();
    for (Map.Entry<J9ClassLoaderPointer, Counter> entry : classloadersCount.entrySet()) {
        J9ObjectPointer classLoaderObject = entry.getKey().classLoaderObject();
        boolean isSystem = classLoaderObject.equals(sys);
        String loader = isSystem ? "*System*" : J9ObjectHelper.getClassName(classLoaderObject);
        /*	For each classloader, iterate through each associated memory segment and identify whether it is  
			 * 	a ROM or a RAM type memory segment  */
        long romSegmentCount = 0;
        long ramSegmentCount = 0;
        long romSegmentAllocatedMem = 0;
        long ramSegmentAllocatedMem = 0;
        J9MemorySegmentPointer segment = entry.getKey().classSegments();
        while (segment.notNull()) {
            if ((segment.type().bitAnd(valueROM)).equals(valueROM)) {
                romSegmentCount += 1;
                romSegmentAllocatedMem += segment.size().longValue();
            } else if ((segment.type().bitAnd(valueRAM)).equals(valueRAM)) {
                ramSegmentCount += 1;
                ramSegmentAllocatedMem += segment.size().longValue();
            }
            segment = segment.nextSegmentInClassLoader();
        }
        ClassloadersSummaryNode cpentry = classloaders.get(loader);
        if (cpentry == null) {
            // If the classLoader is not in the list, add it with "# Classloaders = 1" and "# Loaded Classes = classesLoaded"
            classloaders.put(loader, new ClassloadersSummaryNode(loader, 1L, entry.getValue().getCount(), ramSegmentCount, romSegmentCount, romSegmentAllocatedMem, ramSegmentAllocatedMem));
        } else {
            // If the classLoader is in the list, increment "# Classloaders" by 1 and increment "# Loaded Classes" by classesLoaded
            cpentry.numClassloaders += 1;
            cpentry.numLoadedClasses += entry.getValue().getCount();
            cpentry.ramSegmentCounter += ramSegmentCount;
            cpentry.romSegmentCounter += romSegmentCount;
            cpentry.totalROMSegmentAllocatedMemory += romSegmentAllocatedMem;
            cpentry.totalRAMSegmentAllocatedMemory += ramSegmentAllocatedMem;
        }
    }
    return classloaders.values();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer) LinkedHashMap(java.util.LinkedHashMap) ClassSegmentIterator(com.ibm.j9ddr.vm29.j9.walkers.ClassSegmentIterator) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9JavaVMPointer(com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer) J9MemorySegmentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with GCClassLoaderIterator

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

the class MethodForNameCommand method dbgGetMethodsForName.

int dbgGetMethodsForName(PrintStream out, String pattern) throws CorruptDataException {
    int matchCount = 0;
    // J9ClassWalkState walkState;
    String classNeedle, methodNeedle, sigNeedle;
    long classMatchFlags, methodMatchFlags, sigMatchFlags;
    String classStart, nameStart, sigStart;
    if (pattern.indexOf('.') != -1) {
        // skip the .
        nameStart = pattern.substring(pattern.indexOf('.') + 1);
        classStart = pattern.substring(0, pattern.indexOf('.'));
    } else {
        classStart = "*";
        nameStart = pattern;
    }
    if (pattern.indexOf('(') != -1) {
        sigStart = pattern.substring(pattern.indexOf('('));
    } else {
        sigStart = "*";
    }
    StringBuffer needleBuffer = new StringBuffer();
    classMatchFlags = WildCard.parseWildcard(classStart, needleBuffer);
    classNeedle = needleBuffer.toString();
    if (classMatchFlags == -1) {
        CommandUtils.dbgError(out, "Invalid wildcards in class name\n");
        return 0;
    }
    needleBuffer = new StringBuffer();
    methodMatchFlags = WildCard.parseWildcard(nameStart, needleBuffer);
    methodNeedle = needleBuffer.toString();
    if (methodMatchFlags == -1) {
        CommandUtils.dbgError(out, "Invalid wildcards in method name\n");
        return 0;
    }
    needleBuffer = new StringBuffer();
    sigMatchFlags = WildCard.parseWildcard(sigStart, needleBuffer);
    sigNeedle = needleBuffer.toString();
    if (methodMatchFlags == -1) {
        CommandUtils.dbgError(out, "Invalid wildcards in method name\n");
        return 0;
    }
    Hashtable<String, J9ClassPointer> loadedClasses = new Hashtable<String, J9ClassPointer>();
    GCClassLoaderIterator classLoaderIterator = GCClassLoaderIterator.from();
    while (classLoaderIterator.hasNext()) {
        J9ClassLoaderPointer loader = classLoaderIterator.next();
        Iterator<J9ClassPointer> classItterator = ClassIterator.fromJ9Classloader(loader);
        while (classItterator.hasNext()) {
            J9ClassPointer clazz = classItterator.next();
            J9ROMClassPointer romClazz = clazz.romClass();
            String className = J9UTF8Helper.stringValue(romClazz.className());
            if (loadedClasses.containsValue(clazz)) {
                continue;
            } else {
                loadedClasses.put(clazz.toString(), clazz);
            }
            if (WildCard.wildcardMatch(classMatchFlags, classNeedle, className)) {
                J9MethodPointer methodCursor = clazz.ramMethods();
                for (long count = romClazz.romMethodCount().longValue(); count > 0; count--, methodCursor = methodCursor.add(1)) {
                    J9ROMMethodPointer romMethod = J9MethodHelper.romMethod(methodCursor);
                    J9ROMNameAndSignaturePointer nameAndSignature = romMethod.nameAndSignature();
                    String nameUTF = J9UTF8Helper.stringValue(nameAndSignature.name());
                    if (WildCard.wildcardMatch(methodMatchFlags, methodNeedle, nameUTF)) {
                        String sigUTF = J9UTF8Helper.stringValue(nameAndSignature.signature());
                        if (WildCard.wildcardMatch(sigMatchFlags, sigNeedle, sigUTF)) {
                            matchCount++;
                            CommandUtils.dbgPrint(out, String.format("!j9method %s --> %s.%s%s\n", methodCursor.getHexAddress(), className, nameUTF, sigUTF));
                        }
                    }
                }
            }
        }
    }
    return matchCount;
}
Also used : Hashtable(java.util.Hashtable) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) J9MethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MethodPointer)

Example 3 with GCClassLoaderIterator

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

the class VmCheckCommand method checkJ9ClassSanity.

/*
	 *  Based on vmchk/checkclasses.c r1.7
	 *
	 *	J9Class sanity:
	 *		Eyecatcher check:
	 *			Ensure J9Class->eyecatcher == 0x99669966.
	 *
	 *		Superclasses check:
	 *			Ensure J9Class->superclasses != null unless J9Class is Object.
	 *
	 *		ClassObject null check:
	 *			Ensure J9Class->classObject != null if (J9Class->initializeStatus == J9ClassInitSucceeded)
	 *
	 *		ClassLoader segment check:
	 *			Ensure J9Class->classLoader->classSegments contains J9Class.
	 *
	 *		ConstantPool check:
	 *			Ensure J9Class->ramConstantPool->ramClass is equal to the J9Class.
	 *
	 *		Subclass hierarchy check:
	 *			Ensure subclasses can be traversed per the J9Class classDepth.
	 *
	 *		Obsolete class check:
	 *			Ensure obsolete classes are found in the replacedClass linked list on the currentClass.
	 */
private void checkJ9ClassSanity(J9JavaVMPointer javaVM, PrintStream out) throws CorruptDataException {
    reportMessage(out, "Checking classes");
    // Stolen from RootScaner.scanClasses()
    // GCClassLoaderIterator gcClassLoaderIterator =
    // GCClassLoaderIterator.from();
    GCSegmentIterator segmentIterator = GCSegmentIterator.fromJ9MemorySegmentList(javaVM.classMemorySegments(), J9MemorySegment.MEMORY_TYPE_RAM_CLASS);
    int count = 0;
    int obsoleteCount = 0;
    while (segmentIterator.hasNext()) {
        J9MemorySegmentPointer segment = segmentIterator.next();
        GCClassHeapIterator classHeapIterator = GCClassHeapIterator.fromJ9MemorySegment(segment);
        while (classHeapIterator.hasNext()) {
            J9ClassPointer clazz = classHeapIterator.next();
            if (!J9ClassHelper.isObsolete(clazz)) {
                verifyJ9Class(javaVM, out, clazz);
            } else {
                verifyObsoleteJ9Class(javaVM, out, clazz);
                obsoleteCount++;
            }
            count++;
        }
    }
    reportMessage(out, "Checking %d classes (%d obsolete) done", count, obsoleteCount);
}
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)

Example 4 with GCClassLoaderIterator

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

the class VmCheckCommand method checkJ9MethodSanity.

/*
	 *  Based on vmchk/checkmethods.c r1.5
	 * 
	 *	J9Method sanity:
	 *		Bytecode check:
	 *			Ensure (bytecodes - sizeof(J9ROMMethod) is in the right "area" to be a ROM Method.
	 *			Use ROMClass to determine where ROM methods for that class begin.
	 *		Constant pool check:
	 *			Ensure method's constant pool is the same as that of its J9Class.
	 *			Useful to validate that HCR doesn't violate this invariant.
	 *		VTable check:
	 *			If method of a non-interface class has modifier J9AccMethodVTable,
	 *			ensure it exists in the VTable of its J9Class.
	 *			Useful to validate that HCR doesn't violate this invariant.
	 */
private void checkJ9MethodSanity(J9JavaVMPointer vm, PrintStream out) throws CorruptDataException {
    reportMessage(out, "Checking methods");
    // 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();
            if (!J9ClassHelper.isObsolete(clazz)) {
                count += verifyClassMethods(vm, out, clazz);
            }
        }
    }
    reportMessage(out, "Checking %d methods 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)

Example 5 with GCClassLoaderIterator

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

the class DTFJJavaRuntime method getJavaClassLoaders.

@SuppressWarnings("rawtypes")
public Iterator getJavaClassLoaders() {
    if (classLoaders != null) {
        // return cached set of class loaders
        return classLoaders.iterator();
    }
    classLoaders = new LinkedList<Object>();
    GCClassLoaderIterator classLoaderIterator;
    try {
        classLoaderIterator = GCClassLoaderIterator.from();
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        classLoaders.add(cd);
        return classLoaders.iterator();
    }
    AddCorruptionToListListener corruptionListener = new AddCorruptionToListListener(classLoaders);
    register(corruptionListener);
    try {
        while (!corruptionListener.fatalCorruption() && classLoaderIterator.hasNext()) {
            J9ClassLoaderPointer next = classLoaderIterator.next();
            if (next != null) {
                classLoaders.add(new DTFJJavaClassloader(next));
            }
        }
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        classLoaders.add(cd);
    }
    unregister(corruptionListener);
    return classLoaders.iterator();
}
Also used : GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) AddCorruptionToListListener(com.ibm.j9ddr.vm29.view.dtfj.java.corrupt.AddCorruptionToListListener)

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