Search in sources :

Example 1 with J9ObjectFieldOffset

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

the class VMConstantPool method getFieldOffset.

/**
 * Get a field offset from the constant pool.
 * @param index A J9VmconstantpoolConstants index into the constant pool.  Must be for a static or instance field reference.
 * @return Either the offset to the object, or null if the field's class is not resolved in the constant pool.
 * @throws CorruptDataException If the field cannot be found in the related class or the CP index is not a field reference.
 */
public static J9ObjectFieldOffset getFieldOffset(long index) throws CorruptDataException {
    if (_constantPool.length <= index || 0 > index) {
        throw new IndexOutOfBoundsException("Index outside of constant pool bounds");
    }
    int cpIndex = (int) index;
    long shapeDesc = ConstantPoolHelpers.J9_CP_TYPE(_cpShapeDescription, cpIndex);
    if (J9CPTYPE_FIELD != shapeDesc) {
        throw new CorruptDataException("VMConstantPool[" + index + "] CP_TYPE is not J9CPTYPE_FIELD");
    }
    /* The offset of the field, to be returned */
    J9ObjectFieldOffset offset = null;
    if (null != _constantPool[cpIndex]) {
        offset = (J9ObjectFieldOffset) _constantPool[cpIndex];
    } else {
        J9ROMFieldRefPointer romRef = J9ROMFieldRefPointer.cast(_romCPStart.add(cpIndex));
        J9ClassPointer refClass = getClass(romRef.classRefCPIndex().longValue());
        J9ClassPointer currentClass = refClass;
        if (currentClass.notNull()) {
            /* If the current class is J9ClassPointer.NULL, return null as the field offset */
            /* Resolve the fieldname, starting from the current class,
				 * and working up the class hierarchy towards the super classes. This should
				 * properly handle shadowed fields.
				 */
            String fieldName = J9UTF8Helper.stringValue(romRef.nameAndSignature().name());
            String signature = J9UTF8Helper.stringValue(romRef.nameAndSignature().signature());
            while (currentClass.notNull() && (null == offset)) {
                Iterator<J9ObjectFieldOffset> fields = J9ClassHelper.getFieldOffsets(currentClass);
                while (fields.hasNext()) {
                    J9ObjectFieldOffset field = fields.next();
                    if (field.getName().equals(fieldName) && field.getSignature().equals(signature)) {
                        offset = field;
                        break;
                    }
                }
                currentClass = J9ClassHelper.superclass(currentClass);
            }
            if (null == offset) {
                /* The field should exist in the class it points to, unless the constant pool is corrupt or wrong */
                throw new CorruptDataException("VMConstantPool[" + index + "] field not found: " + J9ClassHelper.getName(refClass) + "." + fieldName + " " + signature);
            } else {
                _constantPool[cpIndex] = offset;
            }
        }
    }
    return offset;
}
Also used : J9ROMFieldRefPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldRefPointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) CorruptDataException(com.ibm.j9ddr.CorruptDataException)

Example 2 with J9ObjectFieldOffset

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

the class RamClassWalker method allSlotsInRAMStaticsDo.

