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 { ...@@ -125,12 +125,19 @@ class V8_EXPORT Platform {
/** /**
* Process-global initialization of the garbage collector. Must be called before * 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(); V8_EXPORT void ShutdownProcess();
......
...@@ -29,14 +29,7 @@ static_assert(v8::base::bits::IsPowerOfTwo(kEntrySize), ...@@ -29,14 +29,7 @@ static_assert(v8::base::bits::IsPowerOfTwo(kEntrySize),
"GCInfoTable entries size must be power of " "GCInfoTable entries size must be power of "
"two"); "two");
} // namespace PageAllocator* GetAllocator(PageAllocator* page_allocator) {
GCInfoTable* GlobalGCInfoTable::global_table_ = nullptr;
constexpr GCInfoIndex GCInfoTable::kMaxIndex;
constexpr GCInfoIndex GCInfoTable::kMinIndex;
constexpr GCInfoIndex GCInfoTable::kInitialWantedLimit;
void GlobalGCInfoTable::Create(PageAllocator* page_allocator) {
if (!page_allocator) { if (!page_allocator) {
static v8::base::LeakyObject<v8::base::PageAllocator> static v8::base::LeakyObject<v8::base::PageAllocator>
default_page_allocator; default_page_allocator;
...@@ -44,9 +37,23 @@ void GlobalGCInfoTable::Create(PageAllocator* page_allocator) { ...@@ -44,9 +37,23 @@ void GlobalGCInfoTable::Create(PageAllocator* page_allocator) {
} }
// TODO(chromium:1056170): Wrap page_allocator into LsanPageAllocator when // TODO(chromium:1056170): Wrap page_allocator into LsanPageAllocator when
// running with LEAK_SANITIZER. // 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_) { if (!global_table_) {
global_table_ = table.get(); global_table_ = table.get();
} else {
CHECK_EQ(page_allocator, global_table_->allocator());
} }
} }
......
...@@ -67,6 +67,8 @@ class V8_EXPORT GCInfoTable final { ...@@ -67,6 +67,8 @@ class V8_EXPORT GCInfoTable final {
GCInfoIndex LimitForTesting() const { return limit_; } GCInfoIndex LimitForTesting() const { return limit_; }
GCInfo& TableSlotForTesting(GCInfoIndex index) { return table_[index]; } GCInfo& TableSlotForTesting(GCInfoIndex index) { return table_[index]; }
PageAllocator* allocator() const { return page_allocator_; }
private: private:
void Resize(); void Resize();
...@@ -93,8 +95,10 @@ class V8_EXPORT GlobalGCInfoTable final { ...@@ -93,8 +95,10 @@ class V8_EXPORT GlobalGCInfoTable final {
GlobalGCInfoTable(const GlobalGCInfoTable&) = delete; GlobalGCInfoTable(const GlobalGCInfoTable&) = delete;
GlobalGCInfoTable& operator=(const GlobalGCInfoTable&) = delete; GlobalGCInfoTable& operator=(const GlobalGCInfoTable&) = delete;
// Sets up a singleton table that can be acquired using Get(). // Sets up the table with the provided `page_allocator`. Will use an internal
static void Create(PageAllocator* page_allocator); // 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. // Accessors for the singleton table.
static GCInfoTable& GetMutable() { return *global_table_; } static GCInfoTable& GetMutable() { return *global_table_; }
......
...@@ -10,19 +10,22 @@ ...@@ -10,19 +10,22 @@
namespace cppgc { namespace cppgc {
namespace {
PageAllocator* g_page_allocator = nullptr;
} // namespace
TracingController* Platform::GetTracingController() { TracingController* Platform::GetTracingController() {
static v8::base::LeakyObject<TracingController> tracing_controller; static v8::base::LeakyObject<TracingController> tracing_controller;
return tracing_controller.get(); return tracing_controller.get();
} }
void InitializeProcess(PageAllocator* page_allocator) { void InitializeProcess(PageAllocator* page_allocator) {
static PageAllocator* allocator = nullptr; CHECK(!g_page_allocator);
CHECK(!allocator); internal::GlobalGCInfoTable::Initialize(page_allocator);
internal::GlobalGCInfoTable::Create(page_allocator); g_page_allocator = page_allocator;
allocator = page_allocator;
} }
void ShutdownProcess() {} void ShutdownProcess() { g_page_allocator = nullptr; }
namespace internal { namespace internal {
......
...@@ -169,7 +169,6 @@ void V8::ShutdownPlatform() { ...@@ -169,7 +169,6 @@ void V8::ShutdownPlatform() {
v8::tracing::TracingCategoryObserver::TearDown(); v8::tracing::TracingCategoryObserver::TearDown();
v8::base::SetPrintStackTrace(nullptr); v8::base::SetPrintStackTrace(nullptr);
platform_ = nullptr; platform_ = nullptr;
cppgc::ShutdownProcess();
} }
v8::Platform* V8::GetCurrentPlatform() { 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