summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-04-16 16:17:24 +0000
committer VladimĂ­r Marko <vmarko@google.com> 2024-04-17 08:17:04 +0000
commitc66a8e55574d3d83f20ba7d0705f52ce34eb3dca (patch)
tree173ae58e618975a7f12580d2ff99f071015c2421
parentde8e6689cb3f829b73e921d843cfa38bbfe996bf (diff)
Clean up target retrieval from `LinkerPatch`.
Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 38313278 Change-Id: I637680589ba6f483b746bce567870f6d896d9fde
-rw-r--r--compiler/linker/linker_patch.h34
-rw-r--r--dex2oat/linker/oat_writer.cc34
-rw-r--r--dex2oat/linker/relative_patcher_test.h5
3 files changed, 28 insertions, 45 deletions
diff --git a/compiler/linker/linker_patch.h b/compiler/linker/linker_patch.h
index 6e09ea8954..19ee0e640c 100644
--- a/compiler/linker/linker_patch.h
+++ b/compiler/linker/linker_patch.h
@@ -25,6 +25,9 @@
#include "base/bit_utils.h"
#include "base/macros.h"
#include "dex/method_reference.h"
+#include "dex/proto_reference.h"
+#include "dex/string_reference.h"
+#include "dex/type_reference.h"
namespace art HIDDEN {
@@ -236,42 +239,23 @@ class LinkerPatch {
return MethodReference(target_dex_file_, method_idx_);
}
- const DexFile* TargetTypeDexFile() const {
+ TypeReference TargetType() const {
DCHECK(patch_type_ == Type::kTypeRelative ||
patch_type_ == Type::kTypeBssEntry ||
patch_type_ == Type::kPublicTypeBssEntry ||
patch_type_ == Type::kPackageTypeBssEntry);
- return target_dex_file_;
+ return TypeReference(target_dex_file_, dex::TypeIndex(type_idx_));
}
- dex::TypeIndex TargetTypeIndex() const {
- DCHECK(patch_type_ == Type::kTypeRelative ||
- patch_type_ == Type::kTypeBssEntry ||
- patch_type_ == Type::kPublicTypeBssEntry ||
- patch_type_ == Type::kPackageTypeBssEntry);
- return dex::TypeIndex(type_idx_);
- }
-
- const DexFile* TargetStringDexFile() const {
+ StringReference TargetString() const {
DCHECK(patch_type_ == Type::kStringRelative ||
patch_type_ == Type::kStringBssEntry);
- return target_dex_file_;
- }
-
- dex::StringIndex TargetStringIndex() const {
- DCHECK(patch_type_ == Type::kStringRelative ||
- patch_type_ == Type::kStringBssEntry);
- return dex::StringIndex(string_idx_);
- }
-
- const DexFile* TargetProtoDexFile() const {
- DCHECK(patch_type_ == Type::kMethodTypeBssEntry);
- return target_dex_file_;
+ return StringReference(target_dex_file_, dex::StringIndex(string_idx_));
}
- dex::ProtoIndex TargetProtoIndex() const {
+ ProtoReference TargetProto() const {
DCHECK(patch_type_ == Type::kMethodTypeBssEntry);
- return dex::ProtoIndex(proto_idx_);
+ return ProtoReference(target_dex_file_, dex::ProtoIndex(proto_idx_));
}
uint32_t PcInsnOffset() const {
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index 03305d9faf..f1b44a8263 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -755,31 +755,31 @@ class OatWriter::InitBssLayoutMethodVisitor : public DexMethodVisitor {
&writer_->bss_method_entry_references_);
writer_->bss_method_entries_.Overwrite(target_method, /* placeholder */ 0u);
} else if (patch.GetType() == LinkerPatch::Type::kTypeBssEntry) {
- TypeReference target_type(patch.TargetTypeDexFile(), patch.TargetTypeIndex());
+ TypeReference target_type = patch.TargetType();
AddBssReference(target_type,
target_type.dex_file->NumTypeIds(),
&writer_->bss_type_entry_references_);
writer_->bss_type_entries_.Overwrite(target_type, /* placeholder */ 0u);
} else if (patch.GetType() == LinkerPatch::Type::kPublicTypeBssEntry) {
- TypeReference target_type(patch.TargetTypeDexFile(), patch.TargetTypeIndex());
+ TypeReference target_type = patch.TargetType();
AddBssReference(target_type,
target_type.dex_file->NumTypeIds(),
&writer_->bss_public_type_entry_references_);
writer_->bss_public_type_entries_.Overwrite(target_type, /* placeholder */ 0u);
} else if (patch.GetType() == LinkerPatch::Type::kPackageTypeBssEntry) {
- TypeReference target_type(patch.TargetTypeDexFile(), patch.TargetTypeIndex());
+ TypeReference target_type = patch.TargetType();
AddBssReference(target_type,
target_type.dex_file->NumTypeIds(),
&writer_->bss_package_type_entry_references_);
writer_->bss_package_type_entries_.Overwrite(target_type, /* placeholder */ 0u);
} else if (patch.GetType() == LinkerPatch::Type::kStringBssEntry) {
- StringReference target_string(patch.TargetStringDexFile(), patch.TargetStringIndex());
+ StringReference target_string = patch.TargetString();
AddBssReference(target_string,
target_string.dex_file->NumStringIds(),
&writer_->bss_string_entry_references_);
writer_->bss_string_entries_.Overwrite(target_string, /* placeholder */ 0u);
} else if (patch.GetType() == LinkerPatch::Type::kMethodTypeBssEntry) {
- ProtoReference target_proto(patch.TargetProtoDexFile(), patch.TargetProtoIndex());
+ ProtoReference target_proto = patch.TargetProto();
AddBssReference(target_proto,
target_proto.dex_file->NumProtoIds(),
&writer_->bss_method_type_entry_references_);
@@ -1685,9 +1685,8 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor {
break;
}
case LinkerPatch::Type::kStringBssEntry: {
- StringReference ref(patch.TargetStringDexFile(), patch.TargetStringIndex());
uint32_t target_offset =
- writer_->bss_start_ + writer_->bss_string_entries_.Get(ref);
+ writer_->bss_start_ + writer_->bss_string_entries_.Get(patch.TargetString());
writer_->relative_patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset_ + literal_offset,
@@ -1695,9 +1694,8 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor {
break;
}
case LinkerPatch::Type::kMethodTypeBssEntry: {
- ProtoReference ref(patch.TargetProtoDexFile(), patch.TargetProtoIndex());
uint32_t target_offset =
- writer_->bss_start_ + writer_->bss_method_type_entries_.Get(ref);
+ writer_->bss_start_ + writer_->bss_method_type_entries_.Get(patch.TargetProto());
writer_->relative_patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset_ + literal_offset,
@@ -1713,8 +1711,8 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor {
break;
}
case LinkerPatch::Type::kTypeBssEntry: {
- TypeReference ref(patch.TargetTypeDexFile(), patch.TargetTypeIndex());
- uint32_t target_offset = writer_->bss_start_ + writer_->bss_type_entries_.Get(ref);
+ uint32_t target_offset =
+ writer_->bss_start_ + writer_->bss_type_entries_.Get(patch.TargetType());
writer_->relative_patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset_ + literal_offset,
@@ -1722,9 +1720,8 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor {
break;
}
case LinkerPatch::Type::kPublicTypeBssEntry: {
- TypeReference ref(patch.TargetTypeDexFile(), patch.TargetTypeIndex());
uint32_t target_offset =
- writer_->bss_start_ + writer_->bss_public_type_entries_.Get(ref);
+ writer_->bss_start_ + writer_->bss_public_type_entries_.Get(patch.TargetType());
writer_->relative_patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset_ + literal_offset,
@@ -1732,9 +1729,8 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor {
break;
}
case LinkerPatch::Type::kPackageTypeBssEntry: {
- TypeReference ref(patch.TargetTypeDexFile(), patch.TargetTypeIndex());
uint32_t target_offset =
- writer_->bss_start_ + writer_->bss_package_type_entries_.Get(ref);
+ writer_->bss_start_ + writer_->bss_package_type_entries_.Get(patch.TargetType());
writer_->relative_patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset_ + literal_offset,
@@ -1865,9 +1861,10 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor {
ObjPtr<mirror::Class> GetTargetType(const LinkerPatch& patch)
REQUIRES_SHARED(Locks::mutator_lock_) {
DCHECK(writer_->HasImage());
- ObjPtr<mirror::DexCache> dex_cache = GetDexCache(patch.TargetTypeDexFile());
+ TypeReference target_type = patch.TargetType();
+ ObjPtr<mirror::DexCache> dex_cache = GetDexCache(target_type.dex_file);
ObjPtr<mirror::Class> type =
- class_linker_->LookupResolvedType(patch.TargetTypeIndex(), dex_cache, class_loader_);
+ class_linker_->LookupResolvedType(target_type.TypeIndex(), dex_cache, class_loader_);
CHECK(type != nullptr);
return type;
}
@@ -1875,8 +1872,9 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor {
ObjPtr<mirror::String> GetTargetString(const LinkerPatch& patch)
REQUIRES_SHARED(Locks::mutator_lock_) {
ClassLinker* linker = Runtime::Current()->GetClassLinker();
+ StringReference target_string = patch.TargetString();
ObjPtr<mirror::String> string =
- linker->LookupString(patch.TargetStringIndex(), GetDexCache(patch.TargetStringDexFile()));
+ linker->LookupString(target_string.StringIndex(), GetDexCache(target_string.dex_file));
DCHECK(string != nullptr);
DCHECK(writer_->GetCompilerOptions().IsBootImage() ||
writer_->GetCompilerOptions().IsBootImageExtension());
diff --git a/dex2oat/linker/relative_patcher_test.h b/dex2oat/linker/relative_patcher_test.h
index 65ca4f8e91..3e7ba796e0 100644
--- a/dex2oat/linker/relative_patcher_test.h
+++ b/dex2oat/linker/relative_patcher_test.h
@@ -182,7 +182,8 @@ class RelativePatcherTest : public testing::Test {
target_offset);
} else if (patch.GetType() == LinkerPatch::Type::kStringBssEntry) {
uint32_t target_offset =
- bss_begin_ + string_index_to_offset_map_.Get(patch.TargetStringIndex().index_);
+ bss_begin_ +
+ string_index_to_offset_map_.Get(patch.TargetString().StringIndex().index_);
patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset + patch.LiteralOffset(),
@@ -196,7 +197,7 @@ class RelativePatcherTest : public testing::Test {
target_offset);
} else if (patch.GetType() == LinkerPatch::Type::kStringRelative) {
uint32_t target_offset =
- string_index_to_offset_map_.Get(patch.TargetStringIndex().index_);
+ string_index_to_offset_map_.Get(patch.TargetString().StringIndex().index_);
patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset + patch.LiteralOffset(),