Commit 76e8b811 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: Allow multiple calls to InitializeProcess/ShutdownProcess

Model cppgc::InitializeProcess()/cppgc::ShutdownProcess() similar to
V8's InitializePlatform()/ShutdownPlatform() in that we allow the pair
to be called multiple times.

GCInfoTable will not be freed on ShutdownProcess though as the current
global design uses static indices to retrieve per-type metadata.

Drive-by: Remove stale ShutdownProcess() call.

Change-Id: Ia9b50325a964e85a72f3ef218e72bc386b69be51
Bug: chromium:1176416, chromium:1056170
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2685171Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72630}
parent f033e2a1
......@@ -125,12 +125,19 @@ class V8_EXPORT Platform {
/**
* Process-global initialization of the garbage collector. Must be called before
* creating a Heap. Must only be called once per process.
* creating a Heap.
*
* Can be called multiple times when paired with `ShutdownProcess()`.
*
* \param page_allocator The allocator used for maintaining meta data. Must not
* change between multiple calls to InitializeProcess.
*/
V8_EXPORT void InitializeProcess(PageAllocator*);
V8_EXPORT void InitializeProcess(PageAllocator* page_allocator);
/**
* Must be called after destroying the last used heap.
* Must be called after destroying the last used heap. Some process-global
* metadata may not be returned and reused upon a subsequent
* `InitializeProcess()` call.
*/
V8_EXPORT void ShutdownProcess();
......
......@@ -29,14 +29,7 @@ static_assert(v8::base::bits::IsPowerOfTwo(kEntrySize),
"GCInfoTable entries size must be power of "
"two");
} // namespace
GCInfoTable* GlobalGCInfoTable::global_table_ = nullptr;
constexpr GCInfoIndex GCInfoTable::kMaxIndex;
constexpr GCInfoIndex GCInfoTable::kMinIndex;
constexpr GCInfoIndex GCInfoTable::kInitialWantedLimit;
void GlobalGCInfoTable::Create(PageAllocator* page_allocator) {
PageAllocator* GetAllocator(PageAllocator* page_allocator) {
if (!page_allocator) {
static v8::base::LeakyObject<v8::base::PageAllocator>
default_page_allocator;
......@@ -44,9 +37,23 @@ void GlobalGCInfoTable::Create(PageAllocator* page_allocator) {
}
// TODO(chromium:1056170): Wrap page_allocator into LsanPageAllocator when
// running with LEAK_SANITIZER.
static v8::base::LeakyObject<GCInfoTable> table(page_allocator);
return page_allocator;
}
} // namespace
GCInfoTable* GlobalGCInfoTable::global_table_ = nullptr;
constexpr GCInfoIndex GCInfoTable::kMaxIndex;
constexpr GCInfoIndex GCInfoTable::kMinIndex;
constexpr GCInfoIndex GCInfoTable::kInitialWantedLimit;
// static
void GlobalGCInfoTable::Initialize(PageAllocator* page_allocator) {
static v8::base::LeakyObject<GCInfoTable> table(GetAllocator(page_allocator));
if (!global_table_) {
global_table_ = table.get();
} else {
CHECK_EQ(page_allocator, global_table_->allocator());
}
}
......
......@@ -67,6 +67,8 @@ class V8_EXPORT GCInfoTable final {
GCInfoIndex LimitForTesting() const { return limit_; }
GCInfo& TableSlotForTesting(GCInfoIndex index) { return table_[index]; }
PageAllocator* allocator() const { return page_allocator_; }
private:
void Resize();
......@@ -93,8 +95,10 @@ class V8_EXPORT GlobalGCInfoTable final {
GlobalGCInfoTable(const GlobalGCInfoTable&) = delete;
GlobalGCInfoTable& operator=(const GlobalGCInfoTable&) = delete;
// Sets up a singleton table that can be acquired using Get().
static void Create(PageAllocator* page_allocator);
// Sets up the table with the provided `page_allocator`. Will use an internal
// allocator in case no PageAllocator is provided. May be called multiple
// times with the same `page_allocator` argument.
static void Initialize(PageAllocator* page_allocator);
// Accessors for the singleton table.
static GCInfoTable& GetMutable() { return *global_table_; }
......
......@@ -10,19 +10,22 @@
namespace cppgc {
namespace {
PageAllocator* g_page_allocator = nullptr;
} // namespace
TracingController* Platform::GetTracingController() {
static v8::base::LeakyObject<TracingController> tracing_controller;
return tracing_controller.get();
}
void InitializeProcess(PageAllocator* page_allocator) {
static PageAllocator* allocator = nullptr;
CHECK(!allocator);
internal::GlobalGCInfoTable::Create(page_allocator);
allocator = page_allocator;
CHECK(!g_page_allocator);
internal::GlobalGCInfoTable::Initialize(page_allocator);
g_page_allocator = page_allocator;
}
void ShutdownProcess() {}
void ShutdownProcess() { g_page_allocator = nullptr; }
namespace internal {
......
......@@ -169,7 +169,6 @@ void V8::ShutdownPlatform() {
v8::tracing::TracingCategoryObserver::TearDown();
v8::base::SetPrintStackTrace(nullptr);
platform_ = nullptr;
cppgc::ShutdownProcess();
}
v8::Platform* V8::GetCurrentPlatform() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment