Search in sources :

Example 11 with J9ClassLoaderPointer

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

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

the class J9ClassLoaderHelper method findClass.

/* TODO: this is slightly bogus, if a class is not found in current classloader, we should use it's parent classloader */
/**
 * Return class for MixedObject or component class type for array classes.
 * @param classLoader
 * @param signature JNI Class signature
 * @return J9ClassPointer of a class or null if class is not found.
 * @throws CorruptDataException
 */
public static J9ClassPointer findClass(J9ClassLoaderPointer classLoader, String signature) throws CorruptDataException {
    J9ClassPointer result = null;
    Iterator<J9ClassPointer> classIterator = ClassIterator.fromJ9Classloader(classLoader);
    int arity = calculateClassArity(signature);
    if (arity > 0 && signature.charAt(arity) != 'L') {
        return PRIMITIVE_TO_CLASS.get(signature.charAt(arity));
    } else {
        while (classIterator.hasNext()) {
            J9ClassPointer clazz = classIterator.next();
            result = match(signature, arity, clazz);
            if (null != result) {
                break;
            }
        }
    }
    return result;
}
Also used : J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)

Example 13 with J9ClassLoaderPointer

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

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

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

the class CheckEngine method checkClassStatics.

private int checkClassStatics(J9ClassPointer clazz) {
    int result = J9MODRON_GCCHK_RC_OK;
    try {
        boolean validationRequired = true;
        if (J9ClassHelper.isSwappedOut(clazz)) {
            /* if class has been hot swapped (J9AccClassHotSwappedOut bit is set) in Fast HCR,
				 * the ramStatics of the existing class may be reused.  The J9ClassReusedStatics
				 * bit in J9Class->extendedClassFlags will be set if that's the case.
				 * In Extended HCR mode ramStatics might be not NULL and must be valid
				 * NOTE: If class is hot swapped and the value in ramStatics is NULL it is valid 
				 * to have the correspondent ROM Class value in objectStaticCount field greater then 0
				 */
            if (J9ClassHelper.isArrayClass(clazz)) {
                /* j9arrayclass should not be hot swapped */
                result = J9MODRON_GCCHK_RC_CLASS_HOT_SWAPPED_FOR_ARRAY;
                CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
                _reporter.report(error);
                return result;
            }
            if (J9ClassHelper.areExtensionsEnabled()) {
                /* This is Extended HSR mode so hot swapped class might have NULL in ramStatics field */
                if (clazz.ramStatics().isNull()) {
                    validationRequired = false;
                }
            }
            try {
                /* This case can also occur when running -Xint with extensions enabled */
                if (J9ClassHelper.extendedClassFlags(clazz).allBitsIn(J9JavaClassFlags.J9ClassReusedStatics)) {
                    validationRequired = false;
                }
            } catch (NoSuchFieldError e) {
            /* Flag must be missing from the core. */
            }
        }
        if (validationRequired) {
            // J9ClassLoaderPointer classLoader = clazz.classLoader();
            J9ROMClassPointer romClazz = clazz.romClass();
            UDATA numberOfReferences = new UDATA(0);
            PointerPointer sectionStart = PointerPointer.NULL;
            PointerPointer sectionEnd = PointerPointer.NULL;
            /*
				 * Note: we have no special recognition for J9ArrayClass here
				 * J9ArrayClass does not have a ramStatics field but something else at this place
				 * so direct check (NULL != clazz->ramStatics) would not be correct,
				 * however romClazz->objectStaticCount must be 0 for this case
				 */
            if (!romClazz.objectStaticCount().eq(0)) {
                sectionStart = PointerPointer.cast(clazz.ramStatics());
                sectionEnd = sectionStart.add(romClazz.objectStaticCount());
            }
            /* Iterate all fields of ROM Class looking to statics fields pointed to java objects */
            Iterator<J9ObjectFieldOffset> objectFieldOffsetIterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(clazz, J9ClassHelper.superclass(clazz), new U32(J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC | J9VM_FIELD_OFFSET_WALK_ONLY_OBJECT_SLOTS));
            while (objectFieldOffsetIterator.hasNext()) {
                J9ObjectFieldOffset fieldOffset = objectFieldOffsetIterator.next();
                // J9ROMFieldShapePointer field = fieldOffset.getField();
                numberOfReferences = numberOfReferences.add(1);
                /* get address of next field */
                PointerPointer address = sectionStart.addOffset(fieldOffset.getOffsetOrAddress());
                /* an address must be in gc scan range */
                if (!(address.gte(sectionStart) && address.lt(sectionEnd))) {
                    result = J9MODRON_GCCHK_RC_CLASS_STATICS_REFERENCE_IS_NOT_IN_SCANNING_RANGE;
                    CheckError error = new CheckError(clazz, address, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
                    _reporter.report(error);
                }
            /* check only if we have an object */
            // TODO kmt : can't easily implement this part of the check
            // J9Class* classToCast = vm->internalVMFunctions->internalFindClassUTF8(currentThread, toSearchString, toSearchLength, classLoader, J9_FINDCLASS_FLAG_EXISTING_ONLY);
            // if ((NULL == classToCast) || (0 == instanceOfOrCheckCast(J9GC_J9OBJECT_CLAZZ(*address), classToCast))) {
            // The issue is that we can't simply call "internalFindClassUTF8" in DDR.
            // We could guess at the behaviour of the ClassLoader, but that makes
            // distingushing a real problem from a weird ClassLoader delegation
            // model difficult.
            }
            if (!numberOfReferences.eq(romClazz.objectStaticCount())) {
                result = J9MODRON_GCCHK_RC_CLASS_STATICS_WRONG_NUMBER_OF_REFERENCES;
                CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
                _reporter.report(error);
            }
        }
    } catch (CorruptDataException e) {
        // TODO : cde should be part of the error
        CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
        _reporter.report(error);
    }
    return result;
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) PointerPointer(com.ibm.j9ddr.vm29.pointer.PointerPointer) U32(com.ibm.j9ddr.vm29.types.U32) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) J9ObjectFieldOffset(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

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