Search in sources :

Example 1 with ObjectFieldInfo

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

the class J9ObjectFieldOffsetIterator_V1 method calculateInstanceSize.

private void calculateInstanceSize(J9ROMClassPointer romClass, J9ClassPointer superClazz) throws CorruptDataException {
    lockwordNeeded = NO_LOCKWORD_NEEDED;
    /* if we only care about statics we can skip all work related to instance size calculations */
    if (!walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE | J9VM_FIELD_OFFSET_WALK_CALCULATE_INSTANCE_SIZE)) {
        return;
    }
    ObjectFieldInfo fieldInfo = new ObjectFieldInfo(romClass);
    /*
		 * Step 1: Calculate the size of the superclass and backfill offset.
		 * Inherit the instance size and backfillOffset from the superclass.
		 */
    if (superClazz.notNull()) {
        /*
			 * Note that in the J9Class, we do not store -1 to indicate no back fill,
			 * we store the total instance size (including the header) instead.
			 */
        fieldInfo.setSuperclassFieldsSize(superClazz.totalInstanceSize().intValue());
        if (!superClazz.backfillOffset().eq(superClazz.totalInstanceSize().add(J9Object.SIZEOF))) {
            fieldInfo.setSuperclassBackfillOffset(superClazz.backfillOffset().sub(J9Object.SIZEOF).intValue());
        }
    } else {
        fieldInfo.setSuperclassFieldsSize(0);
    }
    lockwordNeeded = checkLockwordNeeded(romClass, superClazz, instanceClass);
    /*
		 * remove the lockword from Object (if there is one) only if we don't need a lockword or we do need one
		 * and we are not re-using the one from Object which we can tell because lockwordNeeded is LOCKWORD_NEEDED as
		 * opposed to the value of the existing offset.
		 */
    if ((LOCKWORD_NEEDED.equals(lockwordNeeded)) || (NO_LOCKWORD_NEEDED.equals(lockwordNeeded))) {
        if (superClazz.notNull() && !superClazz.lockOffset().eq(new UDATA(-1)) && J9ClassHelper.classDepth(superClazz).isZero()) {
            int newSuperSize = fieldInfo.getSuperclassFieldsSize() - LOCKWORD_SIZE;
            /* this may  have been rounded to 8 bytes so also get rid of the padding */
            if (fieldInfo.isSuperclassBackfillSlotAvailable()) {
                /* j.l.Object was not end aligned */
                newSuperSize -= BACKFILL_SIZE;
                fieldInfo.setSuperclassBackfillOffset(NO_BACKFILL_AVAILABLE);
            }
            fieldInfo.setSuperclassFieldsSize(newSuperSize);
        }
    }
    /*
		 * Step 2: Determine which extra hidden fields we need and prepend them to the list of hidden fields.
		 */
    LinkedList<HiddenInstanceField> extraHiddenFields = copyHiddenInstanceFieldsList(vm);
    finalizeLinkOffset = new UDATA(0);
    if (!superClazz.isNull() && !superClazz.finalizeLinkOffset().isZero()) {
        /* Superclass is finalizeable */
        finalizeLinkOffset = superClazz.finalizeLinkOffset();
    } else {
        /* Superclass is not finalizeable */
        if (J9ROMClassHelper.finalizeNeeded(romClass)) {
            extraHiddenFields.addFirst(new HiddenInstanceField(vm.hiddenFinalizeLinkFieldShape()));
        }
    }
    lockOffset = new UDATA(lockwordNeeded);
    if (lockOffset.eq(LOCKWORD_NEEDED)) {
        extraHiddenFields.addFirst(new HiddenInstanceField(vm.hiddenLockwordFieldShape()));
    }
    /*
		 * Step 3: Calculate the number of various categories of fields: single word primitive, double word primitive, and object references.
		 * Iterate over fields to count instance fields by size.
		 */
    fieldInfo.countInstanceFields();
    fieldInfo.countAndCopyHiddenFields(extraHiddenFields, hiddenInstanceFieldList);
    new UDATA(fieldInfo.calculateTotalFieldsSizeAndBackfill());
    firstDoubleOffset = new UDATA(fieldInfo.calculateFieldDataStart());
    firstObjectOffset = new UDATA(fieldInfo.addDoublesArea(firstDoubleOffset.intValue()));
    firstSingleOffset = new UDATA(fieldInfo.addObjectsArea(firstObjectOffset.intValue()));
    if (fieldInfo.isMyBackfillSlotAvailable() && fieldInfo.isBackfillSuitableFieldAvailable()) {
        if (fieldInfo.isBackfillSuitableInstanceSingleAvailable()) {
            walkFlags = walkFlags.bitOr(J9VM_FIELD_OFFSET_WALK_BACKFILL_SINGLE_FIELD);
        } else if (fieldInfo.isBackfillSuitableInstanceObjectAvailable()) {
            walkFlags = walkFlags.bitOr(J9VM_FIELD_OFFSET_WALK_BACKFILL_OBJECT_FIELD);
        }
    }
    /*
		 * Calculate offsets (from the object header) for hidden fields.  Hidden fields follow immediately the instance fields of the same type.
		 * Give instance fields priority for backfill slots.
		 * Note that the hidden fields remember their offsets, so this need be done once only.
		 */
    if (!hiddenInstanceFieldList.isEmpty()) {
        UDATA hiddenSingleOffset = firstSingleOffset.add(J9Object.SIZEOF + (fieldInfo.getNonBackfilledInstanceSingleCount() * U32.SIZEOF));
        UDATA hiddenDoubleOffset = firstDoubleOffset.add(J9Object.SIZEOF + (fieldInfo.getInstanceDoubleCount() * U64.SIZEOF));
        UDATA hiddenObjectOffset = firstObjectOffset.add(J9Object.SIZEOF + (fieldInfo.getNonBackfilledInstanceObjectCount() * fj9object_t_SizeOf));
        boolean useBackfillForObject = false;
        boolean useBackfillForSingle = false;
        if (fieldInfo.isMyBackfillSlotAvailable() && !walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_BACKFILL_OBJECT_FIELD | J9VM_FIELD_OFFSET_WALK_BACKFILL_SINGLE_FIELD)) {
            /* There are no backfill-suitable instance fields, so let the hidden fields use the backfill slot */
            if (fieldInfo.isBackfillSuitableSingleAvailable()) {
                useBackfillForSingle = true;
            } else if (fieldInfo.isBackfillSuitableObjectAvailable()) {
                useBackfillForObject = true;
            }
        }
        for (HiddenInstanceField hiddenField : hiddenInstanceFieldList) {
            U32 modifiers = hiddenField.shape().modifiers();
            if (modifiers.allBitsIn(J9FieldFlagObject)) {
                if (useBackfillForObject) {
                    hiddenField.setFieldOffset(fieldInfo.getMyBackfillOffsetForHiddenField());
                    useBackfillForObject = false;
                } else {
                    hiddenField.setFieldOffset(hiddenObjectOffset);
                    hiddenObjectOffset = hiddenObjectOffset.add(fj9object_t_SizeOf);
                }
            } else if (modifiers.allBitsIn(J9FieldSizeDouble)) {
                hiddenField.setFieldOffset(hiddenDoubleOffset);
                hiddenDoubleOffset = hiddenDoubleOffset.add(U64.SIZEOF);
            } else {
                if (useBackfillForSingle) {
                    hiddenField.setFieldOffset(fieldInfo.getMyBackfillOffsetForHiddenField());
                    useBackfillForSingle = false;
                } else {
                    hiddenField.setFieldOffset(hiddenSingleOffset);
                    hiddenSingleOffset = hiddenSingleOffset.add(U32.SIZEOF);
                }
            }
        }
    }
    backfillOffsetToUse = new IDATA(fieldInfo.getMyBackfillOffset());
/* backfill offset for this class's fields */
}
Also used : UDATA(com.ibm.j9ddr.vm29.types.UDATA) U32(com.ibm.j9ddr.vm29.types.U32) IDATA(com.ibm.j9ddr.vm29.types.IDATA)

Aggregations

IDATA (com.ibm.j9ddr.vm29.types.IDATA)1 U32 (com.ibm.j9ddr.vm29.types.U32)1 UDATA (com.ibm.j9ddr.vm29.types.UDATA)1