Title: [249518] trunk/Source/_javascript_Core
- Revision
- 249518
- Author
- [email protected]
- Date
- 2019-09-04 19:52:46 -0700 (Wed, 04 Sep 2019)
Log Message
[JSC] FunctionOverrides should have a lock to ensure concurrent access to hash table does not happen
https://bugs.webkit.org/show_bug.cgi?id=201485
Reviewed by Tadeu Zagallo.
FunctionOverrides is a per-process singleton for registering overrides information. But we are accessing
it without taking a lock. If multiple threads with multiple VMs are accessing this concurrently, we have
a race issue like,
1. While one thread is adding overrides information,
2. Another thread is accessing this hash table.
This patch adds a lock to make sure that only one thread can access this registry.
* tools/FunctionOverrides.cpp:
(JSC::FunctionOverrides::FunctionOverrides):
(JSC::FunctionOverrides::reinstallOverrides):
(JSC::FunctionOverrides::initializeOverrideFor):
(JSC::FunctionOverrides::parseOverridesInFile):
* tools/FunctionOverrides.h:
(JSC::FunctionOverrides::clear):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (249517 => 249518)
--- trunk/Source/_javascript_Core/ChangeLog 2019-09-05 02:52:40 UTC (rev 249517)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-09-05 02:52:46 UTC (rev 249518)
@@ -1,5 +1,29 @@
2019-09-04 Yusuke Suzuki <[email protected]>
+ [JSC] FunctionOverrides should have a lock to ensure concurrent access to hash table does not happen
+ https://bugs.webkit.org/show_bug.cgi?id=201485
+
+ Reviewed by Tadeu Zagallo.
+
+ FunctionOverrides is a per-process singleton for registering overrides information. But we are accessing
+ it without taking a lock. If multiple threads with multiple VMs are accessing this concurrently, we have
+ a race issue like,
+
+ 1. While one thread is adding overrides information,
+ 2. Another thread is accessing this hash table.
+
+ This patch adds a lock to make sure that only one thread can access this registry.
+
+ * tools/FunctionOverrides.cpp:
+ (JSC::FunctionOverrides::FunctionOverrides):
+ (JSC::FunctionOverrides::reinstallOverrides):
+ (JSC::FunctionOverrides::initializeOverrideFor):
+ (JSC::FunctionOverrides::parseOverridesInFile):
+ * tools/FunctionOverrides.h:
+ (JSC::FunctionOverrides::clear):
+
+2019-09-04 Yusuke Suzuki <[email protected]>
+
[JSC] Make Promise implementation faster
https://bugs.webkit.org/show_bug.cgi?id=200898
Modified: trunk/Source/_javascript_Core/tools/FunctionOverrides.cpp (249517 => 249518)
--- trunk/Source/_javascript_Core/tools/FunctionOverrides.cpp 2019-09-05 02:52:40 UTC (rev 249517)
+++ trunk/Source/_javascript_Core/tools/FunctionOverrides.cpp 2019-09-05 02:52:46 UTC (rev 249518)
@@ -102,15 +102,16 @@
FunctionOverrides::FunctionOverrides(const char* overridesFileName)
{
- parseOverridesInFile(overridesFileName);
+ parseOverridesInFile(holdLock(m_lock), overridesFileName);
}
void FunctionOverrides::reinstallOverrides()
{
FunctionOverrides& overrides = FunctionOverrides::overrides();
+ auto locker = holdLock(overrides.m_lock);
const char* overridesFileName = Options::functionOverrides();
- overrides.clear();
- overrides.parseOverridesInFile(overridesFileName);
+ overrides.clear(locker);
+ overrides.parseOverridesInFile(locker, overridesFileName);
}
static void initializeOverrideInfo(const SourceCode& origCode, const String& newBody, FunctionOverrides::OverrideInfo& info)
@@ -151,11 +152,16 @@
return false;
String sourceBodyString = sourceString.substring(sourceBodyStart);
- auto it = overrides.m_entries.find(sourceBodyString);
- if (it == overrides.m_entries.end())
- return false;
+ String newBody;
+ {
+ auto locker = holdLock(overrides.m_lock);
+ auto it = overrides.m_entries.find(sourceBodyString.isolatedCopy());
+ if (it == overrides.m_entries.end())
+ return false;
+ newBody = it->value.isolatedCopy();
+ }
- initializeOverrideInfo(origCode, it->value, result);
+ initializeOverrideInfo(origCode, newBody, result);
return true;
}
@@ -227,7 +233,7 @@
FAIL_WITH_ERROR(SYNTAX_ERROR, ("'", keyword, "' clause end delimiter '", delimiter, "' not found:\n", builder.toString(), "\n", "Are you missing a '}' before the delimiter?\n"));
}
-void FunctionOverrides::parseOverridesInFile(const char* fileName)
+void FunctionOverrides::parseOverridesInFile(const AbstractLocker&, const char* fileName)
{
if (!fileName)
return;
Modified: trunk/Source/_javascript_Core/tools/FunctionOverrides.h (249517 => 249518)
--- trunk/Source/_javascript_Core/tools/FunctionOverrides.h 2019-09-05 02:52:40 UTC (rev 249517)
+++ trunk/Source/_javascript_Core/tools/FunctionOverrides.h 2019-09-05 02:52:46 UTC (rev 249518)
@@ -27,6 +27,7 @@
#include "SourceCode.h"
#include <wtf/HashMap.h>
+#include <wtf/Lock.h>
#include <wtf/text/WTFString.h>
namespace JSC {
@@ -56,10 +57,11 @@
JS_EXPORT_PRIVATE static void reinstallOverrides();
private:
- void parseOverridesInFile(const char* fileName);
- void clear() { m_entries.clear(); }
+ void parseOverridesInFile(const AbstractLocker&, const char* fileName);
+ void clear(const AbstractLocker&) { m_entries.clear(); }
HashMap<String, String> m_entries;
+ Lock m_lock;
};
} // namespace JSC
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes