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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 if (!is_null()) { | 180 if (!is_null()) { |
181 Print(accumulator); | 181 Print(accumulator); |
182 } else { | 182 } else { |
183 accumulator->Add("(null cluster)"); | 183 accumulator->Add("(null cluster)"); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 | 187 |
188 inline ClustersCoarser::ClusterBackRefs::ClusterBackRefs( | 188 inline ClustersCoarser::ClusterBackRefs::ClusterBackRefs( |
189 const JSObjectsCluster& cluster_) | 189 const JSObjectsCluster& cluster_) |
190 : cluster(cluster_), refs(INITIAL_BACKREFS_LIST_CAPACITY) { | 190 : cluster(cluster_), refs(kInitialBackrefsListCapacity) { |
191 } | 191 } |
192 | 192 |
193 | 193 |
194 inline ClustersCoarser::ClusterBackRefs::ClusterBackRefs( | 194 inline ClustersCoarser::ClusterBackRefs::ClusterBackRefs( |
195 const ClustersCoarser::ClusterBackRefs::ClusterBackRefs& src) | 195 const ClustersCoarser::ClusterBackRefs::ClusterBackRefs& src) |
196 : cluster(src.cluster), refs(src.refs.capacity()) { | 196 : cluster(src.cluster), refs(src.refs.capacity()) { |
197 refs.AddAll(src.refs); | 197 refs.AddAll(src.refs); |
198 } | 198 } |
199 | 199 |
200 | 200 |
(...skipping 18 matching lines...) Expand all Loading... | |
219 for (int i = 0; i < a.refs.length(); ++i) { | 219 for (int i = 0; i < a.refs.length(); ++i) { |
220 int cmp = JSObjectsCluster::Compare(a.refs[i], b.refs[i]); | 220 int cmp = JSObjectsCluster::Compare(a.refs[i], b.refs[i]); |
221 if (cmp != 0) return cmp; | 221 if (cmp != 0) return cmp; |
222 } | 222 } |
223 return 0; | 223 return 0; |
224 } | 224 } |
225 | 225 |
226 | 226 |
227 ClustersCoarser::ClustersCoarser() | 227 ClustersCoarser::ClustersCoarser() |
228 : zscope_(DELETE_ON_EXIT), | 228 : zscope_(DELETE_ON_EXIT), |
229 simList_(ClustersCoarser::INITIAL_SIMILARITY_LIST_CAPACITY), | 229 simList_(ClustersCoarser::kInitialSimilarityListCapacity), |
230 currentPair_(NULL) { | 230 currentPair_(NULL) { |
231 } | 231 } |
232 | 232 |
233 | 233 |
234 void ClustersCoarser::Call( | 234 void ClustersCoarser::Call( |
235 const JSObjectsCluster& cluster, JSObjectsClusterTree* tree) { | 235 const JSObjectsCluster& cluster, JSObjectsClusterTree* tree) { |
236 if (tree != NULL) { | 236 if (tree != NULL) { |
237 // First level of retainer graph. | 237 // First level of retainer graph. |
238 if (!cluster.can_be_coarsed()) return; | 238 if (!cluster.can_be_coarsed()) return; |
239 ClusterBackRefs pair(cluster); | 239 ClusterBackRefs pair(cluster); |
(...skipping 16 matching lines...) Expand all Loading... | |
256 currentSet_->Insert(eq, &loc); | 256 currentSet_->Insert(eq, &loc); |
257 } else { | 257 } else { |
258 currentPair_->refs.Add(cluster); | 258 currentPair_->refs.Add(cluster); |
259 } | 259 } |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 | 263 |
264 void ClustersCoarser::Process(JSObjectsClusterTree* tree) { | 264 void ClustersCoarser::Process(JSObjectsClusterTree* tree) { |
265 int last_eq_clusters = -1; | 265 int last_eq_clusters = -1; |
266 for (int i = 0; i < MAX_PASSES_COUNT; ++i) { | 266 for (int i = 0; i < kMaxPassesCount; ++i) { |
267 simList_.Clear(); | 267 simList_.Clear(); |
268 const int curr_eq_clusters = DoProcess(tree); | 268 const int curr_eq_clusters = DoProcess(tree); |
269 // If no new cluster equivalents discovered, abort processing. | 269 // If no new cluster equivalents discovered, abort processing. |
270 if (last_eq_clusters == curr_eq_clusters) break; | 270 if (last_eq_clusters == curr_eq_clusters) break; |
271 last_eq_clusters = curr_eq_clusters; | 271 last_eq_clusters = curr_eq_clusters; |
272 } | 272 } |
273 } | 273 } |
274 | 274 |
275 | 275 |
276 int ClustersCoarser::DoProcess(JSObjectsClusterTree* tree) { | 276 int ClustersCoarser::DoProcess(JSObjectsClusterTree* tree) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 const JSObjectsClusterTreeConfig::Value JSObjectsClusterTreeConfig::kNoValue = | 332 const JSObjectsClusterTreeConfig::Value JSObjectsClusterTreeConfig::kNoValue = |
333 NULL; | 333 NULL; |
334 | 334 |
335 | 335 |
336 RetainerHeapProfile::RetainerHeapProfile() | 336 RetainerHeapProfile::RetainerHeapProfile() |
337 : zscope_(DELETE_ON_EXIT), | 337 : zscope_(DELETE_ON_EXIT), |
338 coarse_cluster_tree_(NULL), | 338 coarse_cluster_tree_(NULL), |
339 retainers_printed_(0), | 339 retainers_printed_(0), |
340 current_printer_(NULL), | 340 current_printer_(NULL), |
341 current_stream_(NULL) { | 341 current_stream_(NULL) { |
342 JSObjectsCluster roots(JSObjectsCluster::ROOTS); | |
342 ReferencesExtractor extractor( | 343 ReferencesExtractor extractor( |
Søren Thygesen Gjesse
2009/09/16 15:04:07
This can be one line now.
| |
343 JSObjectsCluster(JSObjectsCluster::ROOTS), this); | 344 roots, this); |
344 Heap::IterateRoots(&extractor); | 345 Heap::IterateRoots(&extractor); |
345 } | 346 } |
346 | 347 |
347 | 348 |
348 JSObjectsCluster RetainerHeapProfile::Clusterize(Object* obj) { | 349 JSObjectsCluster RetainerHeapProfile::Clusterize(Object* obj) { |
349 if (obj->IsJSObject()) { | 350 if (obj->IsJSObject()) { |
350 String* constructor = JSObject::cast(obj)->constructor_name(); | 351 String* constructor = JSObject::cast(obj)->constructor_name(); |
351 // Differentiate Object and Array instances. | 352 // Differentiate Object and Array instances. |
352 if (constructor == Heap::Object_symbol() || | 353 if (constructor == Heap::Object_symbol() || |
353 constructor == Heap::Array_symbol()) { | 354 constructor == Heap::Array_symbol()) { |
(...skipping 23 matching lines...) Expand all Loading... | |
377 referencedBy->Insert(cluster, &obj_loc); | 378 referencedBy->Insert(cluster, &obj_loc); |
378 } | 379 } |
379 | 380 |
380 | 381 |
381 void RetainerHeapProfile::CollectStats(HeapObject* obj) { | 382 void RetainerHeapProfile::CollectStats(HeapObject* obj) { |
382 if (obj->IsJSObject()) { | 383 if (obj->IsJSObject()) { |
383 const JSObjectsCluster cluster = Clusterize(JSObject::cast(obj)); | 384 const JSObjectsCluster cluster = Clusterize(JSObject::cast(obj)); |
384 ReferencesExtractor extractor(cluster, this); | 385 ReferencesExtractor extractor(cluster, this); |
385 obj->Iterate(&extractor); | 386 obj->Iterate(&extractor); |
386 } else if (obj->IsJSGlobalPropertyCell()) { | 387 } else if (obj->IsJSGlobalPropertyCell()) { |
387 ReferencesExtractor extractor( | 388 JSObjectsCluster global_prop(JSObjectsCluster::GLOBAL_PROPERTY); |
388 JSObjectsCluster(JSObjectsCluster::GLOBAL_PROPERTY), this); | 389 ReferencesExtractor extractor(global_prop, this); |
389 obj->Iterate(&extractor); | 390 obj->Iterate(&extractor); |
390 } | 391 } |
391 } | 392 } |
392 | 393 |
393 | 394 |
394 void RetainerHeapProfile::DebugPrintStats( | 395 void RetainerHeapProfile::DebugPrintStats( |
395 RetainerHeapProfile::Printer* printer) { | 396 RetainerHeapProfile::Printer* printer) { |
396 coarser_.Process(&retainers_tree_); | 397 coarser_.Process(&retainers_tree_); |
397 ASSERT(current_printer_ == NULL); | 398 ASSERT(current_printer_ == NULL); |
398 current_printer_ = printer; | 399 current_printer_ = printer; |
(...skipping 24 matching lines...) Expand all Loading... | |
423 coarse_cluster_tree_ = new JSObjectsClusterTree(); | 424 coarse_cluster_tree_ = new JSObjectsClusterTree(); |
424 retainers_printed_ = 0; | 425 retainers_printed_ = 0; |
425 tree->ForEach(this); | 426 tree->ForEach(this); |
426 coarse_cluster_tree_ = NULL; | 427 coarse_cluster_tree_ = NULL; |
427 current_printer_->PrintRetainers(stream); | 428 current_printer_->PrintRetainers(stream); |
428 current_stream_ = NULL; | 429 current_stream_ = NULL; |
429 } else { | 430 } else { |
430 // Second level of retainer graph. | 431 // Second level of retainer graph. |
431 ASSERT(coarse_cluster_tree_ != NULL); | 432 ASSERT(coarse_cluster_tree_ != NULL); |
432 ASSERT(current_stream_ != NULL); | 433 ASSERT(current_stream_ != NULL); |
433 if (retainers_printed_ >= MAX_RETAINERS_TO_PRINT) { | 434 if (retainers_printed_ >= kMaxRetainersToPrint) { |
434 if (retainers_printed_ == MAX_RETAINERS_TO_PRINT) { | 435 if (retainers_printed_ == kMaxRetainersToPrint) { |
435 // TODO(mnaganov): Print the exact count. | 436 // TODO(mnaganov): Print the exact count. |
436 current_stream_->Add(",..."); | 437 current_stream_->Add(",..."); |
437 ++retainers_printed_; // avoid printing ellipsis next time. | 438 ++retainers_printed_; // avoid printing ellipsis next time. |
438 } | 439 } |
439 return; | 440 return; |
440 } | 441 } |
441 JSObjectsCluster eq = coarser_.GetCoarseEquivalent(cluster); | 442 JSObjectsCluster eq = coarser_.GetCoarseEquivalent(cluster); |
442 if (eq.is_null()) { | 443 if (eq.is_null()) { |
443 current_stream_->Put(','); | 444 current_stream_->Put(','); |
444 cluster.Print(current_stream_); | 445 cluster.Print(current_stream_); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 js_retainer_profile.PrintStats(); | 510 js_retainer_profile.PrintStats(); |
510 | 511 |
511 LOG(HeapSampleEndEvent("Heap", "allocated")); | 512 LOG(HeapSampleEndEvent("Heap", "allocated")); |
512 } | 513 } |
513 | 514 |
514 | 515 |
515 #endif // ENABLE_LOGGING_AND_PROFILING | 516 #endif // ENABLE_LOGGING_AND_PROFILING |
516 | 517 |
517 | 518 |
518 } } // namespace v8::internal | 519 } } // namespace v8::internal |
OLD | NEW |