heap-snapshot-generator.h 21 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_H_
#define V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_H_
7

8
#include <deque>
9
#include <memory>
10
#include <unordered_map>
11
#include <unordered_set>
12
#include <vector>
13

14
#include "include/v8-profiler.h"
15
#include "src/base/platform/time.h"
16
#include "src/objects/fixed-array.h"
17
#include "src/objects/hash-table.h"
18
#include "src/objects/heap-object.h"
19
#include "src/objects/js-objects.h"
20
#include "src/objects/literal-objects.h"
21
#include "src/objects/objects.h"
22
#include "src/objects/visitors.h"
23
#include "src/profiler/strings-storage.h"
24
#include "src/strings/string-hasher.h"
25

26 27 28
namespace v8 {
namespace internal {

29
class AllocationTraceNode;
30
class HeapEntry;
31
class HeapProfiler;
32
class HeapSnapshot;
33
class HeapSnapshotGenerator;
34
class JSArrayBuffer;
35
class JSCollection;
36 37 38 39
class JSGeneratorObject;
class JSGlobalObject;
class JSGlobalProxy;
class JSPromise;
40
class JSWeakCollection;
41

42 43 44 45 46 47 48 49 50 51
struct SourceLocation {
  SourceLocation(int entry_index, int scriptId, int line, int col)
      : entry_index(entry_index), scriptId(scriptId), line(line), col(col) {}

  const int entry_index;
  const int scriptId;
  const int line;
  const int col;
};

52
class HeapGraphEdge {
53 54 55 56 57 58 59 60 61 62 63
 public:
  enum Type {
    kContextVariable = v8::HeapGraphEdge::kContextVariable,
    kElement = v8::HeapGraphEdge::kElement,
    kProperty = v8::HeapGraphEdge::kProperty,
    kInternal = v8::HeapGraphEdge::kInternal,
    kHidden = v8::HeapGraphEdge::kHidden,
    kShortcut = v8::HeapGraphEdge::kShortcut,
    kWeak = v8::HeapGraphEdge::kWeak
  };

64 65
  HeapGraphEdge(Type type, const char* name, HeapEntry* from, HeapEntry* to);
  HeapGraphEdge(Type type, int index, HeapEntry* from, HeapEntry* to);
66

67
  Type type() const { return TypeField::decode(bit_field_); }
68
  int index() const {
69
    DCHECK(type() == kElement || type() == kHidden);
70 71 72
    return index_;
  }
  const char* name() const {
73 74
    DCHECK(type() == kContextVariable || type() == kProperty ||
           type() == kInternal || type() == kShortcut || type() == kWeak);
75 76
    return name_;
  }
77
  V8_INLINE HeapEntry* from() const;
78 79
  HeapEntry* to() const { return to_entry_; }

80
  V8_INLINE Isolate* isolate() const;
81

82
 private:
83
  V8_INLINE HeapSnapshot* snapshot() const;
84
  int from_index() const { return FromIndexField::decode(bit_field_); }
85

86 87
  using TypeField = base::BitField<Type, 0, 3>;
  using FromIndexField = base::BitField<int, 3, 29>;
88
  uint32_t bit_field_;
89
  HeapEntry* to_entry_;
90 91 92 93 94 95 96 97 98
  union {
    int index_;
    const char* name_;
  };
};


// HeapEntry instances represent an entity from the heap (or a special
// virtual node, e.g. root).
99
class HeapEntry {
100 101 102 103 104 105 106 107 108 109 110
 public:
  enum Type {
    kHidden = v8::HeapGraphNode::kHidden,
    kArray = v8::HeapGraphNode::kArray,
    kString = v8::HeapGraphNode::kString,
    kObject = v8::HeapGraphNode::kObject,
    kCode = v8::HeapGraphNode::kCode,
    kClosure = v8::HeapGraphNode::kClosure,
    kRegExp = v8::HeapGraphNode::kRegExp,
    kHeapNumber = v8::HeapGraphNode::kHeapNumber,
    kNative = v8::HeapGraphNode::kNative,
111 112
    kSynthetic = v8::HeapGraphNode::kSynthetic,
    kConsString = v8::HeapGraphNode::kConsString,
113
    kSlicedString = v8::HeapGraphNode::kSlicedString,
114 115
    kSymbol = v8::HeapGraphNode::kSymbol,
    kBigInt = v8::HeapGraphNode::kBigInt
116 117
  };

118 119
  HeapEntry(HeapSnapshot* snapshot, int index, Type type, const char* name,
            SnapshotObjectId id, size_t self_size, unsigned trace_node_id);
120 121

