v8  9.4.146 (node 16.13.0)
V8 is Google's open source JavaScript engine
testing.h
Go to the documentation of this file.
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_TESTING_H_
6 #define INCLUDE_CPPGC_TESTING_H_
7 
8 #include "cppgc/common.h"
9 #include "cppgc/macros.h"
10 #include "v8config.h" // NOLINT(build/include_directory)
11 
12 namespace cppgc {
13 
14 class HeapHandle;
15 
16 /**
17  * Namespace contains testing helpers.
18  */
19 namespace testing {
20 
21 /**
22  * Overrides the state of the stack with the provided value. Takes precedence
23  * over other parameters that set the stack state. Must no be nested.
24  */
25 class V8_EXPORT V8_NODISCARD OverrideEmbedderStackStateScope final {
27 
28  public:
29  /**
30  * Constructs a scoped object that automatically enters and leaves the scope.
31  *
32  * \param heap_handle The corresponding heap.
33  */
34  explicit OverrideEmbedderStackStateScope(HeapHandle& heap_handle,
35  EmbedderStackState state);
37 
38  OverrideEmbedderStackStateScope(const OverrideEmbedderStackStateScope&) =
39  delete;
40  OverrideEmbedderStackStateScope& operator=(
41  const OverrideEmbedderStackStateScope&) = delete;
42 
43  private:
44  HeapHandle& heap_handle_;
45 };
46 
47 /**
48  * Testing interface for managed heaps that allows for controlling garbage
49  * collection timings. Embedders should use this class when testing the
50  * interaction of their code with incremental/concurrent garbage collection.
51  */
52 class V8_EXPORT StandaloneTestingHeap final {
53  public:
54  explicit StandaloneTestingHeap(HeapHandle&);
55 
56  /**
57  * Start an incremental garbage collection.
58  */
60 
61  /**
62  * Perform an incremental step. This will also schedule concurrent steps if
63  * needed.
64  *
65  * \param stack_state The state of the stack during the step.
66  */
68 
69  /**
70  * Finalize the current garbage collection cycle atomically.
71  * Assumes that garbage collection is in progress.
72  *
73  * \param stack_state The state of the stack for finalizing the garbage
74  * collection cycle.
75  */
77 
78  /**
79  * Toggle main thread marking on/off. Allows to stress concurrent marking
80  * (e.g. to better detect data races).
81  *
82  * \param should_mark Denotes whether the main thread should contribute to
83  * marking. Defaults to true.
84  */
85  void ToggleMainThreadMarking(bool should_mark);
86 
87  /**
88  * Force enable compaction for the next garbage collection cycle.
89  */
91 
92  private:
93  HeapHandle& heap_handle_;
94 };
95 
96 } // namespace testing
97 } // namespace cppgc
98 
99 #endif // INCLUDE_CPPGC_TESTING_H_