Commit 187cb431 authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[heap profiler] Refactor visited field tracking.

- Make it explicit that the field marks are supposed to be all-false after each
  object.

- Remove unused param from MarkVisitedField.

BUG=v8:7534

Change-Id: Ibc226290bb09daca60b92819944e0049bb33e594
Reviewed-on: https://chromium-review.googlesource.com/951725Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51799}
parent 383ec7b5
...@@ -790,31 +790,31 @@ class IndexedReferencesExtractor : public ObjectVisitor { ...@@ -790,31 +790,31 @@ class IndexedReferencesExtractor : public ObjectVisitor {
parent_obj_(parent_obj), parent_obj_(parent_obj),
parent_start_(HeapObject::RawField(parent_obj_, 0)), parent_start_(HeapObject::RawField(parent_obj_, 0)),
parent_end_(HeapObject::RawField(parent_obj_, parent_obj_->Size())), parent_end_(HeapObject::RawField(parent_obj_, parent_obj_->Size())),
parent_(parent), parent_(parent) {}
next_index_(0) {}
void VisitPointers(HeapObject* host, Object** start, Object** end) override { void VisitPointers(HeapObject* host, Object** start, Object** end) override {
VisitPointers(host, reinterpret_cast<MaybeObject**>(start), VisitPointers(host, reinterpret_cast<MaybeObject**>(start),
reinterpret_cast<MaybeObject**>(end)); reinterpret_cast<MaybeObject**>(end));
} }
void VisitPointers(HeapObject* host, MaybeObject** start, void VisitPointers(HeapObject* host, MaybeObject** start,
MaybeObject** end) override { MaybeObject** end) override {
int next_index = 0;
for (MaybeObject** p = start; p < end; p++) { for (MaybeObject** p = start; p < end; p++) {
int index = static_cast<int>(reinterpret_cast<Object**>(p) - int index = static_cast<int>(reinterpret_cast<Object**>(p) -
HeapObject::RawField(parent_obj_, 0)); HeapObject::RawField(parent_obj_, 0));
++next_index_; ++next_index;
// |p| could be outside of the object, e.g., while visiting RelocInfo of // |p| could be outside of the object, e.g., while visiting RelocInfo of
// code objects. // code objects.
if (reinterpret_cast<Object**>(p) >= parent_start_ && if (reinterpret_cast<Object**>(p) >= parent_start_ &&
reinterpret_cast<Object**>(p) < parent_end_ && reinterpret_cast<Object**>(p) < parent_end_ &&
generator_->marks_[index]) { generator_->visited_fields_[index]) {
generator_->marks_[index] = false; generator_->visited_fields_[index] = false;
continue; continue;
} }
HeapObject* heap_object; HeapObject* heap_object;
// Weak references have been handled explicitly. // Weak references have been handled explicitly.
DCHECK(!(*p)->ToWeakHeapObject(&heap_object)); DCHECK(!(*p)->ToWeakHeapObject(&heap_object));
if ((*p)->ToStrongHeapObject(&heap_object)) { if ((*p)->ToStrongHeapObject(&heap_object)) {
generator_->SetHiddenReference(parent_obj_, parent_, next_index_, generator_->SetHiddenReference(parent_obj_, parent_, next_index,
heap_object, index * kPointerSize); heap_object, index * kPointerSize);
} }
} }
...@@ -826,7 +826,6 @@ class IndexedReferencesExtractor : public ObjectVisitor { ...@@ -826,7 +826,6 @@ class IndexedReferencesExtractor : public ObjectVisitor {
Object** parent_start_; Object** parent_start_;
Object** parent_end_; Object** parent_end_;
int parent_; int parent_;
int next_index_;
}; };
...@@ -1590,11 +1589,11 @@ bool V8HeapExplorer::IterateAndExtractSinglePass() { ...@@ -1590,11 +1589,11 @@ bool V8HeapExplorer::IterateAndExtractSinglePass() {
if (interrupted) continue; if (interrupted) continue;
size_t max_pointer = obj->Size() / kPointerSize; size_t max_pointer = obj->Size() / kPointerSize;
if (max_pointer > marks_.size()) { if (max_pointer > visited_fields_.size()) {
// Clear the current bits. // Clear the current bits.
std::vector<bool>().swap(marks_); std::vector<bool>().swap(visited_fields_);
// Reallocate to right size. // Reallocate to right size.
marks_.resize(max_pointer, false); visited_fields_.resize(max_pointer, false);
} }
HeapEntry* heap_entry = GetEntry(obj); HeapEntry* heap_entry = GetEntry(obj);
...@@ -1607,6 +1606,10 @@ bool V8HeapExplorer::IterateAndExtractSinglePass() { ...@@ -1607,6 +1606,10 @@ bool V8HeapExplorer::IterateAndExtractSinglePass() {
IndexedReferencesExtractor refs_extractor(this, obj, entry); IndexedReferencesExtractor refs_extractor(this, obj, entry);
obj->Iterate(&refs_extractor); obj->Iterate(&refs_extractor);
} }
// Ensure visited_fields_ doesn't leak to the next object.
for (size_t i = 0; i < max_pointer; ++i) {
DCHECK(!visited_fields_[i]);
}
if (!progress_->ProgressReport(false)) interrupted = true; if (!progress_->ProgressReport(false)) interrupted = true;
} }
...@@ -1651,15 +1654,14 @@ void V8HeapExplorer::SetContextReference(HeapObject* parent_obj, ...@@ -1651,15 +1654,14 @@ void V8HeapExplorer::SetContextReference(HeapObject* parent_obj,
if (child_entry == nullptr) return; if (child_entry == nullptr) return;
filler_->SetNamedReference(HeapGraphEdge::kContextVariable, parent_entry, filler_->SetNamedReference(HeapGraphEdge::kContextVariable, parent_entry,
names_->GetName(reference_name), child_entry); names_->GetName(reference_name), child_entry);
MarkVisitedField(parent_obj, field_offset); MarkVisitedField(field_offset);
} }
void V8HeapExplorer::MarkVisitedField(int offset) {
void V8HeapExplorer::MarkVisitedField(HeapObject* obj, int offset) {
if (offset < 0) return; if (offset < 0) return;
int index = offset / kPointerSize; int index = offset / kPointerSize;
DCHECK(!marks_[index]); DCHECK(!visited_fields_[index]);
marks_[index] = true; visited_fields_[index] = true;
} }
...@@ -1701,7 +1703,7 @@ void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, ...@@ -1701,7 +1703,7 @@ void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
reference_name, reference_name,
child_entry); child_entry);
} }
MarkVisitedField(parent_obj, field_offset); MarkVisitedField(field_offset);
} }
...@@ -1719,7 +1721,7 @@ void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj, ...@@ -1719,7 +1721,7 @@ void V8HeapExplorer::SetInternalReference(HeapObject* parent_obj,
names_->GetName(index), names_->GetName(index),
child_entry); child_entry);
} }
MarkVisitedField(parent_obj, field_offset); MarkVisitedField(field_offset);
} }
void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj, void V8HeapExplorer::SetHiddenReference(HeapObject* parent_obj,
...@@ -1749,7 +1751,7 @@ void V8HeapExplorer::SetWeakReference(HeapObject* parent_obj, ...@@ -1749,7 +1751,7 @@ void V8HeapExplorer::SetWeakReference(HeapObject* parent_obj,
reference_name, reference_name,
child_entry); child_entry);
} }
MarkVisitedField(parent_obj, field_offset); MarkVisitedField(field_offset);
} }
...@@ -1767,7 +1769,7 @@ void V8HeapExplorer::SetWeakReference(HeapObject* parent_obj, ...@@ -1767,7 +1769,7 @@ void V8HeapExplorer::SetWeakReference(HeapObject* parent_obj,
names_->GetFormatted("%d", index), names_->GetFormatted("%d", index),
child_entry); child_entry);
} }
MarkVisitedField(parent_obj, field_offset); MarkVisitedField(field_offset);
} }
...@@ -1808,7 +1810,7 @@ void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj, ...@@ -1808,7 +1810,7 @@ void V8HeapExplorer::SetPropertyReference(HeapObject* parent_obj,
: names_->GetName(reference_name); : names_->GetName(reference_name);
filler_->SetNamedReference(type, parent_entry, name, child_entry); filler_->SetNamedReference(type, parent_entry, name, child_entry);
MarkVisitedField(parent_obj, field_offset); MarkVisitedField(field_offset);
} }
void V8HeapExplorer::SetRootGcRootsReference() { void V8HeapExplorer::SetRootGcRootsReference() {
......
...@@ -355,7 +355,7 @@ class V8HeapExplorer : public HeapEntriesAllocator { ...@@ -355,7 +355,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
typedef bool (V8HeapExplorer::*ExtractReferencesMethod)(int entry, typedef bool (V8HeapExplorer::*ExtractReferencesMethod)(int entry,
HeapObject* object); HeapObject* object);
void MarkVisitedField(HeapObject* obj, int offset); void MarkVisitedField(int offset);
HeapEntry* AddEntry(HeapObject* object); HeapEntry* AddEntry(HeapObject* object);
HeapEntry* AddEntry(HeapObject* object, HeapEntry* AddEntry(HeapObject* object,
...@@ -471,7 +471,7 @@ class V8HeapExplorer : public HeapEntriesAllocator { ...@@ -471,7 +471,7 @@ class V8HeapExplorer : public HeapEntriesAllocator {
std::unordered_map<const FixedArray*, FixedArraySubInstanceType> array_types_; std::unordered_map<const FixedArray*, FixedArraySubInstanceType> array_types_;
v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_; v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_;
std::vector<bool> marks_; std::vector<bool> visited_fields_;
friend class IndexedReferencesExtractor; friend class IndexedReferencesExtractor;
friend class RootsReferencesExtractor; friend class RootsReferencesExtractor;
......
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