Commit 181bbd5c authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

Reland "[heap profiler] Refactor: Replace indices with HeapEntry*"

This is a reland of 69a502ce

TBR=ulan@chromium.org

Original change's description:
> [heap profiler] Refactor: Replace indices with HeapEntry*
>
> Change-Id: I0c176f66711d45e2f59d527f3133a1afbf825ec3
> Reviewed-on: https://chromium-review.googlesource.com/1229613
> Commit-Queue: Alexei Filippov <alph@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#56245}

Change-Id: I416da19eb38a1a55f5e2f5897062bc1ca454ac34
Reviewed-on: https://chromium-review.googlesource.com/1246802
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56250}
parent e6d208b6
......@@ -13,51 +13,41 @@
namespace v8 {
namespace internal {
HeapEntry* HeapGraphEdge::from() const {
return &snapshot()->entries()[from_index()];
}
Isolate* HeapGraphEdge::isolate() const {
return snapshot()->profiler()->isolate();
}
Isolate* HeapGraphEdge::isolate() const { return to_entry_->isolate(); }
HeapSnapshot* HeapGraphEdge::snapshot() const {
return to_entry_->snapshot();
}
int HeapEntry::index() const {
return static_cast<int>(this - &snapshot_->entries().front());
}
int HeapEntry::set_children_index(int index) {
children_index_ = index;
// Note: children_count_ and children_end_index_ are parts of a union.
int next_index = index + children_count_;
children_count_ = 0;
children_end_index_ = index;
return next_index;
}
void HeapEntry::add_child(HeapGraphEdge* edge) {
*(children_begin() + children_count_++) = edge;
snapshot_->children()[children_end_index_++] = edge;
}
HeapGraphEdge* HeapEntry::child(int i) { return *(children_begin() + i); }
HeapGraphEdge* HeapEntry::child(int i) { return children_begin()[i]; }
std::vector<HeapGraphEdge*>::iterator HeapEntry::children_begin() const {
return index_ == 0 ? snapshot_->children().begin()
: snapshot_->entries()[index_ - 1].children_end();
}
std::deque<HeapGraphEdge*>::iterator HeapEntry::children_begin() {
DCHECK_GE(children_index_, 0);
SLOW_DCHECK(
children_index_ < static_cast<int>(snapshot_->children().size()) ||
(children_index_ == static_cast<int>(snapshot_->children().size()) &&
children_count_ == 0));
return snapshot_->children().begin() + children_index_;
std::vector<HeapGraphEdge*>::iterator HeapEntry::children_end() const {
DCHECK_GE(children_end_index_, 0);
return snapshot_->children().begin() + children_end_index_;
}
std::deque<HeapGraphEdge*>::iterator HeapEntry::children_end() {
return children_begin() + children_count_;
int HeapEntry::children_count() const {
return static_cast<int>(children_end() - children_begin());
}
Isolate* HeapEntry::isolate() const { return snapshot_->profiler()->isolate(); }
......
This diff is collapsed.
This diff is collapsed.
......@@ -157,12 +157,9 @@ static Optional<SourceLocation> GetLocation(const v8::HeapSnapshot* s,
const v8::HeapGraphNode* node) {
const i::HeapSnapshot* snapshot = reinterpret_cast<const i::HeapSnapshot*>(s);
const std::vector<SourceLocation>& locations = snapshot->locations();
const int index =
const_cast<i::HeapEntry*>(reinterpret_cast<const i::HeapEntry*>(node))
->index();
const i::HeapEntry* entry = reinterpret_cast<const i::HeapEntry*>(node);
for (const auto& loc : locations) {
if (loc.entry_index == index) {
if (loc.entry_index == entry->index()) {
return Optional<SourceLocation>(loc);
}
}
......@@ -223,7 +220,7 @@ static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) {
entry->value = reinterpret_cast<void*>(ref_count + 1);
}
uint32_t unretained_entries_count = 0;
std::vector<i::HeapEntry>& entries = heap_snapshot->entries();
std::deque<i::HeapEntry>& entries = heap_snapshot->entries();
for (i::HeapEntry& entry : entries) {
v8::base::HashMap::Entry* map_entry = visited.Lookup(
reinterpret_cast<void*>(&entry),
......@@ -1003,21 +1000,6 @@ TEST(HeapEntryIdsAndGC) {
CHECK_EQ(b1->GetId(), b2->GetId());
}
TEST(HeapSnapshotRootPreservedAfterSorting) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* root1 = snapshot->GetRoot();
const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>(
snapshot))->GetSortedEntriesList();
const v8::HeapGraphNode* root2 = snapshot->GetRoot();
CHECK_EQ(root1, root2);
}
namespace {
class TestJSONStream : public v8::OutputStream {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment