Beispiel #1
0
 public ClassObjectInfo(DumpClassObject org, HeapFileAnalyzer analyzer)
 {
     ClassObjectID      = org.ClassObjectID;
     ClassName          = analyzer.ClassNames[org.ClassObjectID];
     SuperClassObjectID = org.SuperClassObjectID;
     SuperClassName     = analyzer.ClassNames.ContainsKey(SuperClassObjectID) ?
                          analyzer.ClassNames[org.SuperClassObjectID] :
                          "未找到基类名称";
     if (org.StaticFieldContent.StaticFields != null)
     {
         StaticFields = org.StaticFieldContent.StaticFields.Select(c =>
                                                                   new PrimitiveObjectInfo()
         {
             NameID = c.NameID,
             Name   = analyzer.StringDatas[c.NameID],
             Type   = c.Type,
             Value  = c.Value,
         }).ToList();
     }
     if (org.InstanceFieldContent.InstanceFields != null)
     {
         InstanceFields = org.InstanceFieldContent.InstanceFields.Select(c =>
                                                                         new PrimitiveObjectInfo()
         {
             NameID = c.NameID,
             Name   = analyzer.StringDatas[c.NameID],
             Type   = c.Type,
         }).ToList();
     }
 }
        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);
        }