1 // Copyright 2019 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_HEAP_COMBINED_HEAP_H_ 6 #define V8_HEAP_COMBINED_HEAP_H_ 7 8 #include "src/heap/heap.h" 9 #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 namespace v8 { 15 namespace internal { 16 17 // This class allows iteration over the entire heap (Heap and ReadOnlyHeap). It 18 // uses the HeapObjectIterator to iterate over non-read-only objects and accepts 19 // the same filtering option. (Interrupting iteration while filtering 20 // unreachable objects is still forbidden) 21 class V8_EXPORT_PRIVATE CombinedHeapObjectIterator final { 22 public: 23 CombinedHeapObjectIterator( 24 Heap* heap, HeapObjectIterator::HeapObjectsFiltering filtering = 25 HeapObjectIterator::HeapObjectsFiltering::kNoFiltering); 26 HeapObject Next(); 27 28 private: 29 SafepointScope safepoint_scope_; 30 HeapObjectIterator heap_iterator_; 31 ReadOnlyHeapObjectIterator ro_heap_iterator_; 32 }; 33 IsValidHeapObject(Heap * heap,HeapObject object)34V8_WARN_UNUSED_RESULT inline bool IsValidHeapObject(Heap* heap, 35 HeapObject object) { 36 if (V8_ENABLE_THIRD_PARTY_HEAP_BOOL) { 37 return third_party_heap::Heap::IsValidHeapObject(object); 38 } 39 return ReadOnlyHeap::Contains(object) || heap->Contains(object) || 40 heap->SharedHeapContains(object); 41 } 42 IsValidCodeObject(Heap * heap,HeapObject object)43V8_WARN_UNUSED_RESULT inline bool IsValidCodeObject(Heap* heap, 44 HeapObject object) { 45 if (V8_ENABLE_THIRD_PARTY_HEAP_BOOL) { 46 return third_party_heap::Heap::IsValidCodeObject(object); 47 } 48 if (V8_EXTERNAL_CODE_SPACE_BOOL) { 49 return heap->ContainsCode(object); 50 } else { 51 return ReadOnlyHeap::Contains(object) || heap->ContainsCode(object); 52 } 53 } 54 55 } // namespace internal 56 } // namespace v8 57 58 #endif // V8_HEAP_COMBINED_HEAP_H_ 59