| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 | 148 |
| 149 void* OS::Allocate(const size_t requested, | 149 void* OS::Allocate(const size_t requested, |
| 150 size_t* allocated, | 150 size_t* allocated, |
| 151 bool executable) { | 151 bool executable) { |
| 152 const size_t msize = RoundUp(requested, getpagesize()); | 152 const size_t msize = RoundUp(requested, getpagesize()); |
| 153 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); | 153 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); |
| 154 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); | 154 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); |
| 155 | 155 |
| 156 if (mbase == MAP_FAILED) { | 156 if (mbase == MAP_FAILED) { |
| 157 LOG(StringEvent("OS::Allocate", "mmap failed")); | 157 LOG(ISOLATE, StringEvent("OS::Allocate", "mmap failed")); |
| 158 return NULL; | 158 return NULL; |
| 159 } | 159 } |
| 160 *allocated = msize; | 160 *allocated = msize; |
| 161 UpdateAllocatedSpaceLimits(mbase, msize); | 161 UpdateAllocatedSpaceLimits(mbase, msize); |
| 162 return mbase; | 162 return mbase; |
| 163 } | 163 } |
| 164 | 164 |
| 165 | 165 |
| 166 void OS::Free(void* buf, const size_t length) { | 166 void OS::Free(void* buf, const size_t length) { |
| 167 int result = munmap(buf, length); | 167 int result = munmap(buf, length); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 bool ThreadHandle::IsSelf() const { | 393 bool ThreadHandle::IsSelf() const { |
| 394 return pthread_equal(data_->thread_, pthread_self()); | 394 return pthread_equal(data_->thread_, pthread_self()); |
| 395 } | 395 } |
| 396 | 396 |
| 397 | 397 |
| 398 bool ThreadHandle::IsValid() const { | 398 bool ThreadHandle::IsValid() const { |
| 399 return data_->thread_ != kNoThread; | 399 return data_->thread_ != kNoThread; |
| 400 } | 400 } |
| 401 | 401 |
| 402 | 402 |
| 403 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 403 Thread::Thread(Isolate* isolate) |
| 404 : ThreadHandle(ThreadHandle::INVALID), |
| 405 isolate_(isolate) { |
| 404 set_name("v8:<unknown>"); | 406 set_name("v8:<unknown>"); |
| 405 } | 407 } |
| 406 | 408 |
| 407 | 409 |
| 408 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { | 410 Thread::Thread(Isolate* isolate, const char* name) |
| 411 : ThreadHandle(ThreadHandle::INVALID), |
| 412 isolate_(isolate) { |
| 409 set_name(name); | 413 set_name(name); |
| 410 } | 414 } |
| 411 | 415 |
| 412 | 416 |
| 413 Thread::~Thread() { | 417 Thread::~Thread() { |
| 414 } | 418 } |
| 415 | 419 |
| 416 | 420 |
| 417 static void* ThreadEntry(void* arg) { | 421 static void* ThreadEntry(void* arg) { |
| 418 Thread* thread = reinterpret_cast<Thread*>(arg); | 422 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 419 // This is also initialized by the first argument to pthread_create() but we | 423 // This is also initialized by the first argument to pthread_create() but we |
| 420 // don't know which thread will run first (the original thread or the new | 424 // don't know which thread will run first (the original thread or the new |
| 421 // one) so we initialize it here too. | 425 // one) so we initialize it here too. |
| 422 thread->thread_handle_data()->thread_ = pthread_self(); | 426 thread->thread_handle_data()->thread_ = pthread_self(); |
| 423 ASSERT(thread->IsValid()); | 427 ASSERT(thread->IsValid()); |
| 428 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); |
| 424 thread->Run(); | 429 thread->Run(); |
| 425 return NULL; | 430 return NULL; |
| 426 } | 431 } |
| 427 | 432 |
| 428 | 433 |
| 429 void Thread::set_name(const char* name) { | 434 void Thread::set_name(const char* name) { |
| 430 strncpy(name_, name, sizeof(name_)); | 435 strncpy(name_, name, sizeof(name_)); |
| 431 name_[sizeof(name_) - 1] = '\0'; | 436 name_[sizeof(name_) - 1] = '\0'; |
| 432 } | 437 } |
| 433 | 438 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 PlatformData() { | 596 PlatformData() { |
| 592 signal_handler_installed_ = false; | 597 signal_handler_installed_ = false; |
| 593 } | 598 } |
| 594 | 599 |
| 595 bool signal_handler_installed_; | 600 bool signal_handler_installed_; |
| 596 struct sigaction old_signal_handler_; | 601 struct sigaction old_signal_handler_; |
| 597 struct itimerval old_timer_value_; | 602 struct itimerval old_timer_value_; |
| 598 }; | 603 }; |
| 599 | 604 |
| 600 | 605 |
| 601 Sampler::Sampler(int interval) | 606 Sampler::Sampler(Isolate* isolate, int interval) |
| 602 : interval_(interval), | 607 : isolate_(isolate), |
| 608 interval_(interval), |
| 603 profiling_(false), | 609 profiling_(false), |
| 604 active_(false), | 610 active_(false), |
| 605 samples_taken_(0) { | 611 samples_taken_(0) { |
| 606 data_ = new PlatformData(); | 612 data_ = new PlatformData(); |
| 607 } | 613 } |
| 608 | 614 |
| 609 | 615 |
| 610 Sampler::~Sampler() { | 616 Sampler::~Sampler() { |
| 611 delete data_; | 617 delete data_; |
| 612 } | 618 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 } | 654 } |
| 649 | 655 |
| 650 // This sampler is no longer the active sampler. | 656 // This sampler is no longer the active sampler. |
| 651 active_sampler_ = NULL; | 657 active_sampler_ = NULL; |
| 652 active_ = false; | 658 active_ = false; |
| 653 } | 659 } |
| 654 | 660 |
| 655 #endif // ENABLE_LOGGING_AND_PROFILING | 661 #endif // ENABLE_LOGGING_AND_PROFILING |
| 656 | 662 |
| 657 } } // namespace v8::internal | 663 } } // namespace v8::internal |
| OLD | NEW |