v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
platform.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
8#include "src/base/logging.h"
9#include "src/base/macros.h"
17
18#if defined(CPPGC_CAGED_HEAP)
20#endif // defined(CPPGC_CAGED_HEAP)
21
22namespace cppgc {
23namespace internal {
24
25namespace {
26
27PageAllocator* g_page_allocator = nullptr;
28
29PageAllocator& CreateAllocatorIfNeeded(PageAllocator* page_allocator) {
30 if (!page_allocator) {
32 default_page_allocator;
33 page_allocator = default_page_allocator.get();
34 }
35#if defined(LEAK_SANITIZER)
36 // If lsan is enabled, override the given allocator with the custom lsan
37 // allocator.
39 page_allocator);
40 page_allocator = lsan_page_allocator.get();
41#endif // LEAK_SANITIZER
42 return *page_allocator;
43}
44
45} // namespace
46
47void Fatal(const std::string& reason, const SourceLocation& loc) {
48#ifdef DEBUG
49 V8_Fatal(loc.FileName(), static_cast<int>(loc.Line()), "%s", reason.c_str());
50#else // !DEBUG
51 V8_Fatal("%s", reason.c_str());
52#endif // !DEBUG
53}
54
55void FatalOutOfMemoryHandler::operator()(const std::string& reason,
56 const SourceLocation& loc) const {
57 if (custom_handler_) {
58 (*custom_handler_)(reason, loc, heap_);
59 FATAL("Custom out of memory handler should not have returned");
60 }
61#ifdef DEBUG
62 V8_Fatal(loc.FileName(), static_cast<int>(loc.Line()),
63 "Oilpan: Out of memory (%s)", reason.c_str());
64#else // !DEBUG
65 V8_Fatal("Oilpan: Out of memory");
66#endif // !DEBUG
67}
68
72
74 static FatalOutOfMemoryHandler oom_handler;
75 return oom_handler;
76}
77
79 CHECK_NOT_NULL(g_page_allocator);
80 return *g_page_allocator;
81}
82
83} // namespace internal
84
86 static v8::base::LeakyObject<TracingController> tracing_controller;
87 return tracing_controller.get();
88}
89
90bool IsInitialized() { return internal::g_page_allocator != nullptr; }
91
92void InitializeProcess(PageAllocator* page_allocator,
93 size_t desired_heap_size) {
94#if defined(V8_USE_ADDRESS_SANITIZER) && defined(V8_HOST_ARCH_64_BIT)
95 // Retrieve asan's internal shadow memory granularity and check that Oilpan's
96 // object alignment/sizes are multiple of this granularity. This is needed to
97 // perform poisoness checks.
98 size_t shadow_scale;
99 __asan_get_shadow_mapping(&shadow_scale, nullptr);
100 DCHECK(shadow_scale);
101 const size_t poisoning_granularity = 1 << shadow_scale;
102 CHECK_EQ(0u, internal::kAllocationGranularity % poisoning_granularity);
103#endif
104
105 auto& allocator = internal::CreateAllocatorIfNeeded(page_allocator);
106
107 CHECK(!internal::g_page_allocator);
109#if defined(CPPGC_CAGED_HEAP)
110 internal::CagedHeap::InitializeIfNeeded(allocator, desired_heap_size);
111#endif // defined(CPPGC_CAGED_HEAP)
112 internal::g_page_allocator = &allocator;
113}
114
115void ShutdownProcess() { internal::g_page_allocator = nullptr; }
116
117} // namespace cppgc
void V8_Fatal(const char *format,...)
Definition logging.cc:170
virtual TracingController * GetTracingController()
Definition platform.cc:85
static void InitializeIfNeeded(PageAllocator &platform_allocator, size_t desired_heap_size)
Definition caged-heap.cc:86
void operator()(const std::string &reason=std::string(), const SourceLocation &=SourceLocation::Current()) const
Definition platform.cc:55
void(const std::string &, const SourceLocation &, HeapBase *) Callback
Definition platform.h:20
static void Initialize(PageAllocator &page_allocator)
constexpr size_t Line() const
constexpr const char * FileName() const
TNode< Object > callback
void Fatal(const std::string &reason, const SourceLocation &loc)
Definition platform.cc:47
PageAllocator & GetGlobalPageAllocator()
Definition platform.cc:78
constexpr size_t kAllocationGranularity
Definition globals.h:37
FatalOutOfMemoryHandler & GetGlobalOOMHandler()
Definition platform.cc:73
void ShutdownProcess()
Definition platform.cc:115
v8::PageAllocator PageAllocator
Definition platform.h:22
void InitializeProcess(PageAllocator *page_allocator, size_t desired_heap_size)
Definition platform.cc:92
bool IsInitialized()
Definition platform.cc:90
#define FATAL(...)
Definition logging.h:47
#define CHECK(condition)
Definition logging.h:124
#define CHECK_NOT_NULL(val)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482