| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include <signal.h> // sigemptyset(), etc | 47 #include <signal.h> // sigemptyset(), etc |
| 48 #include <sys/regset.h> | 48 #include <sys/regset.h> |
| 49 | 49 |
| 50 | 50 |
| 51 #undef MAP_TYPE | 51 #undef MAP_TYPE |
| 52 | 52 |
| 53 #include "v8.h" | 53 #include "v8.h" |
| 54 | 54 |
| 55 #include "platform-posix.h" | 55 #include "platform-posix.h" |
| 56 #include "platform.h" | 56 #include "platform.h" |
| 57 #include "simulator.h" |
| 57 #include "v8threads.h" | 58 #include "v8threads.h" |
| 58 #include "vm-state-inl.h" | 59 #include "vm-state-inl.h" |
| 59 | 60 |
| 60 | 61 |
| 61 // It seems there is a bug in some Solaris distributions (experienced in | 62 // It seems there is a bug in some Solaris distributions (experienced in |
| 62 // SunOS 5.10 Generic_141445-09) which make it difficult or impossible to | 63 // SunOS 5.10 Generic_141445-09) which make it difficult or impossible to |
| 63 // access signbit() despite the availability of other C99 math functions. | 64 // access signbit() despite the availability of other C99 math functions. |
| 64 #ifndef signbit | 65 #ifndef signbit |
| 65 // Test sign - usually defined in math.h | 66 // Test sign - usually defined in math.h |
| 66 int signbit(double x) { | 67 int signbit(double x) { |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 | 660 |
| 660 Semaphore* OS::CreateSemaphore(int count) { | 661 Semaphore* OS::CreateSemaphore(int count) { |
| 661 return new SolarisSemaphore(count); | 662 return new SolarisSemaphore(count); |
| 662 } | 663 } |
| 663 | 664 |
| 664 | 665 |
| 665 static pthread_t GetThreadID() { | 666 static pthread_t GetThreadID() { |
| 666 return pthread_self(); | 667 return pthread_self(); |
| 667 } | 668 } |
| 668 | 669 |
| 670 |
| 671 class Sampler::PlatformData : public Malloced { |
| 672 public: |
| 673 PlatformData() |
| 674 : vm_tid_(GetThreadID()), |
| 675 profiled_thread_id_(ThreadId::Current()) {} |
| 676 |
| 677 pthread_t vm_tid() const { return vm_tid_; } |
| 678 ThreadId profiled_thread_id() { return profiled_thread_id_; } |
| 679 |
| 680 private: |
| 681 pthread_t vm_tid_; |
| 682 ThreadId profiled_thread_id_; |
| 683 }; |
| 684 |
| 685 |
| 669 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { | 686 static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { |
| 670 USE(info); | 687 USE(info); |
| 671 if (signal != SIGPROF) return; | 688 if (signal != SIGPROF) return; |
| 672 Isolate* isolate = Isolate::UncheckedCurrent(); | 689 Isolate* isolate = Isolate::UncheckedCurrent(); |
| 673 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { | 690 if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) { |
| 674 // We require a fully initialized and entered isolate. | 691 // We require a fully initialized and entered isolate. |
| 675 return; | 692 return; |
| 676 } | 693 } |
| 677 if (v8::Locker::IsActive() && | 694 if (v8::Locker::IsActive() && |
| 678 !isolate->thread_manager()->IsLockedByCurrentThread()) { | 695 !isolate->thread_manager()->IsLockedByCurrentThread()) { |
| 679 return; | 696 return; |
| 680 } | 697 } |
| 681 | 698 |
| 682 Sampler* sampler = isolate->logger()->sampler(); | 699 Sampler* sampler = isolate->logger()->sampler(); |
| 683 if (sampler == NULL || !sampler->IsActive()) return; | 700 if (sampler == NULL || !sampler->IsActive()) return; |
| 684 | 701 |
| 685 TickSample sample_obj; | 702 TickSample sample_obj; |
| 686 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); | 703 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); |
| 687 if (sample == NULL) sample = &sample_obj; | 704 if (sample == NULL) sample = &sample_obj; |
| 688 | 705 |
| 706 #if defined(USE_SIMULATOR) |
| 707 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 708 ThreadId thread_id = sampler->platform_data()->profiled_thread_id(); |
| 709 Isolate::PerIsolateThreadData* per_thread_data = isolate-> |
| 710 FindPerThreadDataForThread(thread_id); |
| 711 if (!per_thread_data) return; |
| 712 Simulator* sim = per_thread_data->simulator(); |
| 713 // Check if there is active simulator before allocating TickSample. |
| 714 if (!sim) return; |
| 715 #endif |
| 716 #endif // USE_SIMULATOR |
| 717 |
| 689 // Extracting the sample from the context is extremely machine dependent. | 718 // Extracting the sample from the context is extremely machine dependent. |
| 690 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | 719 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); |
| 691 mcontext_t& mcontext = ucontext->uc_mcontext; | 720 mcontext_t& mcontext = ucontext->uc_mcontext; |
| 692 sample->state = isolate->current_vm_state(); | 721 sample->state = isolate->current_vm_state(); |
| 693 | 722 |
| 723 #if defined(USE_SIMULATOR) |
| 724 #if V8_TARGET_ARCH_ARM |
| 725 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
| 726 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
| 727 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::r11)); |
| 728 #elif V8_TARGET_ARCH_MIPS |
| 729 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
| 730 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
| 731 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::fp)); |
| 732 #endif |
| 733 #else |
| 694 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_PC]); | 734 sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_PC]); |
| 695 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_SP]); | 735 sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_SP]); |
| 696 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_FP]); | 736 sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_FP]); |
| 737 #endif // USE_SIMULATOR |
| 697 | 738 |
| 698 sampler->SampleStack(sample); | 739 sampler->SampleStack(sample); |
| 699 sampler->Tick(sample); | 740 sampler->Tick(sample); |
| 700 } | 741 } |
| 701 | 742 |
| 702 class Sampler::PlatformData : public Malloced { | |
| 703 public: | |
| 704 PlatformData() : vm_tid_(GetThreadID()) {} | |
| 705 | |
| 706 pthread_t vm_tid() const { return vm_tid_; } | |
| 707 | |
| 708 private: | |
| 709 pthread_t vm_tid_; | |
| 710 }; | |
| 711 | |
| 712 | 743 |
| 713 class SignalSender : public Thread { | 744 class SignalSender : public Thread { |
| 714 public: | 745 public: |
| 715 static const int kSignalSenderStackSize = 64 * KB; | 746 static const int kSignalSenderStackSize = 64 * KB; |
| 716 | 747 |
| 717 explicit SignalSender(int interval) | 748 explicit SignalSender(int interval) |
| 718 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), | 749 : Thread(Thread::Options("SignalSender", kSignalSenderStackSize)), |
| 719 interval_(interval) {} | 750 interval_(interval) {} |
| 720 | 751 |
| 721 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } | 752 static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 } | 897 } |
| 867 | 898 |
| 868 | 899 |
| 869 void Sampler::Stop() { | 900 void Sampler::Stop() { |
| 870 ASSERT(IsActive()); | 901 ASSERT(IsActive()); |
| 871 SignalSender::RemoveActiveSampler(this); | 902 SignalSender::RemoveActiveSampler(this); |
| 872 SetActive(false); | 903 SetActive(false); |
| 873 } | 904 } |
| 874 | 905 |
| 875 } } // namespace v8::internal | 906 } } // namespace v8::internal |
| OLD | NEW |