#include "gin/public/cppgc.h"
#include "base/check_op.h"
#include "base/feature_list.h"
#include "build/build_config.h"
#include "gin/gin_features.h"
#include "gin/public/v8_platform.h"
#include "v8/include/cppgc/platform.h"
namespace gin {
namespace {
int g_init_count = 0;
}
void InitializeCppgcFromV8Platform() {
#if BUILDFLAG(IS_ANDROID)
static constexpr size_t kCageSize =
static_cast<size_t>(4) * 1024 * 1024 * 1024;
#else
static constexpr size_t kCageSize =
static_cast<size_t>(16) * 1024 * 1024 * 1024;
#endif
DCHECK_GE(g_init_count, 0);
if (g_init_count++ > 0) {
return;
}
cppgc::InitializeProcess(gin::V8Platform::Get()->GetPageAllocator(),
kCageSize);
}
void MaybeShutdownCppgc() {
DCHECK_GT(g_init_count, 0);
if (--g_init_count > 0)
return;
cppgc::ShutdownProcess();
}
}