chromium/v8/src/heap/cppgc-js/cpp-heap.cc

// Copyright 2020 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.

#include "src/heap/cppgc-js/cpp-heap.h"

#include <cstdint>
#include <memory>
#include <numeric>
#include <optional>

#include "include/cppgc/heap-consistency.h"
#include "include/cppgc/platform.h"
#include "include/v8-isolate.h"
#include "include/v8-local-handle.h"
#include "include/v8-platform.h"
#include "src/base/logging.h"
#include "src/base/macros.h"
#include "src/base/platform/time.h"
#include "src/execution/isolate-inl.h"
#include "src/flags/flags.h"
#include "src/handles/handles.h"
#include "src/handles/traced-handles.h"
#include "src/heap/base/stack.h"
#include "src/heap/cppgc-js/cpp-marking-state.h"
#include "src/heap/cppgc-js/cpp-snapshot.h"
#include "src/heap/cppgc-js/unified-heap-marking-state-inl.h"
#include "src/heap/cppgc-js/unified-heap-marking-state.h"
#include "src/heap/cppgc-js/unified-heap-marking-verifier.h"
#include "src/heap/cppgc-js/unified-heap-marking-visitor.h"
#include "src/heap/cppgc/concurrent-marker.h"
#include "src/heap/cppgc/gc-info-table.h"
#include "src/heap/cppgc/heap-base.h"
#include "src/heap/cppgc/heap-object-header.h"
#include "src/heap/cppgc/marker.h"
#include "src/heap/cppgc/marking-state.h"
#include "src/heap/cppgc/marking-visitor.h"
#include "src/heap/cppgc/metric-recorder.h"
#include "src/heap/cppgc/object-allocator.h"
#include "src/heap/cppgc/page-memory.h"
#include "src/heap/cppgc/platform.h"
#include "src/heap/cppgc/prefinalizer-handler.h"
#include "src/heap/cppgc/raw-heap.h"
#include "src/heap/cppgc/stats-collector.h"
#include "src/heap/cppgc/sweeper.h"
#include "src/heap/cppgc/unmarker.h"
#include "src/heap/cppgc/visitor.h"
#include "src/heap/gc-tracer.h"
#include "src/heap/heap.h"
#include "src/heap/marking-worklist.h"
#include "src/heap/minor-mark-sweep.h"
#include "src/heap/traced-handles-marking-visitor.h"
#include "src/init/v8.h"
#include "src/profiler/heap-profiler.h"

