v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
heap-snapshot-generator.h
Go to the documentation of this file.
1// Copyright 2013 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.
4
5#ifndef V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_H_
6#define V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_H_
7
8#include <deque>
9#include <memory>
10#include <optional>
11#include <unordered_map>
12#include <unordered_set>
13#include <vector>
14
15#include "include/v8-profiler.h"
23#include "src/objects/objects.h"
24#include "src/objects/string.h"
28
29#ifdef V8_ENABLE_HEAP_SNAPSHOT_VERIFY
31#endif
32
33namespace v8::internal {
34
35class AllocationTraceNode;
36class HeapEntry;
37class HeapProfiler;
38class HeapSnapshot;
39class HeapSnapshotGenerator;
40class IsolateSafepointScope;
41class JSArrayBuffer;
42class JSCollection;
43class JSGeneratorObject;
44class JSGlobalObject;
45class JSGlobalProxy;
46class JSPromise;
47class JSWeakCollection;
48
51 : entry_index(entry_index), scriptId(scriptId), line(line), col(col) {}
52
53 const int entry_index;
54 const int scriptId;
55 const int line;
56 const int col;
57};
58
102
103
104// HeapEntry instances represent an entity from the heap (or a special
105// virtual node, e.g. root).
107 public:
126
127 HeapEntry(HeapSnapshot* snapshot, int index, Type type, const char* name,
128 SnapshotObjectId id, size_t self_size, unsigned trace_node_id);
129
131 Type type() const { return static_cast<Type>(type_); }
132 void set_type(Type type) { type_ = static_cast<unsigned>(type); }
133 const char* name() const { return name_; }
134 void set_name(const char* name) { name_ = name; }
135 SnapshotObjectId id() const { return id_; }
136 size_t self_size() const { return self_size_; }
137 void add_self_size(size_t size) { self_size_ += size; }
138 unsigned trace_node_id() const { return trace_node_id_; }
139 int index() const { return index_; }
140 V8_INLINE int children_count() const;
141 V8_INLINE int set_children_index(int index);
144 V8_INLINE Isolate* isolate() const;
145
147 detachedness_ = static_cast<uint8_t>(value);
148 }
149 uint8_t detachedness() const { return detachedness_; }
150
152 // Verify that the reference can be found via marking, if verification is
153 // enabled.
155
156 // Skip verifying that the reference can be found via marking, for any of
157 // the following reasons:
158
162 };
163
165 HeapSnapshotGenerator* generator,
166 ReferenceVerification verification);
167 void SetIndexedReference(HeapGraphEdge::Type type, int index,
168 HeapEntry* entry, HeapSnapshotGenerator* generator,
169 ReferenceVerification verification = kVerify);
170 void SetNamedReference(HeapGraphEdge::Type type, const char* name,
171 HeapEntry* entry, HeapSnapshotGenerator* generator,
172 ReferenceVerification verification = kVerify);
175 HeapSnapshotGenerator* generator,
176 ReferenceVerification verification = kVerify) {
177 SetIndexedReference(type, children_count_ + 1, child, generator,
178 verification);
179 }
181 const char* description, HeapEntry* child,
182 StringsStorage* strings,
183 HeapSnapshotGenerator* generator,
184 ReferenceVerification verification = kVerify);
185
186 V8_EXPORT_PRIVATE void Print(const char* prefix, const char* edge_name,
187 int max_depth, int indent) const;
188
189 private:
190 V8_INLINE std::vector<HeapGraphEdge*>::iterator children_begin() const;
191 V8_INLINE std::vector<HeapGraphEdge*>::iterator children_end() const;
192 const char* TypeAsString() const;
193
194 static_assert(kNumTypes <= 1 << 4);
195 unsigned type_ : 4;
196 unsigned index_ : 28; // Supports up to ~250M objects.
197 union {
198 // The count is used during the snapshot build phase,
199 // then it gets converted into the index by the |FillChildren| function.
202 };
203#ifdef V8_TARGET_ARCH_64_BIT
204 size_t self_size_ : 48;
205#else // !V8_TARGET_ARCH_64_BIT
207#endif // !V8_TARGET_ARCH_64_BIT
208 uint8_t detachedness_ = 0;
210 const char* name_;
212 // id of allocation stack trace top node
214};
215
216// HeapSnapshot represents a single heap snapshot. It is stored in
217// HeapProfiler, which is also a factory for
218// HeapSnapshots. All HeapSnapshots share strings copied from JS heap
219// to be able to return them even if they were collected.
220// HeapSnapshotGenerator fills in a HeapSnapshot.
222 public:
223 HeapSnapshot(HeapProfiler* profiler,
225 v8::HeapProfiler::NumericsMode numerics_mode);
226 HeapSnapshot(const HeapSnapshot&) = delete;
228 void Delete();
229
230 HeapProfiler* profiler() const { return profiler_; }
231 HeapEntry* root() const { return root_entry_; }
232 HeapEntry* gc_roots() const { return gc_roots_entry_; }
234 return gc_subroot_entries_[static_cast<int>(root)];
235 }
236 std::deque<HeapEntry>& entries() { return entries_; }
237 const std::deque<HeapEntry>& entries() const { return entries_; }
238 std::deque<HeapGraphEdge>& edges() { return edges_; }
239 const std::deque<HeapGraphEdge>& edges() const { return edges_; }
240 std::vector<HeapGraphEdge*>& children() { return children_; }
241 const std::vector<EntrySourceLocation>& locations() const {
242 return locations_;
243 }
248 bool is_complete() const { return !children_.empty(); }
257 size_t extra_native_bytes() const { return extra_native_bytes_; }
258 void set_extra_native_bytes(size_t bytes) { extra_native_bytes_ = bytes; }
259
260 void AddLocation(HeapEntry* entry, int scriptId, int line, int col);
262 const char* name,
264 size_t size,
265 unsigned trace_node_id);
268 void FillChildren();
269
270 void AddScriptLineEnds(int script_id, String::LineEndsVector&& line_ends);
272
273 void Print(int max_depth);
274
275 private:
276 void AddRootEntry();
277 void AddGcRootsEntry();
279
284 // For |entries_| we rely on the deque property, that it never reallocates
285 // backing storage, thus all entry pointers remain valid for the duration
286 // of snapshotting.
287 std::deque<HeapEntry> entries_;
288 std::deque<HeapGraphEdge> edges_;
289 std::vector<HeapGraphEdge*> children_;
290 std::unordered_map<SnapshotObjectId, HeapEntry*> entries_by_id_cache_;
291 std::vector<EntrySourceLocation> locations_;
296
297 // The ScriptsLineEndsMap instance stores the line ends of scripts that did
298 // not get their line_ends() information populated in heap.
299 using ScriptId = int;
301 std::unordered_map<ScriptId, String::LineEndsVector>;
303};
304
305
307 public:
310 : id(id), size(0), count(0), timestamp(base::TimeTicks::Now()) {}
313 uint32_t size;
314 uint32_t count;
316 };
317 enum class MarkEntryAccessed {
318 kNo,
319 kYes,
320 };
321 enum class IsNativeObject {
322 kNo,
323 kYes,
324 };
325
326 explicit HeapObjectsMap(Heap* heap);
329
330 Heap* heap() const { return heap_; }
331
334 Address addr, unsigned int size,
336 IsNativeObject is_native_object = IsNativeObject::kNo);
338 void AddMergedNativeEntry(NativeObject addr, Address canonical_addr);
339 bool MoveObject(Address from, Address to, int size);
340 void UpdateObjectSize(Address addr, int size);
352
355 int64_t* timestamp_us);
356 const std::vector<TimeInterval>& samples() const { return time_intervals_; }
357
358 static const int kObjectIdStep = 2;
364
366 void RemoveDeadEntries();
367
368 private:
369 struct EntryInfo {
370 EntryInfo(SnapshotObjectId id, Address addr, unsigned int size,
371 bool accessed)
372 : id(id), addr(addr), size(size), accessed(accessed) {}
375 unsigned int size;
377 };
378
381 // TODO(jkummerow): Use a map that uses {Address} as the key type.
383 std::vector<EntryInfo> entries_;
384 std::vector<TimeInterval> time_intervals_;
385 // Map from NativeObject to EntryInfo index in entries_.
386 std::unordered_map<NativeObject, size_t> merged_native_entries_map_;
388};
389
390// A typedef for referencing anything that can be snapshotted living
391// in any kind of heap memory.
392using HeapThing = void*;
393
394// An interface that creates HeapEntries by HeapThings.
396 public:
397 virtual ~HeapEntriesAllocator() = default;
400};
401
403 public:
405 virtual void ProgressStep() = 0;
406 virtual bool ProgressReport(bool force) = 0;
407};
408
409// An implementation of V8 heap graph extractor.
411 public:
415 ~V8HeapExplorer() override = default;
418
419 V8_INLINE Isolate* isolate() { return Isolate::FromHeap(heap_); }
420
421 HeapEntry* AllocateEntry(HeapThing ptr) override;
422 HeapEntry* AllocateEntry(Tagged<Smi> smi) override;
423 uint32_t EstimateObjectsCount();
424 void PopulateLineEnds();
425 bool IterateAndExtractReferences(HeapSnapshotGenerator* generator);
426
428 std::vector<std::pair<v8::Global<v8::Object>, const char*>>;
429 // Modifies heap. Must not be run during heap traversal. Collects a temporary
430 // list of global objects and their tags. The list may be invalidated after
431 // running GC.
432 TemporaryGlobalObjectTags CollectTemporaryGlobalObjectsTags();
433 // Converts the temporary list of global objects and their tags into a map
434 // that can be used throughout snapshot generation.
435 void MakeGlobalObjectTagMap(TemporaryGlobalObjectTags&&);
436
437 void TagBuiltinCodeObject(Tagged<Code> code, const char* name);
438 HeapEntry* AddEntry(Address address,
439 HeapEntry::Type type,
440 const char* name,
441 size_t size);
442
443 static Tagged<JSFunction> GetConstructor(Isolate* isolate,
445 static Tagged<String> GetConstructorName(Isolate* isolate,
446 Tagged<JSObject> object);
447
448 private:
449 void MarkVisitedField(int offset);
450
451 HeapEntry* AddEntry(Tagged<HeapObject> object);
452 HeapEntry* AddEntry(Tagged<HeapObject> object, HeapEntry::Type type,
453 const char* name);
454
455 const char* GetSystemEntryName(Tagged<HeapObject> object);
456 HeapEntry::Type GetSystemEntryType(Tagged<HeapObject> object);
457
458 Tagged<JSFunction> GetLocationFunction(Tagged<HeapObject> object);
459 void ExtractLocation(HeapEntry* entry, Tagged<HeapObject> object);
460 void ExtractLocationForJSFunction(HeapEntry* entry, Tagged<JSFunction> func);
461 void ExtractReferences(HeapEntry* entry, Tagged<HeapObject> obj);
462 void ExtractJSGlobalProxyReferences(HeapEntry* entry,
464 void ExtractJSObjectReferences(HeapEntry* entry, Tagged<JSObject> js_obj);
465 void ExtractStringReferences(HeapEntry* entry, Tagged<String> obj);
466 void ExtractSymbolReferences(HeapEntry* entry, Tagged<Symbol> symbol);
467 void ExtractJSCollectionReferences(HeapEntry* entry,
468 Tagged<JSCollection> collection);
469 void ExtractJSWeakCollectionReferences(HeapEntry* entry,
470 Tagged<JSWeakCollection> collection);
471 void ExtractEphemeronHashTableReferences(HeapEntry* entry,
473 void ExtractContextReferences(HeapEntry* entry, Tagged<Context> context);
474 void ExtractMapReferences(HeapEntry* entry, Tagged<Map> map);
475 void ExtractSharedFunctionInfoReferences(HeapEntry* entry,
477 void ExtractScriptReferences(HeapEntry* entry, Tagged<Script> script);
478 void ExtractAccessorInfoReferences(HeapEntry* entry,
479 Tagged<AccessorInfo> accessor_info);
480 void ExtractAccessorPairReferences(HeapEntry* entry,
481 Tagged<AccessorPair> accessors);
482 void ExtractCodeReferences(HeapEntry* entry, Tagged<Code> code);
483 void ExtractInstructionStreamReferences(HeapEntry* entry,
485 void ExtractCellReferences(HeapEntry* entry, Tagged<Cell> cell);
486 void ExtractJSWeakRefReferences(HeapEntry* entry,
487 Tagged<JSWeakRef> js_weak_ref);
488 void ExtractWeakCellReferences(HeapEntry* entry, Tagged<WeakCell> weak_cell);
489 void ExtractFeedbackCellReferences(HeapEntry* entry,
490 Tagged<FeedbackCell> feedback_cell);
491 void ExtractPropertyCellReferences(HeapEntry* entry,
493 void ExtractPrototypeInfoReferences(HeapEntry* entry,
495 void ExtractAllocationSiteReferences(HeapEntry* entry,
497 void ExtractArrayBoilerplateDescriptionReferences(
499 void ExtractRegExpBoilerplateDescriptionReferences(
501 void ExtractJSArrayBufferReferences(HeapEntry* entry,
502 Tagged<JSArrayBuffer> buffer);
503 void ExtractJSPromiseReferences(HeapEntry* entry, Tagged<JSPromise> promise);
504 void ExtractJSGeneratorObjectReferences(HeapEntry* entry,
505 Tagged<JSGeneratorObject> generator);
506 void ExtractFixedArrayReferences(HeapEntry* entry, Tagged<FixedArray> array);
507 void ExtractNumberReference(HeapEntry* entry, Tagged<Object> number);
508 void ExtractBytecodeArrayReferences(HeapEntry* entry,
509 Tagged<BytecodeArray> bytecode);
510 void ExtractScopeInfoReferences(HeapEntry* entry, Tagged<ScopeInfo> info);
511 void ExtractFeedbackVectorReferences(HeapEntry* entry,
512 Tagged<FeedbackVector> feedback_vector);
513 void ExtractDescriptorArrayReferences(HeapEntry* entry,
515 void ExtractEnumCacheReferences(HeapEntry* entry, Tagged<EnumCache> cache);
516 void ExtractTransitionArrayReferences(HeapEntry* entry,
517 Tagged<TransitionArray> transitions);
518 template <typename T>
519 void ExtractWeakArrayReferences(int header_size, HeapEntry* entry,
520 Tagged<T> array);
521 void ExtractPropertyReferences(Tagged<JSObject> js_obj, HeapEntry* entry);
522 void ExtractAccessorPairProperty(HeapEntry* entry, Tagged<Name> key,
523 Tagged<Object> callback_obj,
524 int field_offset = -1);
525 void ExtractElementReferences(Tagged<JSObject> js_obj, HeapEntry* entry);
526 void ExtractInternalReferences(Tagged<JSObject> js_obj, HeapEntry* entry);
527
528#if V8_ENABLE_WEBASSEMBLY
529 void ExtractWasmStructReferences(Tagged<WasmStruct> obj, HeapEntry* entry);
530 void ExtractWasmArrayReferences(Tagged<WasmArray> obj, HeapEntry* entry);
531 void ExtractWasmTrustedInstanceDataReferences(
533 void ExtractWasmInstanceObjectReferences(Tagged<WasmInstanceObject> obj,
534 HeapEntry* entry);
535 void ExtractWasmModuleObjectReferences(Tagged<WasmModuleObject> obj,
536 HeapEntry* entry);
537#endif // V8_ENABLE_WEBASSEMBLY
538
539 bool IsEssentialObject(Tagged<Object> object);
540 bool IsEssentialHiddenReference(Tagged<Object> parent, int field_offset);
541
542 void SetContextReference(HeapEntry* parent_entry,
543 Tagged<String> reference_name, Tagged<Object> child,
544 int field_offset);
545 void SetNativeBindReference(HeapEntry* parent_entry,
546 const char* reference_name, Tagged<Object> child);
547 void SetElementReference(HeapEntry* parent_entry, int index,
548 Tagged<Object> child);
549 void SetInternalReference(HeapEntry* parent_entry, const char* reference_name,
550 Tagged<Object> child, int field_offset = -1);
551 void SetInternalReference(HeapEntry* parent_entry, int index,
552 Tagged<Object> child, int field_offset = -1);
553 void SetHiddenReference(Tagged<HeapObject> parent_obj,
554 HeapEntry* parent_entry, int index,
555 Tagged<Object> child, int field_offset);
556 void SetWeakReference(
557 HeapEntry* parent_entry, const char* reference_name,
558 Tagged<Object> child_obj, int field_offset,
559 HeapEntry::ReferenceVerification verification = HeapEntry::kVerify);
560 void SetWeakReference(HeapEntry* parent_entry, int index,
561 Tagged<Object> child_obj,
562 std::optional<int> field_offset);
563 void SetPropertyReference(HeapEntry* parent_entry,
564 Tagged<Name> reference_name, Tagged<Object> child,
565 const char* name_format_string = nullptr,
566 int field_offset = -1);
567 void SetDataOrAccessorPropertyReference(
568 PropertyKind kind, HeapEntry* parent_entry, Tagged<Name> reference_name,
569 Tagged<Object> child, const char* name_format_string = nullptr,
570 int field_offset = -1);
571
572 void SetUserGlobalReference(Tagged<Object> user_global);
573 void SetRootGcRootsReference();
574 void SetGcRootsReference(Root root);
575 void SetGcSubrootReference(Root root, const char* description, bool is_weak,
576 Tagged<Object> child);
577 const char* GetStrongGcSubrootName(Tagged<HeapObject> object);
578 void TagObject(Tagged<Object> obj, const char* tag,
579 std::optional<HeapEntry::Type> type = {},
580 bool overwrite_existing_name = false);
581 void RecursivelyTagConstantPool(Tagged<Object> obj, const char* tag,
582 HeapEntry::Type type, int recursion_limit);
583
584 HeapEntry* GetEntry(Tagged<Object> obj);
585
592 std::unordered_map<Tagged<JSGlobalObject>, const char*, Object::Hasher>
595 std::unordered_set<Tagged<JSGlobalObject>, Object::Hasher> user_roots_;
597
598 std::vector<bool> visited_fields_;
600
603};
604
605// An implementation of retained native objects extractor.
607 public:
613
614 private:
615 // Returns an entry for a given node, where node may be a V8 node or an
616 // embedder node. Returns the coresponding wrapper node if present.
618 void MergeNodeIntoEntry(HeapEntry* entry, EmbedderGraph::Node* original_node,
619 EmbedderGraph::Node* wrapper_node);
620
625 std::unique_ptr<HeapEntriesAllocator> embedder_graph_entries_allocator_;
626 // Used during references extraction.
628
630
632};
633
634class HeapEntryVerifier;
635
637 public:
638 // The HeapEntriesMap instance is used to track a mapping between
639 // real heap objects and their representations in heap snapshots.
641 // The SmiEntriesMap instance is used to track a mapping between smi and
642 // their representations in heap snapshots.
643 using SmiEntriesMap = std::unordered_map<int, HeapEntry*>;
644
647 Heap* heap, cppgc::EmbedderStackState stack_state);
650 bool GenerateSnapshot();
652
654 HeapEntriesMap::Entry* entry =
656 return entry ? static_cast<HeapEntry*>(entry->value) : nullptr;
657 }
658
660 auto it = smis_map_.find(smi.value());
661 return it != smis_map_.end() ? it->second : nullptr;
662 }
663
664#ifdef V8_ENABLE_HEAP_SNAPSHOT_VERIFY
665 HeapThing FindHeapThingForHeapEntry(HeapEntry* entry) {
666 // The reverse lookup map is only populated if the verification flag is
667 // enabled.
668 DCHECK(v8_flags.heap_snapshot_verify);
669
670 auto it = reverse_entries_map_.find(entry);
671 return it == reverse_entries_map_.end() ? nullptr : it->second;
672 }
673
674 HeapEntryVerifier* verifier() const { return verifier_; }
675 void set_verifier(HeapEntryVerifier* verifier) {
676 DCHECK_IMPLIES(verifier_, !verifier);
677 verifier_ = verifier;
678 }
679#endif
680
682 return smis_map_.emplace(smi.value(), allocator->AllocateEntry(smi))
683 .first->second;
684 }
685
687 HeapEntriesMap::Entry* entry =
689 if (entry->value != nullptr) {
690 return static_cast<HeapEntry*>(entry->value);
691 }
692 HeapEntry* result = allocator->AllocateEntry(ptr);
693 entry->value = result;
694#ifdef V8_ENABLE_HEAP_SNAPSHOT_VERIFY
695 if (v8_flags.heap_snapshot_verify) {
696 reverse_entries_map_.emplace(result, ptr);
697 }
698#endif
699 return result;
700 }
701
703 HeapEntry* entry = FindEntry(smi);
704 return entry != nullptr ? entry : AddEntry(smi, allocator);
705 }
706
707 Heap* heap() const { return heap_; }
708
709 private:
710 bool FillReferences();
711 void ProgressStep() override;
712 bool ProgressReport(bool force = false) override;
713 void InitProgressCounter();
714
719 // Mapping from HeapThing pointers to HeapEntry indices.
722 // Used during snapshot generation.
727
728#ifdef V8_ENABLE_HEAP_SNAPSHOT_VERIFY
729 std::unordered_map<HeapEntry*, HeapThing> reverse_entries_map_;
730 HeapEntryVerifier* verifier_ = nullptr;
731#endif
732};
733
735
737 public:
739 : snapshot_(snapshot),
741 next_node_id_(1),
743 writer_(nullptr) {}
746 delete;
747 void Serialize(v8::OutputStream* stream);
748
749 private:
750 V8_INLINE static bool StringsMatch(void* key1, void* key2) {
751 return strcmp(reinterpret_cast<char*>(key1),
752 reinterpret_cast<char*>(key2)) == 0;
753 }
754
755 V8_INLINE static uint32_t StringHash(const void* string);
756
757 int GetStringId(const char* s);
758 V8_INLINE int to_node_index(const HeapEntry* e);
759 V8_INLINE int to_node_index(int entry_index);
760 void SerializeEdge(HeapGraphEdge* edge, bool first_edge);
761 void SerializeEdges();
762 void SerializeImpl();
763 void SerializeNode(const HeapEntry* entry);
764 void SerializeNodes();
765 void SerializeSnapshot();
766 void SerializeTraceTree();
769 void SerializeSamples();
770 void SerializeString(const unsigned char* s);
771 void SerializeStrings();
772 void SerializeLocation(const EntrySourceLocation& location);
773 void SerializeLocations();
774
775 static const int kEdgeFieldsCount;
778
785
788};
789
790} // namespace v8::internal
791
792#endif // V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_H_
Builtins::Kind kind
Definition builtins.cc:40
static constexpr T decode(U value)
Definition bit-field.h:66
Entry * LookupOrInsert(const Key &key, uint32_t hash)
Definition hashmap.h:223
Entry * Lookup(const Key &key, uint32_t hash) const
Definition hashmap.h:214
virtual HeapEntry * AllocateEntry(HeapThing ptr)=0
virtual HeapEntry * AllocateEntry(Tagged< Smi > smi)=0
virtual ~HeapEntriesAllocator()=default
V8_INLINE std::vector< HeapGraphEdge * >::iterator children_end() const
void set_detachedness(v8::EmbedderGraph::Node::Detachedness value)
V8_EXPORT_PRIVATE void Print(const char *prefix, const char *edge_name, int max_depth, int indent) const
void SetIndexedAutoIndexReference(HeapGraphEdge::Type type, HeapEntry *child, HeapSnapshotGenerator *generator, ReferenceVerification verification=kVerify)
HeapEntry(HeapSnapshot *snapshot, int index, Type type, const char *name, SnapshotObjectId id, size_t self_size, unsigned trace_node_id)
SnapshotObjectId id() const
V8_INLINE void add_child(HeapGraphEdge *edge)
void VerifyReference(HeapGraphEdge::Type type, HeapEntry *entry, HeapSnapshotGenerator *generator, ReferenceVerification verification)
void SetNamedAutoIndexReference(HeapGraphEdge::Type type, const char *description, HeapEntry *child, StringsStorage *strings, HeapSnapshotGenerator *generator, ReferenceVerification verification=kVerify)
V8_INLINE int set_children_index(int index)
void SetIndexedReference(HeapGraphEdge::Type type, int index, HeapEntry *entry, HeapSnapshotGenerator *generator, ReferenceVerification verification=kVerify)
V8_INLINE std::vector< HeapGraphEdge * >::iterator children_begin() const
void set_name(const char *name)
V8_INLINE HeapGraphEdge * child(int i)
V8_INLINE Isolate * isolate() const
void SetNamedReference(HeapGraphEdge::Type type, const char *name, HeapEntry *entry, HeapSnapshotGenerator *generator, ReferenceVerification verification=kVerify)
V8_INLINE Isolate * isolate() const
HeapGraphEdge(Type type, const char *name, HeapEntry *from, HeapEntry *to)
V8_INLINE HeapSnapshot * snapshot() const
V8_INLINE HeapEntry * from() const
static const SnapshotObjectId kFirstAvailableObjectId
static const SnapshotObjectId kInternalRootObjectId
static const SnapshotObjectId kGcRootsFirstSubrootId
void UpdateObjectSize(Address addr, int size)
HeapObjectsMap(const HeapObjectsMap &)=delete
SnapshotObjectId FindOrAddEntry(Address addr, unsigned int size, MarkEntryAccessed accessed=MarkEntryAccessed::kYes, IsNativeObject is_native_object=IsNativeObject::kNo)
bool MoveObject(Address from, Address to, int size)
SnapshotObjectId last_assigned_id() const
const std::vector< TimeInterval > & samples() const
SnapshotObjectId FindMergedNativeEntry(NativeObject addr)
HeapObjectsMap & operator=(const HeapObjectsMap &)=delete
SnapshotObjectId PushHeapObjectsStats(OutputStream *stream, int64_t *timestamp_us)
static const SnapshotObjectId kFirstAvailableNativeId
SnapshotObjectId FindEntry(Address addr)
static const SnapshotObjectId kGcRootsObjectId
std::unordered_map< NativeObject, size_t > merged_native_entries_map_
void AddMergedNativeEntry(NativeObject addr, Address canonical_addr)
std::vector< TimeInterval > time_intervals_
HeapSnapshotGenerator & operator=(const HeapSnapshotGenerator &)=delete
HeapEntry * FindEntry(Tagged< Smi > smi)
std::unordered_map< int, HeapEntry * > SmiEntriesMap
bool ProgressReport(bool force=false) override
HeapEntry * FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator *allocator)
HeapSnapshotGenerator(const HeapSnapshotGenerator &)=delete
HeapSnapshotGenerator(HeapSnapshot *snapshot, v8::ActivityControl *control, v8::HeapProfiler::ObjectNameResolver *resolver, Heap *heap, cppgc::EmbedderStackState stack_state)
HeapEntry * AddEntry(Tagged< Smi > smi, HeapEntriesAllocator *allocator)
HeapEntry * FindOrAddEntry(Tagged< Smi > smi, HeapEntriesAllocator *allocator)
void SerializeTraceNode(AllocationTraceNode *node)
static V8_INLINE uint32_t StringHash(const void *string)
void SerializeLocation(const EntrySourceLocation &location)
void SerializeEdge(HeapGraphEdge *edge, bool first_edge)
V8_INLINE int to_node_index(const HeapEntry *e)
HeapSnapshotJSONSerializer & operator=(const HeapSnapshotJSONSerializer &)=delete
static V8_INLINE bool StringsMatch(void *key1, void *key2)
HeapSnapshotJSONSerializer(const HeapSnapshotJSONSerializer &)=delete
HeapSnapshot(HeapProfiler *profiler, v8::HeapProfiler::HeapSnapshotMode snapshot_mode, v8::HeapProfiler::NumericsMode numerics_mode)
void AddScriptLineEnds(int script_id, String::LineEndsVector &&line_ends)
std::deque< HeapEntry > & entries()
String::LineEndsVector & GetScriptLineEnds(int script_id)
std::deque< HeapGraphEdge > edges_
v8::HeapProfiler::NumericsMode numerics_mode_
SnapshotObjectId max_snapshot_js_object_id() const
const std::deque< HeapEntry > & entries() const
v8::HeapProfiler::HeapSnapshotMode snapshot_mode_
void AddLocation(HeapEntry *entry, int scriptId, int line, int col)
HeapEntry * AddEntry(HeapEntry::Type type, const char *name, SnapshotObjectId id, size_t size, unsigned trace_node_id)
const std::deque< HeapGraphEdge > & edges() const
std::vector< EntrySourceLocation > locations_
std::deque< HeapGraphEdge > & edges()
HeapEntry * GetEntryById(SnapshotObjectId id)
std::unordered_map< SnapshotObjectId, HeapEntry * > entries_by_id_cache_
HeapSnapshot(const HeapSnapshot &)=delete
std::unordered_map< ScriptId, String::LineEndsVector > ScriptsLineEndsMap
const std::vector< EntrySourceLocation > & locations() const
HeapEntry * gc_subroot_entries_[static_cast< int >(Root::kNumberOfRoots)]
HeapSnapshot & operator=(const HeapSnapshot &)=delete
void AddGcSubrootEntry(Root root, SnapshotObjectId id)
std::vector< HeapGraphEdge * > children_
HeapEntry * gc_subroot(Root root) const
std::vector< HeapGraphEdge * > & children()
NativeObjectsExplorer(const NativeObjectsExplorer &)=delete
NativeObjectsExplorer & operator=(const NativeObjectsExplorer &)=delete
HeapEntry * EntryForEmbedderGraphNode(EmbedderGraph::Node *node)
bool IterateAndExtractReferences(HeapSnapshotGenerator *generator)
NativeObjectsExplorer(HeapSnapshot *snapshot, SnapshottingProgressReportingInterface *progress)
void MergeNodeIntoEntry(HeapEntry *entry, EmbedderGraph::Node *original_node, EmbedderGraph::Node *wrapper_node)
std::unique_ptr< HeapEntriesAllocator > embedder_graph_entries_allocator_
SnapshottingProgressReportingInterface * progress_
std::unordered_set< Tagged< JSGlobalObject >, Object::Hasher > user_roots_
v8::HeapProfiler::ObjectNameResolver * global_object_name_resolver_
V8HeapExplorer & operator=(const V8HeapExplorer &)=delete
UnorderedHeapObjectMap< const char * > strong_gc_subroot_names_
std::unordered_map< Tagged< JSGlobalObject >, const char *, Object::Hasher > global_object_tag_map_
V8HeapExplorer(const V8HeapExplorer &)=delete
std::vector< std::pair< v8::Global< v8::Object >, const char * > > TemporaryGlobalObjectTags
~V8HeapExplorer() override=default
int32_t offset
TNode< Object > receiver
std::unique_ptr< icu::DateTimePatternGenerator > generator_
ZoneVector< RpoNumber > & result
EmbedderStackState
Definition common.h:15
PointerTemplateHashMapImpl< DefaultAllocationPolicy > HashMap
Definition hashmap.h:520
uint32_t ComputePointerHash(void *ptr)
Definition utils.h:301
V8_EXPORT_PRIVATE FlagValues v8_flags
refactor address components for immediate indexing make OptimizeMaglevOnNextCall optimize to turbofan instead of maglev filter for tracing turbofan compilation nullptr
Definition flags.cc:1263
return value
Definition map-inl.h:893
std::unordered_map< Tagged< HeapObject >, T, Object::Hasher, Object::KeyEqualSafe > UnorderedHeapObjectMap
Definition heap.h:179
void * NativeObject
Definition v8-profiler.h:30
uint32_t SnapshotObjectId
Definition v8-profiler.h:31
SimplifiedLoweringVerifier * verifier_
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482
#define V8_EXPORT_PRIVATE
Definition macros.h:460
EntrySourceLocation(int entry_index, int scriptId, int line, int col)
EntryInfo(SnapshotObjectId id, Address addr, unsigned int size, bool accessed)
Heap * heap_
#define V8_INLINE
Definition v8config.h:500
std::unique_ptr< ValueMirror > key