v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
process-heap.cc
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
6
7#include <algorithm>
8#include <vector>
9
11#include "src/base/logging.h"
15
16namespace cppgc {
17namespace internal {
18
20
21namespace {
22
23v8::base::LazyMutex g_heap_registry_mutex = LAZY_MUTEX_INITIALIZER;
24
25HeapRegistry::Storage& GetHeapRegistryStorage() {
28 return *heap_registry.Pointer();
29}
30
31} // namespace
32
33// static
35 v8::base::MutexGuard guard(g_heap_registry_mutex.Pointer());
36
37 auto& storage = GetHeapRegistryStorage();
38 DCHECK_EQ(storage.end(), std::find(storage.begin(), storage.end(), &heap));
39 storage.push_back(&heap);
40}
41
42// static
44 v8::base::MutexGuard guard(g_heap_registry_mutex.Pointer());
45
46 // HeapRegistry requires access to PageBackend which means it must still
47 // be present by the time a heap is removed from the registry.
48 DCHECK_NOT_NULL(heap.page_backend());
49
50 auto& storage = GetHeapRegistryStorage();
51 const auto pos = std::find(storage.begin(), storage.end(), &heap);
52 DCHECK_NE(storage.end(), pos);
53 storage.erase(pos);
54}
55
56// static
58 v8::base::MutexGuard guard(g_heap_registry_mutex.Pointer());
59
60 for (auto* heap : GetHeapRegistryStorage()) {
61 const auto address =
62 heap->page_backend()->Lookup(reinterpret_cast<ConstAddress>(needle));
63 if (address) return heap;
64 }
65 return nullptr;
66}
67
68// static
70 return GetHeapRegistryStorage();
71}
72
73} // namespace internal
74} // namespace cppgc
SourcePosition pos
static HeapBase * TryFromManagedPointer(const void *needle)
static const Storage & GetRegisteredHeapsForTesting()
std::vector< HeapBase * > Storage
static void UnregisterHeap(HeapBase &)
static void RegisterHeap(HeapBase &)
static v8::base::LazyMutex process_mutex_
#define LAZY_INSTANCE_INITIALIZER
#define LAZY_MUTEX_INITIALIZER
Definition mutex.h:105
const uint8_t * ConstAddress
Definition globals.h:18
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
typename LazyStaticInstance< T, CreateTrait, InitOnceTrait, DestroyTrait >::type type