示例#1
0
文件: HeapBase.cs 项目: lhutyra/clrmd
        protected internal override IEnumerable <ClrObjectReference> EnumerateObjectReferencesWithFields(ulong obj, ClrType type, bool carefully)
        {
            if (type == null)
            {
                type = GetObjectType(obj);
            }
            else
            {
                Debug.Assert(type == GetObjectType(obj));
            }

            if (type == null || (!type.ContainsPointers && !type.IsCollectible))
            {
                return(s_emptyObjectReferenceSet);
            }

            List <ClrObjectReference> result = null;

            if (type.ContainsPointers)
            {
                GCDesc gcdesc = type.GCDesc;
                if (gcdesc == null)
                {
                    return(s_emptyObjectReferenceSet);
                }

                ulong size = type.GetSize(obj);
                if (carefully)
                {
                    ClrSegment seg = GetSegmentByAddress(obj);
                    if (seg == null || obj + size > seg.End || (!seg.IsLarge && size > 85000))
                    {
                        return(s_emptyObjectReferenceSet);
                    }
                }

                result = new List <ClrObjectReference>();
                MemoryReader reader = GetMemoryReaderForAddress(obj);
                gcdesc.WalkObject(obj, size, ptr => ReadPointer(reader, ptr), (reference, offset) => result.Add(new ClrObjectReference(offset, reference, GetObjectType(reference))));
            }

            if (type.IsCollectible)
            {
                result ??= new List <ClrObjectReference>(1);
                ulong loaderAllocatorObject = type.LoaderAllocatorObject;
                result.Add(new ClrObjectReference(-1, loaderAllocatorObject, GetObjectType(loaderAllocatorObject)));
            }

            return(result);
        }
示例#2
0
        protected internal override IEnumerable <ClrObject> EnumerateObjectReferences(ulong obj, ClrType type, bool carefully)
        {
            if (type == null)
            {
                type = GetObjectType(obj);
            }
            else
            {
                Debug.Assert(type == GetObjectType(obj));
            }

            if (!type.ContainsPointers)
            {
                return(s_emptyObjectSet);
            }

            GCDesc gcdesc = type.GCDesc;

            if (gcdesc == null)
            {
                return(s_emptyObjectSet);
            }

            ulong size = type.GetSize(obj);

            if (carefully)
            {
                ClrSegment seg = GetSegmentByAddress(obj);
                if (seg == null || obj + size > seg.End || !seg.IsLarge && size > 85000)
                {
                    return(s_emptyObjectSet);
                }
            }

            List <ClrObject> result = new List <ClrObject>();
            MemoryReader     reader = GetMemoryReaderForAddress(obj);

            gcdesc.WalkObject(obj, size, ptr => ReadPointer(reader, ptr), (reference, offset) => result.Add(new ClrObject(reference, GetObjectType(reference))));
            return(result);
        }
示例#3
0
        protected internal override void EnumerateObjectReferences(ulong obj, ClrType type, bool carefully, Action <ulong, int> callback)
        {
            if (type == null)
            {
                type = GetObjectType(obj);
            }
            else
            {
                Debug.Assert(type == GetObjectType(obj));
            }

            if (!type.ContainsPointers)
            {
                return;
            }

            GCDesc gcdesc = type.GCDesc;

            if (gcdesc == null)
            {
                return;
            }

            ulong size = type.GetSize(obj);

            if (carefully)
            {
                ClrSegment seg = GetSegmentByAddress(obj);
                if (seg == null || obj + size > seg.End || !seg.IsLarge && size > 85000)
                {
                    return;
                }
            }

            MemoryReader reader = GetMemoryReaderForAddress(obj);

            gcdesc.WalkObject(obj, size, ptr => ReadPointer(reader, ptr), callback);
        }