public static HeapDumpSegment Deserialize(this HeapDumpSegment input, BinaryReader br)
        {
            (input as HeapRawData).Deserialize(br);
            if (input.RawData[0] == (byte)DumpObjectTag.HEAP_INFO)
            {
                input.SegmentType = DumpSegmentType.ObjectInstance;

                int startIndex = 1;                                                                //原本正常的情况
                input.HeapInfo        = new HeapInfo().Deserialize(input.RawData, ref startIndex); //原本正常的情况
                input.HeapDumpObjects = new List <HeapDumpObject>();
                //int startIndex = 0; //学长的特殊情况,不导出HeapInfo
                while (startIndex < input.RawData.Length)
                {
                    HeapDumpObject newObject = null;
                    var            flag      = input.RawData[startIndex];
                    ++startIndex;
                    switch (flag)
                    {
                    case (byte)DumpObjectTag.CLASS_OBJECT:
                        newObject = new DumpClassObject().Deserialize(input.RawData, ref startIndex, input);
                        break;

                    case (byte)DumpObjectTag.OBJECT_ARRAY:
                        newObject = new DumpObjectArray().Deserialize(input.RawData, ref startIndex);
                        break;

                    case (byte)DumpObjectTag.OBJECT_INSTANCE:
                        newObject = new DumpObjectInstance().Deserialize(input.RawData, ref startIndex);
                        break;

                    case (byte)DumpObjectTag.PRIMITIVE_ARRAY_WITH_DATA:
                        newObject = new DumpPrimitiveArray().Deserialize(input.RawData, ref startIndex);
                        break;

                    case (byte)DumpObjectTag.PRIMITIVE_ARRAY_WITHOUT_DATA:
                        newObject = new DumpPrimitiveArrayNoData().Deserialize(input.RawData, ref startIndex);
                        break;

                    default:
                        throw new Exception("尚未处理的Dump类型: " + input.RawData[startIndex]);
                    }
                    input.HeapDumpObjects.Add(newObject);
                }
            }
            else
            {
                input.SegmentType = DumpSegmentType.RootSet;
            }
            return(input);
        }
Ejemplo n.º 2
0
        public ObjectInstanceInfo(DumpObjectInstance org, HeapFileAnalyzer analyzer)
        {
            ClassObjectID = org.ClassObjectID;
            if (analyzer.ClassObjectInfos.ContainsKey(org.ClassObjectID))
            {
                ClassObject = analyzer.ClassObjectInfos[org.ClassObjectID];
            }
            else if (analyzer.ClassNames.ContainsKey(org.ClassObjectID))
            {
                ClassObject = analyzer.ClassNames[org.ClassObjectID];
            }
            ObjectID = org.ObjectID;

            int length = org.Length;

            #region ClassObject方法 -ClassObjectInfo
            if (ClassObject is ClassObjectInfo)
            {
                int             templength = 0;
                ClassObjectInfo tempClass  = ClassObject as ClassObjectInfo;
                InstanceFields = new List <PrimitiveObjectInfo>();

                while (templength < length)
                {
                    if (tempClass.InstanceFields == null)
                    {
                        break;
                    }
                    foreach (var it in tempClass.InstanceFields)
                    {
                        var value = PrimitiveTypeHelper.GetPrimitiveValue(it.Type, org.InstanceFieldData, ref templength);
                        if (it.Type != PrimitiveType.HPROF_BASIC_OBJECT)
                        {
                            InstanceFields.Add(new PrimitiveObjectInfo()
                            {
                                Name   = it.Name,
                                NameID = it.NameID,
                                Type   = it.Type,
                                Value  = value,
                            });
                        }
                        else
                        {
                            InstanceFields.Add(new ReferenceObjectInfo()
                            {
                                Name            = it.Name,
                                NameID          = it.NameID,
                                Type            = it.Type,
                                Value           = value,
                                ReferenceTarget = null
                            });
                        }
                    }

                    if (!analyzer.ClassObjectInfos.ContainsKey(tempClass.SuperClassObjectID))
                    {
                        break;
                    }
                    tempClass = analyzer.ClassObjectInfos[tempClass.SuperClassObjectID];
                }
            }
            ;
            #endregion

            #region ClassObject方法 -string
            if (ClassObject is string)
            {
                InstanceFields = new List <PrimitiveObjectInfo>();
                if (ClassName == "java.lang.String")
                {
                    int templength = 0;

                    var value = PrimitiveTypeHelper.GetPrimitiveValue(PrimitiveType.HPROF_BASIC_OBJECT, org.InstanceFieldData, ref templength);
                    InstanceFields.Add(new ReferenceObjectInfo()
                    {
                        Name   = "data",
                        NameID = 0,
                        Type   = PrimitiveType.HPROF_BASIC_OBJECT,
                        Value  = value,
                    });
                }
            }
            ;

            if (ClassName == "android.text.SpannableString" && InstanceFields.Count == 0)
            {
                int templength = 0;

                var value = PrimitiveTypeHelper.GetPrimitiveValue(PrimitiveType.HPROF_BASIC_OBJECT, org.InstanceFieldData, ref templength);
                InstanceFields.Add(new ReferenceObjectInfo()
                {
                    Name   = "data",
                    NameID = 0,
                    Type   = PrimitiveType.HPROF_BASIC_OBJECT,
                    Value  = value,
                });
            }
            #endregion
        }