11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_HEAP_CPPGC_GC_INVOKER_H_
61cb0ef41Sopenharmony_ci#define V8_HEAP_CPPGC_GC_INVOKER_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "include/cppgc/common.h"
91cb0ef41Sopenharmony_ci#include "include/cppgc/heap.h"
101cb0ef41Sopenharmony_ci#include "src/base/macros.h"
111cb0ef41Sopenharmony_ci#include "src/heap/cppgc/garbage-collector.h"
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cinamespace cppgc {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciclass Platform;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cinamespace internal {
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci// GC invoker that dispatches GC depending on StackSupport and StackState:
201cb0ef41Sopenharmony_ci// 1. If StackState specifies no stack scan needed the GC is invoked
211cb0ef41Sopenharmony_ci//    synchronously.
221cb0ef41Sopenharmony_ci// 2. If StackState specifies conservative GC and StackSupport prohibits stack
231cb0ef41Sopenharmony_ci//    scanning: Delay GC until it can be invoked without accessing the stack.
241cb0ef41Sopenharmony_ci//    To do so, a precise GC without stack scan is scheduled using the platform
251cb0ef41Sopenharmony_ci//    if non-nestable tasks are supported, and otherwise no operation is carried
261cb0ef41Sopenharmony_ci//    out. This means that the heuristics allows to arbitrary go over the limit
271cb0ef41Sopenharmony_ci//    in case non-nestable tasks are not supported and only conservative GCs are
281cb0ef41Sopenharmony_ci//    requested.
291cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE GCInvoker final : public GarbageCollector {
301cb0ef41Sopenharmony_ci public:
311cb0ef41Sopenharmony_ci  GCInvoker(GarbageCollector*, cppgc::Platform*, cppgc::Heap::StackSupport);
321cb0ef41Sopenharmony_ci  ~GCInvoker();
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  GCInvoker(const GCInvoker&) = delete;
351cb0ef41Sopenharmony_ci  GCInvoker& operator=(const GCInvoker&) = delete;
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  void CollectGarbage(GarbageCollector::Config) final;
381cb0ef41Sopenharmony_ci  void StartIncrementalGarbageCollection(GarbageCollector::Config) final;
391cb0ef41Sopenharmony_ci  size_t epoch() const final;
401cb0ef41Sopenharmony_ci  const EmbedderStackState* override_stack_state() const final;
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci private:
431cb0ef41Sopenharmony_ci  class GCInvokerImpl;
441cb0ef41Sopenharmony_ci  std::unique_ptr<GCInvokerImpl> impl_;
451cb0ef41Sopenharmony_ci};
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci}  // namespace internal
481cb0ef41Sopenharmony_ci}  // namespace cppgc
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci#endif  // V8_HEAP_CPPGC_GC_INVOKER_H_
51