Skip to content

Commit

Permalink
Fix DWARF line-number generation for JITed methods.
Browse files Browse the repository at this point in the history
Don't strip, repack or compress debug-info if explicitly
requested by the developer (using the -g compiler flag).

If enabled, the DWARF debug info has about 1:1 size
overhead relative to JIT code + data.

Bug: 131422204
Test: Check that gdb shows line numbers for JITed method.
Test: Hard-code always-enable generation and run maps.
Change-Id: If06de8ae2317af4d57d84e8a8bfae86a597dd4e4
  • Loading branch information
dsrbecky committed Apr 29, 2019
1 parent c36a8cc commit 36ec6c7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/jit/jit_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ extern "C" void jit_types_loaded(void* handle, mirror::Class** types, size_t cou
AddNativeDebugInfoForJit(Thread::Current(),
/*code_ptr=*/ nullptr,
elf_file,
debug::PackElfFileForJIT,
/*pack*/ nullptr,
compiler_options.GetInstructionSet(),
compiler_options.GetInstructionSetFeatures());
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizing/optimizing_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ void OptimizingCompiler::GenerateJitDebugInfo(ArtMethod* method ATTRIBUTE_UNUSED
AddNativeDebugInfoForJit(Thread::Current(),
reinterpret_cast<const void*>(info.code_address),
elf_file,
debug::PackElfFileForJIT,
mini_debug_info ? debug::PackElfFileForJIT : nullptr,
compiler_options.GetInstructionSet(),
compiler_options.GetInstructionSetFeatures());
}
Expand Down
19 changes: 17 additions & 2 deletions runtime/jit/debugger_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ static void RepackEntries(PackElfFileForJITFunction pack,
// The number of methods per entry is variable (depending on how many fit in that range).
constexpr uint32_t kGroupSize = 64 * KB;

CHECK(pack != nullptr);
JITCodeEntries packed_entries;
std::vector<ArrayRef<const uint8_t>> added;
std::vector<const void*> removed;
Expand Down Expand Up @@ -367,7 +368,21 @@ void AddNativeDebugInfoForJit(Thread* self,
// Must be done before addition in case the added code_ptr is in the removed set.
if (!g_jit_removed_entries.empty()) {
g_compressed_jit_debug_entries.merge(g_uncompressed_jit_debug_entries);
RepackEntries(pack, isa, features, /*compress=*/ true, &g_compressed_jit_debug_entries);
if (pack != nullptr) {
RepackEntries(pack, isa, features, /*compress=*/ true, &g_compressed_jit_debug_entries);
} else {
// If repacking function is not provided, just remove the individual entries.
for (const void* removed_code_ptr : g_jit_removed_entries) {
auto it = g_compressed_jit_debug_entries.find(removed_code_ptr);
if (it != g_compressed_jit_debug_entries.end()) {
DeleteJITCodeEntryInternal(__jit_debug_descriptor,
__jit_debug_register_code_ptr,
/*entry=*/ it->second,
/*free_symfile=*/ true);
g_compressed_jit_debug_entries.erase(it);
}
}
}
g_jit_removed_entries.clear();
g_jit_num_unpacked_entries = 0;
}
Expand Down Expand Up @@ -397,7 +412,7 @@ void AddNativeDebugInfoForJit(Thread* self,

// Pack (but don't compress) recent entries - this is cheap and reduces memory use by ~4x.
// We delay compression until after GC since it is more expensive (and saves further ~4x).
if (g_jit_num_unpacked_entries >= kJitMaxUnpackedEntries) {
if (g_jit_num_unpacked_entries >= kJitMaxUnpackedEntries && pack != nullptr) {
RepackEntries(pack, isa, features, /*compress=*/ false, &g_uncompressed_jit_debug_entries);
g_jit_num_unpacked_entries = 0;
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/jit/debugger_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ void RemoveNativeDebugInfoForDex(Thread* self, const DexFile* dexfile);

// Notify native tools (e.g. libunwind) that JIT has compiled a new method.
// The method will make copy of the passed ELF file (to shrink it to the minimum size).
// If packing function is provided, ELF files can be merged to save space
// (however, the merging drops advanced gdb debug-info as it is too complex).
void AddNativeDebugInfoForJit(Thread* self,
const void* code_ptr,
const std::vector<uint8_t>& symfile,
Expand Down

0 comments on commit 36ec6c7

Please sign in to comment.