Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: src/heap-snapshot-generator.h

Issue 196133017: Experimental parser: merge r19949 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap-profiler.cc ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 19 matching lines...) Expand all
30 30
31 #include "profile-generator-inl.h" 31 #include "profile-generator-inl.h"
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 class AllocationTracker; 36 class AllocationTracker;
37 class AllocationTraceNode; 37 class AllocationTraceNode;
38 class HeapEntry; 38 class HeapEntry;
39 class HeapSnapshot; 39 class HeapSnapshot;
40 class SnapshotFiller;
40 41
41 class HeapGraphEdge BASE_EMBEDDED { 42 class HeapGraphEdge BASE_EMBEDDED {
42 public: 43 public:
43 enum Type { 44 enum Type {
44 kContextVariable = v8::HeapGraphEdge::kContextVariable, 45 kContextVariable = v8::HeapGraphEdge::kContextVariable,
45 kElement = v8::HeapGraphEdge::kElement, 46 kElement = v8::HeapGraphEdge::kElement,
46 kProperty = v8::HeapGraphEdge::kProperty, 47 kProperty = v8::HeapGraphEdge::kProperty,
47 kInternal = v8::HeapGraphEdge::kInternal, 48 kInternal = v8::HeapGraphEdge::kInternal,
48 kHidden = v8::HeapGraphEdge::kHidden, 49 kHidden = v8::HeapGraphEdge::kHidden,
49 kShortcut = v8::HeapGraphEdge::kShortcut, 50 kShortcut = v8::HeapGraphEdge::kShortcut,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 kConsString = v8::HeapGraphNode::kConsString, 108 kConsString = v8::HeapGraphNode::kConsString,
108 kSlicedString = v8::HeapGraphNode::kSlicedString 109 kSlicedString = v8::HeapGraphNode::kSlicedString
109 }; 110 };
110 static const int kNoEntry; 111 static const int kNoEntry;
111 112
112 HeapEntry() { } 113 HeapEntry() { }
113 HeapEntry(HeapSnapshot* snapshot, 114 HeapEntry(HeapSnapshot* snapshot,
114 Type type, 115 Type type,
115 const char* name, 116 const char* name,
116 SnapshotObjectId id, 117 SnapshotObjectId id,
117 size_t self_size); 118 size_t self_size,
119 unsigned trace_node_id);
118 120
119 HeapSnapshot* snapshot() { return snapshot_; } 121 HeapSnapshot* snapshot() { return snapshot_; }
120 Type type() { return static_cast<Type>(type_); } 122 Type type() { return static_cast<Type>(type_); }
121 const char* name() { return name_; } 123 const char* name() { return name_; }
122 void set_name(const char* name) { name_ = name; } 124 void set_name(const char* name) { name_ = name; }
123 inline SnapshotObjectId id() { return id_; } 125 inline SnapshotObjectId id() { return id_; }
124 size_t self_size() { return self_size_; } 126 size_t self_size() { return self_size_; }
127 unsigned trace_node_id() const { return trace_node_id_; }
125 INLINE(int index() const); 128 INLINE(int index() const);
126 int children_count() const { return children_count_; } 129 int children_count() const { return children_count_; }
127 INLINE(int set_children_index(int index)); 130 INLINE(int set_children_index(int index));
128 void add_child(HeapGraphEdge* edge) { 131 void add_child(HeapGraphEdge* edge) {
129 children_arr()[children_count_++] = edge; 132 children_arr()[children_count_++] = edge;
130 } 133 }
131 Vector<HeapGraphEdge*> children() { 134 Vector<HeapGraphEdge*> children() {
132 return Vector<HeapGraphEdge*>(children_arr(), children_count_); } 135 return Vector<HeapGraphEdge*>(children_arr(), children_count_); }
133 136
134 void SetIndexedReference( 137 void SetIndexedReference(
135 HeapGraphEdge::Type type, int index, HeapEntry* entry); 138 HeapGraphEdge::Type type, int index, HeapEntry* entry);
136 void SetNamedReference( 139 void SetNamedReference(
137 HeapGraphEdge::Type type, const char* name, HeapEntry* entry); 140 HeapGraphEdge::Type type, const char* name, HeapEntry* entry);
138 141
139 void Print( 142 void Print(
140 const char* prefix, const char* edge_name, int max_depth, int indent); 143 const char* prefix, const char* edge_name, int max_depth, int indent);
141 144
142 private: 145 private:
143 INLINE(HeapGraphEdge** children_arr()); 146 INLINE(HeapGraphEdge** children_arr());
144 const char* TypeAsString(); 147 const char* TypeAsString();
145 148
146 unsigned type_: 4; 149 unsigned type_: 4;
147 int children_count_: 28; 150 int children_count_: 28;
148 int children_index_; 151 int children_index_;
149 size_t self_size_; 152 size_t self_size_;
150 SnapshotObjectId id_;
151 HeapSnapshot* snapshot_; 153 HeapSnapshot* snapshot_;
152 const char* name_; 154 const char* name_;
155 SnapshotObjectId id_;
156 // id of allocation stack trace top node
157 unsigned trace_node_id_;
153 }; 158 };
154 159
155 160
156 // HeapSnapshot represents a single heap snapshot. It is stored in 161 // HeapSnapshot represents a single heap snapshot. It is stored in
157 // HeapProfiler, which is also a factory for 162 // HeapProfiler, which is also a factory for
158 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap 163 // HeapSnapshots. All HeapSnapshots share strings copied from JS heap
159 // to be able to return them even if they were collected. 164 // to be able to return them even if they were collected.
160 // HeapSnapshotGenerator fills in a HeapSnapshot. 165 // HeapSnapshotGenerator fills in a HeapSnapshot.
161 class HeapSnapshot { 166 class HeapSnapshot {
162 public: 167 public:
(...skipping 16 matching lines...) Expand all
179 List<HeapGraphEdge>& edges() { return edges_; } 184 List<HeapGraphEdge>& edges() { return edges_; }
180 List<HeapGraphEdge*>& children() { return children_; } 185 List<HeapGraphEdge*>& children() { return children_; }
181 void RememberLastJSObjectId(); 186 void RememberLastJSObjectId();
182 SnapshotObjectId max_snapshot_js_object_id() const { 187 SnapshotObjectId max_snapshot_js_object_id() const {
183 return max_snapshot_js_object_id_; 188 return max_snapshot_js_object_id_;
184 } 189 }
185 190
186 HeapEntry* AddEntry(HeapEntry::Type type, 191 HeapEntry* AddEntry(HeapEntry::Type type,
187 const char* name, 192 const char* name,
188 SnapshotObjectId id, 193 SnapshotObjectId id,
189 size_t size); 194 size_t size,
195 unsigned trace_node_id);
190 HeapEntry* AddRootEntry(); 196 HeapEntry* AddRootEntry();
191 HeapEntry* AddGcRootsEntry(); 197 HeapEntry* AddGcRootsEntry();
192 HeapEntry* AddGcSubrootEntry(int tag); 198 HeapEntry* AddGcSubrootEntry(int tag);
193 HeapEntry* AddNativesRootEntry(); 199 HeapEntry* AddNativesRootEntry();
194 HeapEntry* GetEntryById(SnapshotObjectId id); 200 HeapEntry* GetEntryById(SnapshotObjectId id);
195 List<HeapEntry*>* GetSortedEntriesList(); 201 List<HeapEntry*>* GetSortedEntriesList();
196 void FillChildren(); 202 void FillChildren();
197 203
198 void Print(int max_depth); 204 void Print(int max_depth);
199 void PrintEntriesSize(); 205 void PrintEntriesSize();
(...skipping 21 matching lines...) Expand all
221 class HeapObjectsMap { 227 class HeapObjectsMap {
222 public: 228 public:
223 explicit HeapObjectsMap(Heap* heap); 229 explicit HeapObjectsMap(Heap* heap);
224 230
225 Heap* heap() const { return heap_; } 231 Heap* heap() const { return heap_; }
226 232
227 SnapshotObjectId FindEntry(Address addr); 233 SnapshotObjectId FindEntry(Address addr);
228 SnapshotObjectId FindOrAddEntry(Address addr, 234 SnapshotObjectId FindOrAddEntry(Address addr,
229 unsigned int size, 235 unsigned int size,
230 bool accessed = true); 236 bool accessed = true);
231 void MoveObject(Address from, Address to, int size); 237 bool MoveObject(Address from, Address to, int size);
232 void UpdateObjectSize(Address addr, int size); 238 void UpdateObjectSize(Address addr, int size);
233 SnapshotObjectId last_assigned_id() const { 239 SnapshotObjectId last_assigned_id() const {
234 return next_id_ - kObjectIdStep; 240 return next_id_ - kObjectIdStep;
235 } 241 }
236 242
237 void StopHeapObjectsTracking(); 243 void StopHeapObjectsTracking();
238 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream); 244 SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
239 size_t GetUsedMemorySize() const; 245 size_t GetUsedMemorySize() const;
240 246
241 SnapshotObjectId GenerateId(v8::RetainedObjectInfo* info); 247 SnapshotObjectId GenerateId(v8::RetainedObjectInfo* info);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 void SetTag(Object* obj, const char* tag); 337 void SetTag(Object* obj, const char* tag);
332 bool is_empty() const { return entries_.occupancy() == 0; } 338 bool is_empty() const { return entries_.occupancy() == 0; }
333 339
334 private: 340 private:
335 HashMap entries_; 341 HashMap entries_;
336 342
337 DISALLOW_COPY_AND_ASSIGN(HeapObjectsSet); 343 DISALLOW_COPY_AND_ASSIGN(HeapObjectsSet);
338 }; 344 };
339 345
340 346
341 // An interface used to populate a snapshot with nodes and edges.
342 class SnapshotFillerInterface {
343 public:
344 virtual ~SnapshotFillerInterface() { }
345 virtual HeapEntry* AddEntry(HeapThing ptr,
346 HeapEntriesAllocator* allocator) = 0;
347 virtual HeapEntry* FindEntry(HeapThing ptr) = 0;
348 virtual HeapEntry* FindOrAddEntry(HeapThing ptr,
349 HeapEntriesAllocator* allocator) = 0;
350 virtual void SetIndexedReference(HeapGraphEdge::Type type,
351 int parent_entry,
352 int index,
353 HeapEntry* child_entry) = 0;
354 virtual void SetIndexedAutoIndexReference(HeapGraphEdge::Type type,
355 int parent_entry,
356 HeapEntry* child_entry) = 0;
357 virtual void SetNamedReference(HeapGraphEdge::Type type,
358 int parent_entry,
359 const char* reference_name,
360 HeapEntry* child_entry) = 0;
361 virtual void SetNamedAutoIndexReference(HeapGraphEdge::Type type,
362 int parent_entry,
363 HeapEntry* child_entry) = 0;
364 };
365
366
367 class SnapshottingProgressReportingInterface { 347 class SnapshottingProgressReportingInterface {
368 public: 348 public:
369 virtual ~SnapshottingProgressReportingInterface() { } 349 virtual ~SnapshottingProgressReportingInterface() { }
370 virtual void ProgressStep() = 0; 350 virtual void ProgressStep() = 0;
371 virtual bool ProgressReport(bool force) = 0; 351 virtual bool ProgressReport(bool force) = 0;
372 }; 352 };
373 353
374 354
375 // An implementation of V8 heap graph extractor. 355 // An implementation of V8 heap graph extractor.
376 class V8HeapExplorer : public HeapEntriesAllocator { 356 class V8HeapExplorer : public HeapEntriesAllocator {
377 public: 357 public:
378 V8HeapExplorer(HeapSnapshot* snapshot, 358 V8HeapExplorer(HeapSnapshot* snapshot,
379 SnapshottingProgressReportingInterface* progress, 359 SnapshottingProgressReportingInterface* progress,
380 v8::HeapProfiler::ObjectNameResolver* resolver); 360 v8::HeapProfiler::ObjectNameResolver* resolver);
381 virtual ~V8HeapExplorer(); 361 virtual ~V8HeapExplorer();
382 virtual HeapEntry* AllocateEntry(HeapThing ptr); 362 virtual HeapEntry* AllocateEntry(HeapThing ptr);
383 void AddRootEntries(SnapshotFillerInterface* filler); 363 void AddRootEntries(SnapshotFiller* filler);
384 int EstimateObjectsCount(HeapIterator* iterator); 364 int EstimateObjectsCount(HeapIterator* iterator);
385 bool IterateAndExtractReferences(SnapshotFillerInterface* filler); 365 bool IterateAndExtractReferences(SnapshotFiller* filler);
386 void TagGlobalObjects(); 366 void TagGlobalObjects();
387 void TagCodeObject(Code* code); 367 void TagCodeObject(Code* code);
388 void TagBuiltinCodeObject(Code* code, const char* name); 368 void TagBuiltinCodeObject(Code* code, const char* name);
389 HeapEntry* AddEntry(Address address, 369 HeapEntry* AddEntry(Address address,
390 HeapEntry::Type type, 370 HeapEntry::Type type,
391 const char* name, 371 const char* name,
392 size_t size); 372 size_t size);
393 373
394 static String* GetConstructorName(JSObject* object); 374 static String* GetConstructorName(JSObject* object);
395 375
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 HeapEntry* GetEntry(Object* obj); 456 HeapEntry* GetEntry(Object* obj);
477 457
478 static inline HeapObject* GetNthGcSubrootObject(int delta); 458 static inline HeapObject* GetNthGcSubrootObject(int delta);
479 static inline int GetGcSubrootOrder(HeapObject* subroot); 459 static inline int GetGcSubrootOrder(HeapObject* subroot);
480 460
481 Heap* heap_; 461 Heap* heap_;
482 HeapSnapshot* snapshot_; 462 HeapSnapshot* snapshot_;
483 StringsStorage* names_; 463 StringsStorage* names_;
484 HeapObjectsMap* heap_object_map_; 464 HeapObjectsMap* heap_object_map_;
485 SnapshottingProgressReportingInterface* progress_; 465 SnapshottingProgressReportingInterface* progress_;
486 SnapshotFillerInterface* filler_; 466 SnapshotFiller* filler_;
487 HeapObjectsSet objects_tags_; 467 HeapObjectsSet objects_tags_;
488 HeapObjectsSet strong_gc_subroot_names_; 468 HeapObjectsSet strong_gc_subroot_names_;
489 HeapObjectsSet user_roots_; 469 HeapObjectsSet user_roots_;
490 v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_; 470 v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_;
491 471
492 static HeapObject* const kGcRootsObject; 472 static HeapObject* const kGcRootsObject;
493 static HeapObject* const kFirstGcSubrootObject; 473 static HeapObject* const kFirstGcSubrootObject;
494 static HeapObject* const kLastGcSubrootObject; 474 static HeapObject* const kLastGcSubrootObject;
495 475
496 friend class IndexedReferencesExtractor; 476 friend class IndexedReferencesExtractor;
497 friend class GcSubrootsEnumerator; 477 friend class GcSubrootsEnumerator;
498 friend class RootsReferencesExtractor; 478 friend class RootsReferencesExtractor;
499 479
500 DISALLOW_COPY_AND_ASSIGN(V8HeapExplorer); 480 DISALLOW_COPY_AND_ASSIGN(V8HeapExplorer);
501 }; 481 };
502 482
503 483
504 class NativeGroupRetainedObjectInfo; 484 class NativeGroupRetainedObjectInfo;
505 485
506 486
507 // An implementation of retained native objects extractor. 487 // An implementation of retained native objects extractor.
508 class NativeObjectsExplorer { 488 class NativeObjectsExplorer {
509 public: 489 public:
510 NativeObjectsExplorer(HeapSnapshot* snapshot, 490 NativeObjectsExplorer(HeapSnapshot* snapshot,
511 SnapshottingProgressReportingInterface* progress); 491 SnapshottingProgressReportingInterface* progress);
512 virtual ~NativeObjectsExplorer(); 492 virtual ~NativeObjectsExplorer();
513 void AddRootEntries(SnapshotFillerInterface* filler); 493 void AddRootEntries(SnapshotFiller* filler);
514 int EstimateObjectsCount(); 494 int EstimateObjectsCount();
515 bool IterateAndExtractReferences(SnapshotFillerInterface* filler); 495 bool IterateAndExtractReferences(SnapshotFiller* filler);
516 496
517 private: 497 private:
518 void FillRetainedObjects(); 498 void FillRetainedObjects();
519 void FillImplicitReferences(); 499 void FillImplicitReferences();
520 List<HeapObject*>* GetListMaybeDisposeInfo(v8::RetainedObjectInfo* info); 500 List<HeapObject*>* GetListMaybeDisposeInfo(v8::RetainedObjectInfo* info);
521 void SetNativeRootReference(v8::RetainedObjectInfo* info); 501 void SetNativeRootReference(v8::RetainedObjectInfo* info);
522 void SetRootNativeRootsReference(); 502 void SetRootNativeRootsReference();
523 void SetWrapperNativeReferences(HeapObject* wrapper, 503 void SetWrapperNativeReferences(HeapObject* wrapper,
524 v8::RetainedObjectInfo* info); 504 v8::RetainedObjectInfo* info);
525 void VisitSubtreeWrapper(Object** p, uint16_t class_id); 505 void VisitSubtreeWrapper(Object** p, uint16_t class_id);
(...skipping 19 matching lines...) Expand all
545 StringsStorage* names_; 525 StringsStorage* names_;
546 SnapshottingProgressReportingInterface* progress_; 526 SnapshottingProgressReportingInterface* progress_;
547 bool embedder_queried_; 527 bool embedder_queried_;
548 HeapObjectsSet in_groups_; 528 HeapObjectsSet in_groups_;
549 // RetainedObjectInfo* -> List<HeapObject*>* 529 // RetainedObjectInfo* -> List<HeapObject*>*
550 HashMap objects_by_info_; 530 HashMap objects_by_info_;
551 HashMap native_groups_; 531 HashMap native_groups_;
552 HeapEntriesAllocator* synthetic_entries_allocator_; 532 HeapEntriesAllocator* synthetic_entries_allocator_;
553 HeapEntriesAllocator* native_entries_allocator_; 533 HeapEntriesAllocator* native_entries_allocator_;
554 // Used during references extraction. 534 // Used during references extraction.
555 SnapshotFillerInterface* filler_; 535 SnapshotFiller* filler_;
556 536
557 static HeapThing const kNativesRootObject; 537 static HeapThing const kNativesRootObject;
558 538
559 friend class GlobalHandlesExtractor; 539 friend class GlobalHandlesExtractor;
560 540
561 DISALLOW_COPY_AND_ASSIGN(NativeObjectsExplorer); 541 DISALLOW_COPY_AND_ASSIGN(NativeObjectsExplorer);
562 }; 542 };
563 543
564 544
565 class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface { 545 class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 friend class HeapSnapshotJSONSerializerEnumerator; 622 friend class HeapSnapshotJSONSerializerEnumerator;
643 friend class HeapSnapshotJSONSerializerIterator; 623 friend class HeapSnapshotJSONSerializerIterator;
644 624
645 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer); 625 DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer);
646 }; 626 };
647 627
648 628
649 } } // namespace v8::internal 629 } } // namespace v8::internal
650 630
651 #endif // V8_HEAP_SNAPSHOT_GENERATOR_H_ 631 #endif // V8_HEAP_SNAPSHOT_GENERATOR_H_
OLDNEW
« no previous file with comments | « src/heap-profiler.cc ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698