OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 }; | 46 }; |
47 | 47 |
48 | 48 |
49 // JSObjectsCluster describes a group of JS objects that are | 49 // JSObjectsCluster describes a group of JS objects that are |
50 // considered equivalent in terms of a particular profile. | 50 // considered equivalent in terms of a particular profile. |
51 class JSObjectsCluster BASE_EMBEDDED { | 51 class JSObjectsCluster BASE_EMBEDDED { |
52 public: | 52 public: |
53 // These special cases are used in retainer profile. | 53 // These special cases are used in retainer profile. |
54 enum SpecialCase { | 54 enum SpecialCase { |
55 ROOTS = 1, | 55 ROOTS = 1, |
56 GLOBAL_PROPERTY = 2 | 56 GLOBAL_PROPERTY = 2, |
| 57 SELF = 3 // This case is used in ClustersCoarser only. |
57 }; | 58 }; |
58 | 59 |
59 JSObjectsCluster() : constructor_(NULL), instance_(NULL) {} | 60 JSObjectsCluster() : constructor_(NULL), instance_(NULL) {} |
60 explicit JSObjectsCluster(String* constructor) | 61 explicit JSObjectsCluster(String* constructor) |
61 : constructor_(constructor), instance_(NULL) {} | 62 : constructor_(constructor), instance_(NULL) {} |
62 explicit JSObjectsCluster(SpecialCase special) | 63 explicit JSObjectsCluster(SpecialCase special) |
63 : constructor_(FromSpecialCase(special)), instance_(NULL) {} | 64 : constructor_(FromSpecialCase(special)), instance_(NULL) {} |
64 JSObjectsCluster(String* constructor, Object* instance) | 65 JSObjectsCluster(String* constructor, Object* instance) |
65 : constructor_(constructor), instance_(instance) {} | 66 : constructor_(constructor), instance_(instance) {} |
66 | 67 |
67 static int CompareConstructors(const JSObjectsCluster& a, | 68 static int CompareConstructors(const JSObjectsCluster& a, |
68 const JSObjectsCluster& b) { | 69 const JSObjectsCluster& b) { |
69 // Strings are unique, so it is sufficient to compare their pointers. | 70 // Strings are unique, so it is sufficient to compare their pointers. |
70 return a.constructor_ == b.constructor_ ? 0 | 71 return a.constructor_ == b.constructor_ ? 0 |
71 : (a.constructor_ < b.constructor_ ? -1 : 1); | 72 : (a.constructor_ < b.constructor_ ? -1 : 1); |
72 } | 73 } |
73 static int Compare(const JSObjectsCluster& a, const JSObjectsCluster& b) { | 74 static int Compare(const JSObjectsCluster& a, const JSObjectsCluster& b) { |
74 // Strings are unique, so it is sufficient to compare their pointers. | 75 // Strings are unique, so it is sufficient to compare their pointers. |
75 const int cons_cmp = CompareConstructors(a, b); | 76 const int cons_cmp = CompareConstructors(a, b); |
76 return cons_cmp == 0 ? | 77 return cons_cmp == 0 ? |
77 (a.instance_ == b.instance_ ? 0 : (a.instance_ < b.instance_ ? -1 : 1)) | 78 (a.instance_ == b.instance_ ? 0 : (a.instance_ < b.instance_ ? -1 : 1)) |
78 : cons_cmp; | 79 : cons_cmp; |
79 } | 80 } |
| 81 static int Compare(const JSObjectsCluster* a, const JSObjectsCluster* b) { |
| 82 return Compare(*a, *b); |
| 83 } |
80 | 84 |
81 bool is_null() const { return constructor_ == NULL; } | 85 bool is_null() const { return constructor_ == NULL; } |
82 bool can_be_coarsed() const { return instance_ != NULL; } | 86 bool can_be_coarsed() const { return instance_ != NULL; } |
83 String* constructor() const { return constructor_; } | 87 String* constructor() const { return constructor_; } |
84 | 88 |
85 void Print(StringStream* accumulator) const; | 89 void Print(StringStream* accumulator) const; |
86 // Allows null clusters to be printed. | 90 // Allows null clusters to be printed. |
87 void DebugPrint(StringStream* accumulator) const; | 91 void DebugPrint(StringStream* accumulator) const; |
88 | 92 |
89 private: | 93 private: |
90 static String* FromSpecialCase(SpecialCase special) { | 94 static String* FromSpecialCase(SpecialCase special) { |
91 // We use symbols that are illegal JS identifiers to identify special cases. | 95 // We use symbols that are illegal JS identifiers to identify special cases. |
92 // Their actual value is irrelevant for us. | 96 // Their actual value is irrelevant for us. |
93 switch (special) { | 97 switch (special) { |
94 case ROOTS: return Heap::result_symbol(); | 98 case ROOTS: return Heap::result_symbol(); |
95 case GLOBAL_PROPERTY: return Heap::code_symbol(); | 99 case GLOBAL_PROPERTY: return Heap::code_symbol(); |
| 100 case SELF: return Heap::catch_var_symbol(); |
96 default: | 101 default: |
97 UNREACHABLE(); | 102 UNREACHABLE(); |
98 return NULL; | 103 return NULL; |
99 } | 104 } |
100 } | 105 } |
101 | 106 |
102 String* constructor_; | 107 String* constructor_; |
103 Object* instance_; | 108 Object* instance_; |
104 }; | 109 }; |
105 | 110 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 const NumberAndSizeInfo& number_and_size); | 181 const NumberAndSizeInfo& number_and_size); |
177 | 182 |
178 private: | 183 private: |
179 // Stores a list of back references for a cluster. | 184 // Stores a list of back references for a cluster. |
180 struct ClusterBackRefs { | 185 struct ClusterBackRefs { |
181 explicit ClusterBackRefs(const JSObjectsCluster& cluster_); | 186 explicit ClusterBackRefs(const JSObjectsCluster& cluster_); |
182 ClusterBackRefs(const ClusterBackRefs& src); | 187 ClusterBackRefs(const ClusterBackRefs& src); |
183 ClusterBackRefs& operator=(const ClusterBackRefs& src); | 188 ClusterBackRefs& operator=(const ClusterBackRefs& src); |
184 | 189 |
185 static int Compare(const ClusterBackRefs& a, const ClusterBackRefs& b); | 190 static int Compare(const ClusterBackRefs& a, const ClusterBackRefs& b); |
| 191 void SortRefs() { refs.Sort(JSObjectsCluster::Compare); } |
| 192 static void SortRefsIterator(ClusterBackRefs* ref) { ref->SortRefs(); } |
186 | 193 |
187 JSObjectsCluster cluster; | 194 JSObjectsCluster cluster; |
188 ZoneList<JSObjectsCluster> refs; | 195 ZoneList<JSObjectsCluster> refs; |
189 }; | 196 }; |
190 typedef ZoneList<ClusterBackRefs> SimilarityList; | 197 typedef ZoneList<ClusterBackRefs> SimilarityList; |
191 | 198 |
192 // A tree for storing a list of equivalents for a cluster. | 199 // A tree for storing a list of equivalents for a cluster. |
193 struct ClusterEqualityConfig { | 200 struct ClusterEqualityConfig { |
194 typedef JSObjectsCluster Key; | 201 typedef JSObjectsCluster Key; |
195 typedef JSObjectsCluster Value; | 202 typedef JSObjectsCluster Value; |
(...skipping 16 matching lines...) Expand all Loading... |
212 static const int kInitialSimilarityListCapacity = 2000; | 219 static const int kInitialSimilarityListCapacity = 2000; |
213 // Number of passes for finding equivalents. Limits the length of paths | 220 // Number of passes for finding equivalents. Limits the length of paths |
214 // that can be considered equivalent. | 221 // that can be considered equivalent. |
215 static const int kMaxPassesCount = 10; | 222 static const int kMaxPassesCount = 10; |
216 | 223 |
217 ZoneScope zscope_; | 224 ZoneScope zscope_; |
218 SimilarityList sim_list_; | 225 SimilarityList sim_list_; |
219 EqualityTree eq_tree_; | 226 EqualityTree eq_tree_; |
220 ClusterBackRefs* current_pair_; | 227 ClusterBackRefs* current_pair_; |
221 JSObjectsRetainerTree* current_set_; | 228 JSObjectsRetainerTree* current_set_; |
| 229 const JSObjectsCluster* self_; |
222 }; | 230 }; |
223 | 231 |
224 | 232 |
225 // RetainerHeapProfile is responsible for gathering and logging | 233 // RetainerHeapProfile is responsible for gathering and logging |
226 // "retainer profile" of JS objects allocated on heap. | 234 // "retainer profile" of JS objects allocated on heap. |
227 // It is run during garbage collection cycle, thus it doesn't need | 235 // It is run during garbage collection cycle, thus it doesn't need |
228 // to use handles. | 236 // to use handles. |
229 class RetainerHeapProfile BASE_EMBEDDED { | 237 class RetainerHeapProfile BASE_EMBEDDED { |
230 public: | 238 public: |
231 class Printer { | 239 class Printer { |
232 public: | 240 public: |
233 virtual ~Printer() {} | 241 virtual ~Printer() {} |
234 virtual void PrintRetainers(const JSObjectsCluster& cluster, | 242 virtual void PrintRetainers(const JSObjectsCluster& cluster, |
235 const StringStream& retainers) = 0; | 243 const StringStream& retainers) = 0; |
236 }; | 244 }; |
237 | 245 |
238 RetainerHeapProfile(); | 246 RetainerHeapProfile(); |
239 void CollectStats(HeapObject* obj); | 247 void CollectStats(HeapObject* obj); |
240 void PrintStats(); | 248 void PrintStats(); |
241 void DebugPrintStats(Printer* printer); | 249 void DebugPrintStats(Printer* printer); |
242 void StoreReference(const JSObjectsCluster& cluster, HeapObject* ref); | 250 void StoreReference(const JSObjectsCluster& cluster, HeapObject* ref); |
243 | 251 |
244 private: | 252 private: |
245 // Limit on the number of retainers to be printed per cluster. | |
246 static const int kMaxRetainersToPrint = 50; | |
247 ZoneScope zscope_; | 253 ZoneScope zscope_; |
248 JSObjectsRetainerTree retainers_tree_; | 254 JSObjectsRetainerTree retainers_tree_; |
249 ClustersCoarser coarser_; | 255 ClustersCoarser coarser_; |
250 // TODO(mnaganov): Use some helper class to hold these state variables. | |
251 JSObjectsClusterTree* coarse_cluster_tree_; | |
252 Printer* current_printer_; | |
253 StringStream* current_stream_; | |
254 public: | |
255 // Used by JSObjectsRetainerTree::ForEach. | |
256 void Call(const JSObjectsCluster& cluster, JSObjectsClusterTree* tree); | |
257 void Call(const JSObjectsCluster& cluster, | |
258 const NumberAndSizeInfo& number_and_size); | |
259 }; | 256 }; |
260 | 257 |
261 | 258 |
262 #endif // ENABLE_LOGGING_AND_PROFILING | 259 #endif // ENABLE_LOGGING_AND_PROFILING |
263 | 260 |
264 } } // namespace v8::internal | 261 } } // namespace v8::internal |
265 | 262 |
266 #endif // V8_HEAP_PROFILER_H_ | 263 #endif // V8_HEAP_PROFILER_H_ |
OLD | NEW |