| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 void OS::Free(void* address, const size_t size) { | 176 void OS::Free(void* address, const size_t size) { |
| 177 // TODO(1240712): munmap has a return value which is ignored here. | 177 // TODO(1240712): munmap has a return value which is ignored here. |
| 178 int result = munmap(address, size); | 178 int result = munmap(address, size); |
| 179 USE(result); | 179 USE(result); |
| 180 ASSERT(result == 0); | 180 ASSERT(result == 0); |
| 181 } | 181 } |
| 182 | 182 |
| 183 | 183 |
| 184 // Get rid of writable permission on code allocations. | 184 // Get rid of writable permission on code allocations. |
| 185 void OS::ProtectCode(void* address, const size_t size) { | 185 void OS::ProtectCode(void* address, const size_t size) { |
| 186 #if defined(__CYGWIN__) | 186 #if V8_OS_CYGWIN |
| 187 DWORD old_protect; | 187 DWORD old_protect; |
| 188 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); | 188 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); |
| 189 #elif defined(__native_client__) | 189 #elif V8_OS_NACL |
| 190 // The Native Client port of V8 uses an interpreter, so | 190 // The Native Client port of V8 uses an interpreter, so |
| 191 // code pages don't need PROT_EXEC. | 191 // code pages don't need PROT_EXEC. |
| 192 mprotect(address, size, PROT_READ); | 192 mprotect(address, size, PROT_READ); |
| 193 #else | 193 #else |
| 194 mprotect(address, size, PROT_READ | PROT_EXEC); | 194 mprotect(address, size, PROT_READ | PROT_EXEC); |
| 195 #endif | 195 #endif |
| 196 } | 196 } |
| 197 | 197 |
| 198 | 198 |
| 199 // Create guard pages. | 199 // Create guard pages. |
| 200 void OS::Guard(void* address, const size_t size) { | 200 void OS::Guard(void* address, const size_t size) { |
| 201 #if defined(__CYGWIN__) | 201 #if V8_OS_CYGWIN |
| 202 DWORD oldprotect; | 202 DWORD oldprotect; |
| 203 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); | 203 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); |
| 204 #else | 204 #else |
| 205 mprotect(address, size, PROT_NONE); | 205 mprotect(address, size, PROT_NONE); |
| 206 #endif | 206 #endif |
| 207 } | 207 } |
| 208 | 208 |
| 209 | 209 |
| 210 void* OS::GetRandomMmapAddr() { | 210 void* OS::GetRandomMmapAddr() { |
| 211 #if defined(__native_client__) | 211 #if V8_OS_NACL |
| 212 // TODO(bradchen): restore randomization once Native Client gets | 212 // TODO(bradchen): restore randomization once Native Client gets |
| 213 // smarter about using mmap address hints. | 213 // smarter about using mmap address hints. |
| 214 // See http://code.google.com/p/nativeclient/issues/3341 | 214 // See http://code.google.com/p/nativeclient/issues/3341 |
| 215 return NULL; | 215 return NULL; |
| 216 #endif | 216 #endif |
| 217 Isolate* isolate = Isolate::UncheckedCurrent(); | 217 Isolate* isolate = Isolate::UncheckedCurrent(); |
| 218 // Note that the current isolate isn't set up in a call path via | 218 // Note that the current isolate isn't set up in a call path via |
| 219 // CpuFeatures::Probe. We don't care about randomization in this case because | 219 // CpuFeatures::Probe. We don't care about randomization in this case because |
| 220 // the code page is immediately freed. | 220 // the code page is immediately freed. |
| 221 if (isolate != NULL) { | 221 if (isolate != NULL) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 #else | 291 #else |
| 292 #error Unsupported host architecture. | 292 #error Unsupported host architecture. |
| 293 #endif | 293 #endif |
| 294 } | 294 } |
| 295 | 295 |
| 296 | 296 |
| 297 // ---------------------------------------------------------------------------- | 297 // ---------------------------------------------------------------------------- |
| 298 // Math functions | 298 // Math functions |
| 299 | 299 |
| 300 double modulo(double x, double y) { | 300 double modulo(double x, double y) { |
| 301 return fmod(x, y); | 301 return std::fmod(x, y); |
| 302 } | 302 } |
| 303 | 303 |
| 304 | 304 |
| 305 #define UNARY_MATH_FUNCTION(name, generator) \ | 305 #define UNARY_MATH_FUNCTION(name, generator) \ |
| 306 static UnaryMathFunction fast_##name##_function = NULL; \ | 306 static UnaryMathFunction fast_##name##_function = NULL; \ |
| 307 void init_fast_##name##_function() { \ | 307 void init_fast_##name##_function() { \ |
| 308 fast_##name##_function = generator; \ | 308 fast_##name##_function = generator; \ |
| 309 } \ | 309 } \ |
| 310 double fast_##name(double x) { \ | 310 double fast_##name(double x) { \ |
| 311 return (*fast_##name##_function)(x); \ | 311 return (*fast_##name##_function)(x); \ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 } | 349 } |
| 350 | 350 |
| 351 | 351 |
| 352 double OS::TimeCurrentMillis() { | 352 double OS::TimeCurrentMillis() { |
| 353 return Time::Now().ToJsTime(); | 353 return Time::Now().ToJsTime(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 | 356 |
| 357 double OS::DaylightSavingsOffset(double time) { | 357 double OS::DaylightSavingsOffset(double time) { |
| 358 if (std::isnan(time)) return nan_value(); | 358 if (std::isnan(time)) return nan_value(); |
| 359 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); | 359 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond)); |
| 360 struct tm* t = localtime(&tv); | 360 struct tm* t = localtime(&tv); |
| 361 if (NULL == t) return nan_value(); | 361 if (NULL == t) return nan_value(); |
| 362 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; | 362 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; |
| 363 } | 363 } |
| 364 | 364 |
| 365 | 365 |
| 366 int OS::GetLastError() { | 366 int OS::GetLastError() { |
| 367 return errno; | 367 return errno; |
| 368 } | 368 } |
| 369 | 369 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 // Copy memory area. No restrictions. | 487 // Copy memory area. No restrictions. |
| 488 void OS::MemMove(void* dest, const void* src, size_t size) { | 488 void OS::MemMove(void* dest, const void* src, size_t size) { |
| 489 if (size == 0) return; | 489 if (size == 0) return; |
| 490 // Note: here we rely on dependent reads being ordered. This is true | 490 // Note: here we rely on dependent reads being ordered. This is true |
| 491 // on all architectures we currently support. | 491 // on all architectures we currently support. |
| 492 (*memmove_function)(dest, src, size); | 492 (*memmove_function)(dest, src, size); |
| 493 } | 493 } |
| 494 | 494 |
| 495 #elif defined(V8_HOST_ARCH_ARM) | 495 #elif defined(V8_HOST_ARCH_ARM) |
| 496 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest, | 496 void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest, |
| 497 const uint8_t* src, | 497 const uint8_t* src, |
| 498 size_t chars) { | 498 size_t chars) { |
| 499 uint16_t *limit = dest + chars; | 499 uint16_t *limit = dest + chars; |
| 500 while (dest < limit) { | 500 while (dest < limit) { |
| 501 *dest++ = static_cast<uint16_t>(*src++); | 501 *dest++ = static_cast<uint16_t>(*src++); |
| 502 } | 502 } |
| 503 } | 503 } |
| 504 | 504 |
| 505 | 505 |
| 506 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper; | 506 OS::MemCopyUint8Function OS::memcopy_uint8_function = &OS::MemCopyUint8Wrapper; |
| 507 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = | 507 OS::MemCopyUint16Uint8Function OS::memcopy_uint16_uint8_function = |
| 508 &OS::MemCopyUint16Uint8Wrapper; | 508 &OS::MemCopyUint16Uint8Wrapper; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 set_name(options.name()); | 574 set_name(options.name()); |
| 575 } | 575 } |
| 576 | 576 |
| 577 | 577 |
| 578 Thread::~Thread() { | 578 Thread::~Thread() { |
| 579 delete data_; | 579 delete data_; |
| 580 } | 580 } |
| 581 | 581 |
| 582 | 582 |
| 583 static void SetThreadName(const char* name) { | 583 static void SetThreadName(const char* name) { |
| 584 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) | 584 #if V8_OS_DRAGONFLYBSD || V8_OS_FREEBSD || V8_OS_OPENBSD |
| 585 pthread_set_name_np(pthread_self(), name); | 585 pthread_set_name_np(pthread_self(), name); |
| 586 #elif defined(__NetBSD__) | 586 #elif V8_OS_NETBSD |
| 587 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP); | 587 STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP); |
| 588 pthread_setname_np(pthread_self(), "%s", name); | 588 pthread_setname_np(pthread_self(), "%s", name); |
| 589 #elif defined(__APPLE__) | 589 #elif V8_OS_MACOSX |
| 590 // pthread_setname_np is only available in 10.6 or later, so test | 590 // pthread_setname_np is only available in 10.6 or later, so test |
| 591 // for it at runtime. | 591 // for it at runtime. |
| 592 int (*dynamic_pthread_setname_np)(const char*); | 592 int (*dynamic_pthread_setname_np)(const char*); |
| 593 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = | 593 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = |
| 594 dlsym(RTLD_DEFAULT, "pthread_setname_np"); | 594 dlsym(RTLD_DEFAULT, "pthread_setname_np"); |
| 595 if (dynamic_pthread_setname_np == NULL) | 595 if (dynamic_pthread_setname_np == NULL) |
| 596 return; | 596 return; |
| 597 | 597 |
| 598 // Mac OS X does not expose the length limit of the name, so hardcode it. | 598 // Mac OS X does not expose the length limit of the name, so hardcode it. |
| 599 static const int kMaxNameLength = 63; | 599 static const int kMaxNameLength = 63; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 626 } | 626 } |
| 627 | 627 |
| 628 | 628 |
| 629 void Thread::Start() { | 629 void Thread::Start() { |
| 630 int result; | 630 int result; |
| 631 pthread_attr_t attr; | 631 pthread_attr_t attr; |
| 632 memset(&attr, 0, sizeof(attr)); | 632 memset(&attr, 0, sizeof(attr)); |
| 633 result = pthread_attr_init(&attr); | 633 result = pthread_attr_init(&attr); |
| 634 ASSERT_EQ(0, result); | 634 ASSERT_EQ(0, result); |
| 635 // Native client uses default stack size. | 635 // Native client uses default stack size. |
| 636 #if !defined(__native_client__) | 636 #if !V8_OS_NACL |
| 637 if (stack_size_ > 0) { | 637 if (stack_size_ > 0) { |
| 638 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); | 638 result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); |
| 639 ASSERT_EQ(0, result); | 639 ASSERT_EQ(0, result); |
| 640 } | 640 } |
| 641 #endif | 641 #endif |
| 642 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); | 642 result = pthread_create(&data_->thread_, &attr, ThreadEntry, this); |
| 643 ASSERT_EQ(0, result); | 643 ASSERT_EQ(0, result); |
| 644 result = pthread_attr_destroy(&attr); | 644 result = pthread_attr_destroy(&attr); |
| 645 ASSERT_EQ(0, result); | 645 ASSERT_EQ(0, result); |
| 646 ASSERT(data_->thread_ != kNoThread); | 646 ASSERT(data_->thread_ != kNoThread); |
| 647 USE(result); | 647 USE(result); |
| 648 } | 648 } |
| 649 | 649 |
| 650 | 650 |
| 651 void Thread::Join() { | 651 void Thread::Join() { |
| 652 pthread_join(data_->thread_, NULL); | 652 pthread_join(data_->thread_, NULL); |
| 653 } | 653 } |
| 654 | 654 |
| 655 | 655 |
| 656 void Thread::YieldCPU() { | 656 void Thread::YieldCPU() { |
| 657 int result = sched_yield(); | 657 int result = sched_yield(); |
| 658 ASSERT_EQ(0, result); | 658 ASSERT_EQ(0, result); |
| 659 USE(result); | 659 USE(result); |
| 660 } | 660 } |
| 661 | 661 |
| 662 | 662 |
| 663 static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) { | 663 static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) { |
| 664 #if defined(__CYGWIN__) | 664 #if V8_OS_CYGWIN |
| 665 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps | 665 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps |
| 666 // because pthread_key_t is a pointer type on Cygwin. This will probably not | 666 // because pthread_key_t is a pointer type on Cygwin. This will probably not |
| 667 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway. | 667 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway. |
| 668 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); | 668 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); |
| 669 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key); | 669 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key); |
| 670 return static_cast<Thread::LocalStorageKey>(ptr_key); | 670 return static_cast<Thread::LocalStorageKey>(ptr_key); |
| 671 #else | 671 #else |
| 672 return static_cast<Thread::LocalStorageKey>(pthread_key); | 672 return static_cast<Thread::LocalStorageKey>(pthread_key); |
| 673 #endif | 673 #endif |
| 674 } | 674 } |
| 675 | 675 |
| 676 | 676 |
| 677 static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) { | 677 static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) { |
| 678 #if defined(__CYGWIN__) | 678 #if V8_OS_CYGWIN |
| 679 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); | 679 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); |
| 680 intptr_t ptr_key = static_cast<intptr_t>(local_key); | 680 intptr_t ptr_key = static_cast<intptr_t>(local_key); |
| 681 return reinterpret_cast<pthread_key_t>(ptr_key); | 681 return reinterpret_cast<pthread_key_t>(ptr_key); |
| 682 #else | 682 #else |
| 683 return static_cast<pthread_key_t>(local_key); | 683 return static_cast<pthread_key_t>(local_key); |
| 684 #endif | 684 #endif |
| 685 } | 685 } |
| 686 | 686 |
| 687 | 687 |
| 688 #ifdef V8_FAST_TLS_SUPPORTED | 688 #ifdef V8_FAST_TLS_SUPPORTED |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 778 |
| 779 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 779 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
| 780 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); | 780 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); |
| 781 int result = pthread_setspecific(pthread_key, value); | 781 int result = pthread_setspecific(pthread_key, value); |
| 782 ASSERT_EQ(0, result); | 782 ASSERT_EQ(0, result); |
| 783 USE(result); | 783 USE(result); |
| 784 } | 784 } |
| 785 | 785 |
| 786 | 786 |
| 787 } } // namespace v8::internal | 787 } } // namespace v8::internal |
| OLD | NEW |