1 // Copyright 2020 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_CPPGC_JS_CPP_HEAP_H_ 6 #define V8_HEAP_CPPGC_JS_CPP_HEAP_H_ 7 8 #include "include/v8.h" 9 #include "src/base/macros.h" 10 #include "src/heap/cppgc/heap-base.h" 11 12 namespace v8 { 13 14 class Isolate; 15 16 namespace internal { 17 18 // A C++ heap implementation used with V8 to implement unified heap. 19 class V8_EXPORT_PRIVATE CppHeap final : public cppgc::internal::HeapBase, 20 public v8::EmbedderHeapTracer { 21 public: 22 CppHeap(v8::Isolate* isolate, 23 const std::vector<std::unique_ptr<cppgc::CustomSpaceBase>>& 24 custom_spaces); 25 ~CppHeap() final; 26 27 CppHeap(const CppHeap&) = delete; 28 CppHeap& operator=(const CppHeap&) = delete; 29 AsBase()30 HeapBase& AsBase() { return *this; } AsBase()31 const HeapBase& AsBase() const { return *this; } 32 33 void RegisterV8References( 34 const std::vector<std::pair<void*, void*> >& embedder_fields) final; 35 void TracePrologue(TraceFlags flags) final; 36 bool AdvanceTracing(double deadline_in_ms) final; 37 bool IsTracingDone() final; 38 void TraceEpilogue(TraceSummary* trace_summary) final; 39 void EnterFinalPause(EmbedderStackState stack_state) final; 40 41 private: FinalizeIncrementalGarbageCollectionIfNeeded(cppgc::Heap::StackState)42 void FinalizeIncrementalGarbageCollectionIfNeeded( 43 cppgc::Heap::StackState) final { 44 // For unified heap, CppHeap shouldn't finalize independently (i.e. 45 // finalization is not needed) thus this method is left empty. 46 } 47 48 Isolate& isolate_; 49 bool marking_done_ = false; 50 }; 51 52 } // namespace internal 53 } // namespace v8 54 55 #endif // V8_HEAP_CPPGC_JS_CPP_HEAP_H_ 56