1 // Copyright 2014 the V8 project authors. All rights reserved.
\r
2 // Use of this source code is governed by a BSD-style license that can be
\r
3 // found in the LICENSE file.
\r
5 #ifndef V8_XDK_ALLOCATION_H_
\r
6 #define V8_XDK_ALLOCATION_H_
\r
10 #include "src/base/platform/time.h"
\r
13 namespace internal {
\r
15 class HeapObjectsMap;
\r
19 class SymbolsStorage;
\r
20 class AggregatedChunks;
\r
26 class XDKSnapshotFiller: public SnapshotFiller {
\r
28 explicit XDKSnapshotFiller(HeapObjectsMap* heap_object_map,
\r
29 StringsStorage* names,
\r
30 XDKAllocationTracker* allocation_tracker)
\r
32 heap_object_map_(heap_object_map),
\r
33 allocation_tracker_(allocation_tracker),
\r
34 heap_entries_(HashMap::PointersMatch),
\r
35 index_to_address_(HashMap::PointersMatch) {}
\r
36 virtual ~XDKSnapshotFiller() {}
\r
38 HeapEntry* AddEntry(HeapThing ptr, HeapEntriesAllocator* allocator);
\r
39 HeapEntry* FindEntry(HeapThing thing);
\r
40 HeapEntry* FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator* allocator);
\r
41 void SetIndexedReference(HeapGraphEdge::Type type,
\r
44 HeapEntry* child_entry);
\r
45 void SetIndexedAutoIndexReference(HeapGraphEdge::Type type,
\r
47 HeapEntry* child_entry);
\r
48 void SetNamedReference(HeapGraphEdge::Type type,
\r
50 const char* reference_name,
\r
51 HeapEntry* child_entry);
\r
52 void SetNamedAutoIndexReference(HeapGraphEdge::Type type,
\r
54 HeapEntry* child_entry);
\r
57 StringsStorage* names_;
\r
58 HeapObjectsMap* heap_object_map_;
\r
59 XDKAllocationTracker* allocation_tracker_;
\r
60 HashMap heap_entries_;
\r
61 HashMap index_to_address_;
\r
64 List<HeapEntry> heap_entries_list_;
\r
66 HeapEntry* AddEntry(HeapThing thing,
\r
68 HeapEntry::Type type,
\r
71 static uint32_t Hash(HeapThing thing) {
\r
72 return ComputeIntegerHash(
\r
73 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(thing)),
\r
74 v8::internal::kZeroHashSeed);
\r
76 static uint32_t HashInt(int key) {
\r
77 return ComputeIntegerHash(key, v8::internal::kZeroHashSeed);
\r
82 class XDKAllocationTracker {
\r
84 XDKAllocationTracker(HeapProfiler* heap_profiler,
\r
85 HeapObjectsMap* ids,
\r
86 StringsStorage* names,
\r
88 bool collectRetention,
\r
89 bool strict_collection);
\r
90 ~XDKAllocationTracker();
\r
92 void OnAlloc(Address addr, int size);
\r
93 void OnMove(Address from, Address to, int size);
\r
94 void CollectFreedObjects(bool bAll = false, bool initPreCollect = false);
\r
95 HeapEventXDK* stopTracking();
\r
96 OutputStream::WriteResult SendChunk(OutputStream* stream);
\r
97 unsigned GetTraceNodeId(Address address);
\r
98 void clearIndividualReteiners();
\r
99 std::map<Address, RefSet>* GetIndividualReteiners();
\r
101 unsigned FindOrInitClassName(Address address, unsigned ts);
\r
104 static const int RETAINED_DELTA = 1000;
\r
107 HeapProfiler* heap_profiler_;
\r
108 HeapObjectsMap* ids_;
\r
109 StringsStorage* names_;
\r
111 AggregatedChunks* aggregated_chunks_;
\r
112 RuntimeInfo* runtime_info_;
\r
113 void SerializeChunk(std::string* symbols, std::string* types,
\r
114 std::string* frames, std::string* chunks,
\r
115 std::string* retentions, bool final = false);
\r
117 unsigned FindClassName(Address address);
\r
118 unsigned InitClassName(Address address, unsigned ts, unsigned size);
\r
120 SymbolsStorage* symbols_;
\r
121 ShadowStack* collectedStacks_;
\r
122 ClassNames* classNames_;
\r
124 unsigned outOfContextFrame_;
\r
125 unsigned AllocatedBeforeCollectionFrame_;
\r
127 v8::base::Time baseTime_;
\r
128 unsigned latest_delta_;
\r
129 unsigned int GetTimeDelta();
\r
132 bool collectRetention_;
\r
133 bool strict_collection_;
\r
134 References* references_;
\r
135 std::map<Address, RefSet> individualReteiners_;
\r
139 class HeapEventXDK {
\r
141 HeapEventXDK(unsigned int duration,
\r
142 const std::string& symbols, const std::string& types,
\r
143 const std::string& frames, const std::string& chunks,
\r
144 const std::string& retentions) :
\r
145 symbols_(symbols), types_(types), frames_(frames), chunks_(chunks),
\r
146 duration_(duration), retentions_(retentions) {
\r
149 unsigned int duration() const {return duration_; }
\r
150 const char* symbols() const { return symbols_.c_str(); }
\r
151 const char* types() const { return types_.c_str(); }
\r
152 const char* frames() const { return frames_.c_str(); }
\r
153 const char* chunks() const { return chunks_.c_str(); }
\r
154 const char* retentions() const { return retentions_.c_str(); }
\r
157 std::string symbols_;
\r
158 std::string types_;
\r
159 std::string frames_;
\r
160 std::string chunks_;
\r
161 unsigned int duration_;
\r
162 std::string retentions_;
\r
163 DISALLOW_COPY_AND_ASSIGN(HeapEventXDK);
\r
166 } } // namespace v8::internal
\r
168 #endif // V8_XDK_ALLOCATION_H_
\r