Search in sources :

Example 1 with J9ROMNameAndSignaturePointer

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

the class LinearDumper method addSlot.

public void addSlot(StructurePointer clazz, SlotType type, AbstractPointer slotPtr, String slotName, String additionalInfo) throws CorruptDataException {
    try {
        J9ROMNameAndSignaturePointer nas;
        long offset;
        /* The slots of the type J9_ROM_UTF8 are changed to have 2 slots:
			 * -J9_SRP_TO_STRING
			 * -J9_ROM_UTF8
			 * This is done because we want to print the SRP field and also print
			 * the UTF8 it is pointing to */
        switch(type) {
            case J9_ROM_UTF8:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, SlotType.J9_SRP_TO_STRING, slotName, additionalInfo, type.getSize(), offset, true));
                VoidPointer srp = SelfRelativePointer.cast(slotPtr).get();
                addUTF8Region(clazz, slotName, additionalInfo, srp);
                break;
            case J9_UTF8:
                addUTF8Region(clazz, slotName, additionalInfo, slotPtr);
                break;
            /* The fields of the type J9_SRPNAS or J9_SRP are changed to have 2 J9_ROM_UTF8
				 * fields for their name and signature separated. */
            case J9_SRPNAS:
                nas = J9ROMNameAndSignaturePointer.cast(SelfRelativePointer.cast(slotPtr).get());
                if (nas.notNull()) {
                    addSlot(clazz, SlotType.J9_ROM_UTF8, nas.nameEA(), "name");
                    addSlot(clazz, SlotType.J9_ROM_UTF8, nas.signatureEA(), "signature");
                }
                /* Since it is a SRP to a NAS, also print the SRP field. */
                addSlot(clazz, SlotType.J9_SRP, slotPtr, "cpFieldNAS");
                break;
            case J9_NAS:
                nas = J9ROMNameAndSignaturePointer.cast(slotPtr);
                addSlot(clazz, SlotType.J9_ROM_UTF8, nas.nameEA(), "name");
                addSlot(clazz, SlotType.J9_ROM_UTF8, nas.signatureEA(), "signature");
                break;
            case J9_IntermediateClassData:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, type, slotName, additionalInfo, ((J9ROMClassPointer) clazz).intermediateClassDataLength().longValue(), offset, true));
                break;
            default:
                offset = slotPtr.getAddress() - clazz.getAddress();
                classRegions.add(new J9ClassRegion(slotPtr, type, slotName, additionalInfo, type.getSize(), offset, true));
                break;
        }
    } catch (Exception e) {
    }
}
Also used : J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 2 with J9ROMNameAndSignaturePointer

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

the class J9BCUtil method dumpCallSiteData.

/**
 * This method is Java implementation of rdump.c#dumpCallSiteData function.
 * This method is called when dumping a ROMClass.
 * This method has only affect for invokedDynamic stuff,
 * for other ROMClasses, there wont be anything to print since their callsite and bsm count are zero.
 *
 * @param out PrintStream to print the user info to the console
 * @param romClass ROMClass address in the dump file.
 *
 * @throws CorruptDataException
 */
