コード例 #1
0
        /// <summary>
        /// Reads the minimal information about type layout encoded in the
        /// MethodTable. That doesn't include field information.
        /// </summary>
        public unsafe override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType type, InstanceLayoutKind layoutKind)
        {
            // If we need the field information, delegate to the native layout algorithm or metadata algorithm
            if (layoutKind != InstanceLayoutKind.TypeOnly)
            {
                if (type.HasNativeLayout)
                {
                    return(s_nativeLayoutFieldAlgorithm.ComputeInstanceLayout(type, layoutKind));
                }
                else
                {
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
                    return(_metadataFieldLayoutAlgorithm.ComputeInstanceLayout(type, layoutKind));
#else
                    Debug.Assert(false);
                    return(default);
コード例 #2
0
        /// <summary>
        /// Reads the minimal information about type layout encoded in the
        /// EEType. That doesn't include field information.
        /// </summary>
        public unsafe override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType type, InstanceLayoutKind layoutKind)
        {
            // If we need the field information, delegate to the native layout algorithm or metadata algorithm
            if (layoutKind != InstanceLayoutKind.TypeOnly)
            {
                if (type.HasNativeLayout)
                {
                    return(s_nativeLayoutFieldAlgorithm.ComputeInstanceLayout(type, layoutKind));
                }
                else
                {
                    return(_metadataFieldLayoutAlgorithm.ComputeInstanceLayout(type, layoutKind));
                }
            }

            type.RetrieveRuntimeTypeHandleIfPossible();
            Debug.Assert(!type.RuntimeTypeHandle.IsNull());
            EEType *eeType = type.RuntimeTypeHandle.ToEETypePtr();

            ComputedInstanceFieldLayout layout = new ComputedInstanceFieldLayout()
            {
                ByteCountAlignment = new LayoutInt(IntPtr.Size),
                ByteCountUnaligned = new LayoutInt(eeType->IsInterface ? IntPtr.Size : checked ((int)eeType->FieldByteCountNonGCAligned)),
                FieldAlignment     = new LayoutInt(eeType->FieldAlignmentRequirement),
                Offsets            = (layoutKind == InstanceLayoutKind.TypeOnly) ? null : Array.Empty <FieldAndOffset>(), // No fields in EETypes
                PackValue          = 0,                                                                                   // This isn't explicitly encoded, though FieldSize should take it into account
                // TODO, as we add more metadata handling logic, find out if its necessary.
            };

            if (eeType->IsValueType)
            {
                int valueTypeSize = checked ((int)eeType->ValueTypeSize);
                layout.FieldSize = new LayoutInt(valueTypeSize);
            }
            else
            {
                layout.FieldSize = new LayoutInt(IntPtr.Size);
            }

            if ((eeType->RareFlags & EETypeRareFlags.RequiresAlign8Flag) == EETypeRareFlags.RequiresAlign8Flag)
            {
                layout.ByteCountAlignment = new LayoutInt(8);
            }

            return(layout);
        }