Use internal memcpy when initializing code objects.
authormstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 20 Mar 2013 16:53:31 +0000 (16:53 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 20 Mar 2013 16:53:31 +0000 (16:53 +0000)
R=jkummerow@chromium.org
BUG=chromium:196330

Review URL: https://codereview.chromium.org/12593014

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14011 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/objects.cc
src/v8utils.h

index 00d00d5..f330a5e 100644 (file)
@@ -8817,15 +8817,15 @@ void Code::CopyFrom(const CodeDesc& desc) {
   CHECK(relocation_info()->IsByteArray());
   CHECK(reinterpret_cast<intptr_t>(instruction_start()) ==
         reinterpret_cast<intptr_t>(this) + Code::kHeaderSize - kHeapObjectTag);
-  memmove(instruction_start(), desc.buffer, desc.instr_size);
+  CopyBytes<byte>(instruction_start(), desc.buffer, desc.instr_size);
 
   // copy reloc info
   // TODO(mstarzinger): Remove once we found the bug.
   CHECK(IsCode());
   CHECK(relocation_info()->IsByteArray());
-  memmove(relocation_start(),
-          desc.buffer + desc.buffer_size - desc.reloc_size,
-          desc.reloc_size);
+  CopyBytes<byte>(relocation_start(),
+                  desc.buffer + desc.buffer_size - desc.reloc_size,
+                  desc.reloc_size);
 
   // unbox handles and relocate
   intptr_t delta = instruction_start() - desc.buffer;
index 793d34d..fd78545 100644 (file)
@@ -122,7 +122,7 @@ inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms,
 
 // Memory
 
-// Copies data from |src| to |dst|.  The data spans MUST not overlap.
+// Copies data from |src| to |dst|.  The data spans must not overlap.
 template <typename T>
 inline void CopyWords(T* dst, T* src, int num_words) {
   STATIC_ASSERT(sizeof(T) == kPointerSize);
@@ -145,6 +145,30 @@ inline void CopyWords(T* dst, T* src, int num_words) {
 }
 
 
+// Copies data from |src| to |dst|.  The data spans must not overlap.
+template <typename T>
+inline void CopyBytes(T* dst, T* src, int num_bytes) {
+  STATIC_ASSERT(sizeof(T) == 1);
+  ASSERT(Min(dst, src) + num_bytes <= Max(dst, src));
+  ASSERT(num_bytes >= 0);
+  if (num_bytes == 0) return;
+
+  // Use block copying memcpy if the segment we're copying is
+  // enough to justify the extra call/setup overhead.
+  static const int kBlockCopyLimit = OS::kMinComplexMemCopy;
+
+  if (num_bytes >= kBlockCopyLimit) {
+    OS::MemCopy(dst, src, num_bytes);
+  } else {
+    int remaining = num_bytes;
+    do {
+      remaining--;
+      *dst++ = *src++;
+    } while (remaining > 0);
+  }
+}
+
+
 template <typename T, typename U>
 inline void MemsetPointer(T** dest, U* value, int counter) {
 #ifdef DEBUG