11cb0ef41Sopenharmony_ci// Copyright 2021 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 INCLUDE_CPPGC_HEAP_STATE_H_ 61cb0ef41Sopenharmony_ci#define INCLUDE_CPPGC_HEAP_STATE_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "v8config.h" // NOLINT(build/include_directory) 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cinamespace cppgc { 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciclass HeapHandle; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinamespace subtle { 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci/** 171cb0ef41Sopenharmony_ci * Helpers to peek into heap-internal state. 181cb0ef41Sopenharmony_ci */ 191cb0ef41Sopenharmony_ciclass V8_EXPORT HeapState final { 201cb0ef41Sopenharmony_ci public: 211cb0ef41Sopenharmony_ci /** 221cb0ef41Sopenharmony_ci * Returns whether the garbage collector is marking. This API is experimental 231cb0ef41Sopenharmony_ci * and is expected to be removed in future. 241cb0ef41Sopenharmony_ci * 251cb0ef41Sopenharmony_ci * \param heap_handle The corresponding heap. 261cb0ef41Sopenharmony_ci * \returns true if the garbage collector is currently marking, and false 271cb0ef41Sopenharmony_ci * otherwise. 281cb0ef41Sopenharmony_ci */ 291cb0ef41Sopenharmony_ci static bool IsMarking(const HeapHandle& heap_handle); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci /* 321cb0ef41Sopenharmony_ci * Returns whether the garbage collector is sweeping. This API is experimental 331cb0ef41Sopenharmony_ci * and is expected to be removed in future. 341cb0ef41Sopenharmony_ci * 351cb0ef41Sopenharmony_ci * \param heap_handle The corresponding heap. 361cb0ef41Sopenharmony_ci * \returns true if the garbage collector is currently sweeping, and false 371cb0ef41Sopenharmony_ci * otherwise. 381cb0ef41Sopenharmony_ci */ 391cb0ef41Sopenharmony_ci static bool IsSweeping(const HeapHandle& heap_handle); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci /* 421cb0ef41Sopenharmony_ci * Returns whether the garbage collector is currently sweeping on the thread 431cb0ef41Sopenharmony_ci * owning this heap. This API allows the caller to determine whether it has 441cb0ef41Sopenharmony_ci * been called from a destructor of a managed object. This API is experimental 451cb0ef41Sopenharmony_ci * and may be removed in future. 461cb0ef41Sopenharmony_ci * 471cb0ef41Sopenharmony_ci * \param heap_handle The corresponding heap. 481cb0ef41Sopenharmony_ci * \returns true if the garbage collector is currently sweeping on this 491cb0ef41Sopenharmony_ci * thread, and false otherwise. 501cb0ef41Sopenharmony_ci */ 511cb0ef41Sopenharmony_ci static bool IsSweepingOnOwningThread(const HeapHandle& heap_handle); 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci /** 541cb0ef41Sopenharmony_ci * Returns whether the garbage collector is in the atomic pause, i.e., the 551cb0ef41Sopenharmony_ci * mutator is stopped from running. This API is experimental and is expected 561cb0ef41Sopenharmony_ci * to be removed in future. 571cb0ef41Sopenharmony_ci * 581cb0ef41Sopenharmony_ci * \param heap_handle The corresponding heap. 591cb0ef41Sopenharmony_ci * \returns true if the garbage collector is currently in the atomic pause, 601cb0ef41Sopenharmony_ci * and false otherwise. 611cb0ef41Sopenharmony_ci */ 621cb0ef41Sopenharmony_ci static bool IsInAtomicPause(const HeapHandle& heap_handle); 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci /** 651cb0ef41Sopenharmony_ci * Returns whether the last garbage collection was finalized conservatively 661cb0ef41Sopenharmony_ci * (i.e., with a non-empty stack). This API is experimental and is expected to 671cb0ef41Sopenharmony_ci * be removed in future. 681cb0ef41Sopenharmony_ci * 691cb0ef41Sopenharmony_ci * \param heap_handle The corresponding heap. 701cb0ef41Sopenharmony_ci * \returns true if the last garbage collection was finalized conservatively, 711cb0ef41Sopenharmony_ci * and false otherwise. 721cb0ef41Sopenharmony_ci */ 731cb0ef41Sopenharmony_ci static bool PreviousGCWasConservative(const HeapHandle& heap_handle); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci private: 761cb0ef41Sopenharmony_ci HeapState() = delete; 771cb0ef41Sopenharmony_ci}; 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci} // namespace subtle 801cb0ef41Sopenharmony_ci} // namespace cppgc 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci#endif // INCLUDE_CPPGC_HEAP_STATE_H_ 83