From 2667f4968ac6ca9f1e81d652113f3ef067501750 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 8 Dec 2022 14:42:56 +0100 Subject: [PATCH] src: mark generated `snapshot_data` as `const` This renders the mutex protecting it unnecessary, since mutexes only need to protect concurrent accesses to mutable data. --- src/node_snapshot_builder.h | 2 -- src/node_snapshotable.cc | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/node_snapshot_builder.h b/src/node_snapshot_builder.h index 2bea50a2540b2a..3367cd3d7a6c68 100644 --- a/src/node_snapshot_builder.h +++ b/src/node_snapshot_builder.h @@ -32,8 +32,6 @@ class NODE_EXTERN_PRIVATE SnapshotBuilder { v8::Isolate::CreateParams* params); private: - // Used to synchronize access to the snapshot data - static Mutex snapshot_data_mutex_; static const std::vector& CollectExternalReferences(); static std::unique_ptr registry_; diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index 2a4690b76f306e..145e9fa9c18c3c 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -978,7 +978,7 @@ static void WriteCodeCacheInitializer(std::ostream* ss, const std::string& id) { *ss << " },\n"; } -void FormatBlob(std::ostream& ss, SnapshotData* data) { +void FormatBlob(std::ostream& ss, const SnapshotData* data) { ss << R"(#include #include "env.h" #include "node_snapshot_builder.h" @@ -1004,7 +1004,7 @@ static const int v8_snapshot_blob_size = )" WriteStaticCodeCacheData(&ss, item); } - ss << R"(SnapshotData snapshot_data { + ss << R"(const SnapshotData snapshot_data { // -- data_ownership begins -- SnapshotData::DataOwnership::kNotOwned, // -- data_ownership ends -- @@ -1036,7 +1036,6 @@ static const int v8_snapshot_blob_size = )" }; const SnapshotData* SnapshotBuilder::GetEmbeddedSnapshotData() { - Mutex::ScopedLock lock(snapshot_data_mutex_); return &snapshot_data; } } // namespace node @@ -1053,8 +1052,6 @@ static void ResetContextSettingsBeforeSnapshot(Local context) { context->AllowCodeGenerationFromStrings(true); } -Mutex SnapshotBuilder::snapshot_data_mutex_; - const std::vector& SnapshotBuilder::CollectExternalReferences() { static auto registry = std::make_unique(); return registry->external_references();