| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include <strings.h> // index | 46 #include <strings.h> // index |
| 47 #include <errno.h> | 47 #include <errno.h> |
| 48 #include <stdarg.h> | 48 #include <stdarg.h> |
| 49 | 49 |
| 50 #undef MAP_TYPE | 50 #undef MAP_TYPE |
| 51 | 51 |
| 52 #include "v8.h" | 52 #include "v8.h" |
| 53 | 53 |
| 54 #include "platform-posix.h" | 54 #include "platform-posix.h" |
| 55 #include "platform.h" | 55 #include "platform.h" |
| 56 #include "simulator.h" |
| 56 #include "v8threads.h" | 57 #include "v8threads.h" |
| 57 #include "vm-state-inl.h" | 58 #include "vm-state-inl.h" |
| 58 | 59 |
| 59 | 60 |
| 60 namespace v8 { | 61 namespace v8 { |
| 61 namespace internal { | 62 namespace internal { |
| 62 | 63 |
| 63 // 0 is never a valid thread id on Linux and OpenBSD since tids and pids share a | 64 // 0 is never a valid thread id on Linux and OpenBSD since tids and pids share a |
| 64 // name space and pid 0 is reserved (see man 2 kill). | 65 // name space and pid 0 is reserved (see man 2 kill). |
| 65 static const pthread_t kNoThread = (pthread_t) 0; | 66 static const pthread_t kNoThread = (pthread_t) 0; |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 | 726 |
| 726 Semaphore* OS::CreateSemaphore(int count) { | 727 Semaphore* OS::CreateSemaphore(int count) { |
| 727 return new OpenBSDSemaphore(count); | 728 return new OpenBSDSemaphore(count); |
| 728 } | 729 } |
| 729 | 730 |
| 730 | 731 |
| 731 static pthread_t GetThreadID() { | 732 static pthread_t GetThreadID() { |
| 732 return pthread_self(); | 733 return pthread_self(); |
| 733 } | 734 } |
| 734 | 735 |
| 736 |
| 737 class Sampler::PlatformData : public Malloced { |
| 738 public: |
| 739 PlatformData() |
| 740 : vm_tid_(GetThreadID()), |
| 741 profiled_thread_id_(ThreadId::Current()) {} |
| 742 |
| 743 pthread_t vm_tid() const { return vm_tid_; } |
| 744 ThreadId profiled_thread_id() { return profiled_thread_id_; } |
| 745 |
| 746 private: |
| 747 pthread_t vm_tid_; |
| 748 ThreadId profiled_thread_id_; |
| 749 }; |
| 750 |
| 751 |
| 735 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | 752 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { |
| 736 USE(info); | 753 USE(info); |
| 737 if (signal != SIGPROF) return; | 754 if (signal != SIGPROF) return; |
| 738 Isolate* isolate = Isolate::UncheckedCurrent(); | 755 Isolate* isolate = Isolate::UncheckedCurrent(); |
| 739 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { | 756 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { |
| 740 // We require a fully initialized and entered isolate. | 757 // We require a fully initialized and entered isolate. |
| 741 return; | 758 return; |
| 742 } | 759 } |
| 743 if (v8::Locker::IsActive() && | 760 if (v8::Locker::IsActive() && |
| 744 !isolate->thread_manager()->IsLockedByCurrentThread()) { | 761 !isolate->thread_manager()->IsLockedByCurrentThread()) { |
| 745 return; | 762 return; |
| 746 } | 763 } |
| 747 | 764 |
| 748 Sampler* sampler = isolate->logger()->sampler(); | 765 Sampler* sampler = isolate->logger()->sampler(); |
| 749 if (sampler == NULL || !sampler->IsActive()) return; | 766 if (sampler == NULL || !sampler->IsActive()) return; |
| 750 | 767 |
| 768 #if defined(USE_SIMULATOR) |
| 769 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 770 ThreadId thread_id = sampler->platform_data()->profiled_thread_id(); |
| 771 Isolate::PerIsolateThreadData* per_thread_data = isolate-> |
| 772 FindPerThreadDataForThread(thread_id); |
| 773 if (!per_thread_data) return; |
| 774 Simulator* sim = per_thread_data->simulator(); |
| 775 // Check if there is active simulator before allocating TickSample. |
| 776 if (!sim) return; |
| 777 #endif |
| 778 #endif // USE_SIMULATOR |
| 779 |
| 751 TickSample sample_obj; | 780 TickSample sample_obj; |
| 752 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); | 781 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); |
| 753 if (sample == NULL) sample = &sample_obj; | 782 if (sample == NULL) sample = &sample_obj; |
| 754 | 783 |
| 755 // Extracting the sample from the context is extremely machine dependent. | 784 // Extracting the sample from the context is extremely machine dependent. |
| 756 sample->state = isolate->current_vm_state(); | 785 sample->state = isolate->current_vm_state(); |
| 757 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | 786 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); |
| 787 #if defined(USE_SIMULATOR) |
| 788 #if V8_TARGET_ARCH_ARM |
| 789 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
| 790 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
| 791 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::r11)); |
| 792 #elif V8_TARGET_ARCH_MIPS |
| 793 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
| 794 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
| 795 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::fp)); |
| 796 #endif |
| 797 #else |
| 758 #ifdef __NetBSD__ | 798 #ifdef __NetBSD__ |
| 759 mcontext_t& mcontext = ucontext->uc_mcontext; | 799 mcontext_t& mcontext = ucontext->uc_mcontext; |
| 760 #if V8_HOST_ARCH_IA32 | 800 #if V8_HOST_ARCH_IA32 |
| 761 sample->pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_EIP]); | 801 sample->pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_EIP]); |
| 762 sample->sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_ESP]); | 802 sample->sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_ESP]); |
| 763 sample->fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_EBP]); | 803 sample->fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_EBP]); |
| 764 #elif V8_HOST_ARCH_X64 | 804 #elif V8_HOST_ARCH_X64 |
| 765 sample->pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_RIP]); | 805 sample->pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_RIP]); |
| 766 sample->sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RSP]); | 806 sample->sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RSP]); |
| 767 sample->fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RBP]); | 807 sample->fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RBP]); |
| 768 #endif // V8_HOST_ARCH | 808 #endif // V8_HOST_ARCH |
| 769 #else // OpenBSD | 809 #else // OpenBSD |
| 770 #if V8_HOST_ARCH_IA32 | 810 #if V8_HOST_ARCH_IA32 |
| 771 sample->pc = reinterpret_cast<Address>(ucontext->sc_eip); | 811 sample->pc = reinterpret_cast<Address>(ucontext->sc_eip); |
| 772 sample->sp = reinterpret_cast<Address>(ucontext->sc_esp); | 812 sample->sp = reinterpret_cast<Address>(ucontext->sc_esp); |
| 773 sample->fp = reinterpret_cast<Address>(ucontext->sc_ebp); | 813 sample->fp = reinterpret_cast<Address>(ucontext->sc_ebp); |
| 774 #elif V8_HOST_ARCH_X64 | 814 #elif V8_HOST_ARCH_X64 |
| 775 sample->pc = reinterpret_cast<Address>(ucontext->sc_rip); | 815 sample->pc = reinterpret_cast<Address>(ucontext->sc_rip); |
| 776 sample->sp = reinterpret_cast<Address>(ucontext->sc_rsp); | 816 sample->sp = reinterpret_cast<Address>(ucontext->sc_rsp); |
| 777 sample->fp = reinterpret_cast<Address>(ucontext->sc_rbp); | 817 sample->fp = reinterpret_cast<Address>(ucontext->sc_rbp); |
| 778 #endif // V8_HOST_ARCH | 818 #endif // V8_HOST_ARCH |
| 779 #endif // __NetBSD__ | 819 #endif // __NetBSD__ |
| 820 #endif // USE_SIMULATOR |
| 780 sampler->SampleStack(sample); | 821 sampler->SampleStack(sample); |
| 781 sampler->Tick(sample); | 822 sampler->Tick(sample); |
| 782 } | 823 } |
| 783 | 824 |
| 784 | 825 |
| 785 class Sampler::PlatformData : public Malloced { | |
| 786 public: | |
| 787 PlatformData() : vm_tid_(GetThreadID()) {} | |
| 788 | |
| 789 pthread_t vm_tid() const { return vm_tid_; } | |
| 790 | |
| 791 private: | |
| 792 pthread_t vm_tid_; | |
| 793 }; | |
| 794 | |
| 795 | |
| 796 class SignalSender : public Thread { | 826 class SignalSender : public Thread { |
| 797 public: | 827 public: |
| 798 static const int kSignalSenderStackSize = 64 * KB; | 828 static const int kSignalSenderStackSize = 64 * KB; |
| 799 | 829 |
| 800 explicit SignalSender(int interval) | 830 explicit SignalSender(int interval) |
| 801 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), | 831 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), |
| 802 vm_tgid_(getpid()), | 832 vm_tgid_(getpid()), |
| 803 interval_(interval) {} | 833 interval_(interval) {} |
| 804 | 834 |
| 805 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } | 835 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 | 979 |
| 950 | 980 |
| 951 void Sampler::Stop() { | 981 void Sampler::Stop() { |
| 952 ASSERT(IsActive()); | 982 ASSERT(IsActive()); |
| 953 SignalSender::RemoveActiveSampler(this); | 983 SignalSender::RemoveActiveSampler(this); |
| 954 SetActive(false); | 984 SetActive(false); |
| 955 } | 985 } |
| 956 | 986 |
| 957 | 987 |
| 958 } } // namespace v8::internal | 988 } } // namespace v8::internal |
| OLD | NEW |