Commit 19b89813 authored by Maciej Goszczycki's avatar Maciej Goszczycki Committed by Commit Bot

[roheap] Make all HeapIterators have matching APIs

This makes the API more consistent.

Originally I planned to use this to template iterators inside mkgrokdump, but
I decided against it.

Bug: v8:9183
Change-Id: Iefa372370a7cc7c637dc86c0bfb837a91a2bc6e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1622116Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Commit-Queue: Maciej Goszczycki <goszczycki@google.com>
Cr-Commit-Position: refs/heads/master@{#61705}
parent 29557523
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
HeapObject CombinedHeapIterator::next() { HeapObject CombinedHeapIterator::Next() {
HeapObject object = ro_heap_iterator_.next(); HeapObject object = ro_heap_iterator_.Next();
if (!object.is_null()) { if (!object.is_null()) {
return object; return object;
} }
......
...@@ -23,7 +23,7 @@ class V8_EXPORT_PRIVATE CombinedHeapIterator final { ...@@ -23,7 +23,7 @@ class V8_EXPORT_PRIVATE CombinedHeapIterator final {
HeapIterator::HeapObjectsFiltering::kNoFiltering) HeapIterator::HeapObjectsFiltering::kNoFiltering)
: heap_iterator_(heap, filtering), : heap_iterator_(heap, filtering),
ro_heap_iterator_(heap->read_only_heap()) {} ro_heap_iterator_(heap->read_only_heap()) {}
HeapObject next(); HeapObject Next();
private: private:
HeapIterator heap_iterator_; HeapIterator heap_iterator_;
......
...@@ -514,8 +514,8 @@ void MarkCompactCollector::CollectGarbage() { ...@@ -514,8 +514,8 @@ void MarkCompactCollector::CollectGarbage() {
#ifdef VERIFY_HEAP #ifdef VERIFY_HEAP
void MarkCompactCollector::VerifyMarkbitsAreDirty(ReadOnlySpace* space) { void MarkCompactCollector::VerifyMarkbitsAreDirty(ReadOnlySpace* space) {
ReadOnlyHeapIterator iterator(space); ReadOnlyHeapIterator iterator(space);
for (HeapObject object = iterator.next(); !object.is_null(); for (HeapObject object = iterator.Next(); !object.is_null();
object = iterator.next()) { object = iterator.Next()) {
CHECK(non_atomic_marking_state()->IsBlack(object)); CHECK(non_atomic_marking_state()->IsBlack(object));
} }
} }
......
...@@ -1081,8 +1081,8 @@ namespace { ...@@ -1081,8 +1081,8 @@ namespace {
void IterateHeap(Heap* heap, ObjectStatsVisitor* visitor) { void IterateHeap(Heap* heap, ObjectStatsVisitor* visitor) {
CombinedHeapIterator iterator(heap); CombinedHeapIterator iterator(heap);
for (HeapObject obj = iterator.next(); !obj.is_null(); for (HeapObject obj = iterator.Next(); !obj.is_null();
obj = iterator.next()) { obj = iterator.Next()) {
visitor->Visit(obj, obj->Size()); visitor->Visit(obj, obj->Size());
} }
} }
......
...@@ -142,7 +142,7 @@ ReadOnlyHeapIterator::ReadOnlyHeapIterator(ReadOnlySpace* ro_space) ...@@ -142,7 +142,7 @@ ReadOnlyHeapIterator::ReadOnlyHeapIterator(ReadOnlySpace* ro_space)
current_page_(ro_space->first_page()), current_page_(ro_space->first_page()),
current_addr_(current_page_->area_start()) {} current_addr_(current_page_->area_start()) {}
HeapObject ReadOnlyHeapIterator::next() { HeapObject ReadOnlyHeapIterator::Next() {
if (current_page_ == nullptr) { if (current_page_ == nullptr) {
return HeapObject(); return HeapObject();
} }
......
...@@ -89,7 +89,7 @@ class V8_EXPORT_PRIVATE ReadOnlyHeapIterator { ...@@ -89,7 +89,7 @@ class V8_EXPORT_PRIVATE ReadOnlyHeapIterator {
explicit ReadOnlyHeapIterator(ReadOnlyHeap* ro_heap); explicit ReadOnlyHeapIterator(ReadOnlyHeap* ro_heap);
explicit ReadOnlyHeapIterator(ReadOnlySpace* ro_space); explicit ReadOnlyHeapIterator(ReadOnlySpace* ro_space);
HeapObject next(); HeapObject Next();
private: private:
ReadOnlySpace* const ro_space_; ReadOnlySpace* const ro_space_;
......
...@@ -3423,7 +3423,7 @@ void ReadOnlySpace::ClearStringPaddingIfNeeded() { ...@@ -3423,7 +3423,7 @@ void ReadOnlySpace::ClearStringPaddingIfNeeded() {
if (is_string_padding_cleared_) return; if (is_string_padding_cleared_) return;
ReadOnlyHeapIterator iterator(this); ReadOnlyHeapIterator iterator(this);
for (HeapObject o = iterator.next(); !o.is_null(); o = iterator.next()) { for (HeapObject o = iterator.Next(); !o.is_null(); o = iterator.Next()) {
if (o->IsSeqOneByteString()) { if (o->IsSeqOneByteString()) {
SeqOneByteString::cast(o)->clear_padding(); SeqOneByteString::cast(o)->clear_padding();
} else if (o->IsSeqTwoByteString()) { } else if (o->IsSeqTwoByteString()) {
......
...@@ -175,8 +175,8 @@ Handle<HeapObject> HeapProfiler::FindHeapObjectById(SnapshotObjectId id) { ...@@ -175,8 +175,8 @@ Handle<HeapObject> HeapProfiler::FindHeapObjectById(SnapshotObjectId id) {
HeapObject object; HeapObject object;
CombinedHeapIterator iterator(heap(), HeapIterator::kFilterUnreachable); CombinedHeapIterator iterator(heap(), HeapIterator::kFilterUnreachable);
// Make sure that object with the given id is still reachable. // Make sure that object with the given id is still reachable.
for (HeapObject obj = iterator.next(); !obj.is_null(); for (HeapObject obj = iterator.Next(); !obj.is_null();
obj = iterator.next()) { obj = iterator.Next()) {
if (ids_->FindEntry(obj->address()) == id) { if (ids_->FindEntry(obj->address()) == id) {
DCHECK(object.is_null()); DCHECK(object.is_null());
object = obj; object = obj;
...@@ -206,8 +206,8 @@ void HeapProfiler::QueryObjects(Handle<Context> context, ...@@ -206,8 +206,8 @@ void HeapProfiler::QueryObjects(Handle<Context> context,
// collect all garbage first. // collect all garbage first.
heap()->CollectAllAvailableGarbage(GarbageCollectionReason::kHeapProfiler); heap()->CollectAllAvailableGarbage(GarbageCollectionReason::kHeapProfiler);
CombinedHeapIterator heap_iterator(heap()); CombinedHeapIterator heap_iterator(heap());
for (HeapObject heap_obj = heap_iterator.next(); !heap_obj.is_null(); for (HeapObject heap_obj = heap_iterator.Next(); !heap_obj.is_null();
heap_obj = heap_iterator.next()) { heap_obj = heap_iterator.Next()) {
if (!heap_obj->IsJSObject() || heap_obj->IsExternal(isolate())) continue; if (!heap_obj->IsJSObject() || heap_obj->IsExternal(isolate())) continue;
v8::Local<v8::Object> v8_obj( v8::Local<v8::Object> v8_obj(
Utils::ToLocal(handle(JSObject::cast(heap_obj), isolate()))); Utils::ToLocal(handle(JSObject::cast(heap_obj), isolate())));
......
...@@ -396,8 +396,8 @@ void HeapObjectsMap::UpdateHeapObjectsMap() { ...@@ -396,8 +396,8 @@ void HeapObjectsMap::UpdateHeapObjectsMap() {
heap_->PreciseCollectAllGarbage(Heap::kNoGCFlags, heap_->PreciseCollectAllGarbage(Heap::kNoGCFlags,
GarbageCollectionReason::kHeapProfiler); GarbageCollectionReason::kHeapProfiler);
CombinedHeapIterator iterator(heap_); CombinedHeapIterator iterator(heap_);
for (HeapObject obj = iterator.next(); !obj.is_null(); for (HeapObject obj = iterator.Next(); !obj.is_null();
obj = iterator.next()) { obj = iterator.Next()) {
FindOrAddEntry(obj->address(), obj->Size()); FindOrAddEntry(obj->address(), obj->Size());
if (FLAG_heap_profiler_trace_objects) { if (FLAG_heap_profiler_trace_objects) {
PrintF("Update object : %p %6d. Next address is %p\n", PrintF("Update object : %p %6d. Next address is %p\n",
...@@ -648,7 +648,7 @@ const char* V8HeapExplorer::GetSystemEntryName(HeapObject object) { ...@@ -648,7 +648,7 @@ const char* V8HeapExplorer::GetSystemEntryName(HeapObject object) {
int V8HeapExplorer::EstimateObjectsCount() { int V8HeapExplorer::EstimateObjectsCount() {
CombinedHeapIterator it(heap_, HeapIterator::kFilterUnreachable); CombinedHeapIterator it(heap_, HeapIterator::kFilterUnreachable);
int objects_count = 0; int objects_count = 0;
while (!it.next().is_null()) ++objects_count; while (!it.Next().is_null()) ++objects_count;
return objects_count; return objects_count;
} }
...@@ -1459,8 +1459,8 @@ bool V8HeapExplorer::IterateAndExtractReferences( ...@@ -1459,8 +1459,8 @@ bool V8HeapExplorer::IterateAndExtractReferences(
CombinedHeapIterator iterator(heap_, HeapIterator::kFilterUnreachable); CombinedHeapIterator iterator(heap_, HeapIterator::kFilterUnreachable);
// Heap iteration with filtering must be finished in any case. // Heap iteration with filtering must be finished in any case.
for (HeapObject obj = iterator.next(); !obj.is_null(); for (HeapObject obj = iterator.Next(); !obj.is_null();
obj = iterator.next(), progress_->ProgressStep()) { obj = iterator.Next(), progress_->ProgressStep()) {
if (interrupted) continue; if (interrupted) continue;
size_t max_pointer = obj->Size() / kTaggedSize; size_t max_pointer = obj->Size() / kTaggedSize;
......
...@@ -68,8 +68,8 @@ void ReadOnlySerializer::FinalizeSerialization() { ...@@ -68,8 +68,8 @@ void ReadOnlySerializer::FinalizeSerialization() {
// Check that every object on read-only heap is reachable (and was // Check that every object on read-only heap is reachable (and was
// serialized). // serialized).
ReadOnlyHeapIterator iterator(isolate()->heap()->read_only_heap()); ReadOnlyHeapIterator iterator(isolate()->heap()->read_only_heap());
for (HeapObject object = iterator.next(); !object.is_null(); for (HeapObject object = iterator.Next(); !object.is_null();
object = iterator.next()) { object = iterator.Next()) {
CHECK(serialized_objects_.count(object)); CHECK(serialized_objects_.count(object));
} }
#endif #endif
......
...@@ -28,19 +28,19 @@ TEST(HeapIteratorNullPastEnd) { ...@@ -28,19 +28,19 @@ TEST(HeapIteratorNullPastEnd) {
TEST(ReadOnlyHeapIteratorNullPastEnd) { TEST(ReadOnlyHeapIteratorNullPastEnd) {
ReadOnlyHeapIterator iterator(CcTest::heap()->read_only_heap()); ReadOnlyHeapIterator iterator(CcTest::heap()->read_only_heap());
while (!iterator.next().is_null()) { while (!iterator.Next().is_null()) {
} }
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
CHECK(iterator.next().is_null()); CHECK(iterator.Next().is_null());
} }
} }
TEST(CombinedHeapIteratorNullPastEnd) { TEST(CombinedHeapIteratorNullPastEnd) {
CombinedHeapIterator iterator(CcTest::heap()); CombinedHeapIterator iterator(CcTest::heap());
while (!iterator.next().is_null()) { while (!iterator.Next().is_null()) {
} }
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
CHECK(iterator.next().is_null()); CHECK(iterator.Next().is_null());
} }
} }
...@@ -57,8 +57,8 @@ TEST(ReadOnlyHeapIterator) { ...@@ -57,8 +57,8 @@ TEST(ReadOnlyHeapIterator) {
const Object sample_object = CreateWritableObject(); const Object sample_object = CreateWritableObject();
ReadOnlyHeapIterator iterator(CcTest::read_only_heap()); ReadOnlyHeapIterator iterator(CcTest::read_only_heap());
for (HeapObject obj = iterator.next(); !obj.is_null(); for (HeapObject obj = iterator.Next(); !obj.is_null();
obj = iterator.next()) { obj = iterator.Next()) {
CHECK(ReadOnlyHeap::Contains(obj)); CHECK(ReadOnlyHeap::Contains(obj));
CHECK(!CcTest::heap()->Contains(obj)); CHECK(!CcTest::heap()->Contains(obj));
CHECK_NE(sample_object, obj); CHECK_NE(sample_object, obj);
...@@ -88,8 +88,8 @@ TEST(CombinedHeapIterator) { ...@@ -88,8 +88,8 @@ TEST(CombinedHeapIterator) {
CombinedHeapIterator iterator(CcTest::heap()); CombinedHeapIterator iterator(CcTest::heap());
bool seen_sample_object = false; bool seen_sample_object = false;
for (HeapObject obj = iterator.next(); !obj.is_null(); for (HeapObject obj = iterator.Next(); !obj.is_null();
obj = iterator.next()) { obj = iterator.Next()) {
CHECK(IsValidHeapObject(CcTest::heap(), obj)); CHECK(IsValidHeapObject(CcTest::heap(), obj));
if (sample_object == obj) seen_sample_object = true; if (sample_object == obj) seen_sample_object = true;
} }
......
...@@ -128,8 +128,8 @@ static int DumpHeapConstants(const char* argv0) { ...@@ -128,8 +128,8 @@ static int DumpHeapConstants(const char* argv0) {
i::PrintF("\n# List of known V8 objects.\n"); i::PrintF("\n# List of known V8 objects.\n");
i::PrintF("KNOWN_OBJECTS = {\n"); i::PrintF("KNOWN_OBJECTS = {\n");
i::ReadOnlyHeapIterator ro_iterator(heap->read_only_heap()); i::ReadOnlyHeapIterator ro_iterator(heap->read_only_heap());
for (i::HeapObject object = ro_iterator.next(); !object.is_null(); for (i::HeapObject object = ro_iterator.Next(); !object.is_null();
object = ro_iterator.next()) { object = ro_iterator.Next()) {
// Skip read-only heap maps, they will be reported elsewhere. // Skip read-only heap maps, they will be reported elsewhere.
if (object->IsMap()) continue; if (object->IsMap()) continue;
DumpKnownObject(heap, i::Heap::GetSpaceName(i::RO_SPACE), object); DumpKnownObject(heap, i::Heap::GetSpaceName(i::RO_SPACE), object);
......
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