private static void dumpCallSiteData(PrintStream out, J9ROMClassPointer romClass) throws CorruptDataException {
    int HEX_RADIX = 16;
    long callSiteCount = romClass.callSiteCount().longValue();
    long bsmCount = romClass.bsmCount().longValue();
    SelfRelativePointer callSiteData = SelfRelativePointer.cast(romClass.callSiteData());
    U16Pointer bsmIndices = U16Pointer.cast(callSiteData.addOffset(4 * callSiteCount));
    if (0 != callSiteCount) {
        out.println(String.format("  Call Sites (%d):\n", callSiteCount));
        for (int i = 0; i < callSiteCount; i++) {
            J9ROMNameAndSignaturePointer nameAndSig = J9ROMNameAndSignaturePointer.cast(callSiteData.add(i).get());
            out.println("    Name: " + J9UTF8Helper.stringValue(nameAndSig.name()));
            out.println("    Signature: " + J9UTF8Helper.stringValue(nameAndSig.signature()));
            out.println("    Bootstrap Method Index: " + bsmIndices.at(i).longValue());
            out.println();
        }
    }
    if (0 != bsmCount) {
        J9ROMConstantPoolItemPointer constantPool = ConstantPoolHelpers.J9_ROM_CP_FROM_ROM_CLASS(romClass);
        U32Pointer cpShapeDescription = romClass.cpShapeDescription();
        U16Pointer bsmDataCursor = bsmIndices.add(callSiteCount);
        out.println(String.format("  Bootstrap Methods (%d):", bsmCount));
        for (int i = 0; i < bsmCount; i++) {
            J9ROMMethodHandleRefPointer methodHandleRef = J9ROMMethodHandleRefPointer.cast(constantPool.add(bsmDataCursor.at(0).longValue()));
            bsmDataCursor = bsmDataCursor.add(1);
            /* methodRef will be either a field or a method ref - they both have the same shape so we can pretend it is always a methodref */
            J9ROMMethodRefPointer methodRef = J9ROMMethodRefPointer.cast(constantPool.add(methodHandleRef.methodOrFieldRefIndex().longValue()));
            J9ROMClassRefPointer classRef = J9ROMClassRefPointer.cast(constantPool.add(methodRef.classRefCPIndex().longValue()));
            J9ROMNameAndSignaturePointer nameAndSig = methodRef.nameAndSignature();
            long bsmArgumentCount = bsmDataCursor.at(0).longValue();
            bsmDataCursor = bsmDataCursor.add(1);
            out.println("    Name: " + J9UTF8Helper.stringValue(classRef.name()) + "." + J9UTF8Helper.stringValue(nameAndSig.name()));
            out.println("    Signature: " + J9UTF8Helper.stringValue(nameAndSig.signature()));
            out.println(String.format("    Bootstrap Method Arguments (%d):", bsmArgumentCount));
            for (; 0 != bsmArgumentCount; bsmArgumentCount--) {
                long argCPIndex = bsmDataCursor.at(0).longValue();
                bsmDataCursor = bsmDataCursor.add(1);
                J9ROMConstantPoolItemPointer item = constantPool.add(argCPIndex);
                long shapeDesc = ConstantPoolHelpers.J9_CP_TYPE(cpShapeDescription, (int) argCPIndex);
                if (shapeDesc == J9CPTYPE_CLASS) {
                    J9ROMClassRefPointer romClassRef = J9ROMClassRefPointer.cast(item);
                    out.println("      Class: " + J9UTF8Helper.stringValue(romClassRef.name()));
                } else if (shapeDesc == J9CPTYPE_STRING) {
                    J9ROMStringRefPointer romStringRef = J9ROMStringRefPointer.cast(item);
                    out.println("      String: " + J9UTF8Helper.stringValue(romStringRef.utf8Data()));
                } else if (shapeDesc == J9CPTYPE_INT) {
                    J9ROMSingleSlotConstantRefPointer singleSlotConstantRef = J9ROMSingleSlotConstantRefPointer.cast(item);
                    out.println("      Int: " + singleSlotConstantRef.data().getHexValue());
                } else if (shapeDesc == J9CPTYPE_FLOAT) {
                    J9ROMSingleSlotConstantRefPointer singleSlotConstantRef = J9ROMSingleSlotConstantRefPointer.cast(item);
                    FloatPointer floatPtr = FloatPointer.cast(singleSlotConstantRef.dataEA());
                    out.println("      Float: " + floatPtr.getHexValue() + " (" + floatPtr.floatAt(0) + ")");
                } else if (shapeDesc == J9CPTYPE_LONG) {
                    String hexValue = "";
                    if (J9BuildFlags.env_littleEndian) {
                        hexValue += item.slot2().getHexValue();
                        hexValue += item.slot1().getHexValue().substring(2);
                    } else {
                        hexValue += item.slot1().getHexValue();
                        hexValue += item.slot2().getHexValue().substring(2);
                    }
                    long longValue = Long.parseLong(hexValue.substring(2), HEX_RADIX);
                    out.println("      Long: " + hexValue + "(" + longValue + ")");
                } else if (shapeDesc == J9CPTYPE_DOUBLE) {
                    String hexValue = "";
                    if (J9BuildFlags.env_littleEndian) {
                        hexValue += item.slot2().getHexValue();
                        hexValue += item.slot1().getHexValue().substring(2);
                    } else {
                        hexValue += item.slot1().getHexValue();
                        hexValue += item.slot2().getHexValue().substring(2);
                    }
                    long longValue = Long.parseLong(hexValue.substring(2), HEX_RADIX);
                    double doubleValue = Double.longBitsToDouble(longValue);
                    out.println("      Double: " + hexValue + "(" + Double.toString(doubleValue) + ")");
                } else if (shapeDesc == J9CPTYPE_FIELD) {
                    J9ROMFieldRefPointer romFieldRef = J9ROMFieldRefPointer.cast(item);
                    classRef = J9ROMClassRefPointer.cast(constantPool.add(romFieldRef.classRefCPIndex()));
                    nameAndSig = romFieldRef.nameAndSignature();
                    out.println("      Field: " + J9UTF8Helper.stringValue(classRef.name()) + "." + J9UTF8Helper.stringValue(nameAndSig.name()) + " " + J9UTF8Helper.stringValue(nameAndSig.signature()));
                } else if ((shapeDesc == J9CPTYPE_INSTANCE_METHOD) || (shapeDesc == J9CPTYPE_STATIC_METHOD) || (shapeDesc == J9CPTYPE_HANDLE_METHOD) || (shapeDesc == J9CPTYPE_INTERFACE_METHOD)) {
                    J9ROMMethodRefPointer romMethodRef = J9ROMMethodRefPointer.cast(item);
                    classRef = J9ROMClassRefPointer.cast(constantPool.add(romMethodRef.classRefCPIndex()));
                    nameAndSig = romMethodRef.nameAndSignature();
                    out.println("      Method: " + J9UTF8Helper.stringValue(classRef.name()) + "." + J9UTF8Helper.stringValue(nameAndSig.name()) + " " + J9UTF8Helper.stringValue(nameAndSig.signature()));
                } else if (shapeDesc == J9CPTYPE_METHOD_TYPE) {
                    J9ROMMethodTypeRefPointer romMethodTypeRef = J9ROMMethodTypeRefPointer.cast(item);
                    out.println("      Method Type: " + J9UTF8Helper.stringValue(J9UTF8Pointer.cast(romMethodTypeRef.signature())));
                } else if (shapeDesc == J9CPTYPE_METHODHANDLE) {
                    methodHandleRef = J9ROMMethodHandleRefPointer.cast(item);
                    methodRef = J9ROMMethodRefPointer.cast(constantPool.add(methodHandleRef.methodOrFieldRefIndex()));
                    classRef = J9ROMClassRefPointer.cast(constantPool.add(methodRef.classRefCPIndex()));
                    nameAndSig = methodRef.nameAndSignature();
                    out.print("      Method Handle: " + J9UTF8Helper.stringValue(classRef.name()) + "." + J9UTF8Helper.stringValue(nameAndSig.name()));
                    long methodType = methodHandleRef.handleTypeAndCpType().rightShift((int) J9DescriptionCpTypeShift).longValue();
                    if ((methodType == MH_REF_GETFIELD) || (methodType == MH_REF_PUTFIELD) || (methodType == MH_REF_GETSTATIC) || (methodType == MH_REF_PUTSTATIC)) {
                        out.print(" ");
                    }
                    out.println(J9UTF8Helper.stringValue(nameAndSig.signature()));
                } else {
                    out.println("      <unknown type>");
                }
            }
        }
    }
}
Also used : J9ROMMethodRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodRefPointer) J9ROMFieldRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldRefPointer) J9ROMClassRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassRefPointer) J9ROMMethodHandleRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodHandleRefPointer) J9ROMSingleSlotConstantRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMSingleSlotConstantRefPointer) SelfRelativePointer(com.ibm.j9ddr.vm29.pointer.SelfRelativePointer) J9ROMStringRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMStringRefPointer) J9ROMMethodTypeRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodTypeRefPointer) U16Pointer(com.ibm.j9ddr.vm29.pointer.U16Pointer) J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) J9ROMConstantPoolItemPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMConstantPoolItemPointer) FloatPointer(com.ibm.j9ddr.vm29.pointer.FloatPointer) U32Pointer(com.ibm.j9ddr.vm29.pointer.U32Pointer)

