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 27 matching lines...) Expand all Loading... |
38 #endif // MINGW_HAS_SECURE_API | 38 #endif // MINGW_HAS_SECURE_API |
39 #endif // __MINGW32__ | 39 #endif // __MINGW32__ |
40 | 40 |
41 #define V8_WIN32_HEADERS_FULL | 41 #define V8_WIN32_HEADERS_FULL |
42 #include "win32-headers.h" | 42 #include "win32-headers.h" |
43 | 43 |
44 #include "v8.h" | 44 #include "v8.h" |
45 | 45 |
46 #include "codegen.h" | 46 #include "codegen.h" |
47 #include "platform.h" | 47 #include "platform.h" |
| 48 #include "simulator.h" |
48 #include "vm-state-inl.h" | 49 #include "vm-state-inl.h" |
49 | 50 |
50 #ifdef _MSC_VER | 51 #ifdef _MSC_VER |
51 | 52 |
52 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually | 53 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually |
53 // defined in strings.h. | 54 // defined in strings.h. |
54 int strncasecmp(const char* s1, const char* s2, int n) { | 55 int strncasecmp(const char* s1, const char* s2, int n) { |
55 return _strnicmp(s1, s2, n); | 56 return _strnicmp(s1, s2, n); |
56 } | 57 } |
57 | 58 |
(...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1974 // ---------------------------------------------------------------------------- | 1975 // ---------------------------------------------------------------------------- |
1975 // Win32 profiler support. | 1976 // Win32 profiler support. |
1976 | 1977 |
1977 class Sampler::PlatformData : public Malloced { | 1978 class Sampler::PlatformData : public Malloced { |
1978 public: | 1979 public: |
1979 // Get a handle to the calling thread. This is the thread that we are | 1980 // Get a handle to the calling thread. This is the thread that we are |
1980 // going to profile. We need to make a copy of the handle because we are | 1981 // going to profile. We need to make a copy of the handle because we are |
1981 // going to use it in the sampler thread. Using GetThreadHandle() will | 1982 // going to use it in the sampler thread. Using GetThreadHandle() will |
1982 // not work in this case. We're using OpenThread because DuplicateHandle | 1983 // not work in this case. We're using OpenThread because DuplicateHandle |
1983 // for some reason doesn't work in Chrome's sandbox. | 1984 // for some reason doesn't work in Chrome's sandbox. |
1984 PlatformData() : profiled_thread_(OpenThread(THREAD_GET_CONTEXT | | 1985 PlatformData() |
1985 THREAD_SUSPEND_RESUME | | 1986 : profiled_thread_(OpenThread(THREAD_GET_CONTEXT | |
1986 THREAD_QUERY_INFORMATION, | 1987 THREAD_SUSPEND_RESUME | |
1987 false, | 1988 THREAD_QUERY_INFORMATION, |
1988 GetCurrentThreadId())) {} | 1989 false, |
| 1990 GetCurrentThreadId())), |
| 1991 profiled_thread_id_(ThreadId::Current()) {} |
1989 | 1992 |
1990 ~PlatformData() { | 1993 ~PlatformData() { |
1991 if (profiled_thread_ != NULL) { | 1994 if (profiled_thread_ != NULL) { |
1992 CloseHandle(profiled_thread_); | 1995 CloseHandle(profiled_thread_); |
1993 profiled_thread_ = NULL; | 1996 profiled_thread_ = NULL; |
1994 } | 1997 } |
1995 } | 1998 } |
1996 | 1999 |
1997 HANDLE profiled_thread() { return profiled_thread_; } | 2000 HANDLE profiled_thread() { return profiled_thread_; } |
| 2001 ThreadId profiled_thread_id() { return profiled_thread_id_; } |
1998 | 2002 |
1999 private: | 2003 private: |
2000 HANDLE profiled_thread_; | 2004 HANDLE profiled_thread_; |
| 2005 ThreadId profiled_thread_id_; |
2001 }; | 2006 }; |
2002 | 2007 |
2003 | 2008 |
2004 class SamplerThread : public Thread { | 2009 class SamplerThread : public Thread { |
2005 public: | 2010 public: |
2006 static const int kSamplerThreadStackSize = 64 * KB; | 2011 static const int kSamplerThreadStackSize = 64 * KB; |
2007 | 2012 |
2008 explicit SamplerThread(int interval) | 2013 explicit SamplerThread(int interval) |
2009 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), | 2014 : Thread(Thread::Options("SamplerThread", kSamplerThreadStackSize)), |
2010 interval_(interval) {} | 2015 interval_(interval) {} |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2057 | 2062 |
2058 void SampleContext(Sampler* sampler) { | 2063 void SampleContext(Sampler* sampler) { |
2059 HANDLE profiled_thread = sampler->platform_data()->profiled_thread(); | 2064 HANDLE profiled_thread = sampler->platform_data()->profiled_thread(); |
2060 if (profiled_thread == NULL) return; | 2065 if (profiled_thread == NULL) return; |
2061 | 2066 |
2062 // Context used for sampling the register state of the profiled thread. | 2067 // Context used for sampling the register state of the profiled thread. |
2063 CONTEXT context; | 2068 CONTEXT context; |
2064 memset(&context, 0, sizeof(context)); | 2069 memset(&context, 0, sizeof(context)); |
2065 | 2070 |
2066 Isolate* isolate = sampler->isolate(); | 2071 Isolate* isolate = sampler->isolate(); |
| 2072 #if defined(USE_SIMULATOR) |
| 2073 #if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
| 2074 ThreadId thread_id = sampler->platform_data()->profiled_thread_id(); |
| 2075 Isolate::PerIsolateThreadData* per_thread_data = isolate-> |
| 2076 FindPerThreadDataForThread(thread_id); |
| 2077 if (!per_thread_data) return; |
| 2078 Simulator* sim = per_thread_data->simulator(); |
| 2079 // Check if there is active simulator before allocating TickSample. |
| 2080 if (!sim) return; |
| 2081 #endif |
| 2082 #endif // USE_SIMULATOR |
2067 TickSample sample_obj; | 2083 TickSample sample_obj; |
2068 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); | 2084 TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); |
2069 if (sample == NULL) sample = &sample_obj; | 2085 if (sample == NULL) sample = &sample_obj; |
2070 | 2086 |
2071 static const DWORD kSuspendFailed = static_cast<DWORD>(-1); | 2087 static const DWORD kSuspendFailed = static_cast<DWORD>(-1); |
2072 if (SuspendThread(profiled_thread) == kSuspendFailed) return; | 2088 if (SuspendThread(profiled_thread) == kSuspendFailed) return; |
2073 sample->state = isolate->current_vm_state(); | 2089 sample->state = isolate->current_vm_state(); |
2074 | 2090 |
2075 context.ContextFlags = CONTEXT_FULL; | 2091 context.ContextFlags = CONTEXT_FULL; |
2076 if (GetThreadContext(profiled_thread, &context) != 0) { | 2092 if (GetThreadContext(profiled_thread, &context) != 0) { |
| 2093 #if defined(USE_SIMULATOR) |
| 2094 #if V8_TARGET_ARCH_ARM |
| 2095 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
| 2096 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
| 2097 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::r11)); |
| 2098 #elif V8_TARGET_ARCH_MIPS |
| 2099 sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
| 2100 sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
| 2101 sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::fp)); |
| 2102 #endif |
| 2103 #else |
2077 #if V8_HOST_ARCH_X64 | 2104 #if V8_HOST_ARCH_X64 |
2078 sample->pc = reinterpret_cast<Address>(context.Rip); | 2105 sample->pc = reinterpret_cast<Address>(context.Rip); |
2079 sample->sp = reinterpret_cast<Address>(context.Rsp); | 2106 sample->sp = reinterpret_cast<Address>(context.Rsp); |
2080 sample->fp = reinterpret_cast<Address>(context.Rbp); | 2107 sample->fp = reinterpret_cast<Address>(context.Rbp); |
2081 #else | 2108 #else |
2082 sample->pc = reinterpret_cast<Address>(context.Eip); | 2109 sample->pc = reinterpret_cast<Address>(context.Eip); |
2083 sample->sp = reinterpret_cast<Address>(context.Esp); | 2110 sample->sp = reinterpret_cast<Address>(context.Esp); |
2084 sample->fp = reinterpret_cast<Address>(context.Ebp); | 2111 sample->fp = reinterpret_cast<Address>(context.Ebp); |
2085 #endif | 2112 #endif |
| 2113 #endif // USE_SIMULATOR |
2086 sampler->SampleStack(sample); | 2114 sampler->SampleStack(sample); |
2087 sampler->Tick(sample); | 2115 sampler->Tick(sample); |
2088 } | 2116 } |
2089 ResumeThread(profiled_thread); | 2117 ResumeThread(profiled_thread); |
2090 } | 2118 } |
2091 | 2119 |
2092 const int interval_; | 2120 const int interval_; |
2093 | 2121 |
2094 // Protects the process wide state below. | 2122 // Protects the process wide state below. |
2095 static Mutex* mutex_; | 2123 static Mutex* mutex_; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2147 | 2175 |
2148 | 2176 |
2149 void Sampler::Stop() { | 2177 void Sampler::Stop() { |
2150 ASSERT(IsActive()); | 2178 ASSERT(IsActive()); |
2151 SamplerThread::RemoveActiveSampler(this); | 2179 SamplerThread::RemoveActiveSampler(this); |
2152 SetActive(false); | 2180 SetActive(false); |
2153 } | 2181 } |
2154 | 2182 |
2155 | 2183 |
2156 } } // namespace v8::internal | 2184 } } // namespace v8::internal |
OLD | NEW |