Search in sources :

Example 1 with J9ClassLoaderPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer in project openj9 by eclipse.

the class RootScanner method scanPermanentClasses.

protected void scanPermanentClasses() throws CorruptDataException {
    J9ClassLoaderPointer sysClassLoader = _vm.systemClassLoader();
    J9ClassLoaderPointer appClassLoader = J9ClassLoaderPointer.cast(_vm.applicationClassLoader());
    GCSegmentIterator segmentIterator = GCSegmentIterator.fromJ9MemorySegmentList(_vm.classMemorySegments(), J9MemorySegment.MEMORY_TYPE_RAM_CLASS);
    setReachability(Reachability.STRONG);
    while (segmentIterator.hasNext()) {
        J9MemorySegmentPointer segment = segmentIterator.next();
        if (segment.classLoader().equals(sysClassLoader) || segment.classLoader().equals(appClassLoader)) {
            GCClassHeapIterator classHeapIterator = GCClassHeapIterator.fromJ9MemorySegment(segment);
            while (classHeapIterator.hasNext()) {
                doClass(classHeapIterator.next());
            }
        }
    }
}
Also used : J9ClassLoaderPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer) 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 2 with J9ClassLoaderPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer in project openj9 by eclipse.

the class ClassIterator method fromJ9Classloader.

public static Iterator<J9ClassPointer> fromJ9Classloader(J9ClassLoaderPointer loader) throws CorruptDataException {
    J9HashTablePointer table = loader.classHashTable();
    Iterator<J9ClassPointer> iterator = null;
    if (table.listNodePool().notNull()) {
        iterator = new ClassIterator(Pool.fromJ9Pool(table.listNodePool(), J9ClassPointer.class, false).iterator());
    } else {
        iterator = new ArrayIterator<J9ClassPointer>(J9ClassPointer.class, table.tableSize().intValue(), table.nodes()).iterator();
    }
    return new ClassIterator(iterator);
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9HashTablePointer(com.ibm.j9ddr.vm29.pointer.generated.J9HashTablePointer)

Example 3 with J9ClassLoaderPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer 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 4 with J9ClassLoaderPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer 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 5 with J9ClassLoaderPointer

use of com.ibm.j9ddr.vm29.pointer.generated.J9ClassLoaderPointer in project openj9 by eclipse.

the class VmCheckCommand method findSegmentInClassLoaderForAddress.

/**
 * Based on vmchk/checkclasses.c function: findSegmentInClassLoaderForAddress
 *
 * This method searches classloader's segments to find out on which segment this ROMClass lays in.
 * @param classLoader Classloader that romclass is being searched
 * @param romClassPointer ROMClass that is searched in classloader segments
 * @return Classloader segment which has this romclass, otherwise null.
 * @throws CorruptDataException
 */
public J9MemorySegmentPointer findSegmentInClassLoaderForAddress(J9ClassLoaderPointer classLoader, J9ROMClassPointer romClassPointer) throws CorruptDataException {
    MemorySegmentIterator memorySegmentIterator = new MemorySegmentIterator(classLoader.classSegments(), MemorySegmentIterator.MEMORY_ALL_TYPES, true);
    J9MemorySegmentPointer memorySegmentPointer = J9MemorySegmentPointer.NULL;
    J9MemorySegmentPointer foundMemorySegmentPointer = J9MemorySegmentPointer.NULL;
    while (memorySegmentIterator.hasNext()) {
        Object next2 = memorySegmentIterator.next();
        memorySegmentPointer = (J9MemorySegmentPointer) next2;
        if (romClassPointer.getAddress() >= memorySegmentPointer.heapBase().longValue() && romClassPointer.getAddress() < memorySegmentPointer.heapAlloc().longValue()) {
            foundMemorySegmentPointer = memorySegmentPointer;
            break;
        }
    }
    return foundMemorySegmentPointer;
}
Also used : J9MemorySegmentPointer(com.ibm.j9ddr.vm29.pointer.generated.J9MemorySegmentPointer) MemorySegmentIterator(com.ibm.j9ddr.vm29.j9.walkers.MemorySegmentIterator)

Aggregations

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