2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef HeapGraphSerializer_h
32 #define HeapGraphSerializer_h
36 #include "InspectorFrontend.h"
37 #include <wtf/Forward.h>
38 #include <wtf/HashMap.h>
39 #include <wtf/MemoryInstrumentation.h>
40 #include <wtf/Noncopyable.h>
41 #include <wtf/Vector.h>
42 #include <wtf/text/StringHash.h>
46 class HeapGraphSerializer {
47 WTF_MAKE_NONCOPYABLE(HeapGraphSerializer);
53 virtual void addNativeSnapshotChunk(PassRefPtr<TypeBuilder::Memory::HeapSnapshotChunk>) = 0;
56 explicit HeapGraphSerializer(Client*);
57 ~HeapGraphSerializer();
58 void reportNode(const WTF::MemoryObjectInfo&);
59 void reportEdge(const void*, const char*, WTF::MemberType);
60 void reportLeaf(const WTF::MemoryObjectInfo&, const char*);
61 void reportBaseAddress(const void*, const void*);
65 void reportMemoryUsage(MemoryObjectInfo*) const;
68 void pushUpdateIfNeeded();
71 int toNodeId(const void*);
73 int addString(const String&);
76 void reportEdgeImpl(const int toNodeId, const char* name, int memberType);
77 int reportNodeImpl(const WTF::MemoryObjectInfo&, int edgesCount);
81 typedef HashMap<String, int> StringMap;
82 StringMap m_stringToIndex;
83 typedef TypeBuilder::Array<String> Strings;
84 RefPtr<Strings> m_strings;
86 typedef TypeBuilder::Array<int> Edges;
87 RefPtr<Edges> m_edges;
89 static const size_t s_edgeFieldsCount = 3;
91 typedef TypeBuilder::Array<int> Nodes;
92 RefPtr<Nodes> m_nodes;
93 static const size_t s_nodeFieldsCount = 5;
95 typedef TypeBuilder::Array<int> BaseToRealNodeIdMap;
96 RefPtr<BaseToRealNodeIdMap> m_baseToRealNodeIdMap;
97 static const size_t s_idMapEntryFieldCount = 2;
99 typedef HashMap<const void*, int> Address2NodeId;
100 Address2NodeId m_address2NodeIdMap;
102 Vector<const void*> m_roots;
104 size_t m_edgeTypes[WTF::LastMemberTypeEntry];
105 int m_unknownClassNameId;
108 static const int s_firstNodeId = 1;
111 } // namespace WebCore
113 #endif // !ENABLE(INSPECTOR)
114 #endif // !defined(HeapGraphSerializer_h)