  HeapSnapshot* snapshot() { return snapshot_; }
122
  Type type() const { return static_cast<Type>(type_); }
123
  void set_type(Type type) { type_ = type; }
124
  const char* name() const { return name_; }
125
  void set_name(const char* name) { name_ = name; }
126 127
  SnapshotObjectId id() const { return id_; }
  size_t self_size() const { return self_size_; }
128
  unsigned trace_node_id() const { return trace_node_id_; }
129 130
  int index() const { return index_; }
  V8_INLINE int children_count() const;
131
  V8_INLINE int set_children_index(int index);
132 133
  V8_INLINE void add_child(HeapGraphEdge* edge);
  V8_INLINE HeapGraphEdge* child(int i);
134
  V8_INLINE Isolate* isolate() const;
135 136 137 138 139

  void SetIndexedReference(
      HeapGraphEdge::Type type, int index, HeapEntry* entry);
  void SetNamedReference(
      HeapGraphEdge::Type type, const char* name, HeapEntry* entry);
140 141 142 143 144 145 146
  void SetIndexedAutoIndexReference(HeapGraphEdge::Type type,
                                    HeapEntry* child) {
    SetIndexedReference(type, children_count_ + 1, child);
  }
  void SetNamedAutoIndexReference(HeapGraphEdge::Type type,
                                  const char* description, HeapEntry* child,
                                  StringsStorage* strings);
147

148 149
  V8_EXPORT_PRIVATE void Print(const char* prefix, const char* edge_name,
                               int max_depth, int indent);
150 151

 private:
152 153
  V8_INLINE std::vector<HeapGraphEdge*>::iterator children_begin() const;
  V8_INLINE std::vector<HeapGraphEdge*>::iterator children_end() const;
154 155 156
  const char* TypeAsString();

  unsigned type_: 4;
157 158 159 160 161 162 163
  unsigned index_ : 28;  // Supports up to ~250M objects.
  union {
    // The count is used during the snapshot build phase,
    // then it gets converted into the index by the |FillChildren| function.
    unsigned children_count_;
    unsigned children_end_index_;
  };
164
  size_t self_size_;
165 166
  HeapSnapshot* snapshot_;
  const char* name_;
167 168 169
  SnapshotObjectId id_;
  // id of allocation stack trace top node
  unsigned trace_node_id_;
170 171 172
};

// HeapSnapshot represents a single heap snapshot. It is stored in
173
// HeapProfiler, which is also a factory for
174 175 176 177 178
// HeapSnapshots. All HeapSnapshots share strings copied from JS heap
// to be able to return them even if they were collected.
// HeapSnapshotGenerator fills in a HeapSnapshot.
class HeapSnapshot {
 public:
179
  explicit HeapSnapshot(HeapProfiler* profiler, bool global_objects_as_roots);
180 181
  void Delete();

182 183 184 185 186
  HeapProfiler* profiler() const { return profiler_; }
  HeapEntry* root() const { return root_entry_; }
  HeapEntry* gc_roots() const { return gc_roots_entry_; }
  HeapEntry* gc_subroot(Root root) const {
    return gc_subroot_entries_[static_cast<int>(root)];
187
  }
188
  std::deque<HeapEntry>& entries() { return entries_; }
189
  std::deque<HeapGraphEdge>& edges() { return edges_; }
190
  std::vector<HeapGraphEdge*>& children() { return children_; }
191
  const std::vector<SourceLocation>& locations() const { return locations_; }
192 193 194 195
  void RememberLastJSObjectId();
  SnapshotObjectId max_snapshot_js_object_id() const {
    return max_snapshot_js_object_id_;
  }
196
  bool is_complete() const { return !children_.empty(); }
197 198 199
  bool treat_global_objects_as_roots() const {
    return treat_global_objects_as_roots_;
  }
200

201
  void AddLocation(HeapEntry* entry, int scriptId, int line, int col);
202 203 204
  HeapEntry* AddEntry(HeapEntry::Type type,
                      const char* name,
                      SnapshotObjectId id,
205 206
                      size_t size,
                      unsigned trace_node_id);
207
  void AddSyntheticRootEntries();
208 209 210 211 212 213
  HeapEntry* GetEntryById(SnapshotObjectId id);
  void FillChildren();