Example 3 with J9ROMNameAndSignaturePointer

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

the class J9BCUtil method dumpEnclosingMethod.

private static void dumpEnclosingMethod(PrintStream out, J9ROMClassPointer romClass, long flags) throws CorruptDataException {
    J9EnclosingObjectPointer enclosingMethodForROMClass = OptInfo.getEnclosingMethodForROMClass(romClass);
    if (!enclosingMethodForROMClass.isNull()) {
        J9ROMConstantPoolItemPointer constantPool = ConstantPoolHelpers.J9_ROM_CP_FROM_ROM_CLASS(romClass);
        J9ROMClassRefPointer romClassRefPointer = J9ROMClassRefPointer.cast(constantPool);
        String className = romClassRefPointer.name().toString();
        J9ROMNameAndSignaturePointer nameAndSignature = enclosingMethodForROMClass.nameAndSignature();
        if (!nameAndSignature.isNull()) {
            out.append(String.format("Enclosing Method: %s%s%s", className, J9UTF8Helper.stringValue(nameAndSignature.name()), J9UTF8Helper.stringValue(nameAndSignature.signature())));
        } else {
            out.append(String.format("Enclosing Class: %s", className));
        }
    }
}
Also used : J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) J9ROMClassRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassRefPointer) J9ROMConstantPoolItemPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMConstantPoolItemPointer) J9EnclosingObjectPointer(com.ibm.j9ddr.vm29.pointer.generated.J9EnclosingObjectPointer)

