diff options
author | 2017-12-08 16:27:49 +0000 | |
---|---|---|
committer | 2017-12-11 11:40:35 +0000 | |
commit | a64b52deb0c792b8a0d47546edb8a2f8a7816c33 (patch) | |
tree | 0f98c035e2da07a17501debc4d1f49281d2f9e41 | |
parent | af94020190a2153834e30fc962e28c3b63d7ffc2 (diff) |
Do not pass DexFile to ClassLinker::Lookup/ResolveString().
The DexFile can be easily retrieved from the DexCache,
so reduce the number of arguments that need to be passed.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: I8c4cec43b31b27de7e4e94374fdd69c6d6ca6c13
-rw-r--r-- | compiler/driver/compiler_driver.cc | 13 | ||||
-rw-r--r-- | compiler/optimizing/sharpening.cc | 6 | ||||
-rw-r--r-- | dex2oat/linker/image_writer.cc | 2 | ||||
-rw-r--r-- | dex2oat/linker/oat_writer.cc | 5 | ||||
-rw-r--r-- | runtime/art_field-inl.h | 5 | ||||
-rw-r--r-- | runtime/art_field.cc | 5 | ||||
-rw-r--r-- | runtime/art_field.h | 1 | ||||
-rw-r--r-- | runtime/art_method.cc | 3 | ||||
-rw-r--r-- | runtime/class_linker.cc | 8 | ||||
-rw-r--r-- | runtime/class_linker.h | 14 | ||||
-rw-r--r-- | runtime/dex_file_annotations.cc | 5 | ||||
-rw-r--r-- | runtime/entrypoints/entrypoint_utils-inl.h | 6 | ||||
-rw-r--r-- | runtime/interpreter/interpreter_common.cc | 4 | ||||
-rw-r--r-- | runtime/interpreter/interpreter_common.h | 4 | ||||
-rw-r--r-- | runtime/transaction_test.cc | 6 |
15 files changed, 35 insertions, 52 deletions
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 2d43476d5a..d51bded7eb 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -701,7 +701,6 @@ void CompilerDriver::Resolve(jobject class_loader, // stable order. static void ResolveConstStrings(Handle<mirror::DexCache> dex_cache, - const DexFile& dex_file, const DexFile::CodeItem* code_item) REQUIRES_SHARED(Locks::mutator_lock_) { if (code_item == nullptr) { @@ -717,8 +716,7 @@ static void ResolveConstStrings(Handle<mirror::DexCache> dex_cache, dex::StringIndex string_index((inst->Opcode() == Instruction::CONST_STRING) ? inst->VRegB_21c() : inst->VRegB_31c()); - ObjPtr<mirror::String> string = - class_linker->ResolveString(dex_file, string_index, dex_cache); + ObjPtr<mirror::String> string = class_linker->ResolveString(string_index, dex_cache); CHECK(string != nullptr) << "Could not allocate a string when forcing determinism"; break; } @@ -773,7 +771,7 @@ static void ResolveConstStrings(CompilerDriver* driver, continue; } previous_method_idx = method_idx; - ResolveConstStrings(dex_cache, *dex_file, it.GetMethodCodeItem()); + ResolveConstStrings(dex_cache, it.GetMethodCodeItem()); it.Next(); } DCHECK(!it.HasNext()); @@ -2331,7 +2329,6 @@ class InitializeClassVisitor : public CompilationVisitor { StackHandleScope<1> hs(Thread::Current()); Handle<mirror::DexCache> dex_cache = hs.NewHandle(klass->GetDexCache()); - const DexFile* dex_file = manager_->GetDexFile(); const DexFile::ClassDef* class_def = klass->GetClassDef(); ClassLinker* class_linker = manager_->GetClassLinker(); @@ -2344,7 +2341,7 @@ class InitializeClassVisitor : public CompilationVisitor { if (value_it.GetValueType() == annotations::RuntimeEncodedStaticFieldValueIterator::kString) { // Resolve the string. This will intern the string. art::ObjPtr<mirror::String> resolved = class_linker->ResolveString( - *dex_file, dex::StringIndex(value_it.GetJavaValue().i), dex_cache); + dex::StringIndex(value_it.GetJavaValue().i), dex_cache); CHECK(resolved != nullptr); } } @@ -2357,11 +2354,11 @@ class InitializeClassVisitor : public CompilationVisitor { for (const DexInstructionPcPair& inst : code_item->Instructions()) { if (inst->Opcode() == Instruction::CONST_STRING) { ObjPtr<mirror::String> s = class_linker->ResolveString( - *dex_file, dex::StringIndex(inst->VRegB_21c()), dex_cache); + dex::StringIndex(inst->VRegB_21c()), dex_cache); CHECK(s != nullptr); } else if (inst->Opcode() == Instruction::CONST_STRING_JUMBO) { ObjPtr<mirror::String> s = class_linker->ResolveString( - *dex_file, dex::StringIndex(inst->VRegB_31c()), dex_cache); + dex::StringIndex(inst->VRegB_31c()), dex_cache); CHECK(s != nullptr); } } diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc index 64092d307d..1e49411c72 100644 --- a/compiler/optimizing/sharpening.cc +++ b/compiler/optimizing/sharpening.cc @@ -262,7 +262,7 @@ void HSharpening::ProcessLoadString( // Compiling boot image. Resolve the string and allocate it if needed, to ensure // the string will be added to the boot image. DCHECK(!runtime->UseJitCompilation()); - string = class_linker->ResolveString(dex_file, string_index, dex_cache); + string = class_linker->ResolveString(string_index, dex_cache); CHECK(string != nullptr); if (compiler_driver->GetSupportBootImageFixup()) { DCHECK(ContainsElement(compiler_driver->GetDexFilesForOatFile(), &dex_file)); @@ -273,7 +273,7 @@ void HSharpening::ProcessLoadString( } } else if (runtime->UseJitCompilation()) { DCHECK(!codegen->GetCompilerOptions().GetCompilePic()); - string = class_linker->LookupString(dex_file, string_index, dex_cache.Get()); + string = class_linker->LookupString(string_index, dex_cache.Get()); if (string != nullptr) { if (runtime->GetHeap()->ObjectIsInBootImageSpace(string)) { desired_load_kind = HLoadString::LoadKind::kBootImageAddress; @@ -285,7 +285,7 @@ void HSharpening::ProcessLoadString( } } else { // AOT app compilation. Try to lookup the string without allocating if not found. - string = class_linker->LookupString(dex_file, string_index, dex_cache.Get()); + string = class_linker->LookupString(string_index, dex_cache.Get()); if (string != nullptr && runtime->GetHeap()->ObjectIsInBootImageSpace(string)) { if (codegen->GetCompilerOptions().GetCompilePic()) { desired_load_kind = HLoadString::LoadKind::kBootImageInternTable; diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc index 5ade583b88..28521e1222 100644 --- a/dex2oat/linker/image_writer.cc +++ b/dex2oat/linker/image_writer.cc @@ -1148,7 +1148,7 @@ void ImageWriter::PruneAndPreloadDexCache(ObjPtr<mirror::DexCache> dex_cache, uint32_t stored_index = pair.index; ObjPtr<mirror::String> string = pair.object.Read(); if (string == nullptr || i < stored_index) { - string = class_linker->LookupString(dex_file, string_idx, dex_cache); + string = class_linker->LookupString(string_idx, dex_cache); DCHECK(string == nullptr || dex_cache->GetResolvedString(string_idx) == string); } } diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc index 4be225d881..57d02c532c 100644 --- a/dex2oat/linker/oat_writer.cc +++ b/dex2oat/linker/oat_writer.cc @@ -1964,9 +1964,8 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor { ObjPtr<mirror::String> GetTargetString(const LinkerPatch& patch) REQUIRES_SHARED(Locks::mutator_lock_) { ClassLinker* linker = Runtime::Current()->GetClassLinker(); - ObjPtr<mirror::String> string = linker->LookupString(*patch.TargetStringDexFile(), - patch.TargetStringIndex(), - GetDexCache(patch.TargetStringDexFile())); + ObjPtr<mirror::String> string = + linker->LookupString(patch.TargetStringIndex(), GetDexCache(patch.TargetStringDexFile())); DCHECK(string != nullptr); DCHECK(writer_->HasBootImage() || Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(string)); diff --git a/runtime/art_field-inl.h b/runtime/art_field-inl.h index ae81ee8470..02ae0e32ea 100644 --- a/runtime/art_field-inl.h +++ b/runtime/art_field-inl.h @@ -352,11 +352,10 @@ inline ObjPtr<mirror::String> ArtField::GetStringName(Thread* self, bool resolve auto dex_field_index = GetDexFieldIndex(); CHECK_NE(dex_field_index, dex::kDexNoIndex); ObjPtr<mirror::DexCache> dex_cache = GetDexCache(); - const auto* dex_file = dex_cache->GetDexFile(); - const auto& field_id = dex_file->GetFieldId(dex_field_index); + const DexFile::FieldId& field_id = dex_cache->GetDexFile()->GetFieldId(dex_field_index); ObjPtr<mirror::String> name = dex_cache->GetResolvedString(field_id.name_idx_); if (resolve && name == nullptr) { - name = ResolveGetStringName(self, *dex_file, field_id.name_idx_, dex_cache); + name = ResolveGetStringName(self, field_id.name_idx_, dex_cache); } return name; } diff --git a/runtime/art_field.cc b/runtime/art_field.cc index 54746a3685..dbba2b0918 100644 --- a/runtime/art_field.cc +++ b/runtime/art_field.cc @@ -52,13 +52,10 @@ ObjPtr<mirror::Class> ArtField::ProxyFindSystemClass(const char* descriptor) { } ObjPtr<mirror::String> ArtField::ResolveGetStringName(Thread* self, - const DexFile& dex_file, dex::StringIndex string_idx, ObjPtr<mirror::DexCache> dex_cache) { StackHandleScope<1> hs(self); - return Runtime::Current()->GetClassLinker()->ResolveString(dex_file, - string_idx, - hs.NewHandle(dex_cache)); + return Runtime::Current()->GetClassLinker()->ResolveString(string_idx, hs.NewHandle(dex_cache)); } std::string ArtField::PrettyField(ArtField* f, bool with_type) { diff --git a/runtime/art_field.h b/runtime/art_field.h index a6f050810f..8d2f9ff71b 100644 --- a/runtime/art_field.h +++ b/runtime/art_field.h @@ -234,7 +234,6 @@ class ArtField FINAL { ObjPtr<mirror::Class> ProxyFindSystemClass(const char* descriptor) REQUIRES_SHARED(Locks::mutator_lock_); ObjPtr<mirror::String> ResolveGetStringName(Thread* self, - const DexFile& dex_file, dex::StringIndex string_idx, ObjPtr<mirror::DexCache> dex_cache) REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/art_method.cc b/runtime/art_method.cc index ebfa4feefa..9005120eb0 100644 --- a/runtime/art_method.cc +++ b/runtime/art_method.cc @@ -141,8 +141,7 @@ ObjPtr<mirror::String> ArtMethod::GetNameAsString(Thread* self) { auto* dex_file = dex_cache->GetDexFile(); uint32_t dex_method_idx = GetDexMethodIndex(); const DexFile::MethodId& method_id = dex_file->GetMethodId(dex_method_idx); - return Runtime::Current()->GetClassLinker()->ResolveString(*dex_file, method_id.name_idx_, - dex_cache); + return Runtime::Current()->GetClassLinker()->ResolveString(method_id.name_idx_, dex_cache); } void ArtMethod::ThrowInvocationTimeError() { diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 012e2a4548..093ec6540c 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -7726,8 +7726,7 @@ void ClassLinker::CreateReferenceInstanceOffsets(Handle<mirror::Class> klass) { klass->SetReferenceInstanceOffsets(reference_offsets); } -ObjPtr<mirror::String> ClassLinker::ResolveString(const DexFile& dex_file, - dex::StringIndex string_idx, +ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string_idx, Handle<mirror::DexCache> dex_cache) { DCHECK(dex_cache != nullptr); Thread::PoisonObjectPointersIfDebug(); @@ -7735,6 +7734,7 @@ ObjPtr<mirror::String> ClassLinker::ResolveString(const DexFile& dex_file, if (resolved != nullptr) { return resolved; } + const DexFile& dex_file = *dex_cache->GetDexFile(); uint32_t utf16_length; const char* utf8_data = dex_file.StringDataAndUtf16LengthByIdx(string_idx, &utf16_length); ObjPtr<mirror::String> string = intern_table_->InternStrong(utf16_length, utf8_data); @@ -7744,14 +7744,14 @@ ObjPtr<mirror::String> ClassLinker::ResolveString(const DexFile& dex_file, return string; } -ObjPtr<mirror::String> ClassLinker::LookupString(const DexFile& dex_file, - dex::StringIndex string_idx, +ObjPtr<mirror::String> ClassLinker::LookupString(dex::StringIndex string_idx, ObjPtr<mirror::DexCache> dex_cache) { DCHECK(dex_cache != nullptr); ObjPtr<mirror::String> resolved = dex_cache->GetResolvedString(string_idx); if (resolved != nullptr) { return resolved; } + const DexFile& dex_file = *dex_cache->GetDexFile(); uint32_t utf16_length; const char* utf8_data = dex_file.StringDataAndUtf16LengthByIdx(string_idx, &utf16_length); ObjPtr<mirror::String> string = diff --git a/runtime/class_linker.h b/runtime/class_linker.h index a5cde5b592..6a5768ec27 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -243,17 +243,15 @@ class ClassLinker { REQUIRES(!Locks::classlinker_classes_lock_) REQUIRES_SHARED(Locks::mutator_lock_); - // Resolve a String with the given index from the DexFile, storing the - // result in the DexCache. - ObjPtr<mirror::String> ResolveString(const DexFile& dex_file, - dex::StringIndex string_idx, + // Resolve a String with the given index from the DexFile associated with the given DexCache, + // storing the result in the DexCache. + ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx, Handle<mirror::DexCache> dex_cache) REQUIRES_SHARED(Locks::mutator_lock_); - // Find a String with the given index from the DexFile, storing the - // result in the DexCache if found. Return null if not found. - ObjPtr<mirror::String> LookupString(const DexFile& dex_file, - dex::StringIndex string_idx, + // Find a String with the given index from the DexFile associated with the given DexCache, + // storing the result in the DexCache if found. Return null if not found. + ObjPtr<mirror::String> LookupString(dex::StringIndex string_idx, ObjPtr<mirror::DexCache> dex_cache) REQUIRES_SHARED(Locks::mutator_lock_); diff --git a/runtime/dex_file_annotations.cc b/runtime/dex_file_annotations.cc index 437347403b..eaf31f308f 100644 --- a/runtime/dex_file_annotations.cc +++ b/runtime/dex_file_annotations.cc @@ -458,7 +458,7 @@ bool ProcessAnnotationValue(const ClassData& klass, } else { StackHandleScope<1> hs(self); element_object = Runtime::Current()->GetClassLinker()->ResolveString( - klass.GetDexFile(), dex::StringIndex(index), hs.NewHandle(klass.GetDexCache())); + dex::StringIndex(index), hs.NewHandle(klass.GetDexCache())); set_object = true; if (element_object == nullptr) { return false; @@ -1590,8 +1590,7 @@ void RuntimeEncodedStaticFieldValueIterator::ReadValueToField(ArtField* field) c case kDouble: field->SetDouble<kTransactionActive>(field->GetDeclaringClass(), jval_.d); break; case kNull: field->SetObject<kTransactionActive>(field->GetDeclaringClass(), nullptr); break; case kString: { - ObjPtr<mirror::String> resolved = linker_->ResolveString(dex_file_, - dex::StringIndex(jval_.i), + ObjPtr<mirror::String> resolved = linker_->ResolveString(dex::StringIndex(jval_.i), dex_cache_); field->SetObject<kTransactionActive>(field->GetDeclaringClass(), resolved); break; diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h index df17b30580..fa3c027db8 100644 --- a/runtime/entrypoints/entrypoint_utils-inl.h +++ b/runtime/entrypoints/entrypoint_utils-inl.h @@ -757,8 +757,7 @@ static inline ObjPtr<mirror::String> ResolveString(ClassLinker* class_linker, if (UNLIKELY(string == nullptr)) { StackHandleScope<1> hs(Thread::Current()); Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - const DexFile& dex_file = *dex_cache->GetDexFile(); - string = class_linker->ResolveString(dex_file, string_idx, dex_cache); + string = class_linker->ResolveString(string_idx, dex_cache); } return string; } @@ -770,9 +769,8 @@ inline ObjPtr<mirror::String> ResolveStringFromCode(ArtMethod* referrer, if (UNLIKELY(string == nullptr)) { StackHandleScope<1> hs(Thread::Current()); Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache())); - const DexFile& dex_file = *dex_cache->GetDexFile(); ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - string = class_linker->ResolveString(dex_file, string_idx, dex_cache); + string = class_linker->ResolveString(string_idx, dex_cache); } return string; } diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc index 10cbf8daf1..4d7a576c06 100644 --- a/runtime/interpreter/interpreter_common.cc +++ b/runtime/interpreter/interpreter_common.cc @@ -1062,7 +1062,7 @@ static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self, // The second parameter is the name to lookup. { dex::StringIndex name_idx(static_cast<uint32_t>(it.GetJavaValue().i)); - ObjPtr<mirror::String> name = class_linker->ResolveString(*dex_file, name_idx, dex_cache); + ObjPtr<mirror::String> name = class_linker->ResolveString(name_idx, dex_cache); if (name.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; @@ -1132,7 +1132,7 @@ static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self, } case EncodedArrayValueIterator::ValueType::kString: { dex::StringIndex idx(static_cast<uint32_t>(jvalue.i)); - ObjPtr<mirror::String> ref = class_linker->ResolveString(*dex_file, idx, dex_cache); + ObjPtr<mirror::String> ref = class_linker->ResolveString(idx, dex_cache); if (ref.IsNull()) { DCHECK(self->IsExceptionPending()); return nullptr; diff --git a/runtime/interpreter/interpreter_common.h b/runtime/interpreter/interpreter_common.h index ebd67ab4ec..5937801a0c 100644 --- a/runtime/interpreter/interpreter_common.h +++ b/runtime/interpreter/interpreter_common.h @@ -348,9 +348,7 @@ static inline ObjPtr<mirror::String> ResolveString(Thread* self, if (UNLIKELY(string_ptr == nullptr)) { StackHandleScope<1> hs(self); Handle<mirror::DexCache> dex_cache(hs.NewHandle(method->GetDexCache())); - string_ptr = Runtime::Current()->GetClassLinker()->ResolveString(*dex_cache->GetDexFile(), - string_idx, - dex_cache); + string_ptr = Runtime::Current()->GetClassLinker()->ResolveString(string_idx, dex_cache); } return string_ptr; } diff --git a/runtime/transaction_test.cc b/runtime/transaction_test.cc index f922dd317b..304017eadb 100644 --- a/runtime/transaction_test.cc +++ b/runtime/transaction_test.cc @@ -493,7 +493,7 @@ TEST_F(TransactionTest, ResolveString) { dex::StringIndex string_idx = dex_file->GetIndexForStringId(*string_id); ASSERT_TRUE(string_idx.IsValid()); // String should only get resolved by the initializer. - EXPECT_TRUE(class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get()) == nullptr); + EXPECT_TRUE(class_linker_->LookupString(string_idx, h_dex_cache.Get()) == nullptr); EXPECT_TRUE(h_dex_cache->GetResolvedString(string_idx) == nullptr); // Do the transaction, then roll back. Runtime::Current()->EnterTransactionMode(); @@ -503,14 +503,14 @@ TEST_F(TransactionTest, ResolveString) { // Make sure the string got resolved by the transaction. { ObjPtr<mirror::String> s = - class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get()); + class_linker_->LookupString(string_idx, h_dex_cache.Get()); ASSERT_TRUE(s != nullptr); EXPECT_STREQ(s->ToModifiedUtf8().c_str(), kResolvedString); EXPECT_EQ(s.Ptr(), h_dex_cache->GetResolvedString(string_idx)); } Runtime::Current()->RollbackAndExitTransactionMode(); // Check that the string did not stay resolved. - EXPECT_TRUE(class_linker_->LookupString(*dex_file, string_idx, h_dex_cache.Get()) == nullptr); + EXPECT_TRUE(class_linker_->LookupString(string_idx, h_dex_cache.Get()) == nullptr); EXPECT_TRUE(h_dex_cache->GetResolvedString(string_idx) == nullptr); ASSERT_FALSE(h_klass->IsInitialized()); ASSERT_FALSE(soa.Self()->IsExceptionPending()); |