  void Print(int max_depth);

 private:
214 215 216
  void AddRootEntry();
  void AddGcRootsEntry();
  void AddGcSubrootEntry(Root root, SnapshotObjectId id);
217

218
  HeapProfiler* profiler_;
219 220 221 222 223 224 225
  HeapEntry* root_entry_ = nullptr;
  HeapEntry* gc_roots_entry_ = nullptr;
  HeapEntry* gc_subroot_entries_[static_cast<int>(Root::kNumberOfRoots)];
  // For |entries_| we rely on the deque property, that it never reallocates
  // backing storage, thus all entry pointers remain valid for the duration
  // of snapshotting.
  std::deque<HeapEntry> entries_;
226
  std::deque<HeapGraphEdge> edges_;
227 228
  std::vector<HeapGraphEdge*> children_;
  std::unordered_map<SnapshotObjectId, HeapEntry*> entries_by_id_cache_;
229
  std::vector<SourceLocation> locations_;
230
  SnapshotObjectId max_snapshot_js_object_id_ = -1;
231
  bool treat_global_objects_as_roots_;
232 233 234 235 236 237 238

  DISALLOW_COPY_AND_ASSIGN(HeapSnapshot);
};


class HeapObjectsMap {
 public:
239 240 241 242 243 244 245 246 247 248
  struct TimeInterval {
    explicit TimeInterval(SnapshotObjectId id)
        : id(id), size(0), count(0), timestamp(base::TimeTicks::Now()) {}
    SnapshotObjectId last_assigned_id() const { return id - kObjectIdStep; }
    SnapshotObjectId id;
    uint32_t size;
    uint32_t count;
    base::TimeTicks timestamp;
  };

249 250 251 252 253
  explicit HeapObjectsMap(Heap* heap);

  Heap* heap() const { return heap_; }

  SnapshotObjectId FindEntry(Address addr);
254 255 256
  SnapshotObjectId FindOrAddEntry(Address addr,
                                  unsigned int size,
                                  bool accessed = true);
257 258
  SnapshotObjectId FindMergedNativeEntry(NativeObject addr);
  void AddMergedNativeEntry(NativeObject addr, Address canonical_addr);
259
  bool MoveObject(Address from, Address to, int size);
260
  void UpdateObjectSize(Address addr, int size);
261 262 263 264 265
  SnapshotObjectId last_assigned_id() const {
    return next_id_ - kObjectIdStep;
  }

  void StopHeapObjectsTracking();
266 267
  SnapshotObjectId PushHeapObjectsStats(OutputStream* stream,
                                        int64_t* timestamp_us);
268
  const std::vector<TimeInterval>& samples() const { return time_intervals_; }
269 270 271 272 273 274 275

  static const int kObjectIdStep = 2;
  static const SnapshotObjectId kInternalRootObjectId;
  static const SnapshotObjectId kGcRootsObjectId;
  static const SnapshotObjectId kGcRootsFirstSubrootId;
  static const SnapshotObjectId kFirstAvailableObjectId;

276
  void UpdateHeapObjectsMap();
277
  void RemoveDeadEntries();
278

279 280
 private:
  struct EntryInfo {
281 282 283
    EntryInfo(SnapshotObjectId id, Address addr, unsigned int size,
              bool accessed)
        : id(id), addr(addr), size(size), accessed(accessed) {}
284 285 286 287 288 289 290
    SnapshotObjectId id;
    Address addr;
    unsigned int size;
    bool accessed;
  };

  SnapshotObjectId next_id_;
291
  // TODO(jkummerow): Use a map that uses {Address} as the key type.
lpy's avatar
lpy committed
292
  base::HashMap entries_map_;
293
  std::vector<EntryInfo> entries_;
294
  std::vector<TimeInterval> time_intervals_;
295 296
  // Map from NativeObject to EntryInfo index in entries_.
  std::unordered_map<NativeObject, size_t> merged_native_entries_map_;
297 298 299 300 301 302 303
  Heap* heap_;