private void allSlotsInRAMStaticsDo() throws CorruptDataException {
    if (ramClass.ramStatics().isNull()) {
        return;
    }
    Iterator<?> ofoIterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(ramClass, J9ClassHelper.superclass(ramClass), new U32(J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC));
    J9ObjectFieldOffset fields = null;
    while (ofoIterator.hasNext()) {
        fields = (J9ObjectFieldOffset) ofoIterator.next();
        J9ROMFieldShapePointer field = fields.getField();
        String info = fields.getName();
        U32 modifiers = field.modifiers();
        UDATAPointer fieldAddress = ramClass.ramStatics().addOffset(fields.getOffsetOrAddress());
        String additionalInfo = modifiers.anyBitsIn(J9FieldFlagObject) ? "!j9object" : "";
        if (modifiers.anyBitsIn(J9FieldSizeDouble)) {
            classWalkerCallback.addSlot(clazz, SlotType.J9_I64, I64Pointer.cast(fieldAddress), info, additionalInfo);
        } else {
            classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, fieldAddress, info, additionalInfo);
        }
    }
    U32 staticSlotCount = ramClass.romClass().objectStaticCount().add(ramClass.romClass().singleScalarStaticCount());
    if (J9BuildFlags.env_data64) {
        staticSlotCount = staticSlotCount.add(ramClass.romClass().doubleScalarStaticCount());
    } else {
        staticSlotCount = staticSlotCount.add(1).bitAnd(~1L).add(ramClass.romClass().doubleScalarStaticCount().mult(2));
    }
    UDATA size = Scalar.convertSlotsToBytes(new UDATA(staticSlotCount));
    classWalkerCallback.addSection(clazz, ramClass.ramStatics(), size.longValue(), "Ram static", false);
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) U32(com.ibm.j9ddr.vm29.types.U32) J9_CP_DESCRIPTIONS_PER_U32(com.ibm.j9ddr.vm29.structure.J9ConstantPool.J9_CP_DESCRIPTIONS_PER_U32) UDATAPointer(com.ibm.j9ddr.vm29.pointer.UDATAPointer) J9ROMFieldShapePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldShapePointer) J9ObjectFieldOffset(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset)

Example 3 with J9ObjectFieldOffset

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

the class J9StaticsCommand method run.

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
    try {
        if (args.length != 1) {
            CommandUtils.dbgPrint(out, "Usage: !j9statics <classAddress>\n");
            return;
        }
        long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
        J9ClassPointer ramClass = J9ClassPointer.cast(address);
        J9ROMClassPointer romClass = ramClass.romClass();
        J9UTF8Pointer className = romClass.className();
        CommandUtils.dbgPrint(out, "Static fields in %s:\n", J9UTF8Helper.stringValue(className));
        Iterator<J9ObjectFieldOffset> ofoIterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(ramClass, J9ClassHelper.superclass(ramClass), new U32(J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC));
        while (ofoIterator.hasNext()) {
            J9ObjectFieldOffset fieldOffset = ofoIterator.next();
            J9ROMFieldShapePointer field = fieldOffset.getField();
            String name = J9ROMFieldShapeHelper.getName(field);
            String sig = J9ROMFieldShapeHelper.getSignature(field);
            UDATAPointer fieldAddress = ramClass.ramStatics().addOffset(fieldOffset.getOffsetOrAddress());
            switch(sig.charAt(0)) {
                case 'L':
                case '[':
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticstringfieldshape %s) = !j9object %s\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), fieldAddress.at(0).getHexValue());
                    break;
                case 'D':
                    DoublePointer doublePointer = DoublePointer.cast(fieldAddress);
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticdoublefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), doublePointer.getHexValue(), new Double(doublePointer.doubleAt(0)).toString());
                    break;
                case 'F':
                    FloatPointer floatPointer = FloatPointer.cast(fieldAddress);
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), floatPointer.getHexValue(), new Float(floatPointer.floatAt(0)).toString());
                    break;
                case 'J':
                    I64Pointer longPointer = I64Pointer.cast(fieldAddress);
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticdoublefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), longPointer.getHexValue(), longPointer.at(0).longValue());
                    break;
                case 'I':
                    I32Pointer intPointer = I32Pointer.cast(fieldAddress);
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), intPointer.getHexValue(), intPointer.at(0).intValue());
                    break;
                case 'B':
                    I8Pointer bytePointer = I8Pointer.cast(fieldAddress);
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), bytePointer.getHexValue(), bytePointer.at(0).byteValue());
                    break;
                case 'S':
                    I16Pointer shortPointer = I16Pointer.cast(fieldAddress);
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), shortPointer.getHexValue(), shortPointer.at(0).shortValue());
                    break;
                case 'Z':
                    BoolPointer booleanPointer = BoolPointer.cast(fieldAddress);
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), booleanPointer.getHexValue(), booleanPointer.boolAt(0) ? "true" : "false");
                    break;
                default:
                    CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), fieldAddress.at(0).getHexValue());
                    break;
            }
        }
    } catch (CorruptDataException e) {
        throw new DDRInteractiveCommandException(e);
    }
}
Also used : BoolPointer(com.ibm.j9ddr.vm29.pointer.BoolPointer) I64Pointer(com.ibm.j9ddr.vm29.pointer.I64Pointer) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ROMClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer) UDATAPointer(com.ibm.j9ddr.vm29.pointer.UDATAPointer) DoublePointer(com.ibm.j9ddr.vm29.pointer.DoublePointer) DDRInteractiveCommandException(com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException) J9ObjectFieldOffset(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset) CorruptDataException(com.ibm.j9ddr.CorruptDataException) I16Pointer(com.ibm.j9ddr.vm29.pointer.I16Pointer) I32Pointer(com.ibm.j9ddr.vm29.pointer.I32Pointer) I8Pointer(com.ibm.j9ddr.vm29.pointer.I8Pointer) U32(com.ibm.j9ddr.vm29.types.U32) FloatPointer(com.ibm.j9ddr.vm29.pointer.FloatPointer) J9ROMFieldShapePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldShapePointer) J9UTF8Pointer(com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer)

Example 4 with J9ObjectFieldOffset

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

the class DTFJJavaClass method getDeclaredFields.

@SuppressWarnings("rawtypes")
public Iterator getDeclaredFields() {
    List<Object> list = declaredFieldsCache.get(j9class);
    if (list == null) {
        list = new LinkedList<Object>();
        final List<Object> fieldList = list;
        IEventListener corruptDataListener = new IEventListener() {

            public void corruptData(String message, com.ibm.j9ddr.CorruptDataException e, boolean fatal) {
                J9DDRCorruptData cd = J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), e);
                fieldList.add(cd);
            }
        };
        try {
            register(corruptDataListener);
            J9ClassPointer superclass = J9ClassPointer.NULL;
            try {
                superclass = getSuperClassPointer();
            } catch (com.ibm.j9ddr.CorruptDataException e1) {
                // pass null for the superclass to just list this classes fields as cannot determine superclass
                fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Unable to determine superclass"));
            }
            U32 flags = new U32(J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC | J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE);
            long fieldCount = j9class.romClass().romFieldCount().longValue();
            Iterator<J9ObjectFieldOffset> fields = null;
            if (fieldCount > MAX_CLASS_FIELDS) {
                fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Corrupt field count"));
            } else {
                fields = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(j9class, superclass, flags);
            }
            while (fields != null && fields.hasNext()) {
                try {
                    J9ObjectFieldOffset field = fields.next();
                    log.fine(String.format("Declared field : %s", field.getName()));
                    if (field.isStatic()) {
                        fieldList.add(new DTFJJavaFieldStatic(this, field));
                    } else {
                        fieldList.add(new DTFJJavaFieldInstance(this, field));
                    }
                } catch (com.ibm.j9ddr.CorruptDataException e) {
                    // add the corrupted field to the iterator
                    fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), e));
                }
                if (fieldList.size() > fieldCount) {
                    // The class has returned more fields than it said it contained, it is corrupt.
                    // add the corrupted field to the iterator
                    fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Corrupt class returned more fields than it declared"));
                    break;
                }
            }
            /* Large lists of fields are likely to be corrupt data so
				 * don't cache them.
				 */
            if (fieldList.size() < 1024) {
                declaredFieldsCache.put(j9class, fieldList);
            }
        } catch (Throwable t) {
            fieldList.add(J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t));
        } finally {
            unregister(corruptDataListener);
        }
    }
    return list.iterator();
}
Also used : J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) J9ClassPointer(com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer) J9ObjectFieldOffset(com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) IEventListener(com.ibm.j9ddr.events.IEventListener) U32(com.ibm.j9ddr.vm29.types.U32) JavaObject(com.ibm.dtfj.java.JavaObject) J9Object(com.ibm.j9ddr.vm29.structure.J9Object)

