v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
process-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 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"
13
14namespace cppgc::internal {
15
16class HeapBase;
17
18class ProcessGlobalLock final {
19 public:
20 enum class Reason {
21 kForGC,
23 };
24
25 template <Reason reason>
26 V8_INLINE static void Lock() {
27 process_mutex_.Pointer()->Lock();
28
29#if defined(V8_USE_PERFETTO)
30 switch (reason) {
31 case Reason::kForGC:
32 TRACE_EVENT_BEGIN(TRACE_DISABLED_BY_DEFAULT("cppgc"), "AcquiredForGC",
33 perfetto::NamedTrack("CppGC.ProcessGlobalLock"));
34 break;
36#ifdef DEBUG
37 TRACE_EVENT_BEGIN(TRACE_DISABLED_BY_DEFAULT("cppgc"),
38 "AcquiredForCrossThreadHandleCreation",
39 perfetto::NamedTrack("CppGC.ProcessGlobalLock"));
40#endif // DEBUG
41 break;
42 }
43#endif // defined(V8_USE_PERFETTO)
44 }
45
46 template <Reason reason>
47 V8_INLINE static void Unlock() {
48#if defined(V8_USE_PERFETTO)
49 switch (reason) {
50 case Reason::kForGC:
51 TRACE_EVENT_END(TRACE_DISABLED_BY_DEFAULT("cppgc"),
52 perfetto::NamedTrack("CppGC.ProcessGlobalLock"));
53 break;
55#ifdef DEBUG
56 TRACE_EVENT_END(TRACE_DISABLED_BY_DEFAULT("cppgc"),
57 perfetto::NamedTrack("CppGC.ProcessGlobalLock"));
58#endif // DEBUG
59 break;
60 }
61#endif // defined(V8_USE_PERFETTO)
62
63 process_mutex_.Pointer()->Unlock();
64 }
65
66 V8_INLINE static void AssertHeld() { process_mutex_.Pointer()->AssertHeld(); }
67
68 private:
70};
71
73 public:
74 using Storage = std::vector<HeapBase*>;
75
76 class Subscription final {
77 public:
78 inline explicit Subscription(HeapBase&);
79 inline ~Subscription();
80
81 private:
83 };
84
85 static HeapBase* TryFromManagedPointer(const void* needle);
86
87 // Does not take the registry mutex and is thus only useful for testing.
88 static const Storage& GetRegisteredHeapsForTesting();
89
90 private:
91 static void RegisterHeap(HeapBase&);
92 static void UnregisterHeap(HeapBase&);
93};
94
98
102
103} // namespace cppgc::internal
104
105#endif // V8_HEAP_CPPGC_PROCESS_HEAP_H_
std::vector< HeapBase * > Storage
static void UnregisterHeap(HeapBase &)
static void RegisterHeap(HeapBase &)
static v8::base::LazyMutex process_mutex_
static V8_INLINE void Unlock()
static V8_INLINE void AssertHeld()
static V8_INLINE void Lock()
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define TRACE_DISABLED_BY_DEFAULT(name)
Heap * heap_
#define V8_INLINE
Definition v8config.h:500