Remove CodeItem accessor functions
These are replaced by the accessor helpers.
Bug: 63756964
Test: test-art-host
Test: test/testrunner/testrunner.py --host -j30
Change-Id: Ic93d60b68b684eeb5f69be286b4e15b8f8f97542
diff --git a/runtime/code_item_accessors-no_art-inl.h b/runtime/code_item_accessors-no_art-inl.h
index ebdd78b..38ce8fb 100644
--- a/runtime/code_item_accessors-no_art-inl.h
+++ b/runtime/code_item_accessors-no_art-inl.h
@@ -39,6 +39,7 @@
inline void CodeItemInstructionAccessor::Init(const DexFile* dex_file,
const DexFile::CodeItem* code_item) {
if (code_item != nullptr) {
+ DCHECK(dex_file->HasAddress(code_item));
DCHECK(dex_file != nullptr);
if (dex_file->IsCompactDexFile()) {
Init(down_cast<const CompactDexFile::CodeItem&>(*code_item));
diff --git a/runtime/code_item_accessors_test.cc b/runtime/code_item_accessors_test.cc
index ef5d246..57a5573 100644
--- a/runtime/code_item_accessors_test.cc
+++ b/runtime/code_item_accessors_test.cc
@@ -86,17 +86,17 @@
EXPECT_EQ(data_accessor.TriesSize(), kTriesSize);
};
- uint8_t buffer1[sizeof(CompactDexFile::CodeItem) + kInsnsSizeInCodeUnits * sizeof(uint16_t)] = {};
- CompactDexFile::CodeItem* dex_code_item = reinterpret_cast<CompactDexFile::CodeItem*>(buffer1);
+ StandardDexFile::CodeItem* dex_code_item =
+ reinterpret_cast<StandardDexFile::CodeItem*>(const_cast<uint8_t*>(standard_dex->Begin()));
dex_code_item->registers_size_ = kRegisterSize;
dex_code_item->ins_size_ = kInsSize;
dex_code_item->outs_size_ = kOutsSize;
dex_code_item->tries_size_ = kTriesSize;
dex_code_item->insns_size_in_code_units_ = kInsnsSizeInCodeUnits;
- verify_code_item(compact_dex.get(), dex_code_item, dex_code_item->insns_);
+ verify_code_item(standard_dex.get(), dex_code_item, dex_code_item->insns_);
- uint8_t buffer2[sizeof(CompactDexFile::CodeItem) + kInsnsSizeInCodeUnits * sizeof(uint16_t)] = {};
- CompactDexFile::CodeItem* cdex_code_item = reinterpret_cast<CompactDexFile::CodeItem*>(buffer2);
+ CompactDexFile::CodeItem* cdex_code_item =
+ reinterpret_cast<CompactDexFile::CodeItem*>(const_cast<uint8_t*>(compact_dex->Begin()));
cdex_code_item->registers_size_ = kRegisterSize;
cdex_code_item->ins_size_ = kInsSize;
cdex_code_item->outs_size_ = kOutsSize;
diff --git a/runtime/dex_file-inl.h b/runtime/dex_file-inl.h
index a6f7621..7cc8b87 100644
--- a/runtime/dex_file-inl.h
+++ b/runtime/dex_file-inl.h
@@ -133,10 +133,6 @@
return StringDataByIdx(proto_id.shorty_idx_);
}
-inline const DexFile::TryItem* DexFile::GetTryItems(const CodeItem& code_item, uint32_t offset) {
- return GetTryItems(code_item.Instructions().end(), offset);
-}
-
inline const DexFile::TryItem* DexFile::GetTryItems(const DexInstructionIterator& code_item_end,
uint32_t offset) {
return reinterpret_cast<const TryItem*>
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index d136dc3..d6469c6 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -221,7 +221,10 @@
uintptr_t code_item_start = reinterpret_cast<uintptr_t>(&code_item);
uint32_t insns_size = code_item.insns_size_in_code_units_;
uint32_t tries_size = code_item.tries_size_;
- const uint8_t* handler_data = GetCatchHandlerData(code_item, 0);
+ const uint8_t* handler_data = GetCatchHandlerData(
+ DexInstructionIterator(code_item.insns_, code_item.insns_size_in_code_units_),
+ code_item.tries_size_,
+ 0);
if (tries_size == 0 || handler_data == nullptr) {
uintptr_t insns_end = reinterpret_cast<uintptr_t>(&code_item.insns_[insns_size]);
@@ -511,11 +514,6 @@
return -1;
}
-int32_t DexFile::FindCatchHandlerOffset(const CodeItem &code_item, uint32_t address) {
- int32_t try_item = FindTryItem(GetTryItems(code_item, 0), code_item.tries_size_, address);
- return (try_item == -1) ? -1 : DexFile::GetTryItems(code_item, try_item)->handler_off_;
-}
-
bool DexFile::LineNumForPcCb(void* raw_context, const PositionInfo& entry) {
LineNumFromPcContext* context = reinterpret_cast<LineNumFromPcContext*>(raw_context);
diff --git a/runtime/dex_file.h b/runtime/dex_file.h
index 6c6ae2d..b9bf119 100644
--- a/runtime/dex_file.h
+++ b/runtime/dex_file.h
@@ -303,16 +303,6 @@
// Raw code_item.
struct CodeItem {
- IterationRange<DexInstructionIterator> Instructions(uint32_t start_dex_pc = 0u) const {
- DCHECK_LE(start_dex_pc, insns_size_in_code_units_);
- return { DexInstructionIterator(insns_, start_dex_pc),
- DexInstructionIterator(insns_, insns_size_in_code_units_) };
- }
-
- const Instruction& InstructionAt(uint32_t dex_pc) const {
- return *Instruction::At(insns_ + dex_pc);
- }
-
// Used when quickening / unquickening.
void SetDebugInfoOffset(uint32_t new_offset) {
debug_info_off_ = new_offset;
@@ -784,7 +774,6 @@
}
static const TryItem* GetTryItems(const DexInstructionIterator& code_item_end, uint32_t offset);
- static const TryItem* GetTryItems(const CodeItem& code_item, uint32_t offset);
// Get the base of the encoded data for the given DexCode.
static const uint8_t* GetCatchHandlerData(const DexInstructionIterator& code_item_end,
@@ -794,16 +783,10 @@
reinterpret_cast<const uint8_t*>(GetTryItems(code_item_end, tries_size));
return handler_data + offset;
}
- static const uint8_t* GetCatchHandlerData(const CodeItem& code_item, uint32_t offset) {
- return GetCatchHandlerData(code_item.Instructions().end(), code_item.tries_size_, offset);
- }
// Find which try region is associated with the given address (ie dex pc). Returns -1 if none.
static int32_t FindTryItem(const TryItem* try_items, uint32_t tries_size, uint32_t address);
- // Find the handler offset associated with the given address (ie dex pc). Returns -1 if none.
- static int32_t FindCatchHandlerOffset(const CodeItem &code_item, uint32_t address);
-
// Get the pointer to the start of the debugging data
const uint8_t* GetDebugInfoStream(uint32_t debug_info_off) const {
// Check that the offset is in bounds.
@@ -1044,6 +1027,10 @@
ALWAYS_INLINE const StandardDexFile* AsStandardDexFile() const;
ALWAYS_INLINE const CompactDexFile* AsCompactDexFile() const;
+ bool HasAddress(const void* addr) const {
+ return Begin() <= addr && addr < Begin() + Size();
+ }
+
protected:
// First Dex format version supporting default methods.
static const uint32_t kDefaultMethodsVersion = 37;
diff --git a/runtime/dex_to_dex_decompiler.cc b/runtime/dex_to_dex_decompiler.cc
index a4e4fb5..dc7e11b 100644
--- a/runtime/dex_to_dex_decompiler.cc
+++ b/runtime/dex_to_dex_decompiler.cc
@@ -21,6 +21,7 @@
#include "base/macros.h"
#include "base/mutex.h"
#include "bytecode_utils.h"
+#include "code_item_accessors-inl.h"
#include "dex_file-inl.h"
#include "dex_instruction-inl.h"
#include "quicken_info.h"
@@ -30,10 +31,11 @@
class DexDecompiler {
public:
- DexDecompiler(const DexFile::CodeItem& code_item,
+ DexDecompiler(const DexFile* dex_file,
+ const DexFile::CodeItem& code_item,
const ArrayRef<const uint8_t>& quickened_info,
bool decompile_return_instruction)
- : code_item_(code_item),
+ : code_item_accessor_(dex_file, &code_item),
quicken_info_(quickened_info.data()),
quicken_info_number_of_indices_(QuickenInfoTable::NumberOfIndices(quickened_info.size())),
decompile_return_instruction_(decompile_return_instruction) {}
@@ -76,7 +78,7 @@
return ret;
}
- const DexFile::CodeItem& code_item_;
+ const CodeItemInstructionAccessor code_item_accessor_;
const QuickenInfoTable quicken_info_;
const size_t quicken_info_number_of_indices_;
const bool decompile_return_instruction_;
@@ -91,7 +93,7 @@
// because the RETURN_VOID quickening is not encoded in the quickening data. Because
// unquickening is a rare need and not performance sensitive, it is not worth the
// added storage to also add the RETURN_VOID quickening in the quickened data.
- for (const DexInstructionPcPair& pair : code_item_.Instructions()) {
+ for (const DexInstructionPcPair& pair : code_item_accessor_) {
Instruction* inst = const_cast<Instruction*>(&pair.Inst());
switch (inst->Opcode()) {
@@ -194,13 +196,14 @@
return true;
}
-bool ArtDecompileDEX(const DexFile::CodeItem& code_item,
+bool ArtDecompileDEX(const DexFile* dex_file,
+ const DexFile::CodeItem& code_item,
const ArrayRef<const uint8_t>& quickened_info,
bool decompile_return_instruction) {
if (quickened_info.size() == 0 && !decompile_return_instruction) {
return true;
}
- DexDecompiler decompiler(code_item, quickened_info, decompile_return_instruction);
+ DexDecompiler decompiler(dex_file, code_item, quickened_info, decompile_return_instruction);
return decompiler.Decompile();
}
diff --git a/runtime/dex_to_dex_decompiler.h b/runtime/dex_to_dex_decompiler.h
index d7cb164..804b7e8 100644
--- a/runtime/dex_to_dex_decompiler.h
+++ b/runtime/dex_to_dex_decompiler.h
@@ -29,7 +29,8 @@
// to non-const has too many repercussions on the code base. We make it
// consistent with DexToDexCompiler, but we should really change it to
// DexFile::CodeItem*.
-bool ArtDecompileDEX(const DexFile::CodeItem& code_item,
+bool ArtDecompileDEX(const DexFile* dex_file,
+ const DexFile::CodeItem& code_item,
const ArrayRef<const uint8_t>& quickened_data,
bool decompile_return_instruction);
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index a4d14ec..7192058 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -2564,8 +2564,7 @@
// From the instruction, get the |callsite_shorty| and expose arguments on the stack to the GC.
ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp);
uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp);
- const DexFile::CodeItem* code = caller_method->GetCodeItem();
- const Instruction& inst = code->InstructionAt(dex_pc);
+ const Instruction& inst = caller_method->DexInstructions().InstructionAt(dex_pc);
DCHECK(inst.Opcode() == Instruction::INVOKE_POLYMORPHIC ||
inst.Opcode() == Instruction::INVOKE_POLYMORPHIC_RANGE);
const uint32_t proto_idx = inst.VRegH();
diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc
index fe768a1..a9af97d 100644
--- a/runtime/vdex_file.cc
+++ b/runtime/vdex_file.cc
@@ -254,6 +254,7 @@
quickening_info));
}
optimizer::ArtDecompileDEX(
+ &target_dex_file,
*code_item,
GetQuickeningInfoAt(quickening_info, quickening_offset),
decompile_return_instruction);