Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2021-01-28 17:00:03 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2021-02-16 17:12:39 +0300
commit2a5f67b3812a531f2bfed3330d827da165283163 (patch)
tree8bcc52d3dfe2a01b52e72016f40d1dc21015ae91 /src
parentacd087dffbb221530da900ac4fe1bc6ee4b2fe2b (diff)
src: refactor bookkeeping of bootstrap status
This patch 1. Refactors the bootstrap routine of the main instance so that when --no-node-snapshot is used, Environment::InitializeMainContext() will only be called once (previously it would be called twice, which was harmless for now but not ideal). 2. Mark the number of BaseObjects in RunBootstrapping() when creating the Environment from scratch and in InitializeMainContext() when the Environment is deserialized. Previously the marking was done in the Environment constructor and InitializeMainContext() respectively for the cctest which was incorrect because the cctest never uses an Environment that's not bootstrapped. Also renames the mark to base_object_created_after_bootstrap to reflect what it's intended for. PR-URL: https://github.com/nodejs/node/pull/37113 Refs: https://github.com/nodejs/node/pull/36943 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/env-inl.h14
-rw-r--r--src/env.cc9
-rw-r--r--src/env.h5
-rw-r--r--src/node.cc2
-rw-r--r--src/node_main_instance.cc24
5 files changed, 27 insertions, 27 deletions
diff --git a/src/env-inl.h b/src/env-inl.h
index 98badcd0362..95b818373b9 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -784,8 +784,12 @@ inline bool Environment::has_run_bootstrapping_code() const {
return has_run_bootstrapping_code_;
}
-inline void Environment::set_has_run_bootstrapping_code(bool value) {
- has_run_bootstrapping_code_ = value;
+inline void Environment::DoneBootstrapping() {
+ has_run_bootstrapping_code_ = true;
+ // This adjusts the return value of base_object_created_after_bootstrap() so
+ // that tests that check the count do not have to account for internally
+ // created BaseObjects.
+ base_object_created_by_bootstrap_ = base_object_count_;
}
inline bool Environment::has_serialized_options() const {
@@ -1089,8 +1093,12 @@ void Environment::modify_base_object_count(int64_t delta) {
base_object_count_ += delta;
}
+int64_t Environment::base_object_created_after_bootstrap() const {
+ return base_object_count_ - base_object_created_by_bootstrap_;
+}
+
int64_t Environment::base_object_count() const {
- return base_object_count_ - initial_base_object_count_;
+ return base_object_count_;
}
void Environment::set_main_utf16(std::unique_ptr<v8::String::Value> str) {
diff --git a/src/env.cc b/src/env.cc
index 69d5a33a945..16c6fcc3db4 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -422,10 +422,6 @@ Environment::Environment(IsolateData* isolate_data,
"args",
std::move(traced_value));
}
-
- // This adjusts the return value of base_object_count() so that tests that
- // check the count do not have to account for internally created BaseObjects.
- initial_base_object_count_ = base_object_count();
}
Environment::Environment(IsolateData* isolate_data,
@@ -468,10 +464,6 @@ void Environment::InitializeMainContext(Local<Context> context,
per_process::node_start_time);
performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_V8_START,
performance::performance_v8_start);
-
- // This adjusts the return value of base_object_count() so that tests that
- // check the count do not have to account for internally created BaseObjects.
- initial_base_object_count_ = base_object_count();
}
Environment::~Environment() {
@@ -662,7 +654,6 @@ void Environment::RunCleanup() {
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
"RunCleanup", this);
bindings_.clear();
- initial_base_object_count_ = 0;
CleanupHandles();
while (!cleanup_hooks_.empty() ||
diff --git a/src/env.h b/src/env.h
index 38c087b650e..f2fc681f56e 100644
--- a/src/env.h
+++ b/src/env.h
@@ -1132,7 +1132,7 @@ class Environment : public MemoryRetainer {
inline void add_refs(int64_t diff);
inline bool has_run_bootstrapping_code() const;
- inline void set_has_run_bootstrapping_code(bool has_run_bootstrapping_code);
+ inline void DoneBootstrapping();
inline bool has_serialized_options() const;
inline void set_has_serialized_options(bool has_serialized_options);
@@ -1318,6 +1318,7 @@ class Environment : public MemoryRetainer {
// no memory leaks caused by BaseObjects staying alive longer than expected
// (in particular, no circular BaseObjectPtr references).
inline void modify_base_object_count(int64_t delta);
+ inline int64_t base_object_created_after_bootstrap() const;
inline int64_t base_object_count() const;
inline int32_t stack_trace_limit() const { return 10; }
@@ -1511,7 +1512,7 @@ class Environment : public MemoryRetainer {
bool started_cleanup_ = false;
int64_t base_object_count_ = 0;
- int64_t initial_base_object_count_ = 0;
+ int64_t base_object_created_by_bootstrap_ = 0;
std::atomic_bool is_stopping_ { false };
std::unordered_set<int> unmanaged_fds_;
diff --git a/src/node.cc b/src/node.cc
index efb4876002f..decaa755e39 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -415,7 +415,7 @@ MaybeLocal<Value> Environment::RunBootstrapping() {
CHECK(req_wrap_queue()->IsEmpty());
CHECK(handle_wrap_queue()->IsEmpty());
- set_has_run_bootstrapping_code(true);
+ DoneBootstrapping();
return scope.Escape(result);
}
diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc
index 84d39831dcd..37d9dbb9b75 100644
--- a/src/node_main_instance.cc
+++ b/src/node_main_instance.cc
@@ -209,10 +209,18 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
{DeserializeNodeInternalFields, env.get()})
.ToLocalChecked();
+ CHECK(!context.IsEmpty());
+ Context::Scope context_scope(context);
InitializeContextRuntime(context);
SetIsolateErrorHandlers(isolate_, {});
+ env->InitializeMainContext(context, env_info);
+#if HAVE_INSPECTOR
+ env->InitializeInspector({});
+#endif
+ env->DoneBootstrapping();
} else {
context = NewContext(isolate_);
+ CHECK(!context.IsEmpty());
Context::Scope context_scope(context);
env.reset(new Environment(isolate_data_.get(),
context,
@@ -221,24 +229,16 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
nullptr,
EnvironmentFlags::kDefaultFlags,
{}));
- }
-
- CHECK(!context.IsEmpty());
- Context::Scope context_scope(context);
-
- env->InitializeMainContext(context, env_info);
-
#if HAVE_INSPECTOR
- env->InitializeInspector({});
+ env->InitializeInspector({});
#endif
-
- if (!deserialize_mode_ && env->RunBootstrapping().IsEmpty()) {
- return nullptr;
+ if (env->RunBootstrapping().IsEmpty()) {
+ return nullptr;
+ }
}
CHECK(env->req_wrap_queue()->IsEmpty());
CHECK(env->handle_wrap_queue()->IsEmpty());
- env->set_has_run_bootstrapping_code(true);
return env;
}