Upstream version 11.39.244.0
[platform/framework/web/crosswalk.git] / src / v8 / src / xdk-allocation.h
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
4 \r
5 #ifndef V8_XDK_ALLOCATION_H_\r
6 #define V8_XDK_ALLOCATION_H_\r
7 \r
8 #include <map>\r
9 #include <string>\r
10 #include "src/base/platform/time.h"\r
11 \r
12 namespace v8 {\r
13 namespace internal {\r
14 \r
15 class HeapObjectsMap;\r
16 class HeapEventXDK;\r
17 class ClassNames;\r
18 class ShadowStack;\r
19 class SymbolsStorage;\r
20 class AggregatedChunks;\r
21 class RuntimeInfo;\r
22 class References;\r
23 class RefSet;\r
24 \r
25 \r
26 class XDKSnapshotFiller: public SnapshotFiller {\r
27  public:\r
28   explicit XDKSnapshotFiller(HeapObjectsMap* heap_object_map,\r
29                              StringsStorage* names,\r
30                              XDKAllocationTracker* allocation_tracker)\r
31       : names_(names),\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
37 \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
42                            int parent,\r
43                            int index,\r
44                            HeapEntry* child_entry);\r
45   void SetIndexedAutoIndexReference(HeapGraphEdge::Type type,\r
46                                     int parent,\r
47                                     HeapEntry* child_entry);\r
48   void SetNamedReference(HeapGraphEdge::Type type,\r
49                          int parent,\r
50                          const char* reference_name,\r
51                          HeapEntry* child_entry);\r
52   void SetNamedAutoIndexReference(HeapGraphEdge::Type type,\r
53                                   int parent,\r
54                                   HeapEntry* child_entry);\r
55 \r
56  private:\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
62 \r
63 \r
64   List<HeapEntry> heap_entries_list_;\r
65 \r
66   HeapEntry* AddEntry(HeapThing thing,\r
67                       HeapObject* object,\r
68                       HeapEntry::Type type,\r
69                       const char* name);\r
70 \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
75   }\r
76   static uint32_t HashInt(int key) {\r
77     return ComputeIntegerHash(key, v8::internal::kZeroHashSeed);\r
78   }\r
79 };\r
80 \r
81 \r
82 class XDKAllocationTracker {\r
83  public:\r
84   XDKAllocationTracker(HeapProfiler* heap_profiler,\r
85                        HeapObjectsMap* ids,\r
86                        StringsStorage* names,\r
87                        int stackDepth,\r
88                        bool collectRetention,\r
89                        bool strict_collection);\r
90   ~XDKAllocationTracker();\r
91 \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
100 \r
101   unsigned FindOrInitClassName(Address address, unsigned ts);\r
102 \r
103  private:\r
104   static const int RETAINED_DELTA = 1000;\r
105 \r
106   // external object\r
107   HeapProfiler* heap_profiler_;\r
108   HeapObjectsMap* ids_;\r
109   StringsStorage* names_;\r
110 \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
116 \r
117   unsigned FindClassName(Address address);\r
118   unsigned InitClassName(Address address, unsigned ts, unsigned size);\r
119 \r
120   SymbolsStorage* symbols_;\r
121   ShadowStack* collectedStacks_;\r
122   ClassNames* classNames_;\r
123 \r
124   unsigned outOfContextFrame_;\r
125   unsigned AllocatedBeforeCollectionFrame_;\r
126 \r
127   v8::base::Time baseTime_;\r
128   unsigned latest_delta_;\r
129   unsigned int GetTimeDelta();\r
130 \r
131   int stackDepth_;\r
132   bool collectRetention_;\r
133   bool strict_collection_;\r
134   References* references_;\r
135   std::map<Address, RefSet> individualReteiners_;\r
136 };\r
137 \r
138 \r
139 class HeapEventXDK {\r
140  public:\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
147   }\r
148 \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
155 \r
156  private:\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
164 };\r
165 \r
166 } }  // namespace v8::internal\r
167 \r
168 #endif  // V8_XDK_ALLOCATION_H_\r