JIT mini-debug-info: Compression micro-optimization.

Don't compress the last group to avoid repeated
compression and decompression in jit-zygote.

Test: device boots, check compression in logcat.
Change-Id: I117cb6486710508554efa982beb2dc0774799bee
diff --git a/runtime/jit/debugger_interface.cc b/runtime/jit/debugger_interface.cc
index eb26aac..61ae909 100644
--- a/runtime/jit/debugger_interface.cc
+++ b/runtime/jit/debugger_interface.cc
@@ -441,7 +441,7 @@
 // Split the JIT code cache into groups of fixed size and create single JITCodeEntry for each group.
 // The start address of method's code determines which group it belongs to.  The end is irrelevant.
 // New mini debug infos will be merged if possible, and entries for GCed functions will be removed.
-static void RepackEntries(bool compress, ArrayRef<const void*> removed)
+static void RepackEntries(bool compress_entries, ArrayRef<const void*> removed)
     REQUIRES(g_jit_debug_lock) {
   DCHECK(std::is_sorted(removed.begin(), removed.end()));
   jit::Jit* jit = Runtime::Current()->GetJit();
@@ -459,7 +459,7 @@
       break;  // Memory owned by the zygote process (read-only for an app).
     }
     if (it->allow_packing_) {
-      if (!compress && it->is_compressed_ && removed.empty()) {
+      if (!compress_entries && it->is_compressed_ && removed.empty()) {
         continue;  // If we are not compressing, also avoid decompressing.
       }
       entries.push_back(it);
@@ -485,6 +485,9 @@
     CHECK(removed_end >= removed_begin);
     ArrayRef<const void*> removed_subset(&*removed_begin, removed_end - removed_begin);
 
+    // Optimization: Don't compress the last group since it will likely change again soon.
+    bool compress = compress_entries && end != entries.end();
+
     // Bail out early if there is nothing to do for this group.
     if (elfs.size() == 1 && removed_subset.empty() && (*begin)->is_compressed_ == compress) {
       group_it = end;  // Go to next group.
@@ -540,13 +543,13 @@
   // Always compress zygote, since it does not GC and we want to keep the high-water mark low.
   if (++g_jit_num_unpacked_entries >= kJitRepackFrequency) {
     bool is_zygote = Runtime::Current()->IsZygote();
-    RepackEntries(/*compress=*/ is_zygote, /*removed=*/ ArrayRef<const void*>());
+    RepackEntries(/*compress_entries=*/ is_zygote, /*removed=*/ ArrayRef<const void*>());
   }
 }
 
 void RemoveNativeDebugInfoForJit(ArrayRef<const void*> removed) {
   MutexLock mu(Thread::Current(), g_jit_debug_lock);
-  RepackEntries(/*compress=*/ true, removed);
+  RepackEntries(/*compress_entries=*/ true, removed);
 
   // Remove entries which are not allowed to be packed (containing single method each).
   for (const JITCodeEntry* it = __jit_debug_descriptor.head_; it != nullptr; it = it->next_) {