Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: src/platform-macos.cc

Issue 13845014: Fix cctest/test-cpu-profiler/CollectCpuProfile test on Arm and MIPS simulators (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Updared OpenBSD Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include <stdlib.h> 53 #include <stdlib.h>
54 #include <string.h> 54 #include <string.h>
55 #include <errno.h> 55 #include <errno.h>
56 56
57 #undef MAP_TYPE 57 #undef MAP_TYPE
58 58
59 #include "v8.h" 59 #include "v8.h"
60 60
61 #include "platform-posix.h" 61 #include "platform-posix.h"
62 #include "platform.h" 62 #include "platform.h"
63 #include "simulator.h"
63 #include "vm-state-inl.h" 64 #include "vm-state-inl.h"
64 65
65 // Manually define these here as weak imports, rather than including execinfo.h. 66 // Manually define these here as weak imports, rather than including execinfo.h.
66 // This lets us launch on 10.4 which does not have these calls. 67 // This lets us launch on 10.4 which does not have these calls.
67 extern "C" { 68 extern "C" {
68 extern int backtrace(void**, int) __attribute__((weak_import)); 69 extern int backtrace(void**, int) __attribute__((weak_import));
69 extern char** backtrace_symbols(void* const*, int) 70 extern char** backtrace_symbols(void* const*, int)
70 __attribute__((weak_import)); 71 __attribute__((weak_import));
71 extern void backtrace_symbols_fd(void* const*, int, int) 72 extern void backtrace_symbols_fd(void* const*, int, int)
72 __attribute__((weak_import)); 73 __attribute__((weak_import));
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 738 }
738 739
739 740
740 Semaphore* OS::CreateSemaphore(int count) { 741 Semaphore* OS::CreateSemaphore(int count) {
741 return new MacOSSemaphore(count); 742 return new MacOSSemaphore(count);
742 } 743 }
743 744
744 745
745 class Sampler::PlatformData : public Malloced { 746 class Sampler::PlatformData : public Malloced {
746 public: 747 public:
747 PlatformData() : profiled_thread_(mach_thread_self()) {} 748 PlatformData()
749 : profiled_thread_(mach_thread_self()),
750 profiled_thread_id_(ThreadId::Current()) {}
748 751
749 ~PlatformData() { 752 ~PlatformData() {
750 // Deallocate Mach port for thread. 753 // Deallocate Mach port for thread.
751 mach_port_deallocate(mach_task_self(), profiled_thread_); 754 mach_port_deallocate(mach_task_self(), profiled_thread_);
752 } 755 }
753 756
754 thread_act_t profiled_thread() { return profiled_thread_; } 757 thread_act_t profiled_thread() { return profiled_thread_; }
758 ThreadId profiled_thread_id() { return profiled_thread_id_; }
755 759
756 private: 760 private:
757 // Note: for profiled_thread_ Mach primitives are used instead of PThread's 761 // Note: for profiled_thread_ Mach primitives are used instead of PThread's
758 // because the latter doesn't provide thread manipulation primitives required. 762 // because the latter doesn't provide thread manipulation primitives required.
759 // For details, consult "Mac OS X Internals" book, Section 7.3. 763 // For details, consult "Mac OS X Internals" book, Section 7.3.
760 thread_act_t profiled_thread_; 764 thread_act_t profiled_thread_;
765 ThreadId profiled_thread_id_;
761 }; 766 };
762 767
763 768
764 class SamplerThread : public Thread { 769 class SamplerThread : public Thread {
765 public: 770 public:
766 static const int kSamplerThreadStackSize = 64 * KB; 771 static const int kSamplerThreadStackSize = 64 * KB;
767 772
768 explicit SamplerThread(int interval) 773 explicit SamplerThread(int interval)
769 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), 774 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)),
770 interval_(interval) {} 775 interval_(interval) {}
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 if (!sampler->isolate()->IsInitialized()) return; 816 if (!sampler->isolate()->IsInitialized()) return;
812 if (!sampler->IsProfiling()) return; 817 if (!sampler->IsProfiling()) return;
813 SamplerThread* sampler_thread = 818 SamplerThread* sampler_thread =
814 reinterpret_cast<SamplerThread*>(raw_sampler_thread); 819 reinterpret_cast<SamplerThread*>(raw_sampler_thread);
815 sampler_thread->SampleContext(sampler); 820 sampler_thread->SampleContext(sampler);
816 } 821 }
817 822
818 void SampleContext(Sampler* sampler) { 823 void SampleContext(Sampler* sampler) {
819 thread_act_t profiled_thread = sampler->platform_data()->profiled_thread(); 824 thread_act_t profiled_thread = sampler->platform_data()->profiled_thread();
820 Isolate* isolate = sampler->isolate(); 825 Isolate* isolate = sampler->isolate();
826 #if defined(USE_SIMULATOR)
827 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS
828 ThreadId thread_id = sampler->platform_data()->profiled_thread_id();
829 Isolate::PerIsolateThreadData* per_thread_data = isolate->
830 FindPerThreadDataForThread(thread_id);
831 if (!per_thread_data) return;
832 Simulator* sim = per_thread_data->simulator();
833 // Check if there is active simulator before allocating TickSample.
834 if (!sim) return;
835 #endif
836 #endif // USE_SIMULATOR
821 TickSample sample_obj; 837 TickSample sample_obj;
822 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); 838 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
823 if (sample == NULL) sample = &sample_obj; 839 if (sample == NULL) sample = &sample_obj;
824 840
825 if (KERN_SUCCESS != thread_suspend(profiled_thread)) return; 841 if (KERN_SUCCESS != thread_suspend(profiled_thread)) return;
826 842
827 #if V8_HOST_ARCH_X64 843 #if V8_HOST_ARCH_X64
828 thread_state_flavor_t flavor = x86_THREAD_STATE64; 844 thread_state_flavor_t flavor = x86_THREAD_STATE64;
829 x86_thread_state64_t state; 845 x86_thread_state64_t state;
830 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT; 846 mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT;
(...skipping 13 matching lines...) Expand all
844 #endif // __DARWIN_UNIX03 860 #endif // __DARWIN_UNIX03
845 #else 861 #else
846 #error Unsupported Mac OS X host architecture. 862 #error Unsupported Mac OS X host architecture.
847 #endif // V8_HOST_ARCH 863 #endif // V8_HOST_ARCH
848 864
849 if (thread_get_state(profiled_thread, 865 if (thread_get_state(profiled_thread,
850 flavor, 866 flavor,
851 reinterpret_cast<natural_t*>(&state), 867 reinterpret_cast<natural_t*>(&state),
852 &count) == KERN_SUCCESS) { 868 &count) == KERN_SUCCESS) {
853 sample->state = isolate->current_vm_state(); 869 sample->state = isolate->current_vm_state();
870 #if defined(USE_SIMULATOR)
871 #if V8_TARGET_ARCH_ARM
872 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc));
873 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp));
874 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::r11));
875 #elif V8_TARGET_ARCH_MIPS
876 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc));
877 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp));
878 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::fp));
879 #endif
880 #else
854 sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip)); 881 sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip));
855 sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp)); 882 sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp));
856 sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp)); 883 sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp));
884 #endif // USE_SIMULATOR
857 sampler->SampleStack(sample); 885 sampler->SampleStack(sample);
858 sampler->Tick(sample); 886 sampler->Tick(sample);
859 } 887 }
860 thread_resume(profiled_thread); 888 thread_resume(profiled_thread);
861 } 889 }
862 890
863 const int interval_; 891 const int interval_;
864 892
865 // Protects the process wide state below. 893 // Protects the process wide state below.
866 static Mutex* mutex_; 894 static Mutex* mutex_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 944
917 945
918 void Sampler::Stop() { 946 void Sampler::Stop() {
919 ASSERT(IsActive()); 947 ASSERT(IsActive());
920 SamplerThread::RemoveActiveSampler(this); 948 SamplerThread::RemoveActiveSampler(this);
921 SetActive(false); 949 SetActive(false);
922 } 950 }
923 951
924 952
925 } } // namespace v8::internal 953 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698