  DISALLOW_COPY_AND_ASSIGN(HeapObjectsMap);
};

// A typedef for referencing anything that can be snapshotted living
// in any kind of heap memory.
304
using HeapThing = void*;
305 306 307 308

// An interface that creates HeapEntries by HeapThings.
class HeapEntriesAllocator {
 public:
309
  virtual ~HeapEntriesAllocator() = default;
310 311 312 313 314
  virtual HeapEntry* AllocateEntry(HeapThing ptr) = 0;
};

class SnapshottingProgressReportingInterface {
 public:
315
  virtual ~SnapshottingProgressReportingInterface() = default;
316 317 318 319 320
  virtual void ProgressStep() = 0;
  virtual bool ProgressReport(bool force) = 0;
};

// An implementation of V8 heap graph extractor.
321
class V8_EXPORT_PRIVATE V8HeapExplorer : public HeapEntriesAllocator {
322 323 324 325
 public:
  V8HeapExplorer(HeapSnapshot* snapshot,
                 SnapshottingProgressReportingInterface* progress,
                 v8::HeapProfiler::ObjectNameResolver* resolver);
326
  ~V8HeapExplorer() override = default;
327

328
  HeapEntry* AllocateEntry(HeapThing ptr) override;
329
  int EstimateObjectsCount();
330
  bool IterateAndExtractReferences(HeapSnapshotGenerator* generator);
331
  void TagGlobalObjects();
332
  void TagBuiltinCodeObject(Code code, const char* name);
333 334 335
  HeapEntry* AddEntry(Address address,
                      HeapEntry::Type type,
                      const char* name,
336
                      size_t size);
337

338 339
  static JSFunction GetConstructor(JSReceiver receiver);
  static String GetConstructorName(JSObject object);
340 341

 private:
342
  void MarkVisitedField(int offset);
343

344 345
  HeapEntry* AddEntry(HeapObject object);
  HeapEntry* AddEntry(HeapObject object, HeapEntry::Type type,
346
                      const char* name);
347

348
  const char* GetSystemEntryName(HeapObject object);
349

350
  void ExtractLocation(HeapEntry* entry, HeapObject object);
351
  void ExtractLocationForJSFunction(HeapEntry* entry, JSFunction func);
352
  void ExtractReferences(HeapEntry* entry, HeapObject obj);
353 354
  void ExtractJSGlobalProxyReferences(HeapEntry* entry, JSGlobalProxy proxy);
  void ExtractJSObjectReferences(HeapEntry* entry, JSObject js_obj);
355 356
  void ExtractStringReferences(HeapEntry* entry, String obj);
  void ExtractSymbolReferences(HeapEntry* entry, Symbol symbol);
357
  void ExtractJSCollectionReferences(HeapEntry* entry, JSCollection collection);
358
  void ExtractJSWeakCollectionReferences(HeapEntry* entry,
359
                                         JSWeakCollection collection);
360
  void ExtractEphemeronHashTableReferences(HeapEntry* entry,
361
                                           EphemeronHashTable table);
362
  void ExtractContextReferences(HeapEntry* entry, Context context);
363
  void ExtractMapReferences(HeapEntry* entry, Map map);
364
  void ExtractSharedFunctionInfoReferences(HeapEntry* entry,
365
                                           SharedFunctionInfo shared);
366
  void ExtractScriptReferences(HeapEntry* entry, Script script);
367
  void ExtractAccessorInfoReferences(HeapEntry* entry,
368 369
                                     AccessorInfo accessor_info);
  void ExtractAccessorPairReferences(HeapEntry* entry, AccessorPair accessors);
370
  void ExtractCodeReferences(HeapEntry* entry, Code code);
371
  void ExtractCellReferences(HeapEntry* entry, Cell cell);
372
  void ExtractFeedbackCellReferences(HeapEntry* entry,
373
                                     FeedbackCell feedback_cell);
374
  void ExtractPropertyCellReferences(HeapEntry* entry, PropertyCell cell);
375
  void ExtractAllocationSiteReferences(HeapEntry* entry, AllocationSite site);
376
  void ExtractArrayBoilerplateDescriptionReferences(
377
      HeapEntry* entry, ArrayBoilerplateDescription value);
378 379
  void ExtractJSArrayBufferReferences(HeapEntry* entry, JSArrayBuffer buffer);
  void ExtractJSPromiseReferences(HeapEntry* entry, JSPromise promise);
380
  void ExtractJSGeneratorObjectReferences(HeapEntry* entry,
381
                                          JSGeneratorObject generator);
382
  void ExtractFixedArrayReferences(HeapEntry* entry, FixedArray array);
383
  void ExtractFeedbackVectorReferences(HeapEntry* entry,
384
                                       FeedbackVector feedback_vector);
385
  void ExtractDescriptorArrayReferences(HeapEntry* entry,
386
                                        DescriptorArray array);
387
  template <typename T>
388
  void ExtractWeakArrayReferences(int header_size, HeapEntry* entry, T array);
389
  void ExtractPropertyReferences(JSObject js_obj, HeapEntry* entry);
390
  void ExtractAccessorPairProperty(HeapEntry* entry, Name key,
391
                                   Object callback_obj, int field_offset = -1);
392 393
  void ExtractElementReferences(JSObject js_obj, HeapEntry* entry);
  void ExtractInternalReferences(JSObject js_obj, HeapEntry* entry);
394

395 396
  bool IsEssentialObject(Object object);
  bool IsEssentialHiddenReference(Object parent, int field_offset);
397

398
  void SetContextReference(HeapEntry* parent_entry, String reference_name,
399
                           Object child, int field_offset);
400
  void SetNativeBindReference(HeapEntry* parent_entry,
401 402
                              const char* reference_name, Object child);
  void SetElementReference(HeapEntry* parent_entry, int index, Object child);
403
  void SetInternalReference(HeapEntry* parent_entry, const char* reference_name,
404 405
                            Object child, int field_offset = -1);
  void SetInternalReference(HeapEntry* parent_entry, int index, Object child,
406
                            int field_offset = -1);
407
  void SetHiddenReference(HeapObject parent_obj, HeapEntry* parent_entry,
408
                          int index, Object child, int field_offset);
409
  void SetWeakReference(HeapEntry* parent_entry, const char* reference_name,
410 411
                        Object child_obj, int field_offset);
  void SetWeakReference(HeapEntry* parent_entry, int index, Object child_obj,
412
                        int field_offset);
413
  void SetPropertyReference(HeapEntry* parent_entry, Name reference_name,
414
                            Object child,
415
                            const char* name_format_string = nullptr,
416
                            int field_offset = -1);
417
  void SetDataOrAccessorPropertyReference(
418
      PropertyKind kind, HeapEntry* parent_entry, Name reference_name,
419
      Object child, const char* name_format_string = nullptr,
420
      int field_offset = -1);
421

422
  void SetUserGlobalReference(Object user_global);
423
  void SetRootGcRootsReference();
424 425
  void SetGcRootsReference(Root root);
  void SetGcSubrootReference(Root root, const char* description, bool is_weak,
426 427 428
                             Object child);
  const char* GetStrongGcSubrootName(Object object);
  void TagObject(Object obj, const char* tag);
429

430
  HeapEntry* GetEntry(Object obj);
431 432 433

