summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Dashti <mdashti@gmail.com>2022-11-22 21:15:06 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-22 22:12:53 +0000
commitb50819d5ffaeea1e195598b19d47bcc76f507b57 (patch)
treef8d20ab9cfc512ef1dd47761dbecd70215812bcf
parentc9a912b2757dacc50462a88197250677d73af69c (diff)
downloadmongo-b50819d5ffaeea1e195598b19d47bcc76f507b57.tar.gz
SERVER-68286 Improved lifetime issues with `mongo::mozjs::currentJSScope`
-rw-r--r--buildscripts/gdb/mongo.py6
-rw-r--r--src/mongo/scripting/mozjs/implscope.cpp25
2 files changed, 14 insertions, 17 deletions
diff --git a/buildscripts/gdb/mongo.py b/buildscripts/gdb/mongo.py
index 03e89d89c54..6e43aeb7095 100644
--- a/buildscripts/gdb/mongo.py
+++ b/buildscripts/gdb/mongo.py
@@ -815,7 +815,7 @@ class MongoDBJavaScriptStack(gdb.Command):
# Switch frames so gdb actually knows about the mongo::mozjs namespace. It doesn't
# actually matter which frame so long as it isn't the top of the stack. This also
- # enables gdb to know about the mongo::mozjs::kCurrentScope thread-local variable
+ # enables gdb to know about the mongo::mozjs::currentJSScope thread-local variable
# when using gdb.parse_and_eval().
gdb.selected_frame().older().select()
except gdb.error as err:
@@ -825,11 +825,11 @@ class MongoDBJavaScriptStack(gdb.Command):
try:
# The following block is roughly equivalent to this:
# namespace mongo::mozjs {
- # std::atomic<MozJSImplScope*> kCurrentScope = ...;
+ # std::atomic<MozJSImplScope*> currentJSScope = ...;
# }
# if (!scope || scope->_inOp == 0) { continue; }
# print(scope->buildStackString()->c_str());
- atomic_scope = gdb.parse_and_eval("mongo::mozjs::kCurrentScope")
+ atomic_scope = gdb.parse_and_eval("mongo::mozjs::currentJSScope")
ptr = MongoDBJavaScriptStack.atomic_get_ptr(atomic_scope)
if not ptr:
continue
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp
index 94b1d8ed096..1f9ef16522f 100644
--- a/src/mongo/scripting/mozjs/implscope.cpp
+++ b/src/mongo/scripting/mozjs/implscope.cpp
@@ -118,7 +118,7 @@ bool closeToMaxMemory() {
}
} // namespace
-thread_local MozJSImplScope::ASANHandles* kCurrentASANHandles = nullptr;
+thread_local MozJSImplScope::ASANHandles* currentASANHandles = nullptr;
// You may wonder what the point is to making this thread local
@@ -132,7 +132,7 @@ thread_local MozJSImplScope::ASANHandles* kCurrentASANHandles = nullptr;
// this from "another thread" (being GDB), it makes some sense. Or it
// might be a GDB bug of some sort that forcing it into an atomic
// papers over.
-thread_local std::atomic<MozJSImplScope*> kCurrentScope = nullptr; // NOLINT
+thread_local std::atomic<MozJSImplScope*> currentJSScope = nullptr; // NOLINT
struct MozJSImplScope::MozJSEntry {
MozJSEntry(MozJSImplScope* scope) : ac(scope->_context, scope->_global), _scope(scope) {
@@ -264,12 +264,12 @@ void MozJSImplScope::_gcCallback(JSContext* rt,
#if __has_feature(address_sanitizer)
MozJSImplScope::ASANHandles::ASANHandles() {
- kCurrentASANHandles = this;
+ currentASANHandles = this;
}
MozJSImplScope::ASANHandles::~ASANHandles() {
- invariant(kCurrentASANHandles == this);
- kCurrentASANHandles = nullptr;
+ invariant(currentASANHandles == this);
+ currentASANHandles = nullptr;
}
void MozJSImplScope::ASANHandles::addPointer(void* ptr) {
@@ -473,9 +473,7 @@ MozJSImplScope::MozJSImplScope(MozJSScriptEngine* engine, boost::optional<int> j
"Failed to initialize ModuleLoader",
_moduleLoader->init(_context, boost::filesystem::current_path()));
- try {
- kCurrentScope = this;
-
+ {
JS_AddInterruptCallback(_context, _interruptCallback);
JS_SetGCCallback(_context, _gcCallback, this);
JS_SetContextPrivate(_context, this);
@@ -499,14 +497,13 @@ MozJSImplScope::MozJSImplScope(MozJSScriptEngine* engine, boost::optional<int> j
// assert.js)
if (_engine->getScopeInitCallback())
_engine->getScopeInitCallback()(*this);
- } catch (...) {
- kCurrentScope = nullptr;
- throw;
}
+
+ currentJSScope = this;
}
MozJSImplScope::~MozJSImplScope() {
- kCurrentScope = nullptr;
+ currentJSScope = nullptr;
for (auto&& x : _funcs) {
x.reset();
@@ -1089,11 +1086,11 @@ bool MozJSImplScope::_checkErrorState(bool success, bool reportError, bool asser
void MozJSImplScope::setCompileOptions(JS::CompileOptions* co) {}
MozJSImplScope* MozJSImplScope::getThreadScope() {
- return kCurrentScope;
+ return currentJSScope;
}
auto MozJSImplScope::ASANHandles::getThreadASANHandles() -> ASANHandles* {
- return kCurrentASANHandles;
+ return currentASANHandles;
}
void MozJSImplScope::setOOM() {