Example 4 with J9ROMNameAndSignaturePointer

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

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

the class FilteredROMMethodsIterator method next.

public J9ROMClassAndMethod next() {
    J9ROMClassAndMethod result = nextMethod;
    /* hasNext may have already go the next method */
    nextMethod = null;
    /* destructive read */
    if (null == result) {
        do {
            try {
                if ((null != currentRomMethod) && (remainingMethods > 0)) {
                    J9ROMMethodPointer romMethod = currentRomMethod;
                    J9ROMNameAndSignaturePointer nameAndSignature = romMethod.nameAndSignature();
                    J9UTF8Pointer methNameUTF = nameAndSignature.name();
                    String methName = J9UTF8Helper.stringValue(methNameUTF);
                    if (methodPattern.isMatch(methName)) {
                        String methSig = J9UTF8Helper.stringValue(nameAndSignature.signature());
                        if (signaturePattern.isMatch(methSig)) {
                            result = new J9ROMClassAndMethod(romMethod, currentRomClass);
                        }
                    }
                    currentRomMethod = ROMHelp.nextROMMethod(currentRomMethod);
                    --remainingMethods;
                } else {
                    if (!goToNextClass()) {
                        break;
                    /* ran out of classes */
                    }
                }
            } catch (CorruptDataException e) {
                throw new NoSuchElementException();
            }
        } while (null == result);
    }
    return result;
}
Also used : J9ROMNameAndSignaturePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer) J9ROMMethodPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer) J9UTF8Pointer(com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer) PatternString(com.ibm.j9ddr.util.PatternString) CorruptDataException(com.ibm.j9ddr.CorruptDataException) NoSuchElementException(java.util.NoSuchElementException) J9ROMClassAndMethod(com.ibm.j9ddr.vm29.j9.walkers.J9ROMClassAndMethod)

Aggregations

J9ROMNameAndSignaturePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMNameAndSignaturePointer)10 J9ROMConstantPoolItemPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMConstantPoolItemPointer)4 SelfRelativePointer (com.ibm.j9ddr.vm29.pointer.SelfRelativePointer)3 U32Pointer (com.ibm.j9ddr.vm29.pointer.U32Pointer)3 J9ROMClassRefPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassRefPointer)3 J9ROMMethodPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodPointer)3 J9UTF8Pointer (com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer)3 U32 (com.ibm.j9ddr.vm29.types.U32)3 CorruptDataException (com.ibm.j9ddr.CorruptDataException)2 U16Pointer (com.ibm.j9ddr.vm29.pointer.U16Pointer)2 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)2 J9ROMFieldRefPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldRefPointer)2 J9ROMMethodRefPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMMethodRefPointer)2 J9ROMSingleSlotConstantRefPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMSingleSlotConstantRefPointer)2 J9ROMStringRefPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMStringRefPointer)2 PatternString (com.ibm.j9ddr.util.PatternString)1 GCClassLoaderIterator (com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator)1 J9ROMClassAndMethod (com.ibm.j9ddr.vm29.j9.walkers.J9ROMClassAndMethod)1 FloatPointer (com.ibm.j9ddr.vm29.pointer.FloatPointer)1 VoidPointer (com.ibm.j9ddr.vm29.pointer.VoidPointer)1