Index: src/platform-macos.cc |
diff --git a/src/platform-macos.cc b/src/platform-macos.cc |
index 097691be07b01db92e0d1d4a581ced98be366521..6135cd13740f03bb15f62ddfb26e4c80ae83bea8 100644 |
--- a/src/platform-macos.cc |
+++ b/src/platform-macos.cc |
@@ -78,29 +78,10 @@ extern "C" { |
namespace v8 { |
namespace internal { |
-// 0 is never a valid thread id on MacOSX since a pthread_t is |
-// a pointer. |
-static const pthread_t kNoThread = (pthread_t) 0; |
- |
- |
-double ceiling(double x) { |
- // Correct Mac OS X Leopard 'ceil' behavior. |
- if (-1.0 < x && x < 0.0) { |
- return -0.0; |
- } else { |
- return ceil(x); |
- } |
-} |
- |
static Mutex* limit_mutex = NULL; |
-void OS::PostSetUp() { |
- POSIXPostSetUp(); |
-} |
- |
- |
// We keep the lowest and highest addresses mapped as a quick way of |
// determining that pointers are outside the heap (used mostly in assertions |
// and verification). The estimate is conservative, i.e., not all addresses in |
@@ -126,11 +107,6 @@ bool OS::IsOutsideAllocatedSpace(void* address) { |
} |
-size_t OS::AllocateAlignment() { |
- return getpagesize(); |
-} |
- |
- |
// Constants used for mmap. |
// kMmapFd is used to pass vm_alloc flags to tag the region with the user |
// defined tag 255 This helps identify V8-allocated regions in memory analysis |
@@ -160,35 +136,6 @@ void* OS::Allocate(const size_t requested, |
} |
-void OS::Free(void* address, const size_t size) { |
- // TODO(1240712): munmap has a return value which is ignored here. |
- int result = munmap(address, size); |
- USE(result); |
- ASSERT(result == 0); |
-} |
- |
- |
-void OS::Sleep(int milliseconds) { |
- usleep(1000 * milliseconds); |
-} |
- |
- |
-int OS::NumberOfCores() { |
- return sysconf(_SC_NPROCESSORS_ONLN); |
-} |
- |
- |
-void OS::Abort() { |
- // Redirect to std abort to signal abnormal program termination |
- abort(); |
-} |
- |
- |
-void OS::DebugBreak() { |
- asm("int $3"); |
-} |
- |
- |
void OS::DumpBacktrace() { |
// If weak link to execinfo lib has failed, ie because we are on 10.4, abort. |
if (backtrace == NULL) return; |
@@ -284,21 +231,6 @@ void OS::SignalCodeMovingGC() { |
} |
-uint64_t OS::CpuFeaturesImpliedByPlatform() { |
- // MacOSX requires all these to install so we can assume they are present. |
- // These constants are defined by the CPUid instructions. |
- const uint64_t one = 1; |
- return (one << SSE2) | (one << CMOV) | (one << RDTSC) | (one << CPUID); |
-} |
- |
- |
-int OS::ActivationFrameAlignment() { |
- // OS X activation frames must be 16 byte-aligned; see "Mac OS X ABI |
- // Function Call Guide". |
- return 16; |
-} |
- |
- |
const char* OS::LocalTimezone(double time) { |
if (std::isnan(time)) return ""; |
time_t tv = static_cast<time_t>(floor(time/msPerSecond)); |
@@ -460,177 +392,6 @@ bool VirtualMemory::HasLazyCommits() { |
} |
-class Thread::PlatformData : public Malloced { |
- public: |
- PlatformData() : thread_(kNoThread) {} |
- pthread_t thread_; // Thread handle for pthread. |
-}; |
- |
- |
-Thread::Thread(const Options& options) |
- : data_(new PlatformData), |
- stack_size_(options.stack_size()), |
- start_semaphore_(NULL) { |
- set_name(options.name()); |
-} |
- |
- |
-Thread::~Thread() { |
- delete data_; |
-} |
- |
- |
-static void SetThreadName(const char* name) { |
- // pthread_setname_np is only available in 10.6 or later, so test |
- // for it at runtime. |
- int (*dynamic_pthread_setname_np)(const char*); |
- *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = |
- dlsym(RTLD_DEFAULT, "pthread_setname_np"); |
- if (!dynamic_pthread_setname_np) |
- return; |
- |
- // Mac OS X does not expose the length limit of the name, so hardcode it. |
- static const int kMaxNameLength = 63; |
- USE(kMaxNameLength); |
- ASSERT(Thread::kMaxThreadNameLength <= kMaxNameLength); |
- dynamic_pthread_setname_np(name); |
-} |
- |
- |
-static void* ThreadEntry(void* arg) { |
- Thread* thread = reinterpret_cast<Thread*>(arg); |
- // This is also initialized by the first argument to pthread_create() but we |
- // don't know which thread will run first (the original thread or the new |
- // one) so we initialize it here too. |
- thread->data()->thread_ = pthread_self(); |
- SetThreadName(thread->name()); |
- ASSERT(thread->data()->thread_ != kNoThread); |
- thread->NotifyStartedAndRun(); |
- return NULL; |
-} |
- |
- |
-void Thread::set_name(const char* name) { |
- strncpy(name_, name, sizeof(name_)); |
- name_[sizeof(name_) - 1] = '\0'; |
-} |
- |
- |
-void Thread::Start() { |
- pthread_attr_t* attr_ptr = NULL; |
- pthread_attr_t attr; |
- if (stack_size_ > 0) { |
- pthread_attr_init(&attr); |
- pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); |
- attr_ptr = &attr; |
- } |
- pthread_create(&data_->thread_, attr_ptr, ThreadEntry, this); |
- ASSERT(data_->thread_ != kNoThread); |
-} |
- |
- |
-void Thread::Join() { |
- pthread_join(data_->thread_, NULL); |
-} |
- |
- |
-#ifdef V8_FAST_TLS_SUPPORTED |
- |
-static Atomic32 tls_base_offset_initialized = 0; |
-intptr_t kMacTlsBaseOffset = 0; |
- |
-// It's safe to do the initialization more that once, but it has to be |
-// done at least once. |
-static void InitializeTlsBaseOffset() { |
- const size_t kBufferSize = 128; |
- char buffer[kBufferSize]; |
- size_t buffer_size = kBufferSize; |
- int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; |
- if (sysctl(ctl_name, 2, buffer, &buffer_size, NULL, 0) != 0) { |
- V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); |
- } |
- // The buffer now contains a string of the form XX.YY.ZZ, where |
- // XX is the major kernel version component. |
- // Make sure the buffer is 0-terminated. |
- buffer[kBufferSize - 1] = '\0'; |
- char* period_pos = strchr(buffer, '.'); |
- *period_pos = '\0'; |
- int kernel_version_major = |
- static_cast<int>(strtol(buffer, NULL, 10)); // NOLINT |
- // The constants below are taken from pthreads.s from the XNU kernel |
- // sources archive at www.opensource.apple.com. |
- if (kernel_version_major < 11) { |
- // 8.x.x (Tiger), 9.x.x (Leopard), 10.x.x (Snow Leopard) have the |
- // same offsets. |
-#if V8_HOST_ARCH_IA32 |
- kMacTlsBaseOffset = 0x48; |
-#else |
- kMacTlsBaseOffset = 0x60; |
-#endif |
- } else { |
- // 11.x.x (Lion) changed the offset. |
- kMacTlsBaseOffset = 0; |
- } |
- |
- Release_Store(&tls_base_offset_initialized, 1); |
-} |
- |
- |
-static void CheckFastTls(Thread::LocalStorageKey key) { |
- void* expected = reinterpret_cast<void*>(0x1234CAFE); |
- Thread::SetThreadLocal(key, expected); |
- void* actual = Thread::GetExistingThreadLocal(key); |
- if (expected != actual) { |
- V8_Fatal(__FILE__, __LINE__, |
- "V8 failed to initialize fast TLS on current kernel"); |
- } |
- Thread::SetThreadLocal(key, NULL); |
-} |
- |
-#endif // V8_FAST_TLS_SUPPORTED |
- |
- |
-Thread::LocalStorageKey Thread::CreateThreadLocalKey() { |
-#ifdef V8_FAST_TLS_SUPPORTED |
- bool check_fast_tls = false; |
- if (tls_base_offset_initialized == 0) { |
- check_fast_tls = true; |
- InitializeTlsBaseOffset(); |
- } |
-#endif |
- pthread_key_t key; |
- int result = pthread_key_create(&key, NULL); |
- USE(result); |
- ASSERT(result == 0); |
- LocalStorageKey typed_key = static_cast<LocalStorageKey>(key); |
-#ifdef V8_FAST_TLS_SUPPORTED |
- // If we just initialized fast TLS support, make sure it works. |
- if (check_fast_tls) CheckFastTls(typed_key); |
-#endif |
- return typed_key; |
-} |
- |
- |
-void Thread::DeleteThreadLocalKey(LocalStorageKey key) { |
- pthread_key_t pthread_key = static_cast<pthread_key_t>(key); |
- int result = pthread_key_delete(pthread_key); |
- USE(result); |
- ASSERT(result == 0); |
-} |
- |
- |
-void* Thread::GetThreadLocal(LocalStorageKey key) { |
- pthread_key_t pthread_key = static_cast<pthread_key_t>(key); |
- return pthread_getspecific(pthread_key); |
-} |
- |
- |
-void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
- pthread_key_t pthread_key = static_cast<pthread_key_t>(key); |
- pthread_setspecific(pthread_key, value); |
-} |
- |
- |
class MacOSSemaphore : public Semaphore { |
public: |
explicit MacOSSemaphore(int count) { |