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());
}
}
}
}
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);
}
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();
}
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;
}
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;
}
Aggregations