Example 5 with J9ObjectFieldOffset

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

the class J9ObjectStructureFormatter method printObjectField.

public void printObjectField(PrintStream out, int tabLevel, J9ClassPointer localClazz, U8Pointer dataStart, J9ClassPointer fromClass, J9ObjectFieldOffset objectFieldOffset) throws CorruptDataException {
    J9ROMFieldShapePointer fieldShape = objectFieldOffset.getField();
    UDATA fieldOffset = objectFieldOffset.getOffsetOrAddress();
    boolean isHiddenField = objectFieldOffset.isHidden();
    String className = J9UTF8Helper.stringValue(fromClass.romClass().className());
    String fieldName = J9UTF8Helper.stringValue(fieldShape.nameAndSignature().name());
    String fieldSignature = J9UTF8Helper.stringValue(fieldShape.nameAndSignature().signature());
    U8Pointer valuePtr = dataStart;
    valuePtr = valuePtr.add(fieldOffset);
    padding(out, tabLevel);
    out.print(String.format("%s %s = ", fieldSignature, fieldName));
    if (fieldShape.modifiers().anyBitsIn(J9FieldSizeDouble)) {
        out.print(U64Pointer.cast(valuePtr).at(0).getHexValue());
    } else if (fieldShape.modifiers().anyBitsIn(J9FieldFlagObject)) {
        AbstractPointer ptr = J9BuildFlags.gc_compressedPointers ? U32Pointer.cast(valuePtr) : UDATAPointer.cast(valuePtr);
        out.print(String.format("!fj9object 0x%x", ptr.at(0).longValue()));
    } else {
        out.print(I32Pointer.cast(valuePtr).at(0).getHexValue());
    }
    out.print(String.format(" (offset=%d) (%s)", fieldOffset.longValue(), className));
    if (isHiddenField) {
        out.print(" <hidden>");
    }
}
Also used : AbstractPointer(com.ibm.j9ddr.vm29.pointer.AbstractPointer) UDATA(com.ibm.j9ddr.vm29.types.UDATA) J9ROMFieldShapePointer(com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldShapePointer) U8Pointer(com.ibm.j9ddr.vm29.pointer.U8Pointer)

Aggregations

J9ObjectFieldOffset (com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset)8 J9ClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ClassPointer)6 U32 (com.ibm.j9ddr.vm29.types.U32)6 CorruptDataException (com.ibm.j9ddr.CorruptDataException)5 UDATA (com.ibm.j9ddr.vm29.types.UDATA)4 J9ROMFieldShapePointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMFieldShapePointer)3 DDRInteractiveCommandException (com.ibm.j9ddr.tools.ddrinteractive.DDRInteractiveCommandException)2 UDATAPointer (com.ibm.j9ddr.vm29.pointer.UDATAPointer)2 J9JavaVMPointer (com.ibm.j9ddr.vm29.pointer.generated.J9JavaVMPointer)2 J9ROMClassPointer (com.ibm.j9ddr.vm29.pointer.generated.J9ROMClassPointer)2 J9UTF8Pointer (com.ibm.j9ddr.vm29.pointer.generated.J9UTF8Pointer)2 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 JavaObject (com.ibm.dtfj.java.JavaObject)1 IEventListener (com.ibm.j9ddr.events.IEventListener)1 PatternString (com.ibm.j9ddr.util.PatternString)1 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)1 AbstractPointer (com.ibm.j9ddr.vm29.pointer.AbstractPointer)1 BoolPointer (com.ibm.j9ddr.vm29.pointer.BoolPointer)1 DoublePointer (com.ibm.j9ddr.vm29.pointer.DoublePointer)1 FloatPointer (com.ibm.j9ddr.vm29.pointer.FloatPointer)1