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
13namespace v8 {
14namespace internal {
15
16HeapEntry* HeapGraphEdge::from() const {
17 return &snapshot()->entries()[from_index()];
18}
19
20Isolate* HeapGraphEdge::isolate() const { return to_entry_->isolate(); }
21
22HeapSnapshot* HeapGraphEdge::snapshot() const {
23 return to_entry_->snapshot();
24}
25
26int HeapEntry::set_children_index(int index) {
27 // Note: children_count_ and children_end_index_ are parts of a union.
28 int next_index = index + children_count_;
29 children_end_index_ = index;
30 return next_index;
31}
32
33void HeapEntry::add_child(HeapGraphEdge* edge) {
34 snapshot_->children()[children_end_index_++] = edge;
35}
36
37HeapGraphEdge* HeapEntry::child(int i) { return children_begin()[i]; }
38
39std::vector<HeapGraphEdge*>::iterator HeapEntry::children_begin() const {
40 return index_ == 0 ? snapshot_->children().begin()
41 : snapshot_->entries()[index_ - 1].children_end();
42}
43
44std::vector<HeapGraphEdge*>::iterator HeapEntry::children_end() const {
45 DCHECK_GE(children_end_index_, 0);
46 return snapshot_->children().begin() + children_end_index_;
47}
48
49int HeapEntry::children_count() const {
50 return static_cast<int>(children_end() - children_begin());
51}
52
53Isolate* HeapEntry::isolate() const { return snapshot_->profiler()->isolate(); }
54
55uint32_t HeapSnapshotJSONSerializer::StringHash(const void* string) {
56 const char* s = reinterpret_cast<const char*>(string);
57 int len = static_cast<int>(strlen(s));
58 return StringHasher::HashSequentialString(s, len,
59 v8::internal::kZeroHashSeed);
60}
61
62int HeapSnapshotJSONSerializer::to_node_index(const HeapEntry* e) {
63 return to_node_index(e->index());
64}
65
66int HeapSnapshotJSONSerializer::to_node_index(int entry_index) {
67 return entry_index * kNodeFieldsCount;
68}
69
70} // namespace internal
71} // namespace v8
72
73#endif // V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_
74