v8  8.4.371 (node 14.15.5)
V8 is Google's open source JavaScript engine
heap.h
Go to the documentation of this file.
1 // Copyright 2020 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_H_
6 #define INCLUDE_CPPGC_HEAP_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "cppgc/common.h"
12 #include "cppgc/custom-space.h"
13 #include "v8config.h" // NOLINT(build/include_directory)
14 
15 namespace cppgc {
16 namespace internal {
17 class Heap;
18 } // namespace internal
19 
20 class V8_EXPORT Heap {
21  public:
22  /**
23  * Specifies the stack state the embedder is in.
24  */
25  using StackState = EmbedderStackState;
26 
27  struct HeapOptions {
28  static HeapOptions Default() { return {}; }
29 
30  /**
31  * Custom spaces added to heap are required to have indices forming a
32  * numbered sequence starting at 0, i.e., their kSpaceIndex must correspond
33  * to the index they reside in the vector.
34  */
35  std::vector<std::unique_ptr<CustomSpaceBase>> custom_spaces;
36  };
37 
38  static std::unique_ptr<Heap> Create(HeapOptions = HeapOptions::Default());
39 
40  virtual ~Heap() = default;
41 
42  /**
43  * Forces garbage collection.
44  *
45  * \param source String specifying the source (or caller) triggering a
46  * forced garbage collection.
47  * \param reason String specifying the reason for the forced garbage
48  * collection.
49  * \param stack_state The embedder stack state, see StackState.
50  */
52  const char* source, const char* reason,
53  StackState stack_state = StackState::kMayContainHeapPointers);
54 
55  private:
56  Heap() = default;
57 
58  friend class internal::Heap;
59 };
60 
61 } // namespace cppgc
62 
63 #endif // INCLUDE_CPPGC_HEAP_H_