  Heap* heap_;
  HeapSnapshot* snapshot_;
434 435
  StringsStorage* names_;
  HeapObjectsMap* heap_object_map_;
436
  SnapshottingProgressReportingInterface* progress_;
437
  HeapSnapshotGenerator* generator_ = nullptr;
438
  std::unordered_map<JSGlobalObject, const char*, Object::Hasher> objects_tags_;
439 440
  std::unordered_map<Object, const char*, Object::Hasher>
      strong_gc_subroot_names_;
441
  std::unordered_set<JSGlobalObject, Object::Hasher> user_roots_;
442 443
  v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_;

444
  std::vector<bool> visited_fields_;
445

446 447 448 449 450 451 452 453 454 455
  friend class IndexedReferencesExtractor;
  friend class RootsReferencesExtractor;

  DISALLOW_COPY_AND_ASSIGN(V8HeapExplorer);
};

// An implementation of retained native objects extractor.
class NativeObjectsExplorer {
 public:
  NativeObjectsExplorer(HeapSnapshot* snapshot,
456
                        SnapshottingProgressReportingInterface* progress);
457
  bool IterateAndExtractReferences(HeapSnapshotGenerator* generator);
458 459

 private:
460 461
  HeapEntry* EntryForEmbedderGraphNode(EmbedderGraph::Node* node);

462
  Isolate* isolate_;
463
  HeapSnapshot* snapshot_;
464
  StringsStorage* names_;
465
  HeapObjectsMap* heap_object_map_;
466
  std::unique_ptr<HeapEntriesAllocator> embedder_graph_entries_allocator_;
467
  // Used during references extraction.
468
  HeapSnapshotGenerator* generator_ = nullptr;
469 470 471 472 473 474 475 476 477 478

