Optimizing: Clean up after const-string sharpening.
Do not look up the String for JIT, just check if it's in the
dex cache. Strings on hot paths should already be resolved
and we don't want to unnecessarily increase JIT compile time
to have a chance of improving a cold path.
Also, change the enum LinkerPatchType to be an inner enum
class of LinkerPatch and clean up casts between pointers and
uint64_t.
Change-Id: Ia6e0513af1a84ce94a3b30edac0c592157d374ec
diff --git a/compiler/linker/arm/relative_patcher_arm_base.cc b/compiler/linker/arm/relative_patcher_arm_base.cc
index 682b008..d4dd978 100644
--- a/compiler/linker/arm/relative_patcher_arm_base.cc
+++ b/compiler/linker/arm/relative_patcher_arm_base.cc
@@ -112,7 +112,7 @@
}
}
for (const LinkerPatch& patch : compiled_method->GetPatches()) {
- if (patch.Type() == kLinkerPatchCallRelative) {
+ if (patch.GetType() == LinkerPatch::Type::kCallRelative) {
unprocessed_patches_.emplace_back(patch.TargetMethod(),
quick_code_offset + patch.LiteralOffset());
}
diff --git a/compiler/linker/arm64/relative_patcher_arm64.cc b/compiler/linker/arm64/relative_patcher_arm64.cc
index 0549327..e3e3121 100644
--- a/compiler/linker/arm64/relative_patcher_arm64.cc
+++ b/compiler/linker/arm64/relative_patcher_arm64.cc
@@ -31,8 +31,9 @@
namespace {
inline bool IsAdrpPatch(const LinkerPatch& patch) {
- LinkerPatchType type = patch.Type();
- return (type == kLinkerPatchStringRelative || type == kLinkerPatchDexCacheArray) &&
+ LinkerPatch::Type type = patch.GetType();
+ return
+ (type == LinkerPatch::Type::kStringRelative || type == LinkerPatch::Type::kDexCacheArray) &&
patch.LiteralOffset() == patch.PcInsnOffset();
}
@@ -209,11 +210,11 @@
} else {
if ((insn & 0xfffffc00) == 0x91000000) {
// ADD immediate, 64-bit with imm12 == 0 (unset).
- DCHECK(patch.Type() == kLinkerPatchStringRelative) << patch.Type();
+ DCHECK(patch.GetType() == LinkerPatch::Type::kStringRelative) << patch.GetType();
shift = 0u; // No shift for ADD.
} else {
// LDR 32-bit or 64-bit with imm12 == 0 (unset).
- DCHECK(patch.Type() == kLinkerPatchDexCacheArray) << patch.Type();
+ DCHECK(patch.GetType() == LinkerPatch::Type::kDexCacheArray) << patch.GetType();
DCHECK_EQ(insn & 0xbffffc00, 0xb9400000) << std::hex << insn;
}
if (kIsDebugBuild) {
@@ -292,9 +293,10 @@
return false;
}
- // And since kLinkerPatchStringRelative is using the result of the ADRP for an ADD immediate,
- // check for that as well. We generalize a bit to include ADD/ADDS/SUB/SUBS immediate that
- // either uses the ADRP destination or stores the result to a different register.
+ // And since LinkerPatch::Type::kStringRelative is using the result of the ADRP
+ // for an ADD immediate, check for that as well. We generalize a bit to include
+ // ADD/ADDS/SUB/SUBS immediate that either uses the ADRP destination or stores
+ // the result to a different register.
if ((next_insn & 0x1f000000) == 0x11000000 &&
((((next_insn >> 5) ^ adrp) & 0x1f) == 0 || ((next_insn ^ adrp) & 0x1f) != 0)) {
return false;
diff --git a/compiler/linker/relative_patcher_test.h b/compiler/linker/relative_patcher_test.h
index c9fb543..bf61ea0 100644
--- a/compiler/linker/relative_patcher_test.h
+++ b/compiler/linker/relative_patcher_test.h
@@ -142,26 +142,26 @@
patched_code_.assign(code.begin(), code.end());
code = ArrayRef<const uint8_t>(patched_code_);
for (const LinkerPatch& patch : compiled_method->GetPatches()) {
- if (patch.Type() == kLinkerPatchCallRelative) {
+ if (patch.GetType() == LinkerPatch::Type::kCallRelative) {
auto result = method_offset_map_.FindMethodOffset(patch.TargetMethod());
uint32_t target_offset =
result.first ? result.second : kTrampolineOffset + compiled_method->CodeDelta();
patcher_->PatchCall(&patched_code_, patch.LiteralOffset(),
offset + patch.LiteralOffset(), target_offset);
- } else if (patch.Type() == kLinkerPatchDexCacheArray) {
+ } else if (patch.GetType() == LinkerPatch::Type::kDexCacheArray) {
uint32_t target_offset = dex_cache_arrays_begin_ + patch.TargetDexCacheElementOffset();
patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset + patch.LiteralOffset(),
target_offset);
- } else if (patch.Type() == kLinkerPatchStringRelative) {
+ } else if (patch.GetType() == LinkerPatch::Type::kStringRelative) {
uint32_t target_offset = string_index_to_offset_map_.Get(patch.TargetStringIndex());
patcher_->PatchPcRelativeReference(&patched_code_,
patch,
offset + patch.LiteralOffset(),
target_offset);
} else {
- LOG(FATAL) << "Bad patch type. " << patch.Type();
+ LOG(FATAL) << "Bad patch type. " << patch.GetType();
UNREACHABLE();
}
}