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_INL_H_ 6 #define V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_ 7 8 #include "src/profiler/heap-snapshot-generator.h" 9 10 #include "src/profiler/heap-profiler.h" 11 #include "src/string-hasher-inl.h" 12 13 namespace v8 { 14 namespace internal { 15 16 from()17HeapEntry* HeapGraphEdge::from() const { 18 return &snapshot()->entries()[from_index()]; 19 } 20 21 isolate()22Isolate* HeapGraphEdge::isolate() const { 23 return snapshot()->profiler()->isolate(); 24 } 25 26 snapshot()27HeapSnapshot* HeapGraphEdge::snapshot() const { 28 return to_entry_->snapshot(); 29 } 30 31 index()32int HeapEntry::index() const { 33 return static_cast<int>(this - &snapshot_->entries().front()); 34 } 35 36 set_children_index(int index)37int HeapEntry::set_children_index(int index) { 38 children_index_ = index; 39 int next_index = index + children_count_; 40 children_count_ = 0; 41 return next_index; 42 } 43 add_child(HeapGraphEdge * edge)44void HeapEntry::add_child(HeapGraphEdge* edge) { 45 *(children_begin() + children_count_++) = edge; 46 } 47 child(int i)48HeapGraphEdge* HeapEntry::child(int i) { return *(children_begin() + i); } 49 children_begin()50std::deque<HeapGraphEdge*>::iterator HeapEntry::children_begin() { 51 DCHECK_GE(children_index_, 0); 52 SLOW_DCHECK( 53 children_index_ < static_cast<int>(snapshot_->children().size()) || 54 (children_index_ == static_cast<int>(snapshot_->children().size()) && 55 children_count_ == 0)); 56 return snapshot_->children().begin() + children_index_; 57 } 58 children_end()59std::deque<HeapGraphEdge*>::iterator HeapEntry::children_end() { 60 return children_begin() + children_count_; 61 } 62 isolate()63Isolate* HeapEntry::isolate() const { return snapshot_->profiler()->isolate(); } 64 StringHash(const void * string)65uint32_t HeapSnapshotJSONSerializer::StringHash(const void* string) { 66 const char* s = reinterpret_cast<const char*>(string); 67 int len = static_cast<int>(strlen(s)); 68 return StringHasher::HashSequentialString(s, len, 69 v8::internal::kZeroHashSeed); 70 } 71 to_node_index(const HeapEntry * e)72int HeapSnapshotJSONSerializer::to_node_index(const HeapEntry* e) { 73 return to_node_index(e->index()); 74 } 75 to_node_index(int entry_index)76int HeapSnapshotJSONSerializer::to_node_index(int entry_index) { 77 return entry_index * kNodeFieldsCount; 78 } 79 80 } // namespace internal 81 } // namespace v8 82 83 #endif // V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_ 84