1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef __xdk_utils_h__
6 #define __xdk_utils_h__
12 #include "src/hashmap.h"
17 class AggregatedChunks;
19 class JavaScriptFrame;
25 explicit ClassNames(StringsStorage* names, Heap* heap);
27 unsigned registerName(const char* className);
28 std::string SerializeChunk();
29 bool IsEssentialObject(Object* object);
30 void registerNameForDependent(HeapObject* object,
31 RuntimeInfo* runtime_info,
33 unsigned GetConstructorName(Address address, RuntimeInfo* runtime_info);
39 StringsStorage* names_;
42 unsigned id_native_bind_;
43 unsigned id_conc_string_;
44 unsigned id_sliced_string_;
48 unsigned id_system_ncontext_;
49 unsigned id_system_context_;
53 unsigned id_shared_fi_;
56 unsigned id_function_bindings_;
57 unsigned id_function_literals_;
58 unsigned id_objects_properties_;
59 unsigned id_objects_elements_;
60 unsigned id_shared_function_info_;
62 unsigned id_code_relocation_info_;
63 unsigned id_code_deopt_data_;
70 // For quick search we use below member. it is not reasnable to use here
71 // map because it occupies a lot of space even in empty state and such nodes
72 // will be many. In opposite to map, std::map uses binary tree search and
73 // don't store buffer, but allocates it dinamically
74 std::map<unsigned, CallTree*> children_;
76 // This is _not_ the same as index in the children_. This index is
77 // incremental value from list of all nodes, but the key in the children_ is
81 // the only one field which characterize the call point
89 // unsigned here is ok, size_t is not required because even 10 millions
90 // objects in this class will lead to the significant memory consumption
93 // TODO(amalyshe): rewrite using List, storing nodes and use index in the list
94 // instead pointer to CallTree in the children_
95 std::map<unsigned, CallTree*> allNodes_;
96 unsigned serializedCounter_;
100 // Returns unique stack id. This method can work with incremental stacks when
101 // we have old stack id, new tail and number of functions that we need to
103 unsigned registerStack(const List<unsigned>& shadow_stack_);
104 std::string SerializeChunk();
108 // --- SymbolsStorage
115 bool inline operator == (const SymInfoKey& key1, const SymInfoKey& key2) {
116 return key1.function_id_ == key2.function_id_ &&
117 key1.line_ == key2.line_ &&
118 key1.column_ == key2.column_;
122 struct SymInfoValue {
124 std::string funcName_;
125 std::string sourceFile_;
129 class SymbolsStorage {
131 unsigned registerSymInfo(size_t functionId,
132 std::string functionName,
133 std::string sourceName, unsigned line,
135 unsigned FindOrRegisterFrame(JavaScriptFrame* frame);
136 SymbolsStorage(Heap* heap, StringsStorage* names);
138 std::string SerializeChunk();
143 // fast living storage which duplicate info but is cleaned regularly
144 SymInfoKey* reserved_key_;
145 HashMap sym_info_hash_;
147 StringsStorage* names_;
151 struct PostCollectedInfo {
162 explicit RuntimeInfo(AggregatedChunks* aggregated_chunks);
163 PostCollectedInfo* FindPostCollectedInfo(Address addr);
164 PostCollectedInfo* AddPostCollectedInfo(Address addr,
165 unsigned time_delta = 0,
166 PostCollectedInfo* info = NULL);
167 PostCollectedInfo* AddPreCollectionInfo(Address addr, unsigned size);
168 void RemoveInfo(Address addr);
169 void InitABCFrame(unsigned abc_frame);
170 void CollectGarbaged(unsigned ts);
173 HashMap working_set_hash_;
174 AggregatedChunks* aggregated_chunks_;
175 unsigned AllocatedBeforeCollectionFrame_;
179 struct AggregatedKey {
181 // do we need class here? is not it defined by the stack id?
187 bool inline operator == (const AggregatedKey& key1, const AggregatedKey& key2) {
188 return key1.stackId_ == key2.stackId_ &&
189 key1.classId_ == key2.classId_ &&
190 key1.tsBegin_ == key2.tsBegin_ &&
191 key1.tsEnd_ == key2.tsEnd_;
195 struct AggregatedValue {
201 class AggregatedChunks {
205 void addObjectToAggregated(PostCollectedInfo* info, unsigned td);
206 std::string SerializeChunk();
209 HashMap aggregated_map_;
211 AggregatedKey* reserved_key_;
221 inline bool operator < (const RefId& first, const RefId& second ) {
222 if (first.stackId_ < second.stackId_ )
224 else if (first.stackId_ > second.stackId_ )
226 if (first.classId_ < second.classId_ )
228 if (first.classId_ > second.classId_ )
230 if (first.field_.compare(second.field_) < 0 )
236 typedef std::set<RefId> REFERENCESET;
240 REFERENCESET references_;
243 inline bool operator < (const RefSet& first, const RefSet& second) {
244 // compare the sizes first of all
245 if (first.references_.size() != second.references_.size() )
246 return first.references_.size() < second.references_.size();
247 // iterating by the first
248 REFERENCESET::const_iterator cit1 = first.references_.begin();
249 REFERENCESET::const_iterator cit2 = second.references_.begin();
250 while (cit1 != first.references_.end()) {
260 typedef std::map<unsigned int, int> TIMETOCOUNT;
261 typedef std::map<RefSet, TIMETOCOUNT> REFERENCESETS;
262 typedef std::map<RefId, REFERENCESETS> PARENTREFMAP;
267 void addReference(const RefId& parent,
268 const RefSet& refSet,
271 std::string serialize() const;
274 PARENTREFMAP refMap_;
278 } } // namespace v8::internal
279 #endif // __xdk_utils_h__