fix: use the gin PageAllocator instead of V8::PageAllocator (#26331)
* fix: use the gin PageAllocator instead of V8::PageAllocator This makes browser-process JS allocate pages using the base/gin allocator thus ensuring flags such as MAP_JIT are appropriately applied. * chore: add gin patch * update patches Co-authored-by: Electron Bot <electron@github.com>
This commit is contained in:
parent
02a8c0a640
commit
40ebdb5c42
5 changed files with 159 additions and 1 deletions
|
@ -101,3 +101,4 @@ fix_properly_honor_printing_page_ranges.patch
|
|||
fix_use_electron_generated_resources.patch
|
||||
chore_expose_v8_initialization_isolate_callbacks.patch
|
||||
rename_the_v8_context_snapshot_on_arm64_macos_builds.patch
|
||||
export_gin_v8platform_pageallocator_for_usage_outside_of_the_gin.patch
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Samuel Attard <samuel.r.attard@gmail.com>
|
||||
Date: Tue, 3 Nov 2020 16:49:32 -0800
|
||||
Subject: export gin::V8Platform::PageAllocator for usage outside of the gin
|
||||
platform
|
||||
|
||||
diff --git a/gin/public/v8_platform.h b/gin/public/v8_platform.h
|
||||
index da2aeb2f2da84fe47d5cc7d721f8d3dade0c0972..4ddad9065782fad5927bc0481ad772014af0d689 100644
|
||||
--- a/gin/public/v8_platform.h
|
||||
+++ b/gin/public/v8_platform.h
|
||||
@@ -23,6 +23,7 @@ class GIN_EXPORT V8Platform : public v8::Platform {
|
||||
// Some configurations do not use page_allocator.
|
||||
#if BUILDFLAG(USE_PARTITION_ALLOC)
|
||||
v8::PageAllocator* GetPageAllocator() override;
|
||||
+ static v8::PageAllocator* PageAllocator();
|
||||
void OnCriticalMemoryPressure() override;
|
||||
#endif
|
||||
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
|
||||
diff --git a/gin/v8_platform.cc b/gin/v8_platform.cc
|
||||
index 9cec7468189af7f290ff32c184f0a7baa636be62..e4f20e56680e652ca99b416d352e4a2ec1b79509 100644
|
||||
--- a/gin/v8_platform.cc
|
||||
+++ b/gin/v8_platform.cc
|
||||
@@ -439,6 +439,10 @@ v8::PageAllocator* V8Platform::GetPageAllocator() {
|
||||
return g_page_allocator.Pointer();
|
||||
}
|
||||
|
||||
+v8::PageAllocator* V8Platform::PageAllocator() {
|
||||
+ return g_page_allocator.Pointer();
|
||||
+}
|
||||
+
|
||||
void V8Platform::OnCriticalMemoryPressure() {
|
||||
// We only have a reservation on 32-bit Windows systems.
|
||||
// TODO(bbudge) Make the #if's in BlinkInitializer match.
|
|
@ -28,3 +28,4 @@ feat_add_implementation_of_v8_platform_postjob.patch
|
|||
fix_-wincompatible-pointer-types-discards-qualifiers_error.patch
|
||||
fix_add_v8_enable_reverse_jsargs_defines_in_common_gypi.patch
|
||||
fix_allow_preventing_initializeinspector_in_env.patch
|
||||
src_allow_embedders_to_provide_a_custom_pageallocator_to.patch
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Samuel Attard <samuel.r.attard@gmail.com>
|
||||
Date: Tue, 3 Nov 2020 16:17:38 -0800
|
||||
Subject: src: allow embedders to provide a custom PageAllocator to
|
||||
NodePlatform
|
||||
|
||||
For certain embedder use cases there are more complex memory allocation requirements that the default V8 page allocator does not handle, for example using MAP_JIT when running under a hardened runtime environment on macOS. This allows such embedders to provide their own allocator that does handle these cases.
|
||||
|
||||
diff --git a/src/api/environment.cc b/src/api/environment.cc
|
||||
index c08fe4b32d4155badb572f15529f903c0ec63146..a8cf0d763f78c2752e3aa22479dadd9fa53c222f 100644
|
||||
--- a/src/api/environment.cc
|
||||
+++ b/src/api/environment.cc
|
||||
@@ -488,8 +488,9 @@ MultiIsolatePlatform* CreatePlatform(
|
||||
|
||||
MultiIsolatePlatform* CreatePlatform(
|
||||
int thread_pool_size,
|
||||
- v8::TracingController* tracing_controller) {
|
||||
- return MultiIsolatePlatform::Create(thread_pool_size, tracing_controller)
|
||||
+ v8::TracingController* tracing_controller,
|
||||
+ v8::PageAllocator* page_allocator) {
|
||||
+ return MultiIsolatePlatform::Create(thread_pool_size, tracing_controller, page_allocator)
|
||||
.release();
|
||||
}
|
||||
|
||||
@@ -499,8 +500,9 @@ void FreePlatform(MultiIsolatePlatform* platform) {
|
||||
|
||||
std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
|
||||
int thread_pool_size,
|
||||
- v8::TracingController* tracing_controller) {
|
||||
- return std::make_unique<NodePlatform>(thread_pool_size, tracing_controller);
|
||||
+ v8::TracingController* tracing_controller,
|
||||
+ v8::PageAllocator* page_allocator) {
|
||||
+ return std::make_unique<NodePlatform>(thread_pool_size, tracing_controller, page_allocator);
|
||||
}
|
||||
|
||||
MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
|
||||
diff --git a/src/node.h b/src/node.h
|
||||
index b646fdda58ebcbf2dd92ee4fc9cb0d9c039174d1..14893ad605b9f8c64b0b8fc28625e235655dcd63 100644
|
||||
--- a/src/node.h
|
||||
+++ b/src/node.h
|
||||
@@ -333,7 +333,8 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform {
|
||||
|
||||
static std::unique_ptr<MultiIsolatePlatform> Create(
|
||||
int thread_pool_size,
|
||||
- v8::TracingController* tracing_controller = nullptr);
|
||||
+ v8::TracingController* tracing_controller = nullptr,
|
||||
+ v8::PageAllocator* page_allocator = nullptr);
|
||||
};
|
||||
|
||||
enum IsolateSettingsFlags {
|
||||
@@ -536,7 +537,8 @@ NODE_DEPRECATED("Use variant taking a v8::TracingController* pointer instead",
|
||||
node::tracing::TracingController* tracing_controller));
|
||||
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
|
||||
int thread_pool_size,
|
||||
- v8::TracingController* tracing_controller);
|
||||
+ v8::TracingController* tracing_controller,
|
||||
+ v8::PageAllocator* = nullptr);
|
||||
NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform);
|
||||
|
||||
// Get/set the currently active tracing controller. Using CreatePlatform()
|
||||
diff --git a/src/node_platform.cc b/src/node_platform.cc
|
||||
index aac0682670fcffd235fcf450bc5e2b0d45985b47..96be2281b562c44b276483970c06862250ea8941 100644
|
||||
--- a/src/node_platform.cc
|
||||
+++ b/src/node_platform.cc
|
||||
@@ -324,12 +324,16 @@ void PerIsolatePlatformData::DecreaseHandleCount() {
|
||||
}
|
||||
|
||||
NodePlatform::NodePlatform(int thread_pool_size,
|
||||
- v8::TracingController* tracing_controller) {
|
||||
+ v8::TracingController* tracing_controller,
|
||||
+ v8::PageAllocator* page_allocator) {
|
||||
if (tracing_controller != nullptr) {
|
||||
tracing_controller_ = tracing_controller;
|
||||
} else {
|
||||
tracing_controller_ = new v8::TracingController();
|
||||
}
|
||||
+ // This being nullptr is acceptable as V8 will default to its built
|
||||
+ // in allocator if none is provided
|
||||
+ page_allocator_ = page_allocator;
|
||||
// TODO(addaleax): It's a bit icky that we use global state here, but we can't
|
||||
// really do anything about it unless V8 starts exposing a way to access the
|
||||
// current v8::Platform instance.
|
||||
@@ -544,6 +548,10 @@ Platform::StackTracePrinter NodePlatform::GetStackTracePrinter() {
|
||||
};
|
||||
}
|
||||
|
||||
+v8::PageAllocator* NodePlatform::GetPageAllocator() {
|
||||
+ return page_allocator_;
|
||||
+}
|
||||
+
|
||||
std::unique_ptr<v8::JobHandle> NodePlatform::PostJob(v8::TaskPriority priority, std::unique_ptr<v8::JobTask> job_task) {
|
||||
return v8::platform::NewDefaultJobHandle(this, priority, std::move(job_task), 1 /* num_worker_threads */);
|
||||
}
|
||||
diff --git a/src/node_platform.h b/src/node_platform.h
|
||||
index a274be6bbea19a4488bca393712a9ac8b50fe16a..314cf2d1056d30a77ead400d100a4d4c6f844be6 100644
|
||||
--- a/src/node_platform.h
|
||||
+++ b/src/node_platform.h
|
||||
@@ -138,7 +138,8 @@ class WorkerThreadsTaskRunner {
|
||||
class NodePlatform : public MultiIsolatePlatform {
|
||||
public:
|
||||
NodePlatform(int thread_pool_size,
|
||||
- v8::TracingController* tracing_controller);
|
||||
+ v8::TracingController* tracing_controller,
|
||||
+ v8::PageAllocator* page_allocator = nullptr);
|
||||
~NodePlatform() override;
|
||||
|
||||
void DrainTasks(v8::Isolate* isolate) override;
|
||||
@@ -168,6 +169,7 @@ class NodePlatform : public MultiIsolatePlatform {
|
||||
v8::Isolate* isolate) override;
|
||||
|
||||
Platform::StackTracePrinter GetStackTracePrinter() override;
|
||||
+ v8::PageAllocator* GetPageAllocator() override;
|
||||
|
||||
private:
|
||||
IsolatePlatformDelegate* ForIsolate(v8::Isolate* isolate);
|
||||
@@ -179,6 +181,7 @@ class NodePlatform : public MultiIsolatePlatform {
|
||||
std::unordered_map<v8::Isolate*, DelegatePair> per_isolate_;
|
||||
|
||||
v8::TracingController* tracing_controller_;
|
||||
+ v8::PageAllocator* page_allocator_;
|
||||
std::shared_ptr<WorkerThreadsTaskRunner> worker_thread_task_runner_;
|
||||
bool has_shut_down_ = false;
|
||||
};
|
|
@ -246,7 +246,7 @@ v8::Isolate* JavascriptEnvironment::Initialize(uv_loop_t* event_loop) {
|
|||
node::tracing::TraceEventHelper::SetAgent(tracing_agent);
|
||||
platform_ = node::CreatePlatform(
|
||||
base::RecommendedMaxNumberOfThreadsInThreadGroup(3, 8, 0.1, 0),
|
||||
tracing_controller);
|
||||
tracing_controller, gin::V8Platform::PageAllocator());
|
||||
|
||||
v8::V8::InitializePlatform(platform_);
|
||||
gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue