| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/address_sanitizer.h" | 5 #include "platform/address_sanitizer.h" |
| 6 #include "platform/memory_sanitizer.h" | 6 #include "platform/memory_sanitizer.h" |
| 7 #include "platform/utils.h" | 7 #include "platform/utils.h" |
| 8 | 8 |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/atomic.h" | 10 #include "vm/atomic.h" |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 740 |
| 741 | 741 |
| 742 // Get |isolate|'s stack boundary and verify that |sp| and |fp| are within | 742 // Get |isolate|'s stack boundary and verify that |sp| and |fp| are within |
| 743 // it. Return |false| if anything looks suspicious. | 743 // it. Return |false| if anything looks suspicious. |
| 744 static bool GetAndValidateIsolateStackBounds(Thread* thread, | 744 static bool GetAndValidateIsolateStackBounds(Thread* thread, |
| 745 uintptr_t fp, | 745 uintptr_t fp, |
| 746 uintptr_t sp, | 746 uintptr_t sp, |
| 747 uword* stack_lower, | 747 uword* stack_lower, |
| 748 uword* stack_upper) { | 748 uword* stack_upper) { |
| 749 ASSERT(thread != NULL); | 749 ASSERT(thread != NULL); |
| 750 Isolate* isolate = thread->isolate(); | 750 OSThread* os_thread = thread->os_thread(); |
| 751 ASSERT(isolate != NULL); | 751 ASSERT(os_thread != NULL); |
| 752 ASSERT(stack_lower != NULL); | 752 ASSERT(stack_lower != NULL); |
| 753 ASSERT(stack_upper != NULL); | 753 ASSERT(stack_upper != NULL); |
| 754 #if defined(USING_SIMULATOR) | 754 #if defined(USING_SIMULATOR) |
| 755 const bool in_dart_code = thread->IsExecutingDartCode(); | 755 const bool in_dart_code = thread->IsExecutingDartCode(); |
| 756 if (in_dart_code) { | 756 if (in_dart_code) { |
| 757 Isolate* isolate = thread->isolate(); |
| 758 ASSERT(isolate != NULL); |
| 757 Simulator* simulator = isolate->simulator(); | 759 Simulator* simulator = isolate->simulator(); |
| 758 *stack_lower = simulator->StackBase(); | 760 *stack_lower = simulator->StackBase(); |
| 759 *stack_upper = simulator->StackTop(); | 761 *stack_upper = simulator->StackTop(); |
| 760 } else if (!isolate->GetProfilerStackBounds(stack_lower, stack_upper)) { | 762 } else if (!os_thread->GetProfilerStackBounds(stack_lower, stack_upper)) { |
| 761 // Could not get stack boundary. | 763 // Could not get stack boundary. |
| 762 return false; | 764 return false; |
| 763 } | 765 } |
| 764 if ((*stack_lower == 0) || (*stack_upper == 0)) { | 766 if ((*stack_lower == 0) || (*stack_upper == 0)) { |
| 765 return false; | 767 return false; |
| 766 } | 768 } |
| 767 #else | 769 #else |
| 768 if (!isolate->GetProfilerStackBounds(stack_lower, stack_upper) || | 770 if (!os_thread->GetProfilerStackBounds(stack_lower, stack_upper) || |
| 769 (*stack_lower == 0) || (*stack_upper == 0)) { | 771 (*stack_lower == 0) || (*stack_upper == 0)) { |
| 770 // Could not get stack boundary. | 772 // Could not get stack boundary. |
| 771 return false; | 773 return false; |
| 772 } | 774 } |
| 773 #endif | 775 #endif |
| 774 if (sp > *stack_lower) { | 776 if (sp > *stack_lower) { |
| 775 // The stack pointer gives us a tighter lower bound. | 777 // The stack pointer gives us a tighter lower bound. |
| 776 *stack_lower = sp; | 778 *stack_lower = sp; |
| 777 } | 779 } |
| 778 | 780 |
| 779 if (*stack_lower >= *stack_upper) { | 781 if (*stack_lower >= *stack_upper) { |
| 780 // Stack boundary is invalid. | 782 // Stack boundary is invalid. |
| 781 return false; | 783 return false; |
| 782 } | 784 } |
| 783 | 785 |
| 784 if ((sp < *stack_lower) || (sp >= *stack_upper)) { | 786 if ((sp < *stack_lower) || (sp >= *stack_upper)) { |
| 785 // Stack pointer is outside isolate stack boundary. | 787 // Stack pointer is outside thread's stack boundary. |
| 786 return false; | 788 return false; |
| 787 } | 789 } |
| 788 | 790 |
| 789 if ((fp < *stack_lower) || (fp >= *stack_upper)) { | 791 if ((fp < *stack_lower) || (fp >= *stack_upper)) { |
| 790 // Frame pointer is outside isolate stack boundary. | 792 // Frame pointer is outside threads's stack boundary. |
| 791 return false; | 793 return false; |
| 792 } | 794 } |
| 793 | 795 |
| 794 return true; | 796 return true; |
| 795 } | 797 } |
| 796 | 798 |
| 797 | 799 |
| 798 // Some simple sanity checking of |pc|, |fp|, and |sp|. | 800 // Some simple sanity checking of |pc|, |fp|, and |sp|. |
| 799 static bool InitialRegisterCheck(uintptr_t pc, uintptr_t fp, uintptr_t sp) { | 801 static bool InitialRegisterCheck(uintptr_t pc, uintptr_t fp, uintptr_t sp) { |
| 800 if ((sp == 0) || (fp == 0) || (pc == 0)) { | 802 if ((sp == 0) || (fp == 0) || (pc == 0)) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 } | 854 } |
| 853 #else | 855 #else |
| 854 static uintptr_t __attribute__((noinline)) GetProgramCounter() { | 856 static uintptr_t __attribute__((noinline)) GetProgramCounter() { |
| 855 return reinterpret_cast<uintptr_t>( | 857 return reinterpret_cast<uintptr_t>( |
| 856 __builtin_extract_return_addr(__builtin_return_address(0))); | 858 __builtin_extract_return_addr(__builtin_return_address(0))); |
| 857 } | 859 } |
| 858 #endif | 860 #endif |
| 859 | 861 |
| 860 void Profiler::SampleAllocation(Thread* thread, intptr_t cid) { | 862 void Profiler::SampleAllocation(Thread* thread, intptr_t cid) { |
| 861 ASSERT(thread != NULL); | 863 ASSERT(thread != NULL); |
| 864 OSThread* os_thread = thread->os_thread(); |
| 865 ASSERT(os_thread != NULL); |
| 862 Isolate* isolate = thread->isolate(); | 866 Isolate* isolate = thread->isolate(); |
| 863 if (!CheckIsolate(isolate)) { | 867 if (!CheckIsolate(isolate)) { |
| 864 return; | 868 return; |
| 865 } | 869 } |
| 866 | 870 |
| 867 const bool exited_dart_code = thread->HasExitedDartCode(); | 871 const bool exited_dart_code = thread->HasExitedDartCode(); |
| 868 | 872 |
| 869 SampleBuffer* sample_buffer = Profiler::sample_buffer(); | 873 SampleBuffer* sample_buffer = Profiler::sample_buffer(); |
| 870 if (sample_buffer == NULL) { | 874 if (sample_buffer == NULL) { |
| 871 // Profiler not initialized. | 875 // Profiler not initialized. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 888 | 892 |
| 889 if (!GetAndValidateIsolateStackBounds(thread, | 893 if (!GetAndValidateIsolateStackBounds(thread, |
| 890 fp, | 894 fp, |
| 891 sp, | 895 sp, |
| 892 &stack_lower, | 896 &stack_lower, |
| 893 &stack_upper)) { | 897 &stack_upper)) { |
| 894 // Could not get stack boundary. | 898 // Could not get stack boundary. |
| 895 return; | 899 return; |
| 896 } | 900 } |
| 897 | 901 |
| 898 Sample* sample = SetupSample(thread, | 902 Sample* sample = SetupSample(thread, sample_buffer, os_thread->id()); |
| 899 sample_buffer, | |
| 900 OSThread::GetCurrentThreadId()); | |
| 901 sample->SetAllocationCid(cid); | 903 sample->SetAllocationCid(cid); |
| 902 ProfilerNativeStackWalker native_stack_walker(isolate, | 904 ProfilerNativeStackWalker native_stack_walker(isolate, |
| 903 sample, | 905 sample, |
| 904 sample_buffer, | 906 sample_buffer, |
| 905 stack_lower, | 907 stack_lower, |
| 906 stack_upper, | 908 stack_upper, |
| 907 pc, | 909 pc, |
| 908 fp, | 910 fp, |
| 909 sp); | 911 sp); |
| 910 native_stack_walker.walk(); | 912 native_stack_walker.walk(); |
| 911 } else if (exited_dart_code) { | 913 } else if (exited_dart_code) { |
| 912 Sample* sample = SetupSample(thread, | 914 Sample* sample = SetupSample(thread, sample_buffer, os_thread->id()); |
| 913 sample_buffer, | |
| 914 OSThread::GetCurrentThreadId()); | |
| 915 sample->SetAllocationCid(cid); | 915 sample->SetAllocationCid(cid); |
| 916 ProfilerDartExitStackWalker dart_exit_stack_walker(thread, | 916 ProfilerDartExitStackWalker dart_exit_stack_walker(thread, |
| 917 isolate, | 917 isolate, |
| 918 sample, | 918 sample, |
| 919 sample_buffer); | 919 sample_buffer); |
| 920 dart_exit_stack_walker.walk(); | 920 dart_exit_stack_walker.walk(); |
| 921 } else { | 921 } else { |
| 922 // Fall back. | 922 // Fall back. |
| 923 uintptr_t pc = GetProgramCounter(); | 923 uintptr_t pc = GetProgramCounter(); |
| 924 Sample* sample = SetupSample(thread, | 924 Sample* sample = SetupSample(thread, sample_buffer, os_thread->id()); |
| 925 sample_buffer, | |
| 926 OSThread::GetCurrentThreadId()); | |
| 927 sample->SetAllocationCid(cid); | 925 sample->SetAllocationCid(cid); |
| 928 sample->set_vm_tag(VMTag::kEmbedderTagId); | 926 sample->set_vm_tag(VMTag::kEmbedderTagId); |
| 929 sample->SetAt(0, pc); | 927 sample->SetAt(0, pc); |
| 930 } | 928 } |
| 931 } | 929 } |
| 932 | 930 |
| 933 | 931 |
| 934 void Profiler::SampleThread(Thread* thread, | 932 void Profiler::SampleThread(Thread* thread, |
| 935 const InterruptedThreadState& state) { | 933 const InterruptedThreadState& state) { |
| 936 ASSERT(thread != NULL); | 934 ASSERT(thread != NULL); |
| 935 OSThread* os_thread = thread->os_thread(); |
| 936 ASSERT(os_thread != NULL); |
| 937 Isolate* isolate = thread->isolate(); | 937 Isolate* isolate = thread->isolate(); |
| 938 | 938 |
| 939 if (StubCode::HasBeenInitialized() && | 939 if (StubCode::HasBeenInitialized() && |
| 940 StubCode::InJumpToExceptionHandlerStub(state.pc)) { | 940 StubCode::InJumpToExceptionHandlerStub(state.pc)) { |
| 941 // The JumpToExceptionHandler stub manually adjusts the stack pointer, | 941 // The JumpToExceptionHandler stub manually adjusts the stack pointer, |
| 942 // frame pointer, and some isolate state before jumping to a catch entry. | 942 // frame pointer, and some isolate state before jumping to a catch entry. |
| 943 // It is not safe to walk the stack when executing this stub. | 943 // It is not safe to walk the stack when executing this stub. |
| 944 return; | 944 return; |
| 945 } | 945 } |
| 946 | 946 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 995 |
| 996 // At this point we have a valid stack boundary for this isolate and | 996 // At this point we have a valid stack boundary for this isolate and |
| 997 // know that our initial stack and frame pointers are within the boundary. | 997 // know that our initial stack and frame pointers are within the boundary. |
| 998 SampleBuffer* sample_buffer = Profiler::sample_buffer(); | 998 SampleBuffer* sample_buffer = Profiler::sample_buffer(); |
| 999 if (sample_buffer == NULL) { | 999 if (sample_buffer == NULL) { |
| 1000 // Profiler not initialized. | 1000 // Profiler not initialized. |
| 1001 return; | 1001 return; |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 // Setup sample. | 1004 // Setup sample. |
| 1005 Sample* sample = SetupSample(thread, | 1005 Sample* sample = SetupSample(thread, sample_buffer, os_thread->id()); |
| 1006 sample_buffer, | |
| 1007 OSThread::GetCurrentThreadId()); | |
| 1008 // Increment counter for vm tag. | 1006 // Increment counter for vm tag. |
| 1009 VMTagCounters* counters = isolate->vm_tag_counters(); | 1007 VMTagCounters* counters = isolate->vm_tag_counters(); |
| 1010 ASSERT(counters != NULL); | 1008 ASSERT(counters != NULL); |
| 1011 counters->Increment(sample->vm_tag()); | 1009 counters->Increment(sample->vm_tag()); |
| 1012 | 1010 |
| 1013 ProfilerNativeStackWalker native_stack_walker(isolate, | 1011 ProfilerNativeStackWalker native_stack_walker(isolate, |
| 1014 sample, | 1012 sample, |
| 1015 sample_buffer, | 1013 sample_buffer, |
| 1016 stack_lower, | 1014 stack_lower, |
| 1017 stack_upper, | 1015 stack_upper, |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 } | 1363 } |
| 1366 } | 1364 } |
| 1367 | 1365 |
| 1368 | 1366 |
| 1369 ProcessedSampleBuffer::ProcessedSampleBuffer() | 1367 ProcessedSampleBuffer::ProcessedSampleBuffer() |
| 1370 : code_lookup_table_(new CodeLookupTable(Thread::Current())) { | 1368 : code_lookup_table_(new CodeLookupTable(Thread::Current())) { |
| 1371 ASSERT(code_lookup_table_ != NULL); | 1369 ASSERT(code_lookup_table_ != NULL); |
| 1372 } | 1370 } |
| 1373 | 1371 |
| 1374 } // namespace dart | 1372 } // namespace dart |
| OLD | NEW |