Commit 34e79456 authored by neis's avatar neis Committed by Commit bot

[simulator] Make reference redirection thread-safe.

In the simulators, the ExternalReference constructor rewrites external
addresses, which involves mutating a linked list rooted in the isolate.

We already construct external references concurrently (at least in Turbofan),
but the list mutation was not thread-safe (though no crashes are known). This
CL adds the necessary locking.

BUG=v8:6048

Review-Url: https://codereview.chromium.org/2852983002
Cr-Commit-Position: refs/heads/master@{#45014}
parent 8f4e8c0a
......@@ -803,6 +803,8 @@ void Simulator::TearDown(base::CustomMatcherHashMap* i_cache,
void* Simulator::RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type) {
base::LockGuard<base::Mutex> lock_guard(
isolate->simulator_redirection_mutex());
Redirection* redirection = Redirection::Get(isolate, external_function, type);
return redirection->address_of_swi_instruction();
}
......
......@@ -361,7 +361,7 @@ class Simulator {
static CachePage* GetCachePage(base::CustomMatcherHashMap* i_cache,
void* page);
// Runtime call support.
// Runtime call support. Uses the isolate in a thread-safe way.
static void* RedirectExternalReference(
Isolate* isolate, void* external_function,
v8::internal::ExternalReference::Type type);
......
......@@ -801,6 +801,8 @@ void Simulator::DoRuntimeCall(Instruction* instr) {
void* Simulator::RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type) {
base::LockGuard<base::Mutex> lock_guard(
isolate->simulator_redirection_mutex());
Redirection* redirection = Redirection::Get(isolate, external_function, type);
return redirection->address_of_redirect_call();
}
......
......@@ -273,7 +273,7 @@ class Simulator : public DecoderVisitor {
void ResetState();
// Runtime call support.
// Runtime call support. Uses the isolate in a thread-safe way.
static void* RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type);
......
......@@ -818,6 +818,7 @@ class ExternalReference BASE_EMBEDDED {
static void SetUp();
// These functions must use the isolate in a thread-safe way.
typedef void* ExternalReferenceRedirector(Isolate* isolate, void* original,
Type type);
......
......@@ -1250,6 +1250,9 @@ class Isolate {
#ifdef USE_SIMULATOR
base::Mutex* simulator_i_cache_mutex() { return &simulator_i_cache_mutex_; }
base::Mutex* simulator_redirection_mutex() {
return &simulator_redirection_mutex_;
}
#endif
void set_allow_atomics_wait(bool set) { allow_atomics_wait_ = set; }
......@@ -1570,6 +1573,7 @@ class Isolate {
#ifdef USE_SIMULATOR
base::Mutex simulator_i_cache_mutex_;
base::Mutex simulator_redirection_mutex_;
#endif
bool allow_atomics_wait_;
......
......@@ -1016,6 +1016,8 @@ void Simulator::TearDown(base::CustomMatcherHashMap* i_cache,
void* Simulator::RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type) {
base::LockGuard<base::Mutex> lock_guard(
isolate->simulator_redirection_mutex());
Redirection* redirection = Redirection::Get(isolate, external_function, type);
return redirection->address_of_swi_instruction();
}
......
......@@ -463,7 +463,7 @@ class Simulator {
// Exceptions.
void SignalException(Exception e);
// Runtime call support.
// Runtime call support. Uses the isolate in a thread-safe way.
static void* RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type);
......
......@@ -949,6 +949,8 @@ void Simulator::TearDown(base::CustomMatcherHashMap* i_cache,
void* Simulator::RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type) {
base::LockGuard<base::Mutex> lock_guard(
isolate->simulator_redirection_mutex());
Redirection* redirection = Redirection::Get(isolate, external_function, type);
return redirection->address_of_swi_instruction();
}
......
......@@ -493,7 +493,7 @@ class Simulator {
// Exceptions.
void SignalException(Exception e);
// Runtime call support.
// Runtime call support. Uses the isolate in a thread-safe way.
static void* RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type);
......
......@@ -894,6 +894,8 @@ void Simulator::TearDown(base::CustomMatcherHashMap* i_cache,
void* Simulator::RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type) {
base::LockGuard<base::Mutex> lock_guard(
isolate->simulator_redirection_mutex());
Redirection* redirection = Redirection::Get(isolate, external_function, type);
return redirection->address();
}
......
......@@ -341,7 +341,7 @@ class Simulator {
static CachePage* GetCachePage(base::CustomMatcherHashMap* i_cache,
void* page);
// Runtime call support.
// Runtime call support. Uses the isolate in a thread-safe way.
static void* RedirectExternalReference(
Isolate* isolate, void* external_function,
v8::internal::ExternalReference::Type type);
......
......@@ -1644,6 +1644,8 @@ void Simulator::TearDown(base::CustomMatcherHashMap* i_cache,
void* Simulator::RedirectExternalReference(Isolate* isolate,
void* external_function,
ExternalReference::Type type) {
base::LockGuard<base::Mutex> lock_guard(
isolate->simulator_redirection_mutex());
Redirection* redirection = Redirection::Get(isolate, external_function, type);
return redirection->address();
}
......
......@@ -440,7 +440,7 @@ class Simulator {
static CachePage* GetCachePage(base::CustomMatcherHashMap* i_cache,
void* page);
// Runtime call support.
// Runtime call support. Uses the isolate in a thread-safe way.
static void* RedirectExternalReference(
Isolate* isolate, void* external_function,
v8::internal::ExternalReference::Type type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment