• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 V8_HEAP_CPPGC_PROCESS_HEAP_H_
6 #define V8_HEAP_CPPGC_PROCESS_HEAP_H_
7 
8 #include <vector>
9 
10 #include "src/base/macros.h"
11 #include "src/base/platform/mutex.h"
12 
13 namespace cppgc {
14 namespace internal {
15 
16 class HeapBase;
17 
18 extern v8::base::LazyMutex g_process_mutex;
19 
20 class V8_EXPORT_PRIVATE HeapRegistry final {
21  public:
22   using Storage = std::vector<HeapBase*>;
23 
24   class Subscription final {
25    public:
26     inline explicit Subscription(HeapBase&);
27     inline ~Subscription();
28 
29    private:
30     HeapBase& heap_;
31   };
32 
33   static HeapBase* TryFromManagedPointer(const void* needle);
34 
35   // Does not take the registry mutex and is thus only useful for testing.
36   static const Storage& GetRegisteredHeapsForTesting();
37 
38  private:
39   static void RegisterHeap(HeapBase&);
40   static void UnregisterHeap(HeapBase&);
41 };
42 
Subscription(HeapBase & heap)43 HeapRegistry::Subscription::Subscription(HeapBase& heap) : heap_(heap) {
44   HeapRegistry::RegisterHeap(heap_);
45 }
46 
~Subscription()47 HeapRegistry::Subscription::~Subscription() {
48   HeapRegistry::UnregisterHeap(heap_);
49 }
50 
51 }  // namespace internal
52 }  // namespace cppgc
53 
54 #endif  // V8_HEAP_CPPGC_PROCESS_HEAP_H_
55