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;
// 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);
}
+// 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