diff options
| author | 2015-10-29 22:33:20 +0000 | |
|---|---|---|
| committer | 2015-10-29 22:33:20 +0000 | |
| commit | c7534d1f650a9179e204c16a2ac5b16f7257cd5c (patch) | |
| tree | f8facbd68dabc781cc4f8e76353a418ef633896e | |
| parent | b8f6d7c3360180174276bab7618760724500d148 (diff) | |
| parent | 8cb0bc28b1161dad0d2c2c1e75318b7e504faa46 (diff) | |
Merge "Change a few places to use string version of GetTypeId"
am: 8cb0bc28b1
* commit '8cb0bc28b1161dad0d2c2c1e75318b7e504faa46':
Change a few places to use string version of GetTypeId
| -rw-r--r-- | compiler/dex/quick/dex_file_method_inliner.cc | 9 | ||||
| -rw-r--r-- | compiler/driver/compiler_driver-inl.h | 14 | ||||
| -rw-r--r-- | runtime/art_method.cc | 19 | ||||
| -rw-r--r-- | runtime/class_linker.cc | 23 | ||||
| -rw-r--r-- | runtime/class_linker_test.cc | 4 | ||||
| -rw-r--r-- | runtime/dex_file.cc | 6 | ||||
| -rw-r--r-- | runtime/dex_file_test.cc | 1 | ||||
| -rw-r--r-- | runtime/mirror/object_test.cc | 15 |
8 files changed, 27 insertions, 64 deletions
diff --git a/compiler/dex/quick/dex_file_method_inliner.cc b/compiler/dex/quick/dex_file_method_inliner.cc index e1a2838f3e..eaf2408763 100644 --- a/compiler/dex/quick/dex_file_method_inliner.cc +++ b/compiler/dex/quick/dex_file_method_inliner.cc @@ -756,14 +756,7 @@ uint32_t DexFileMethodInliner::FindClassIndex(const DexFile* dex_file, IndexCach return *class_index; } - const DexFile::StringId* string_id = dex_file->FindStringId(kClassCacheNames[index]); - if (string_id == nullptr) { - *class_index = kIndexNotFound; - return *class_index; - } - uint32_t string_index = dex_file->GetIndexForStringId(*string_id); - - const DexFile::TypeId* type_id = dex_file->FindTypeId(string_index); + const DexFile::TypeId* type_id = dex_file->FindTypeId(kClassCacheNames[index]); if (type_id == nullptr) { *class_index = kIndexNotFound; return *class_index; diff --git a/compiler/driver/compiler_driver-inl.h b/compiler/driver/compiler_driver-inl.h index 1a7dbe3a9f..14ba81d193 100644 --- a/compiler/driver/compiler_driver-inl.h +++ b/compiler/driver/compiler_driver-inl.h @@ -187,15 +187,11 @@ inline std::pair<bool, bool> CompilerDriver::IsClassOfStaticMemberAvailableToRef // Search dex file for localized ssb index, may fail if member's class is a parent // of the class mentioned in the dex file and there is no dex cache entry. std::string temp; - const DexFile::StringId* string_id = - dex_file->FindStringId(resolved_member->GetDeclaringClass()->GetDescriptor(&temp)); - if (string_id != nullptr) { - const DexFile::TypeId* type_id = - dex_file->FindTypeId(dex_file->GetIndexForStringId(*string_id)); - if (type_id != nullptr) { - // medium path, needs check of static storage base being initialized - storage_idx = dex_file->GetIndexForTypeId(*type_id); - } + const DexFile::TypeId* type_id = + dex_file->FindTypeId(resolved_member->GetDeclaringClass()->GetDescriptor(&temp)); + if (type_id != nullptr) { + // medium path, needs check of static storage base being initialized + storage_idx = dex_file->GetIndexForTypeId(*type_id); } } if (storage_idx != DexFile::kDexNoIndex) { diff --git a/runtime/art_method.cc b/runtime/art_method.cc index fe0afa6ebf..3f17702fa4 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -163,18 +163,13 @@ uint32_t ArtMethod::FindDexMethodIndexInOtherDexFile(const DexFile& other_dexfil return dex_method_idx; } const char* mid_declaring_class_descriptor = dexfile->StringByTypeIdx(mid.class_idx_); - const DexFile::StringId* other_descriptor = - other_dexfile.FindStringId(mid_declaring_class_descriptor); - if (other_descriptor != nullptr) { - const DexFile::TypeId* other_type_id = - other_dexfile.FindTypeId(other_dexfile.GetIndexForStringId(*other_descriptor)); - if (other_type_id != nullptr) { - const DexFile::MethodId* other_mid = other_dexfile.FindMethodId( - *other_type_id, other_dexfile.GetStringId(name_and_sig_mid.name_idx_), - other_dexfile.GetProtoId(name_and_sig_mid.proto_idx_)); - if (other_mid != nullptr) { - return other_dexfile.GetIndexForMethodId(*other_mid); - } + const DexFile::TypeId* other_type_id = other_dexfile.FindTypeId(mid_declaring_class_descriptor); + if (other_type_id != nullptr) { + const DexFile::MethodId* other_mid = other_dexfile.FindMethodId( + *other_type_id, other_dexfile.GetStringId(name_and_sig_mid.name_idx_), + other_dexfile.GetProtoId(name_and_sig_mid.proto_idx_)); + if (other_mid != nullptr) { + return other_dexfile.GetIndexForMethodId(*other_mid); } } return DexFile::kDexNoIndex; diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 69d0799096..5de1cacba8 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -616,10 +616,7 @@ void ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b // initialized. { const DexFile& dex_file = java_lang_Object->GetDexFile(); - const DexFile::StringId* void_string_id = dex_file.FindStringId("V"); - CHECK(void_string_id != nullptr); - uint32_t void_string_index = dex_file.GetIndexForStringId(*void_string_id); - const DexFile::TypeId* void_type_id = dex_file.FindTypeId(void_string_index); + const DexFile::TypeId* void_type_id = dex_file.FindTypeId("V"); CHECK(void_type_id != nullptr); uint16_t void_type_idx = dex_file.GetIndexForTypeId(*void_type_id); // Now we resolve void type so the dex cache contains it. We use java.lang.Object class @@ -2740,17 +2737,13 @@ mirror::Class* ClassLinker::LookupClassFromImage(const char* descriptor) { for (int32_t i = 0; i < dex_caches->GetLength(); ++i) { mirror::DexCache* dex_cache = dex_caches->Get(i); const DexFile* dex_file = dex_cache->GetDexFile(); - // Try binary searching the string/type index. - const DexFile::StringId* string_id = dex_file->FindStringId(descriptor); - if (string_id != nullptr) { - const DexFile::TypeId* type_id = - dex_file->FindTypeId(dex_file->GetIndexForStringId(*string_id)); - if (type_id != nullptr) { - uint16_t type_idx = dex_file->GetIndexForTypeId(*type_id); - mirror::Class* klass = dex_cache->GetResolvedType(type_idx); - if (klass != nullptr) { - return klass; - } + // Try binary searching the type index by descriptor. + const DexFile::TypeId* type_id = dex_file->FindTypeId(descriptor); + if (type_id != nullptr) { + uint16_t type_idx = dex_file->GetIndexForTypeId(*type_id); + mirror::Class* klass = dex_cache->GetResolvedType(type_idx); + if (klass != nullptr) { + return klass; } } } diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc index 0926ce3f6a..04b890063d 100644 --- a/runtime/class_linker_test.cc +++ b/runtime/class_linker_test.cc @@ -1032,9 +1032,7 @@ TEST_F(ClassLinkerTest, ResolveVerifyAndClinit) { mirror::Class* klass = class_linker_->FindClass(soa.Self(), "LStaticsFromCode;", class_loader); ArtMethod* clinit = klass->FindClassInitializer(sizeof(void*)); ArtMethod* getS0 = klass->FindDirectMethod("getS0", "()Ljava/lang/Object;", sizeof(void*)); - const DexFile::StringId* string_id = dex_file->FindStringId("LStaticsFromCode;"); - ASSERT_TRUE(string_id != nullptr); - const DexFile::TypeId* type_id = dex_file->FindTypeId(dex_file->GetIndexForStringId(*string_id)); + const DexFile::TypeId* type_id = dex_file->FindTypeId("LStaticsFromCode;"); ASSERT_TRUE(type_id != nullptr); uint32_t type_idx = dex_file->GetIndexForTypeId(*type_id); mirror::Class* uninit = ResolveVerifyAndClinit(type_idx, clinit, soa.Self(), true, false); diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc index b3ca6ac131..3a93aace83 100644 --- a/runtime/dex_file.cc +++ b/runtime/dex_file.cc @@ -738,11 +738,7 @@ bool DexFile::CreateTypeList(const StringPiece& signature, uint16_t* return_type } // TODO: avoid creating a std::string just to get a 0-terminated char array std::string descriptor(signature.data() + start_offset, offset - start_offset); - const DexFile::StringId* string_id = FindStringId(descriptor.c_str()); - if (string_id == nullptr) { - return false; - } - const DexFile::TypeId* type_id = FindTypeId(GetIndexForStringId(*string_id)); + const DexFile::TypeId* type_id = FindTypeId(descriptor.c_str()); if (type_id == nullptr) { return false; } diff --git a/runtime/dex_file_test.cc b/runtime/dex_file_test.cc index 90b35a3e04..0a167bb8f7 100644 --- a/runtime/dex_file_test.cc +++ b/runtime/dex_file_test.cc @@ -297,6 +297,7 @@ TEST_F(DexFileTest, FindTypeId) { ASSERT_TRUE(type_str_id != nullptr); uint32_t type_str_idx = java_lang_dex_file_->GetIndexForStringId(*type_str_id); const DexFile::TypeId* type_id = java_lang_dex_file_->FindTypeId(type_str_idx); + ASSERT_EQ(type_id, java_lang_dex_file_->FindTypeId(type_str)); ASSERT_TRUE(type_id != nullptr); EXPECT_EQ(java_lang_dex_file_->GetIndexForTypeId(*type_id), i); } diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc index f5a04457e7..c1284a639f 100644 --- a/runtime/mirror/object_test.cc +++ b/runtime/mirror/object_test.cc @@ -307,10 +307,7 @@ TEST_F(ObjectTest, CheckAndAllocArrayFromCode) { ScopedObjectAccess soa(Thread::Current()); Class* java_util_Arrays = class_linker_->FindSystemClass(soa.Self(), "Ljava/util/Arrays;"); ArtMethod* sort = java_util_Arrays->FindDirectMethod("sort", "([I)V", sizeof(void*)); - const DexFile::StringId* string_id = java_lang_dex_file_->FindStringId("[I"); - ASSERT_TRUE(string_id != nullptr); - const DexFile::TypeId* type_id = java_lang_dex_file_->FindTypeId( - java_lang_dex_file_->GetIndexForStringId(*string_id)); + const DexFile::TypeId* type_id = java_lang_dex_file_->FindTypeId("[I"); ASSERT_TRUE(type_id != nullptr); uint32_t type_idx = java_lang_dex_file_->GetIndexForTypeId(*type_id); Object* array = CheckAndAllocArrayFromCodeInstrumented( @@ -367,16 +364,10 @@ TEST_F(ObjectTest, StaticFieldFromCode) { Handle<mirror::ClassLoader> loader(hs.NewHandle(soa.Decode<ClassLoader*>(class_loader))); Class* klass = class_linker_->FindClass(soa.Self(), "LStaticsFromCode;", loader); ArtMethod* clinit = klass->FindClassInitializer(sizeof(void*)); - const DexFile::StringId* klass_string_id = dex_file->FindStringId("LStaticsFromCode;"); - ASSERT_TRUE(klass_string_id != nullptr); - const DexFile::TypeId* klass_type_id = dex_file->FindTypeId( - dex_file->GetIndexForStringId(*klass_string_id)); + const DexFile::TypeId* klass_type_id = dex_file->FindTypeId("LStaticsFromCode;"); ASSERT_TRUE(klass_type_id != nullptr); - const DexFile::StringId* type_string_id = dex_file->FindStringId("Ljava/lang/Object;"); - ASSERT_TRUE(type_string_id != nullptr); - const DexFile::TypeId* type_type_id = dex_file->FindTypeId( - dex_file->GetIndexForStringId(*type_string_id)); + const DexFile::TypeId* type_type_id = dex_file->FindTypeId("Ljava/lang/Object;"); ASSERT_TRUE(type_type_id != nullptr); const DexFile::StringId* name_str_id = dex_file->FindStringId("s0"); |