jitzygote: only copy contents if they differ.

memcpy will write to the page and dirty it, so avoid it if
contents are the same.

Bug: 119800099
Test: boot
Change-Id: I075a36eaa448f1214b0d8f452bfa65026b293658
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index bde0ed8..c6e0702 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -834,6 +834,12 @@
   DISALLOW_COPY_AND_ASSIGN(JitProfileTask);
 };
 
+static void CopyIfDifferent(void* s1, const void* s2, size_t n) {
+  if (memcmp(s1, s2, n) != 0) {
+    memcpy(s1, s2, n);
+  }
+}
+
 void Jit::MapBootImageMethods() {
   if (!GetChildMappingMethods().IsValid()) {
     return;
@@ -911,9 +917,9 @@
         //                            |/////////| -> copy -> |/////////|
         //                            |         |            |         |
         //
-        memcpy(GetChildMappingMethods().Begin() + offset,
-               page_start,
-               pointer + sizeof(ArtMethod) - page_start);
+        CopyIfDifferent(GetChildMappingMethods().Begin() + offset,
+                        page_start,
+                        pointer + sizeof(ArtMethod) - page_start);
       } else if (pointer < page_end && (pointer + sizeof(ArtMethod)) > page_end) {
         LOG(INFO) << "Copying parts of the contents of an ArtMethod spanning page_end";
         // If the method spans `page_end`, copy the contents of the child
@@ -926,9 +932,9 @@
         //         section end   -->  -----------
         //
         size_t bytes_to_copy = (page_end - pointer);
-        memcpy(GetChildMappingMethods().Begin() + offset + capacity - bytes_to_copy,
-               page_end - bytes_to_copy,
-               bytes_to_copy);
+        CopyIfDifferent(GetChildMappingMethods().Begin() + offset + capacity - bytes_to_copy,
+                        page_end - bytes_to_copy,
+                        bytes_to_copy);
       }
     }, space->Begin(), kRuntimePointerSize);