Split dex_pc<->native_pc mapping table
First of 2 related CLs - this one moves to a split table, a future
CL will compress the table to save image space.
The current MappingTable mixes two flavors of entries: dex->pc and
pc(return address)->dex. The problem is that we can have two
entries with the same native pc address but two different dex pcs.
The reason is that when we go from native pc to dex, the native
pc is actually the return address from the previous call, whereas
when we go from dex to native pc, the mapping refers to the first
native instruction of the sequence.
Previously, the first entry in the mapping table was the number
of subsequent entries. That will remain the same, but now
the second entry will be a count of the number of entries in
the pc->dex section of the table. The difference between the
two counts gives us the number of entries in the following dex->pc
section.
Change-Id: Ibadb96cb50bf1f93e079dff3832130b9f9782723
diff --git a/src/object.cc b/src/object.cc
index 284f221..90342ff 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -514,14 +514,37 @@
return pc - reinterpret_cast<uintptr_t>(GetOatCode(this));
}
-uint32_t AbstractMethod::ToDexPc(const uintptr_t pc) const {
+// Find the lowest-address native safepoint pc for a given dex pc
+uint32_t AbstractMethod::ToFirstNativeSafepointPc(const uintptr_t dex_pc) const {
#if !defined(ART_USE_LLVM_COMPILER)
- const uint32_t* mapping_table = GetMappingTable();
+ const uint32_t* mapping_table = GetPcToDexMappingTable();
if (mapping_table == NULL) {
DCHECK(IsNative() || IsCalleeSaveMethod() || IsProxyMethod()) << PrettyMethod(this);
return DexFile::kDexNoIndex; // Special no mapping case
}
- size_t mapping_table_length = GetMappingTableLength();
+ size_t mapping_table_length = GetPcToDexMappingTableLength();
+ for (size_t i = 0; i < mapping_table_length; i += 2) {
+ if (mapping_table[i + 1] == dex_pc) {
+ return mapping_table[i] + reinterpret_cast<uintptr_t>(GetOatCode(this));
+ }
+ }
+ LOG(FATAL) << "Failed to find native offset for dex pc 0x" << std::hex << dex_pc
+ << " in " << PrettyMethod(this);
+ return 0;
+#else
+ // Compiler LLVM doesn't use the machine pc, we just use dex pc instead.
+ return static_cast<uint32_t>(dex_pc);
+#endif
+}
+
+uint32_t AbstractMethod::ToDexPc(const uintptr_t pc) const {
+#if !defined(ART_USE_LLVM_COMPILER)
+ const uint32_t* mapping_table = GetPcToDexMappingTable();
+ if (mapping_table == NULL) {
+ DCHECK(IsNative() || IsCalleeSaveMethod() || IsProxyMethod()) << PrettyMethod(this);
+ return DexFile::kDexNoIndex; // Special no mapping case
+ }
+ size_t mapping_table_length = GetPcToDexMappingTableLength();
uint32_t sought_offset = pc - reinterpret_cast<uintptr_t>(GetOatCode(this));
for (size_t i = 0; i < mapping_table_length; i += 2) {
if (mapping_table[i] == sought_offset) {
@@ -538,12 +561,12 @@
}
uintptr_t AbstractMethod::ToNativePc(const uint32_t dex_pc) const {
- const uint32_t* mapping_table = GetMappingTable();
+ const uint32_t* mapping_table = GetDexToPcMappingTable();
if (mapping_table == NULL) {
DCHECK_EQ(dex_pc, 0U);
return 0; // Special no mapping/pc == 0 case
}
- size_t mapping_table_length = GetMappingTableLength();
+ size_t mapping_table_length = GetDexToPcMappingTableLength();
for (size_t i = 0; i < mapping_table_length; i += 2) {
uint32_t map_offset = mapping_table[i];
uint32_t map_dex_offset = mapping_table[i + 1];
@@ -551,7 +574,8 @@
return reinterpret_cast<uintptr_t>(GetOatCode(this)) + map_offset;
}
}
- LOG(FATAL) << "Looking up Dex PC not contained in method";
+ LOG(FATAL) << "Looking up Dex PC not contained in method, 0x" << std::hex << dex_pc
+ << " in " << PrettyMethod(this);
return 0;
}