1 // Copyright 2021 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 INCLUDE_CPPGC_HEAP_STATE_H_ 6 #define INCLUDE_CPPGC_HEAP_STATE_H_ 7 8 #include "v8config.h" // NOLINT(build/include_directory) 9 10 namespace cppgc { 11 12 class HeapHandle; 13 14 namespace subtle { 15 16 /** 17 * Helpers to peek into heap-internal state. 18 */ 19 class V8_EXPORT HeapState final { 20 public: 21 /** 22 * Returns whether the garbage collector is marking. This API is experimental 23 * and is expected to be removed in future. 24 * 25 * \param heap_handle The corresponding heap. 26 * \returns true if the garbage collector is currently marking, and false 27 * otherwise. 28 */ 29 static bool IsMarking(const HeapHandle& heap_handle); 30 31 /* 32 * Returns whether the garbage collector is sweeping. This API is experimental 33 * and is expected to be removed in future. 34 * 35 * \param heap_handle The corresponding heap. 36 * \returns true if the garbage collector is currently sweeping, and false 37 * otherwise. 38 */ 39 static bool IsSweeping(const HeapHandle& heap_handle); 40 41 /* 42 * Returns whether the garbage collector is currently sweeping on the thread 43 * owning this heap. This API allows the caller to determine whether it has 44 * been called from a destructor of a managed object. This API is experimental 45 * and may be removed in future. 46 * 47 * \param heap_handle The corresponding heap. 48 * \returns true if the garbage collector is currently sweeping on this 49 * thread, and false otherwise. 50 */ 51 static bool IsSweepingOnOwningThread(const HeapHandle& heap_handle); 52 53 /** 54 * Returns whether the garbage collector is in the atomic pause, i.e., the 55 * mutator is stopped from running. This API is experimental and is expected 56 * to be removed in future. 57 * 58 * \param heap_handle The corresponding heap. 59 * \returns true if the garbage collector is currently in the atomic pause, 60 * and false otherwise. 61 */ 62 static bool IsInAtomicPause(const HeapHandle& heap_handle); 63 64 /** 65 * Returns whether the last garbage collection was finalized conservatively 66 * (i.e., with a non-empty stack). This API is experimental and is expected to 67 * be removed in future. 68 * 69 * \param heap_handle The corresponding heap. 70 * \returns true if the last garbage collection was finalized conservatively, 71 * and false otherwise. 72 */ 73 static bool PreviousGCWasConservative(const HeapHandle& heap_handle); 74 75 private: 76 HeapState() = delete; 77 }; 78 79 } // namespace subtle 80 } // namespace cppgc 81 82 #endif // INCLUDE_CPPGC_HEAP_STATE_H_ 83