Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/sampler.h" | 5 #include "src/sampler.h" |
| 6 | 6 |
| 7 #if V8_OS_POSIX && !V8_OS_CYGWIN | 7 #if V8_OS_POSIX && !V8_OS_CYGWIN |
| 8 | 8 |
| 9 #define USE_SIGNALS | 9 #define USE_SIGNALS |
| 10 | 10 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 PlatformDataCommon() : profiled_thread_id_(ThreadId::Current()) {} | 166 PlatformDataCommon() : profiled_thread_id_(ThreadId::Current()) {} |
| 167 ThreadId profiled_thread_id() { return profiled_thread_id_; } | 167 ThreadId profiled_thread_id() { return profiled_thread_id_; } |
| 168 | 168 |
| 169 protected: | 169 protected: |
| 170 ~PlatformDataCommon() {} | 170 ~PlatformDataCommon() {} |
| 171 | 171 |
| 172 private: | 172 private: |
| 173 ThreadId profiled_thread_id_; | 173 ThreadId profiled_thread_id_; |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 | |
| 177 // Check if the code at specified address could potentially be a | |
| 178 // frame setup code. | |
| 179 bool IsNoFrameRegion(Address address) { | |
| 180 struct Pattern { | |
| 181 int bytes_count; | |
| 182 byte bytes[8]; | |
| 183 int offsets[4]; | |
| 184 }; | |
| 185 byte* pc = reinterpret_cast<byte*>(address); | |
| 186 static Pattern patterns[] = { | |
| 187 #if V8_HOST_ARCH_IA32 | |
| 188 // push %ebp | |
| 189 // mov %esp,%ebp | |
| 190 {3, {0x55, 0x89, 0xe5}, {0, 1, -1}}, | |
| 191 // pop %ebp | |
| 192 // ret N | |
| 193 {2, {0x5d, 0xc2}, {0, 1, -1}}, | |
| 194 // pop %ebp | |
| 195 // ret | |
| 196 {2, {0x5d, 0xc3}, {0, 1, -1}}, | |
| 197 #elif V8_HOST_ARCH_X64 | |
| 198 // pushq %rbp | |
| 199 // movq %rsp,%rbp | |
| 200 {4, {0x55, 0x48, 0x89, 0xe5}, {0, 1, -1}}, | |
| 201 // popq %rbp | |
| 202 // ret N | |
| 203 {2, {0x5d, 0xc2}, {0, 1, -1}}, | |
| 204 // popq %rbp | |
| 205 // ret | |
| 206 {2, {0x5d, 0xc3}, {0, 1, -1}}, | |
| 207 #endif | |
| 208 {0, {}, {}} | |
| 209 }; | |
| 210 for (Pattern* pattern = patterns; pattern->bytes_count; ++pattern) { | |
| 211 for (int* offset = pattern->offsets; *offset != -1; ++offset) { | |
| 212 if (!memcmp(pc - *offset, pattern->bytes, pattern->bytes_count)) | |
|
yurys
2015/09/16 14:42:01
what about the potential case that we discussed of
alph
2015/09/16 17:28:50
It should never happen for JS code, because of Cod
| |
| 213 return true; | |
| 214 } | |
| 215 } | |
| 216 return false; | |
| 217 } | |
| 218 | |
| 176 } // namespace | 219 } // namespace |
| 177 | 220 |
| 178 #if defined(USE_SIGNALS) | 221 #if defined(USE_SIGNALS) |
| 179 | 222 |
| 180 class Sampler::PlatformData : public PlatformDataCommon { | 223 class Sampler::PlatformData : public PlatformDataCommon { |
| 181 public: | 224 public: |
| 182 PlatformData() : vm_tid_(pthread_self()) {} | 225 PlatformData() : vm_tid_(pthread_self()) {} |
| 183 pthread_t vm_tid() const { return vm_tid_; } | 226 pthread_t vm_tid() const { return vm_tid_; } |
| 184 | 227 |
| 185 private: | 228 private: |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 timestamp = base::TimeTicks::HighResolutionNow(); | 628 timestamp = base::TimeTicks::HighResolutionNow(); |
| 586 pc = reinterpret_cast<Address>(regs.pc); | 629 pc = reinterpret_cast<Address>(regs.pc); |
| 587 state = isolate->current_vm_state(); | 630 state = isolate->current_vm_state(); |
| 588 | 631 |
| 589 // Avoid collecting traces while doing GC. | 632 // Avoid collecting traces while doing GC. |
| 590 if (state == GC) return; | 633 if (state == GC) return; |
| 591 | 634 |
| 592 Address js_entry_sp = isolate->js_entry_sp(); | 635 Address js_entry_sp = isolate->js_entry_sp(); |
| 593 if (js_entry_sp == 0) return; // Not executing JS now. | 636 if (js_entry_sp == 0) return; // Not executing JS now. |
| 594 | 637 |
| 638 if (pc && IsNoFrameRegion(pc)) { | |
| 639 pc = 0; | |
| 640 return; | |
| 641 } | |
| 642 | |
| 595 ExternalCallbackScope* scope = isolate->external_callback_scope(); | 643 ExternalCallbackScope* scope = isolate->external_callback_scope(); |
| 596 Address handler = Isolate::handler(isolate->thread_local_top()); | 644 Address handler = Isolate::handler(isolate->thread_local_top()); |
| 597 // If there is a handler on top of the external callback scope then | 645 // If there is a handler on top of the external callback scope then |
| 598 // we have already entrered JavaScript again and the external callback | 646 // we have already entrered JavaScript again and the external callback |
| 599 // is not the top function. | 647 // is not the top function. |
| 600 if (scope && scope->scope_address() < handler) { | 648 if (scope && scope->scope_address() < handler) { |
| 601 external_callback = scope->callback(); | 649 external_callback = scope->callback(); |
| 602 has_external_callback = true; | 650 has_external_callback = true; |
| 603 } else { | 651 } else { |
| 604 // Sample potential return address value for frameless invocation of | 652 // Sample potential return address value for frameless invocation of |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 768 SampleStack(state); | 816 SampleStack(state); |
| 769 } | 817 } |
| 770 ResumeThread(profiled_thread); | 818 ResumeThread(profiled_thread); |
| 771 } | 819 } |
| 772 | 820 |
| 773 #endif // USE_SIGNALS | 821 #endif // USE_SIGNALS |
| 774 | 822 |
| 775 | 823 |
| 776 } // namespace internal | 824 } // namespace internal |
| 777 } // namespace v8 | 825 } // namespace v8 |
| OLD | NEW |