diff options
author | 2015-09-18 22:58:22 +0000 | |
---|---|---|
committer | 2015-09-18 22:58:22 +0000 | |
commit | 9e30c0e177adabaaf94a66c91130a19a7632fc7c (patch) | |
tree | e3177c7686cb6203c5f4c91cb9a38b6e80fcbec0 | |
parent | 8e7b964be2fab9b6bbb30cf8897617424d0fe85f (diff) | |
parent | 4686c52394c0221ee3236753ad6be48f18b79365 (diff) |
Merge "Fix locking on string init map."
-rw-r--r-- | runtime/interpreter/interpreter_common.cc | 22 | ||||
-rw-r--r-- | runtime/safe_map.h | 3 |
2 files changed, 12 insertions, 13 deletions
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc index 02ec90c78f..68d56f5198 100644 --- a/runtime/interpreter/interpreter_common.cc +++ b/runtime/interpreter/interpreter_common.cc @@ -696,22 +696,20 @@ static inline bool DoCallCommon(ArtMethod* called_method, // new result of the StringFactory. Use the verifier to find this set of registers. ArtMethod* method = shadow_frame.GetMethod(); MethodReference method_ref = method->ToMethodReference(); - SafeMap<uint32_t, std::set<uint32_t>> string_init_map; - SafeMap<uint32_t, std::set<uint32_t>>* string_init_map_ptr; + SafeMap<uint32_t, std::set<uint32_t>>* string_init_map_ptr = nullptr; MethodRefToStringInitRegMap& method_to_string_init_map = Runtime::Current()->GetStringInitMap(); - MethodRefToStringInitRegMap::iterator it; { MutexLock mu(self, *Locks::interpreter_string_init_map_lock_); - it = method_to_string_init_map.find(method_ref); - } - if (it == method_to_string_init_map.end()) { - string_init_map = std::move(verifier::MethodVerifier::FindStringInitMap(method)); - { - MutexLock mu(self, *Locks::interpreter_string_init_map_lock_); - method_to_string_init_map.Overwrite(method_ref, string_init_map); + auto it = method_to_string_init_map.find(method_ref); + if (it != method_to_string_init_map.end()) { + string_init_map_ptr = &it->second; } - string_init_map_ptr = &string_init_map; - } else { + } + if (string_init_map_ptr == nullptr) { + SafeMap<uint32_t, std::set<uint32_t>> string_init_map = + verifier::MethodVerifier::FindStringInitMap(method); + MutexLock mu(self, *Locks::interpreter_string_init_map_lock_); + auto it = method_to_string_init_map.Overwrite(method_ref, string_init_map); string_init_map_ptr = &it->second; } if (string_init_map_ptr->size() != 0) { diff --git a/runtime/safe_map.h b/runtime/safe_map.h index 402c7e9cb5..04549c7889 100644 --- a/runtime/safe_map.h +++ b/runtime/safe_map.h @@ -104,12 +104,13 @@ class SafeMap { // Used to insert a new mapping or overwrite an existing mapping. Note that if the value type // of this container is a pointer, any overwritten pointer will be lost and if this container // was the owner, you have a leak. - void Overwrite(const K& k, const V& v) { + iterator Overwrite(const K& k, const V& v) { std::pair<iterator, bool> result = map_.insert(std::make_pair(k, v)); if (!result.second) { // Already there - update the value for the existing key result.first->second = v; } + return result.first; } bool Equals(const Self& rhs) const { |