combined-heap.h 1.49 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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.

#ifndef V8_HEAP_COMBINED_HEAP_H_
#define V8_HEAP_COMBINED_HEAP_H_

#include "src/heap/heap.h"
#include "src/heap/read-only-heap.h"
10
#include "src/heap/safepoint.h"
11
#include "src/heap/third-party/heap-api.h"
12
#include "src/objects/objects.h"
13 14 15 16 17

namespace v8 {
namespace internal {

// This class allows iteration over the entire heap (Heap and ReadOnlyHeap). It
18 19 20 21
// uses the HeapObjectIterator to iterate over non-read-only objects and accepts
// the same filtering option. (Interrupting iteration while filtering
// unreachable objects is still forbidden)
class V8_EXPORT_PRIVATE CombinedHeapObjectIterator final {
22
 public:
23 24
  CombinedHeapObjectIterator(
      Heap* heap, HeapObjectIterator::HeapObjectsFiltering filtering =
25
                      HeapObjectIterator::HeapObjectsFiltering::kNoFiltering);
26
  HeapObject Next();
27 28

 private:
29
  SafepointScope safepoint_scope_;
30 31
  HeapObjectIterator heap_iterator_;
  ReadOnlyHeapObjectIterator ro_heap_iterator_;
32 33
};

34 35
V8_WARN_UNUSED_RESULT inline bool IsValidHeapObject(Heap* heap,
                                                    HeapObject object) {
36 37 38 39
  if (V8_ENABLE_THIRD_PARTY_HEAP_BOOL)
    return third_party_heap::Heap::IsValidHeapObject(object);
  else
    return ReadOnlyHeap::Contains(object) || heap->Contains(object);
40 41
}

42 43 44 45
}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_COMBINED_HEAP_H_