| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return x < 0; | 74 return x < 0; |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 } // namespace std | 77 } // namespace std |
| 78 #endif // signbit | 78 #endif // signbit |
| 79 | 79 |
| 80 namespace v8 { | 80 namespace v8 { |
| 81 namespace internal { | 81 namespace internal { |
| 82 | 82 |
| 83 | 83 |
| 84 // 0 is never a valid thread id on Solaris since the main thread is 1 and | |
| 85 // subsequent have their ids incremented from there | |
| 86 static const pthread_t kNoThread = (pthread_t) 0; | |
| 87 | |
| 88 | |
| 89 double ceiling(double x) { | |
| 90 return ceil(x); | |
| 91 } | |
| 92 | |
| 93 | |
| 94 static Mutex* limit_mutex = NULL; | 84 static Mutex* limit_mutex = NULL; |
| 95 | 85 |
| 96 | 86 |
| 97 void OS::PostSetUp() { | |
| 98 POSIXPostSetUp(); | |
| 99 } | |
| 100 | |
| 101 | |
| 102 uint64_t OS::CpuFeaturesImpliedByPlatform() { | |
| 103 return 0; // Solaris runs on a lot of things. | |
| 104 } | |
| 105 | |
| 106 | |
| 107 int OS::ActivationFrameAlignment() { | |
| 108 // GCC generates code that requires 16 byte alignment such as movdqa. | |
| 109 return Max(STACK_ALIGN, 16); | |
| 110 } | |
| 111 | |
| 112 | |
| 113 const char* OS::LocalTimezone(double time) { | 87 const char* OS::LocalTimezone(double time) { |
| 114 if (std::isnan(time)) return ""; | 88 if (std::isnan(time)) return ""; |
| 115 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); | 89 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); |
| 116 struct tm* t = localtime(&tv); | 90 struct tm* t = localtime(&tv); |
| 117 if (NULL == t) return ""; | 91 if (NULL == t) return ""; |
| 118 return tzname[0]; // The location of the timezone string on Solaris. | 92 return tzname[0]; // The location of the timezone string on Solaris. |
| 119 } | 93 } |
| 120 | 94 |
| 121 | 95 |
| 122 double OS::LocalTimeOffset() { | 96 double OS::LocalTimeOffset() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 143 Max(highest_ever_allocated, | 117 Max(highest_ever_allocated, |
| 144 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); | 118 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); |
| 145 } | 119 } |
| 146 | 120 |
| 147 | 121 |
| 148 bool OS::IsOutsideAllocatedSpace(void* address) { | 122 bool OS::IsOutsideAllocatedSpace(void* address) { |
| 149 return address < lowest_ever_allocated || address >= highest_ever_allocated; | 123 return address < lowest_ever_allocated || address >= highest_ever_allocated; |
| 150 } | 124 } |
| 151 | 125 |
| 152 | 126 |
| 153 size_t OS::AllocateAlignment() { | |
| 154 return static_cast<size_t>(getpagesize()); | |
| 155 } | |
| 156 | |
| 157 | |
| 158 void* OS::Allocate(const size_t requested, | 127 void* OS::Allocate(const size_t requested, |
| 159 size_t* allocated, | 128 size_t* allocated, |
| 160 bool is_executable) { | 129 bool is_executable) { |
| 161 const size_t msize = RoundUp(requested, getpagesize()); | 130 const size_t msize = RoundUp(requested, getpagesize()); |
| 162 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); | 131 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); |
| 163 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); | 132 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); |
| 164 | 133 |
| 165 if (mbase == MAP_FAILED) { | 134 if (mbase == MAP_FAILED) { |
| 166 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed")); | 135 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed")); |
| 167 return NULL; | 136 return NULL; |
| 168 } | 137 } |
| 169 *allocated = msize; | 138 *allocated = msize; |
| 170 UpdateAllocatedSpaceLimits(mbase, msize); | 139 UpdateAllocatedSpaceLimits(mbase, msize); |
| 171 return mbase; | 140 return mbase; |
| 172 } | 141 } |
| 173 | 142 |
| 174 | 143 |
| 175 void OS::Free(void* address, const size_t size) { | |
| 176 // TODO(1240712): munmap has a return value which is ignored here. | |
| 177 int result = munmap(address, size); | |
| 178 USE(result); | |
| 179 ASSERT(result == 0); | |
| 180 } | |
| 181 | |
| 182 | |
| 183 void OS::Sleep(int milliseconds) { | |
| 184 useconds_t ms = static_cast<useconds_t>(milliseconds); | |
| 185 usleep(1000 * ms); | |
| 186 } | |
| 187 | |
| 188 | |
| 189 int OS::NumberOfCores() { | |
| 190 return sysconf(_SC_NPROCESSORS_ONLN); | |
| 191 } | |
| 192 | |
| 193 | |
| 194 void OS::Abort() { | |
| 195 // Redirect to std abort to signal abnormal program termination. | |
| 196 abort(); | |
| 197 } | |
| 198 | |
| 199 | |
| 200 void OS::DebugBreak() { | |
| 201 asm("int $3"); | |
| 202 } | |
| 203 | |
| 204 | |
| 205 void OS::DumpBacktrace() { | 144 void OS::DumpBacktrace() { |
| 206 // Currently unsupported. | 145 // Currently unsupported. |
| 207 } | 146 } |
| 208 | 147 |
| 209 | 148 |
| 210 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | 149 class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
| 211 public: | 150 public: |
| 212 PosixMemoryMappedFile(FILE* file, void* memory, int size) | 151 PosixMemoryMappedFile(FILE* file, void* memory, int size) |
| 213 : file_(file), memory_(memory), size_(size) { } | 152 : file_(file), memory_(memory), size_(size) { } |
| 214 virtual ~PosixMemoryMappedFile(); | 153 virtual ~PosixMemoryMappedFile(); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 return munmap(base, size) == 0; | 386 return munmap(base, size) == 0; |
| 448 } | 387 } |
| 449 | 388 |
| 450 | 389 |
| 451 bool VirtualMemory::HasLazyCommits() { | 390 bool VirtualMemory::HasLazyCommits() { |
| 452 // TODO(alph): implement for the platform. | 391 // TODO(alph): implement for the platform. |
| 453 return false; | 392 return false; |
| 454 } | 393 } |
| 455 | 394 |
| 456 | 395 |
| 457 class Thread::PlatformData : public Malloced { | |
| 458 public: | |
| 459 PlatformData() : thread_(kNoThread) { } | |
| 460 | |
| 461 pthread_t thread_; // Thread handle for pthread. | |
| 462 }; | |
| 463 | |
| 464 | |
| 465 Thread::Thread(const Options& options) | |
| 466 : data_(new PlatformData()), | |
| 467 stack_size_(options.stack_size()), | |
| 468 start_semaphore_(NULL) { | |
| 469 set_name(options.name()); | |
| 470 } | |
| 471 | |
| 472 | |
| 473 Thread::~Thread() { | |
| 474 delete data_; | |
| 475 } | |
| 476 | |
| 477 | |
| 478 static void* ThreadEntry(void* arg) { | |
| 479 Thread* thread = reinterpret_cast<Thread*>(arg); | |
| 480 // This is also initialized by the first argument to pthread_create() but we | |
| 481 // don't know which thread will run first (the original thread or the new | |
| 482 // one) so we initialize it here too. | |
| 483 thread->data()->thread_ = pthread_self(); | |
| 484 ASSERT(thread->data()->thread_ != kNoThread); | |
| 485 thread->NotifyStartedAndRun(); | |
| 486 return NULL; | |
| 487 } | |
| 488 | |
| 489 | |
| 490 void Thread::set_name(const char* name) { | |
| 491 strncpy(name_, name, sizeof(name_)); | |
| 492 name_[sizeof(name_) - 1] = '\0'; | |
| 493 } | |
| 494 | |
| 495 | |
| 496 void Thread::Start() { | |
| 497 pthread_attr_t attr; | |
| 498 if (stack_size_ > 0) { | |
| 499 pthread_attr_init(&attr); | |
| 500 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); | |
| 501 } | |
| 502 pthread_create(&data_->thread_, NULL, ThreadEntry, this); | |
| 503 ASSERT(data_->thread_ != kNoThread); | |
| 504 } | |
| 505 | |
| 506 | |
| 507 void Thread::Join() { | |
| 508 pthread_join(data_->thread_, NULL); | |
| 509 } | |
| 510 | |
| 511 | |
| 512 Thread::LocalStorageKey Thread::CreateThreadLocalKey() { | |
| 513 pthread_key_t key; | |
| 514 int result = pthread_key_create(&key, NULL); | |
| 515 USE(result); | |
| 516 ASSERT(result == 0); | |
| 517 return static_cast<LocalStorageKey>(key); | |
| 518 } | |
| 519 | |
| 520 | |
| 521 void Thread::DeleteThreadLocalKey(LocalStorageKey key) { | |
| 522 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); | |
| 523 int result = pthread_key_delete(pthread_key); | |
| 524 USE(result); | |
| 525 ASSERT(result == 0); | |
| 526 } | |
| 527 | |
| 528 | |
| 529 void* Thread::GetThreadLocal(LocalStorageKey key) { | |
| 530 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); | |
| 531 return pthread_getspecific(pthread_key); | |
| 532 } | |
| 533 | |
| 534 | |
| 535 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | |
| 536 pthread_key_t pthread_key = static_cast<pthread_key_t>(key); | |
| 537 pthread_setspecific(pthread_key, value); | |
| 538 } | |
| 539 | |
| 540 | |
| 541 class SolarisSemaphore : public Semaphore { | 396 class SolarisSemaphore : public Semaphore { |
| 542 public: | 397 public: |
| 543 explicit SolarisSemaphore(int count) { sem_init(&sem_, 0, count); } | 398 explicit SolarisSemaphore(int count) { sem_init(&sem_, 0, count); } |
| 544 virtual ~SolarisSemaphore() { sem_destroy(&sem_); } | 399 virtual ~SolarisSemaphore() { sem_destroy(&sem_); } |
| 545 | 400 |
| 546 virtual void Wait(); | 401 virtual void Wait(); |
| 547 virtual bool Wait(int timeout); | 402 virtual bool Wait(int timeout); |
| 548 virtual void Signal() { sem_post(&sem_); } | 403 virtual void Signal() { sem_post(&sem_); } |
| 549 private: | 404 private: |
| 550 sem_t sem_; | 405 sem_t sem_; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 limit_mutex = CreateMutex(); | 482 limit_mutex = CreateMutex(); |
| 628 } | 483 } |
| 629 | 484 |
| 630 | 485 |
| 631 void OS::TearDown() { | 486 void OS::TearDown() { |
| 632 delete limit_mutex; | 487 delete limit_mutex; |
| 633 } | 488 } |
| 634 | 489 |
| 635 | 490 |
| 636 } } // namespace v8::internal | 491 } } // namespace v8::internal |
| OLD | NEW |