| 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 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Platform specific code for MacOS goes here. For the POSIX comaptible parts | 28 // Platform specific code for MacOS goes here. For the POSIX comaptible parts |
| 29 // the implementation is in platform-posix.cc. | 29 // the implementation is in platform-posix.cc. |
| 30 | 30 |
| 31 #include <dlfcn.h> |
| 31 #include <unistd.h> | 32 #include <unistd.h> |
| 32 #include <sys/mman.h> | 33 #include <sys/mman.h> |
| 33 #include <mach/mach_init.h> | 34 #include <mach/mach_init.h> |
| 34 #include <mach-o/dyld.h> | 35 #include <mach-o/dyld.h> |
| 35 #include <mach-o/getsect.h> | 36 #include <mach-o/getsect.h> |
| 36 | 37 |
| 37 #include <AvailabilityMacros.h> | 38 #include <AvailabilityMacros.h> |
| 38 | 39 |
| 39 #include <pthread.h> | 40 #include <pthread.h> |
| 40 #include <semaphore.h> | 41 #include <semaphore.h> |
| 41 #include <signal.h> | 42 #include <signal.h> |
| 42 #include <libkern/OSAtomic.h> | 43 #include <libkern/OSAtomic.h> |
| 43 #include <mach/mach.h> | 44 #include <mach/mach.h> |
| 44 #include <mach/semaphore.h> | 45 #include <mach/semaphore.h> |
| 45 #include <mach/task.h> | 46 #include <mach/task.h> |
| 46 #include <mach/vm_statistics.h> | 47 #include <mach/vm_statistics.h> |
| 47 #include <sys/time.h> | 48 #include <sys/time.h> |
| 48 #include <sys/resource.h> | 49 #include <sys/resource.h> |
| 49 #include <sys/types.h> | 50 #include <sys/types.h> |
| 50 #include <stdarg.h> | 51 #include <stdarg.h> |
| 51 #include <stdlib.h> | 52 #include <stdlib.h> |
| 52 | |
| 53 #include <errno.h> | 53 #include <errno.h> |
| 54 | 54 |
| 55 #undef MAP_TYPE | 55 #undef MAP_TYPE |
| 56 | 56 |
| 57 #include "v8.h" | 57 #include "v8.h" |
| 58 | 58 |
| 59 #include "platform.h" | 59 #include "platform.h" |
| 60 #include "vm-state-inl.h" | 60 #include "vm-state-inl.h" |
| 61 | 61 |
| 62 // Manually define these here as weak imports, rather than including execinfo.h. | 62 // Manually define these here as weak imports, rather than including execinfo.h. |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 return pthread_equal(data_->thread_, pthread_self()); | 404 return pthread_equal(data_->thread_, pthread_self()); |
| 405 } | 405 } |
| 406 | 406 |
| 407 | 407 |
| 408 bool ThreadHandle::IsValid() const { | 408 bool ThreadHandle::IsValid() const { |
| 409 return data_->thread_ != kNoThread; | 409 return data_->thread_ != kNoThread; |
| 410 } | 410 } |
| 411 | 411 |
| 412 | 412 |
| 413 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { | 413 Thread::Thread() : ThreadHandle(ThreadHandle::INVALID) { |
| 414 set_name("v8:<unknown>"); |
| 415 } |
| 416 |
| 417 |
| 418 Thread::Thread(const char* name) : ThreadHandle(ThreadHandle::INVALID) { |
| 419 set_name(name); |
| 414 } | 420 } |
| 415 | 421 |
| 416 | 422 |
| 417 Thread::~Thread() { | 423 Thread::~Thread() { |
| 418 } | 424 } |
| 419 | 425 |
| 420 | 426 |
| 427 |
| 428 static void SetThreadName(const char* name) { |
| 429 // pthread_setname_np is only available in 10.6 or later, so test |
| 430 // for it at runtime. |
| 431 int (*dynamic_pthread_setname_np)(const char*); |
| 432 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = |
| 433 dlsym(RTLD_DEFAULT, "pthread_setname_np"); |
| 434 if (!dynamic_pthread_setname_np) |
| 435 return; |
| 436 |
| 437 // Mac OS X does not expose the length limit of the name, so hardcode it. |
| 438 static const int kMaxNameLength = 63; |
| 439 USE(kMaxNameLength); |
| 440 ASSERT(Thread::kMaxThreadNameLength <= kMaxNameLength); |
| 441 dynamic_pthread_setname_np(name); |
| 442 } |
| 443 |
| 444 |
| 421 static void* ThreadEntry(void* arg) { | 445 static void* ThreadEntry(void* arg) { |
| 422 Thread* thread = reinterpret_cast<Thread*>(arg); | 446 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 423 // 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 |
| 424 // 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 |
| 425 // one) so we initialize it here too. | 449 // one) so we initialize it here too. |
| 426 thread->thread_handle_data()->thread_ = pthread_self(); | 450 thread->thread_handle_data()->thread_ = pthread_self(); |
| 451 SetThreadName(thread->name()); |
| 427 ASSERT(thread->IsValid()); | 452 ASSERT(thread->IsValid()); |
| 428 thread->Run(); | 453 thread->Run(); |
| 429 return NULL; | 454 return NULL; |
| 430 } | 455 } |
| 431 | 456 |
| 432 | 457 |
| 458 void Thread::set_name(const char* name) { |
| 459 strncpy(name_, name, sizeof(name_)); |
| 460 name_[sizeof(name_) - 1] = '\0'; |
| 461 } |
| 462 |
| 463 |
| 433 void Thread::Start() { | 464 void Thread::Start() { |
| 434 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); | 465 pthread_create(&thread_handle_data()->thread_, NULL, ThreadEntry, this); |
| 435 } | 466 } |
| 436 | 467 |
| 437 | 468 |
| 438 void Thread::Join() { | 469 void Thread::Join() { |
| 439 pthread_join(thread_handle_data()->thread_, NULL); | 470 pthread_join(thread_handle_data()->thread_, NULL); |
| 440 } | 471 } |
| 441 | 472 |
| 442 | 473 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 Top::WakeUpRuntimeProfilerThreadBeforeShutdown(); | 709 Top::WakeUpRuntimeProfilerThreadBeforeShutdown(); |
| 679 pthread_join(data_->sampler_thread_, NULL); | 710 pthread_join(data_->sampler_thread_, NULL); |
| 680 | 711 |
| 681 // Deallocate Mach port for thread. | 712 // Deallocate Mach port for thread. |
| 682 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); | 713 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); |
| 683 } | 714 } |
| 684 | 715 |
| 685 #endif // ENABLE_LOGGING_AND_PROFILING | 716 #endif // ENABLE_LOGGING_AND_PROFILING |
| 686 | 717 |
| 687 } } // namespace v8::internal | 718 } } // namespace v8::internal |
| OLD | NEW |