From cd556b003adbb53739d4b3f43135e6a0ae69509a Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Fri, 3 Feb 2017 11:47:34 +0000 Subject: Fix dex cache resolved types and class table mismatch. Record class table in ClassLinker::DexCacheData and use it in DexCache.setResolvedType() to store the type also in the initiating loader's class table if the dex file has been registered. Also throw InternalError when trying to register the same DexFile with multiple class loaders. (Different DexFile instances referencing the same file are OK.) Test: 155-java-set-resolved-type Test: m test-art-host Bug: 30627598 Bug: 34193123 Bug: 34839984 Change-Id: Ia48acb300337c45880ea1459d2d32789546d67f4 --- runtime/native/java_lang_DexCache.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'runtime/native/java_lang_DexCache.cc') diff --git a/runtime/native/java_lang_DexCache.cc b/runtime/native/java_lang_DexCache.cc index f1c350f23c..b1ed74a6de 100644 --- a/runtime/native/java_lang_DexCache.cc +++ b/runtime/native/java_lang_DexCache.cc @@ -65,12 +65,22 @@ static jobject DexCache_getResolvedString(JNIEnv* env, jobject javaDexCache, jin dex_cache->GetResolvedString(dex::StringIndex(string_index))); } -static void DexCache_setResolvedType(JNIEnv* env, jobject javaDexCache, jint type_index, +static void DexCache_setResolvedType(JNIEnv* env, + jobject javaDexCache, + jint type_index, jobject type) { ScopedFastNativeObjectAccess soa(env); ObjPtr dex_cache = soa.Decode(javaDexCache); - CHECK_LT(static_cast(type_index), dex_cache->NumResolvedTypes()); - dex_cache->SetResolvedType(dex::TypeIndex(type_index), soa.Decode(type)); + const DexFile& dex_file = *dex_cache->GetDexFile(); + CHECK_LT(static_cast(type_index), dex_file.NumTypeIds()); + ObjPtr t = soa.Decode(type); + if (t != nullptr && t->DescriptorEquals(dex_file.StringByTypeIdx(dex::TypeIndex(type_index)))) { + ClassTable* table = + Runtime::Current()->GetClassLinker()->FindClassTable(soa.Self(), dex_cache); + if (table != nullptr && table->TryInsert(t) == t) { + dex_cache->SetResolvedType(dex::TypeIndex(type_index), t); + } + } } static void DexCache_setResolvedString(JNIEnv* env, jobject javaDexCache, jint string_index, @@ -78,7 +88,10 @@ static void DexCache_setResolvedString(JNIEnv* env, jobject javaDexCache, jint s ScopedFastNativeObjectAccess soa(env); ObjPtr dex_cache = soa.Decode(javaDexCache); CHECK_LT(static_cast(string_index), dex_cache->GetDexFile()->NumStringIds()); - dex_cache->SetResolvedString(dex::StringIndex(string_index), soa.Decode(string)); + ObjPtr s = soa.Decode(string); + if (s != nullptr) { + dex_cache->SetResolvedString(dex::StringIndex(string_index), s); + } } static JNINativeMethod gMethods[] = { -- cgit v1.2.3-59-g8ed1b