| |
| |
| |
|
|
| #ifndef INCLUDE_V8_CPPGC_H_ |
| #define INCLUDE_V8_CPPGC_H_ |
|
|
| #include <cstdint> |
| #include <memory> |
| #include <vector> |
|
|
| #include "cppgc/common.h" |
| #include "cppgc/custom-space.h" |
| #include "cppgc/heap-statistics.h" |
| #include "cppgc/visitor.h" |
| #include "v8-internal.h" |
| #include "v8-platform.h" |
| #include "v8-traced-handle.h" |
|
|
| namespace cppgc { |
| class AllocationHandle; |
| class HeapHandle; |
| } |
|
|
| namespace v8 { |
|
|
| class Object; |
|
|
| namespace internal { |
| class CppHeap; |
| } |
|
|
| class CustomSpaceStatisticsReceiver; |
|
|
| |
| |
| |
| |
| struct WrapperDescriptor final { |
| |
| |
| |
| |
| |
| using InternalFieldIndex = int; |
|
|
| |
| |
| |
| |
| static constexpr uint16_t kUnknownEmbedderId = UINT16_MAX; |
|
|
| constexpr WrapperDescriptor(InternalFieldIndex wrappable_type_index, |
| InternalFieldIndex wrappable_instance_index, |
| uint16_t embedder_id_for_garbage_collected) |
| : wrappable_type_index(wrappable_type_index), |
| wrappable_instance_index(wrappable_instance_index), |
| embedder_id_for_garbage_collected(embedder_id_for_garbage_collected) {} |
|
|
| |
| |
| |
| InternalFieldIndex wrappable_type_index; |
|
|
| |
| |
| |
| InternalFieldIndex wrappable_instance_index; |
|
|
| |
| |
| |
| |
| |
| |
| uint16_t embedder_id_for_garbage_collected; |
| }; |
|
|
| struct V8_EXPORT CppHeapCreateParams { |
| CppHeapCreateParams( |
| std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces, |
| WrapperDescriptor wrapper_descriptor) |
| : custom_spaces(std::move(custom_spaces)), |
| wrapper_descriptor(wrapper_descriptor) {} |
|
|
| CppHeapCreateParams(const CppHeapCreateParams&) = delete; |
| CppHeapCreateParams& operator=(const CppHeapCreateParams&) = delete; |
|
|
| std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces; |
| WrapperDescriptor wrapper_descriptor; |
| |
| |
| |
| |
| cppgc::Heap::MarkingType marking_support = |
| cppgc::Heap::MarkingType::kIncrementalAndConcurrent; |
| |
| |
| |
| |
| cppgc::Heap::SweepingType sweeping_support = |
| cppgc::Heap::SweepingType::kIncrementalAndConcurrent; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| class V8_EXPORT CppHeap { |
| public: |
| static std::unique_ptr<CppHeap> Create(v8::Platform* platform, |
| const CppHeapCreateParams& params); |
|
|
| virtual ~CppHeap() = default; |
|
|
| |
| |
| |
| |
| cppgc::AllocationHandle& GetAllocationHandle(); |
|
|
| |
| |
| |
| |
| cppgc::HeapHandle& GetHeapHandle(); |
|
|
| |
| |
| |
| |
| |
| |
| void Terminate(); |
|
|
| |
| |
| |
| |
| |
| |
| cppgc::HeapStatistics CollectStatistics( |
| cppgc::HeapStatistics::DetailLevel detail_level); |
|
|
| |
| |
| |
| |
| |
| |
| void CollectCustomSpaceStatisticsAtLastGC( |
| std::vector<cppgc::CustomSpaceIndex> custom_spaces, |
| std::unique_ptr<CustomSpaceStatisticsReceiver> receiver); |
|
|
| |
| |
| |
| |
| |
| void EnableDetachedGarbageCollectionsForTesting(); |
|
|
| |
| |
| |
| |
| |
| void CollectGarbageForTesting(cppgc::EmbedderStackState stack_state); |
|
|
| |
| |
| |
| |
| |
| void CollectGarbageInYoungGenerationForTesting( |
| cppgc::EmbedderStackState stack_state); |
|
|
| |
| |
| |
| v8::WrapperDescriptor wrapper_descriptor() const; |
|
|
| private: |
| CppHeap() = default; |
|
|
| friend class internal::CppHeap; |
| }; |
|
|
| class JSVisitor : public cppgc::Visitor { |
| public: |
| explicit JSVisitor(cppgc::Visitor::Key key) : cppgc::Visitor(key) {} |
| ~JSVisitor() override = default; |
|
|
| void Trace(const TracedReferenceBase& ref) { |
| if (ref.IsEmptyThreadSafe()) return; |
| Visit(ref); |
| } |
|
|
| protected: |
| using cppgc::Visitor::Visit; |
|
|
| virtual void Visit(const TracedReferenceBase& ref) {} |
| }; |
|
|
| |
| |
| |
| |
| |
| class CustomSpaceStatisticsReceiver { |
| public: |
| virtual ~CustomSpaceStatisticsReceiver() = default; |
| |
| |
| |
| |
| |
| |
| |
| |
| virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index, |
| size_t bytes) = 0; |
| }; |
|
|
| } |
|
|
| namespace cppgc { |
|
|
| template <typename T> |
| struct TraceTrait<v8::TracedReference<T>> { |
| static cppgc::TraceDescriptor GetTraceDescriptor(const void* self) { |
| return {nullptr, Trace}; |
| } |
|
|
| static void Trace(Visitor* visitor, const void* self) { |
| static_cast<v8::JSVisitor*>(visitor)->Trace( |
| *static_cast<const v8::TracedReference<T>*>(self)); |
| } |
| }; |
|
|
| } |
|
|
| #endif |
|
|