namespace v8 {

namespace internal {

class MinorGCHeapGrowing
    : public cppgc::internal::StatsCollector::AllocationObserver {};

}  // namespace internal

// static
std::unique_ptr<CppHeap> CppHeap::Create(v8::Platform* platform,
                                         const CppHeapCreateParams& params) {}

cppgc::AllocationHandle& CppHeap::GetAllocationHandle() {}

cppgc::HeapHandle& CppHeap::GetHeapHandle() {}

void CppHeap::Terminate() {}

cppgc::HeapStatistics CppHeap::CollectStatistics(
    cppgc::HeapStatistics::DetailLevel detail_level) {}

void CppHeap::CollectCustomSpaceStatisticsAtLastGC(
    std::vector<cppgc::CustomSpaceIndex> custom_spaces,
    std::unique_ptr<CustomSpaceStatisticsReceiver> receiver) {}

void CppHeap::EnableDetachedGarbageCollectionsForTesting() {}

void CppHeap::CollectGarbageForTesting(cppgc::EmbedderStackState stack_state) {}

void CppHeap::CollectGarbageInYoungGenerationForTesting(
    cppgc::EmbedderStackState stack_state) {}

namespace internal {

namespace {

class CppgcPlatformAdapter final : public cppgc::Platform {};

class UnifiedHeapConcurrentMarker
    : public cppgc::internal::ConcurrentMarkerBase {};

std::unique_ptr<cppgc::Visitor>
UnifiedHeapConcurrentMarker::CreateConcurrentMarkingVisitor(
    cppgc::internal::ConcurrentMarkingState& marking_state) const {}

void FatalOutOfMemoryHandlerImpl(const std::string& reason,
                                 const SourceLocation&, HeapBase* heap) {}

void GlobalFatalOutOfMemoryHandlerImpl(const std::string& reason,
                                       const SourceLocation&, HeapBase* heap) {}

class UnifiedHeapConservativeMarkingVisitor final
    : public cppgc::internal::ConservativeMarkingVisitor {};

}  // namespace

class UnifiedHeapMarker final : public cppgc::internal::MarkerBase {};

UnifiedHeapMarker::UnifiedHeapMarker(Heap* v8_heap,
                                     cppgc::internal::HeapBase& heap,
                                     cppgc::Platform* platform,
                                     cppgc::internal::MarkingConfig config)
    :{}

void CppHeap::MetricRecorderAdapter::AddMainThreadEvent(
    const GCCycle& cppgc_event) {}

void CppHeap::MetricRecorderAdapter::AddMainThreadEvent(
    const MainThreadIncrementalMark& cppgc_event) {}

void CppHeap::MetricRecorderAdapter::AddMainThreadEvent(
    const MainThreadIncrementalSweep& cppgc_event) {}

void CppHeap::MetricRecorderAdapter::FlushBatchedIncrementalEvents() {}

bool CppHeap::MetricRecorderAdapter::FullGCMetricsReportPending() const {}

bool CppHeap::MetricRecorderAdapter::YoungGCMetricsReportPending() const {}

const std::optional<cppgc::internal::MetricRecorder::GCCycle>
CppHeap::MetricRecorderAdapter::ExtractLastFullGcEvent() {}

const std::optional<cppgc::internal::MetricRecorder::GCCycle>
CppHeap::MetricRecorderAdapter::ExtractLastYoungGcEvent() {}

const std::optional<cppgc::internal::MetricRecorder::MainThreadIncrementalMark>
CppHeap::MetricRecorderAdapter::ExtractLastIncrementalMarkEvent() {}

void CppHeap::MetricRecorderAdapter::ClearCachedEvents() {}

Isolate* CppHeap::MetricRecorderAdapter::GetIsolate() const {}

v8::metrics::Recorder::ContextId CppHeap::MetricRecorderAdapter::GetContextId()
    const {}

// static
void CppHeap::InitializeOncePerProcess() {}

CppHeap::CppHeap(
    v8::Platform* platform,
    const std::vector<std::unique_ptr<cppgc::CustomSpaceBase>>& custom_spaces,
    cppgc::Heap::MarkingType marking_support,
    cppgc::Heap::SweepingType sweeping_support)
    :{}

CppHeap::~CppHeap() {}

void CppHeap::Terminate() {}

namespace {

class SweepingOnMutatorThreadForGlobalHandlesScope final {};

class SweepingOnMutatorThreadForGlobalHandlesObserver final
    : public cppgc::internal::Sweeper::SweepingOnMutatorThreadObserver {};

class MoveListenerImpl final : public HeapProfilerNativeMoveListener,
                               public cppgc::internal::MoveListener {};

}  // namespace

void CppHeap::AttachIsolate(Isolate* isolate) {}

void CppHeap::DetachIsolate() {}

::heap::base::Stack* CppHeap::stack() {}

namespace {

bool IsMemoryReducingGC(CppHeap::GarbageCollectionFlags flags) {}

bool IsForceGC(CppHeap::GarbageCollectionFlags flags) {}

bool ShouldReduceMemory(CppHeap::GarbageCollectionFlags flags) {}

constexpr size_t kIncrementalMarkingCheckInterval =;

}  // namespace

CppHeap::MarkingType CppHeap::SelectMarkingType() const {}

CppHeap::SweepingType CppHeap::SelectSweepingType() const {}

void CppHeap::UpdateGCCapabilitiesFromFlags() {}

void CppHeap::InitializeMarking(CollectionType collection_type,
                                GarbageCollectionFlags gc_flags) {}

namespace {
MarkingWorklists::Local* GetV8MarkingWorklists(
    Isolate* isolate, cppgc::internal::CollectionType collection_type) {}
}  // namespace

void CppHeap::StartMarking() {}

bool CppHeap::AdvanceTracing(v8::base::TimeDelta max_duration) {}

bool CppHeap::IsTracingDone() const {}

bool CppHeap::ShouldFinalizeIncrementalMarking() const {}

void CppHeap::EnterProcessGlobalAtomicPause() {}

void CppHeap::EnterFinalPause(cppgc::EmbedderStackState stack_state) {}

bool CppHeap::FinishConcurrentMarkingIfNeeded() {}

void CppHeap::ReEnableConcurrentMarking() {}

void CppHeap::WriteBarrier(void* object) {}

namespace {

void RecordEmbedderSpeed(GCTracer* tracer, base::TimeDelta marking_time,
                         size_t marked_bytes) {}

}  // namespace

void CppHeap::FinishMarkingAndProcessWeakness() {}

void CppHeap::CompactAndSweep() {}

void CppHeap::AllocatedObjectSizeIncreased(size_t bytes) {}

void CppHeap::AllocatedObjectSizeDecreased(size_t bytes) {}

void CppHeap::ReportBufferedAllocationSizeIfPossible() {}

void CppHeap::CollectGarbageForTesting(CollectionType collection_type,
                                       StackState stack_state) {}

void CppHeap::EnableDetachedGarbageCollectionsForTesting() {}

void CppHeap::StartIncrementalGarbageCollectionForTesting() {}

void CppHeap::FinalizeIncrementalGarbageCollectionForTesting(
    cppgc::EmbedderStackState stack_state) {}

namespace {

void ReportCustomSpaceStatistics(
    cppgc::internal::RawHeap& raw_heap,
    std::vector<cppgc::CustomSpaceIndex> custom_spaces,
    std::unique_ptr<CustomSpaceStatisticsReceiver> receiver) {}

class CollectCustomSpaceStatisticsAtLastGCTask final : public v8::Task {};

constexpr v8::base::TimeDelta
    CollectCustomSpaceStatisticsAtLastGCTask::kTaskDelayMs;
constexpr v8::base::TimeDelta
    CollectCustomSpaceStatisticsAtLastGCTask::kStepSizeMs;

}  // namespace

void CppHeap::CollectCustomSpaceStatisticsAtLastGC(
    std::vector<cppgc::CustomSpaceIndex> custom_spaces,
    std::unique_ptr<CustomSpaceStatisticsReceiver> receiver) {}

CppHeap::MetricRecorderAdapter* CppHeap::GetMetricRecorder() const {}

void CppHeap::FinishSweepingIfRunning() {}

void CppHeap::FinishAtomicSweepingIfRunning() {}

void CppHeap::FinishSweepingIfOutOfWork() {}

std::unique_ptr<CppMarkingState> CppHeap::CreateCppMarkingState() {}

std::unique_ptr<CppMarkingState>
CppHeap::CreateCppMarkingStateForMutatorThread() {}

CppHeap::PauseConcurrentMarkingScope::PauseConcurrentMarkingScope(
    CppHeap* cpp_heap) {}

void CppHeap::CollectGarbage(cppgc::internal::GCConfig config) {}

std::optional<cppgc::EmbedderStackState> CppHeap::overridden_stack_state()
    const {}

void CppHeap::set_override_stack_state(cppgc::EmbedderStackState state) {}

void CppHeap::clear_overridden_stack_state() {}

void CppHeap::StartIncrementalGarbageCollection(cppgc::internal::GCConfig) {}

size_t CppHeap::epoch() const {}

#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
std::optional<int> CppHeap::UpdateAllocationTimeout() {}
#endif  // V8_ENABLE_ALLOCATION_TIMEOUT

void CppHeap::ResetCrossHeapRememberedSet() {}

void CppHeap::UpdateGCCapabilitiesFromFlagsForTesting() {}

bool CppHeap::IsDetachedGCAllowed() const {}

bool CppHeap::IsGCAllowed() const {}

bool CppHeap::IsGCForbidden() const {}

}  // namespace internal
}  // namespace v8