Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: src/v8utils.h

Issue 6777007: Add thread-safety to creation of MemCopy and modulo functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add Release_Store to change. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-win32.cc ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 private: 247 private:
248 Vector<char> buffer_; 248 Vector<char> buffer_;
249 int position_; 249 int position_;
250 250
251 bool is_finalized() const { return position_ < 0; } 251 bool is_finalized() const { return position_ < 0; }
252 252
253 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); 253 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder);
254 }; 254 };
255 255
256 256
257 // Custom memcpy implementation for platforms where the standard version
258 // may not be good enough.
259 #if defined(V8_TARGET_ARCH_IA32)
260
261 // The default memcpy on ia32 architectures is generally not as efficient
262 // as possible. (If any further ia32 platforms are introduced where the
263 // memcpy function is efficient, exclude them from this branch).
264
265 typedef void (*MemCopyFunction)(void* dest, const void* src, size_t size);
266
267 // Implemented in codegen-<arch>.cc.
268 MemCopyFunction CreateMemCopyFunction();
269
270 // Copy memory area to disjoint memory area.
271 static inline void MemCopy(void* dest, const void* src, size_t size) {
272 static MemCopyFunction memcopy = CreateMemCopyFunction();
273 (*memcopy)(dest, src, size);
274 #ifdef DEBUG
275 CHECK_EQ(0, memcmp(dest, src, size));
276 #endif
277 }
278
279 // Limit below which the extra overhead of the MemCopy function is likely
280 // to outweigh the benefits of faster copying.
281 static const int kMinComplexMemCopy = 64;
282
283 #else // V8_TARGET_ARCH_IA32
284
285 static inline void MemCopy(void* dest, const void* src, size_t size) {
286 memcpy(dest, src, size);
287 }
288
289 static const int kMinComplexMemCopy = 256;
290
291 #endif // V8_TARGET_ARCH_IA32
292
293
294 // Copy from ASCII/16bit chars to ASCII/16bit chars. 257 // Copy from ASCII/16bit chars to ASCII/16bit chars.
295 template <typename sourcechar, typename sinkchar> 258 template <typename sourcechar, typename sinkchar>
296 static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) { 259 static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) {
297 sinkchar* limit = dest + chars; 260 sinkchar* limit = dest + chars;
298 #ifdef V8_HOST_CAN_READ_UNALIGNED 261 #ifdef V8_HOST_CAN_READ_UNALIGNED
299 if (sizeof(*dest) == sizeof(*src)) { 262 if (sizeof(*dest) == sizeof(*src)) {
300 if (chars >= static_cast<int>(kMinComplexMemCopy / sizeof(*dest))) { 263 if (chars >= static_cast<int>(OS::kMinComplexMemCopy / sizeof(*dest))) {
301 MemCopy(dest, src, chars * sizeof(*dest)); 264 OS::MemCopy(dest, src, chars * sizeof(*dest));
302 return; 265 return;
303 } 266 }
304 // Number of characters in a uintptr_t. 267 // Number of characters in a uintptr_t.
305 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT 268 static const int kStepSize = sizeof(uintptr_t) / sizeof(*dest); // NOLINT
306 while (dest <= limit - kStepSize) { 269 while (dest <= limit - kStepSize) {
307 *reinterpret_cast<uintptr_t*>(dest) = 270 *reinterpret_cast<uintptr_t*>(dest) =
308 *reinterpret_cast<const uintptr_t*>(src); 271 *reinterpret_cast<const uintptr_t*>(src);
309 dest += kStepSize; 272 dest += kStepSize;
310 src += kStepSize; 273 src += kStepSize;
311 } 274 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 308
346 const char* data_; 309 const char* data_;
347 size_t length_; 310 size_t length_;
348 bool remove_file_on_cleanup_; 311 bool remove_file_on_cleanup_;
349 }; 312 };
350 313
351 314
352 } } // namespace v8::internal 315 } } // namespace v8::internal
353 316
354 #endif // V8_V8UTILS_H_ 317 #endif // V8_V8UTILS_H_
OLDNEW
« no previous file with comments | « src/platform-win32.cc ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698