| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 | 150 |
| 151 void* OS::Allocate(const size_t requested, | 151 void* OS::Allocate(const size_t requested, |
| 152 size_t* allocated, | 152 size_t* allocated, |
| 153 bool executable) { | 153 bool executable) { |
| 154 const size_t msize = RoundUp(requested, getpagesize()); | 154 const size_t msize = RoundUp(requested, getpagesize()); |
| 155 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); | 155 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); |
| 156 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); | 156 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); |
| 157 | 157 |
| 158 if (mbase == MAP_FAILED) { | 158 if (mbase == MAP_FAILED) { |
| 159 LOG(StringEvent("OS::Allocate", "mmap failed")); | 159 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed")); |
| 160 return NULL; | 160 return NULL; |
| 161 } | 161 } |
| 162 *allocated = msize; | 162 *allocated = msize; |
| 163 UpdateAllocatedSpaceLimits(mbase, msize); | 163 UpdateAllocatedSpaceLimits(mbase, msize); |
| 164 return mbase; | 164 return mbase; |
| 165 } | 165 } |
| 166 | 166 |
| 167 | 167 |
| 168 void OS::Free(void* buf, const size_t length) { | 168 void OS::Free(void* buf, const size_t length) { |
| 169 // TODO(1240712): munmap has a return value which is ignored here. | 169 // TODO(1240712): munmap has a return value which is ignored here. |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 bool ThreadHandle::IsSelf() const { | 418 bool ThreadHandle::IsSelf() const { |
| 419 return pthread_equal(data_->thread_, pthread_self()); | 419 return pthread_equal(data_->thread_, pthread_self()); |
| 420 } | 420 } |
| 421 | 421 |
| 422 | 422 |
| 423 bool ThreadHandle::IsValid() const { | 423 bool ThreadHandle::IsValid() const { |
| 424 return data_->thread_ != kNoThread; | 424 return data_->thread_ != kNoThread; |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 428 Thread::Thread(Isolate* isolate) |
| 429 : ThreadHandle(ThreadHandle::INVALID), |
| 430 isolate_(isolate) { |
| 429 set_name("v8:<unknown>"); | 431 set_name("v8:<unknown>"); |
| 430 } | 432 } |
| 431 | 433 |
| 432 | 434 Thread::Thread(Isolate* isolate, const char* name) |
| 433 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { | 435 : ThreadHandle(ThreadHandle::INVALID), |
| 436 isolate_(isolate) { |
| 434 set_name(name); | 437 set_name(name); |
| 435 } | 438 } |
| 436 | 439 |
| 437 | 440 |
| 438 Thread::~Thread() { | 441 Thread::~Thread() { |
| 439 } | 442 } |
| 440 | 443 |
| 441 | 444 |
| 442 static void* ThreadEntry(void* arg) { | 445 static void* ThreadEntry(void* arg) { |
| 443 Thread* thread = reinterpret_cast<Thread*>(arg); | 446 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 444 // This is also initialized by the first argument to pthread_create() but we | 447 // This is also initialized by the first argument to pthread_create() but we |
| 445 // don't know which thread will run first (the original thread or the new | 448 // don't know which thread will run first (the original thread or the new |
| 446 // one) so we initialize it here too. | 449 // one) so we initialize it here too. |
| 447 thread->thread_handle_data()->thread_ = pthread_self(); | 450 thread->thread_handle_data()->thread_ = pthread_self(); |
| 448 ASSERT(thread->IsValid()); | 451 ASSERT(thread->IsValid()); |
| 452 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); |
| 449 thread->Run(); | 453 thread->Run(); |
| 450 return NULL; | 454 return NULL; |
| 451 } | 455 } |
| 452 | 456 |
| 453 | 457 |
| 454 void Thread::set_name(const char* name) { | 458 void Thread::set_name(const char* name) { |
| 455 strncpy(name_, name, sizeof(name_)); | 459 strncpy(name_, name, sizeof(name_)); |
| 456 name_[sizeof(name_) - 1] = '\0'; | 460 name_[sizeof(name_) - 1] = '\0'; |
| 457 } | 461 } |
| 458 | 462 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 | 715 |
| 712 | 716 |
| 713 static void* SenderEntry(void* arg) { | 717 static void* SenderEntry(void* arg) { |
| 714 Sampler::PlatformData* data = | 718 Sampler::PlatformData* data = |
| 715 reinterpret_cast<Sampler::PlatformData*>(arg); | 719 reinterpret_cast<Sampler::PlatformData*>(arg); |
| 716 data->SignalSender(); | 720 data->SignalSender(); |
| 717 return 0; | 721 return 0; |
| 718 } | 722 } |
| 719 | 723 |
| 720 | 724 |
| 721 Sampler::Sampler(int interval) | 725 Sampler::Sampler(Isolate* isolate, int interval) |
| 722 : interval_(interval), | 726 : isolate_(isolate), |
| 727 interval_(interval), |
| 723 profiling_(false), | 728 profiling_(false), |
| 724 active_(false), | 729 active_(false), |
| 725 samples_taken_(0) { | 730 samples_taken_(0) { |
| 726 data_ = new PlatformData(this); | 731 data_ = new PlatformData(this); |
| 727 } | 732 } |
| 728 | 733 |
| 729 | 734 |
| 730 Sampler::~Sampler() { | 735 Sampler::~Sampler() { |
| 731 delete data_; | 736 delete data_; |
| 732 } | 737 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 if (data_->signal_sender_launched_) { | 782 if (data_->signal_sender_launched_) { |
| 778 Top::WakeUpRuntimeProfilerThreadBeforeShutdown(); | 783 Top::WakeUpRuntimeProfilerThreadBeforeShutdown(); |
| 779 pthread_join(data_->signal_sender_thread_, NULL); | 784 pthread_join(data_->signal_sender_thread_, NULL); |
| 780 data_->signal_sender_launched_ = false; | 785 data_->signal_sender_launched_ = false; |
| 781 } | 786 } |
| 782 } | 787 } |
| 783 | 788 |
| 784 #endif // ENABLE_LOGGING_AND_PROFILING | 789 #endif // ENABLE_LOGGING_AND_PROFILING |
| 785 | 790 |
| 786 } } // namespace v8::internal | 791 } } // namespace v8::internal |
| OLD | NEW |