  static HeapThing const kNativesRootObject;

  friend class GlobalHandlesExtractor;

  DISALLOW_COPY_AND_ASSIGN(NativeObjectsExplorer);
};

class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface {
 public:
479 480
  // The HeapEntriesMap instance is used to track a mapping between
  // real heap objects and their representations in heap snapshots.
481
  using HeapEntriesMap = std::unordered_map<HeapThing, HeapEntry*>;
482

483 484 485 486 487 488
  HeapSnapshotGenerator(HeapSnapshot* snapshot,
                        v8::ActivityControl* control,
                        v8::HeapProfiler::ObjectNameResolver* resolver,
                        Heap* heap);
  bool GenerateSnapshot();

489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
  HeapEntry* FindEntry(HeapThing ptr) {
    auto it = entries_map_.find(ptr);
    return it != entries_map_.end() ? it->second : nullptr;
  }

  HeapEntry* AddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
    return entries_map_.emplace(ptr, allocator->AllocateEntry(ptr))
        .first->second;
  }

  HeapEntry* FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) {
    HeapEntry* entry = FindEntry(ptr);
    return entry != nullptr ? entry : AddEntry(ptr, allocator);
  }

504 505
 private:
  bool FillReferences();
506 507
  void ProgressStep() override;
  bool ProgressReport(bool force = false) override;
508
  void InitProgressCounter();
509 510 511 512 513

  HeapSnapshot* snapshot_;
  v8::ActivityControl* control_;
  V8HeapExplorer v8_heap_explorer_;
  NativeObjectsExplorer dom_explorer_;
514 515
  // Mapping from HeapThing pointers to HeapEntry indices.
  HeapEntriesMap entries_map_;
516 517 518 519 520 521 522 523 524 525 526 527 528 529
  // Used during snapshot generation.
  int progress_counter_;
  int progress_total_;
  Heap* heap_;

  DISALLOW_COPY_AND_ASSIGN(HeapSnapshotGenerator);
};

class OutputStreamWriter;

class HeapSnapshotJSONSerializer {
 public:
  explicit HeapSnapshotJSONSerializer(HeapSnapshot* snapshot)
      : snapshot_(snapshot),
530
        strings_(StringsMatch),
531 532
        next_node_id_(1),
        next_string_id_(1),
533
        writer_(nullptr) {}
534 535 536
  void Serialize(v8::OutputStream* stream);

 private:
537
  V8_INLINE static bool StringsMatch(void* key1, void* key2) {
538 539
    return strcmp(reinterpret_cast<char*>(key1),
                  reinterpret_cast<char*>(key2)) == 0;
540 541
  }

542
  V8_INLINE static uint32_t StringHash(const void* string);
543 544

  int GetStringId(const char* s);
545 546
  V8_INLINE int to_node_index(const HeapEntry* e);
  V8_INLINE int to_node_index(int entry_index);
547 548 549
  void SerializeEdge(HeapGraphEdge* edge, bool first_edge);
  void SerializeEdges();
  void SerializeImpl();
550
  void SerializeNode(const HeapEntry* entry);
551 552
  void SerializeNodes();
  void SerializeSnapshot();
553 554 555
  void SerializeTraceTree();
  void SerializeTraceNode(AllocationTraceNode* node);
  void SerializeTraceNodeInfos();
556
  void SerializeSamples();
557 558
  void SerializeString(const unsigned char* s);
  void SerializeStrings();
559 560
  void SerializeLocation(const SourceLocation& location);
  void SerializeLocations();
561 562 563 564 565

  static const int kEdgeFieldsCount;
  static const int kNodeFieldsCount;

  HeapSnapshot* snapshot_;
566
  base::CustomMatcherHashMap strings_;
567 568 569 570 571 572 573 574 575 576 577
  int next_node_id_;
  int next_string_id_;
  OutputStreamWriter* writer_;

  friend class HeapSnapshotJSONSerializerEnumerator;
  friend class HeapSnapshotJSONSerializerIterator;

  DISALLOW_COPY_AND_ASSIGN(HeapSnapshotJSONSerializer);
};


578 579
}  // namespace internal
}  // namespace v8
580

581
#endif  // V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_H_