2019-05-02 15:35:51 +00:00
|
|
|
// Copyright 2019 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "include/v8.h"
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2019-05-02 15:35:51 +00:00
|
|
|
#include "src/heap/combined-heap.h"
|
|
|
|
#include "src/heap/heap.h"
|
|
|
|
#include "src/heap/read-only-heap.h"
|
|
|
|
#include "src/objects.h"
|
|
|
|
#include "src/objects/heap-object.h"
|
|
|
|
#include "src/roots-inl.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace heap {
|
|
|
|
|
|
|
|
TEST(HeapIteratorNullPastEnd) {
|
|
|
|
HeapIterator iterator(CcTest::heap());
|
|
|
|
while (!iterator.next().is_null()) {
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
CHECK(iterator.next().is_null());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ReadOnlyHeapIteratorNullPastEnd) {
|
|
|
|
ReadOnlyHeapIterator iterator(CcTest::heap()->read_only_heap());
|
2019-05-21 15:45:58 +00:00
|
|
|
while (!iterator.Next().is_null()) {
|
2019-05-02 15:35:51 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < 20; i++) {
|
2019-05-21 15:45:58 +00:00
|
|
|
CHECK(iterator.Next().is_null());
|
2019-05-02 15:35:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CombinedHeapIteratorNullPastEnd) {
|
|
|
|
CombinedHeapIterator iterator(CcTest::heap());
|
2019-05-21 15:45:58 +00:00
|
|
|
while (!iterator.Next().is_null()) {
|
2019-05-02 15:35:51 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < 20; i++) {
|
2019-05-21 15:45:58 +00:00
|
|
|
CHECK(iterator.Next().is_null());
|
2019-05-02 15:35:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// An arbitrary object guaranteed to live on the non-read-only heap.
|
|
|
|
Object CreateWritableObject() {
|
|
|
|
return *v8::Utils::OpenHandle(*v8::Object::New(CcTest::isolate()));
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(ReadOnlyHeapIterator) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
HandleScope handle_scope(CcTest::i_isolate());
|
|
|
|
const Object sample_object = CreateWritableObject();
|
|
|
|
ReadOnlyHeapIterator iterator(CcTest::read_only_heap());
|
|
|
|
|
2019-05-21 15:45:58 +00:00
|
|
|
for (HeapObject obj = iterator.Next(); !obj.is_null();
|
|
|
|
obj = iterator.Next()) {
|
2019-05-02 15:35:51 +00:00
|
|
|
CHECK(ReadOnlyHeap::Contains(obj));
|
2019-05-13 16:13:44 +00:00
|
|
|
CHECK(!CcTest::heap()->Contains(obj));
|
2019-05-02 15:35:51 +00:00
|
|
|
CHECK_NE(sample_object, obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HeapIterator) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
HandleScope handle_scope(CcTest::i_isolate());
|
|
|
|
const Object sample_object = CreateWritableObject();
|
|
|
|
HeapIterator iterator(CcTest::heap());
|
|
|
|
bool seen_sample_object = false;
|
|
|
|
|
|
|
|
for (HeapObject obj = iterator.next(); !obj.is_null();
|
|
|
|
obj = iterator.next()) {
|
|
|
|
CHECK(!ReadOnlyHeap::Contains(obj));
|
2019-05-13 16:13:44 +00:00
|
|
|
CHECK(CcTest::heap()->Contains(obj));
|
2019-05-02 15:35:51 +00:00
|
|
|
if (sample_object == obj) seen_sample_object = true;
|
|
|
|
}
|
|
|
|
CHECK(seen_sample_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CombinedHeapIterator) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
HandleScope handle_scope(CcTest::i_isolate());
|
|
|
|
const Object sample_object = CreateWritableObject();
|
|
|
|
CombinedHeapIterator iterator(CcTest::heap());
|
|
|
|
bool seen_sample_object = false;
|
|
|
|
|
2019-05-21 15:45:58 +00:00
|
|
|
for (HeapObject obj = iterator.Next(); !obj.is_null();
|
|
|
|
obj = iterator.Next()) {
|
2019-05-13 16:13:44 +00:00
|
|
|
CHECK(IsValidHeapObject(CcTest::heap(), obj));
|
2019-05-02 15:35:51 +00:00
|
|
|
if (sample_object == obj) seen_sample_object = true;
|
|
|
|
}
|
|
|
|
CHECK(seen_sample_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace heap
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|