Use internal memcpy when initializing code objects.

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
parent ff3e7980
...@@ -8817,15 +8817,15 @@ void Code::CopyFrom(const CodeDesc& desc) { ...@@ -8817,15 +8817,15 @@ void Code::CopyFrom(const CodeDesc& desc) {
CHECK(relocation_info()->IsByteArray()); CHECK(relocation_info()->IsByteArray());
CHECK(reinterpret_cast<intptr_t>(instruction_start()) == CHECK(reinterpret_cast<intptr_t>(instruction_start()) ==
reinterpret_cast<intptr_t>(this) + Code::kHeaderSize - kHeapObjectTag); 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 // copy reloc info
// TODO(mstarzinger): Remove once we found the bug. // TODO(mstarzinger): Remove once we found the bug.
CHECK(IsCode()); CHECK(IsCode());
CHECK(relocation_info()->IsByteArray()); CHECK(relocation_info()->IsByteArray());
memmove(relocation_start(), CopyBytes<byte>(relocation_start(),
desc.buffer + desc.buffer_size - desc.reloc_size, desc.buffer + desc.buffer_size - desc.reloc_size,
desc.reloc_size); desc.reloc_size);
// unbox handles and relocate // unbox handles and relocate
intptr_t delta = instruction_start() - desc.buffer; intptr_t delta = instruction_start() - desc.buffer;
......
...@@ -122,7 +122,7 @@ inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms, ...@@ -122,7 +122,7 @@ inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms,
// Memory // 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> template <typename T>
inline void CopyWords(T* dst, T* src, int num_words) { inline void CopyWords(T* dst, T* src, int num_words) {
STATIC_ASSERT(sizeof(T) == kPointerSize); STATIC_ASSERT(sizeof(T) == kPointerSize);
...@@ -145,6 +145,30 @@ inline void CopyWords(T* dst, T* src, int num_words) { ...@@ -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> template <typename T, typename U>
inline void MemsetPointer(T** dest, U* value, int counter) { inline void MemsetPointer(T** dest, U* value, int counter) {
#ifdef DEBUG #ifdef DEBUG
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment