From 4686c52394c0221ee3236753ad6be48f18b79365 Mon Sep 17 00:00:00 2001 From: Jeff Hao Date: Fri, 18 Sep 2015 14:44:32 -0700 Subject: Fix locking on string init map. Related to: https://android-review.googlesource.com/#/c/171621 Change-Id: Ib6dcf9914f490f1d744c0abe1f520e5b307c7acd --- runtime/interpreter/interpreter_common.cc | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'runtime/interpreter') 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> string_init_map; - SafeMap>* string_init_map_ptr; + SafeMap>* 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> 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) { -- cgit v1.2.3-59-g8ed1b