};
-HeapIterator::HeapIterator(Heap* heap)
- : make_heap_iterable_helper_(heap),
- no_heap_allocation_(),
- heap_(heap),
- filtering_(HeapIterator::kNoFiltering),
- filter_(NULL) {
- Init();
-}
-
-
HeapIterator::HeapIterator(Heap* heap,
HeapIterator::HeapObjectsFiltering filtering)
: make_heap_iterable_helper_(heap),
no_heap_allocation_(),
heap_(heap),
filtering_(filtering),
- filter_(NULL) {
- Init();
-}
-
-
-HeapIterator::~HeapIterator() { Shutdown(); }
-
-
-void HeapIterator::Init() {
+ filter_(nullptr),
+ space_iterator_(nullptr),
+ object_iterator_(nullptr) {
// Start the iteration.
space_iterator_ = new SpaceIterator(heap_);
switch (filtering_) {
}
-void HeapIterator::Shutdown() {
+HeapIterator::~HeapIterator() {
#ifdef DEBUG
// Assert that in filtering mode we have iterated through all
// objects. Otherwise, heap will be left in an inconsistent state.
if (filtering_ != kNoFiltering) {
- DCHECK(object_iterator_ == NULL);
+ DCHECK(object_iterator_ == nullptr);
}
#endif
// Make sure the last iterator is deallocated.
+ delete object_iterator_;
delete space_iterator_;
- space_iterator_ = NULL;
- object_iterator_ = NULL;
delete filter_;
- filter_ = NULL;
}
HeapObject* HeapIterator::next() {
- if (filter_ == NULL) return NextObject();
+ if (filter_ == nullptr) return NextObject();
HeapObject* obj = NextObject();
- while (obj != NULL && filter_->SkipObject(obj)) obj = NextObject();
+ while ((obj != nullptr) && (filter_->SkipObject(obj))) obj = NextObject();
return obj;
}
HeapObject* HeapIterator::NextObject() {
// No iterator means we are done.
- if (object_iterator_ == NULL) return NULL;
+ if (object_iterator_ == nullptr) return nullptr;
if (HeapObject* obj = object_iterator_->next_object()) {
// If the current iterator has more objects we are fine.
}
}
// Done with the last space.
- object_iterator_ = NULL;
- return NULL;
-}
-
-
-void HeapIterator::reset() {
- // Restart the iterator.
- Shutdown();
- Init();
+ object_iterator_ = nullptr;
+ return nullptr;
}
public:
enum HeapObjectsFiltering { kNoFiltering, kFilterUnreachable };
- explicit HeapIterator(Heap* heap);
- HeapIterator(Heap* heap, HeapObjectsFiltering filtering);
+ explicit HeapIterator(Heap* heap,
+ HeapObjectsFiltering filtering = kNoFiltering);
~HeapIterator();
HeapObject* next();
- void reset();
private:
struct MakeHeapIterableHelper {
explicit MakeHeapIterableHelper(Heap* heap) { heap->MakeHeapIterable(); }
};
- // Perform the initialization.
- void Init();
- // Perform all necessary shutdown (destruction) work.
- void Shutdown();
HeapObject* NextObject();
+ // The following two fields need to be declared in this order. Initialization
+ // order guarantees that we first make the heap iterable (which may involve
+ // allocations) and only then lock it down by not allowing further
+ // allocations.
MakeHeapIterableHelper make_heap_iterable_helper_;
DisallowHeapAllocation no_heap_allocation_;
+
Heap* heap_;
HeapObjectsFiltering filtering_;
HeapObjectsFilter* filter_;