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 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 ASSERT(isolate != Dart::vm_isolate()); | 947 ASSERT(isolate != Dart::vm_isolate()); |
948 | 948 |
949 const bool exited_dart_code = (isolate->stub_code() != NULL) && | 949 const bool exited_dart_code = (isolate->stub_code() != NULL) && |
950 (isolate->top_exit_frame_info() != 0) && | 950 (isolate->top_exit_frame_info() != 0) && |
951 (isolate->vm_tag() != VMTag::kDartTagId); | 951 (isolate->vm_tag() != VMTag::kDartTagId); |
952 const bool in_dart_code = (isolate->stub_code() != NULL) && | 952 const bool in_dart_code = (isolate->stub_code() != NULL) && |
953 (isolate->top_exit_frame_info() == 0) && | 953 (isolate->top_exit_frame_info() == 0) && |
954 (isolate->vm_tag() == VMTag::kDartTagId); | 954 (isolate->vm_tag() == VMTag::kDartTagId); |
955 | 955 |
956 uintptr_t sp = 0; | 956 uintptr_t sp = 0; |
| 957 uintptr_t fp = state.fp; |
| 958 uintptr_t pc = state.pc; |
| 959 uintptr_t lr = state.lr; |
| 960 #if defined(USING_SIMULATOR) |
| 961 Simulator* simulator = NULL; |
| 962 #endif |
957 | 963 |
958 if (in_dart_code) { | 964 if (in_dart_code) { |
959 // If we're in Dart code, use the Dart stack pointer. | 965 // If we're in Dart code, use the Dart stack pointer. |
| 966 #if defined(USING_SIMULATOR) |
| 967 simulator = isolate->simulator(); |
| 968 sp = simulator->get_register(SPREG); |
| 969 fp = simulator->get_register(FPREG); |
| 970 pc = simulator->get_pc(); |
| 971 lr = simulator->get_register(LRREG); |
| 972 #else |
960 sp = state.dsp; | 973 sp = state.dsp; |
| 974 #endif |
961 } else { | 975 } else { |
962 // If we're in runtime code, use the C stack pointer. | 976 // If we're in runtime code, use the C stack pointer. |
963 sp = state.csp; | 977 sp = state.csp; |
964 } | 978 } |
965 | 979 |
966 IsolateProfilerData* profiler_data = isolate->profiler_data(); | 980 IsolateProfilerData* profiler_data = isolate->profiler_data(); |
967 if (profiler_data == NULL) { | 981 if (profiler_data == NULL) { |
968 // Profiler not initialized. | 982 // Profiler not initialized. |
969 return; | 983 return; |
970 } | 984 } |
971 | 985 |
972 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); | 986 SampleBuffer* sample_buffer = profiler_data->sample_buffer(); |
973 if (sample_buffer == NULL) { | 987 if (sample_buffer == NULL) { |
974 // Profiler not initialized. | 988 // Profiler not initialized. |
975 return; | 989 return; |
976 } | 990 } |
977 | 991 |
978 if ((sp == 0) || (state.fp == 0) || (state.pc == 0)) { | 992 if ((sp == 0) || (fp == 0) || (pc == 0)) { |
979 // None of these registers should be zero. | 993 // None of these registers should be zero. |
980 return; | 994 return; |
981 } | 995 } |
982 | 996 |
983 if (sp > state.fp) { | 997 if (sp > fp) { |
984 // Assuming the stack grows down, we should never have a stack pointer above | 998 // Assuming the stack grows down, we should never have a stack pointer above |
985 // the frame pointer. | 999 // the frame pointer. |
986 return; | 1000 return; |
987 } | 1001 } |
988 | 1002 |
989 if (StubCode::InJumpToExceptionHandlerStub(state.pc)) { | 1003 if (StubCode::InJumpToExceptionHandlerStub(pc)) { |
990 // The JumpToExceptionHandler stub manually adjusts the stack pointer, | 1004 // The JumpToExceptionHandler stub manually adjusts the stack pointer, |
991 // frame pointer, and some isolate state before jumping to a catch entry. | 1005 // frame pointer, and some isolate state before jumping to a catch entry. |
992 // It is not safe to walk the stack when executing this stub. | 1006 // It is not safe to walk the stack when executing this stub. |
993 return; | 1007 return; |
994 } | 1008 } |
995 | 1009 |
996 uword stack_lower = 0; | 1010 uword stack_lower = 0; |
997 uword stack_upper = 0; | 1011 uword stack_upper = 0; |
| 1012 #if defined(USING_SIMULATOR) |
| 1013 if (in_dart_code) { |
| 1014 stack_lower = simulator->StackBase(); |
| 1015 stack_upper = simulator->StackTop(); |
| 1016 } else if (!isolate->GetProfilerStackBounds(&stack_lower, &stack_upper)) { |
| 1017 // Could not get stack boundary. |
| 1018 return; |
| 1019 } |
| 1020 if ((stack_lower == 0) || (stack_upper == 0)) { |
| 1021 return; |
| 1022 } |
| 1023 #else |
998 if (!isolate->GetProfilerStackBounds(&stack_lower, &stack_upper) || | 1024 if (!isolate->GetProfilerStackBounds(&stack_lower, &stack_upper) || |
999 (stack_lower == 0) || (stack_upper == 0)) { | 1025 (stack_lower == 0) || (stack_upper == 0)) { |
1000 // Could not get stack boundary. | 1026 // Could not get stack boundary. |
1001 return; | 1027 return; |
1002 } | 1028 } |
| 1029 #endif |
1003 | 1030 |
1004 if (sp > stack_lower) { | 1031 if (sp > stack_lower) { |
1005 // The stack pointer gives us a tighter lower bound. | 1032 // The stack pointer gives us a tighter lower bound. |
1006 stack_lower = sp; | 1033 stack_lower = sp; |
1007 } | 1034 } |
1008 | 1035 |
1009 if (stack_lower >= stack_upper) { | 1036 if (stack_lower >= stack_upper) { |
1010 // Stack boundary is invalid. | 1037 // Stack boundary is invalid. |
1011 return; | 1038 return; |
1012 } | 1039 } |
1013 | 1040 |
1014 if ((sp < stack_lower) || (sp >= stack_upper)) { | 1041 if ((sp < stack_lower) || (sp >= stack_upper)) { |
1015 // Stack pointer is outside isolate stack boundary. | 1042 // Stack pointer is outside isolate stack boundary. |
1016 return; | 1043 return; |
1017 } | 1044 } |
1018 | 1045 |
1019 if ((state.fp < stack_lower) || (state.fp >= stack_upper)) { | 1046 if ((fp < stack_lower) || (fp >= stack_upper)) { |
1020 // Frame pointer is outside isolate stack boundary. | 1047 // Frame pointer is outside isolate stack boundary. |
1021 return; | 1048 return; |
1022 } | 1049 } |
1023 | 1050 |
1024 // At this point we have a valid stack boundary for this isolate and | 1051 // At this point we have a valid stack boundary for this isolate and |
1025 // know that our initial stack and frame pointers are within the boundary. | 1052 // know that our initial stack and frame pointers are within the boundary. |
1026 | 1053 |
1027 // Setup sample. | 1054 // Setup sample. |
1028 Sample* sample = sample_buffer->ReserveSample(); | 1055 Sample* sample = sample_buffer->ReserveSample(); |
1029 sample->Init(isolate, OS::GetCurrentTimeMicros(), state.tid); | 1056 sample->Init(isolate, OS::GetCurrentTimeMicros(), state.tid); |
1030 uword vm_tag = isolate->vm_tag(); | 1057 uword vm_tag = isolate->vm_tag(); |
1031 #if defined(USING_SIMULATOR) | 1058 #if defined(USING_SIMULATOR) |
1032 // When running in the simulator, the runtime entry function address | 1059 // When running in the simulator, the runtime entry function address |
1033 // (stored as the vm tag) is the address of a redirect function. | 1060 // (stored as the vm tag) is the address of a redirect function. |
1034 // Attempt to find the real runtime entry function address and use that. | 1061 // Attempt to find the real runtime entry function address and use that. |
1035 uword redirect_vm_tag = Simulator::FunctionForRedirect(vm_tag); | 1062 uword redirect_vm_tag = Simulator::FunctionForRedirect(vm_tag); |
1036 if (redirect_vm_tag != 0) { | 1063 if (redirect_vm_tag != 0) { |
1037 vm_tag = redirect_vm_tag; | 1064 vm_tag = redirect_vm_tag; |
1038 } | 1065 } |
1039 #endif | 1066 #endif |
1040 // Increment counter for vm tag. | 1067 // Increment counter for vm tag. |
1041 VMTagCounters* counters = isolate->vm_tag_counters(); | 1068 VMTagCounters* counters = isolate->vm_tag_counters(); |
1042 ASSERT(counters != NULL); | 1069 ASSERT(counters != NULL); |
1043 counters->Increment(vm_tag); | 1070 counters->Increment(vm_tag); |
1044 sample->set_vm_tag(vm_tag); | 1071 sample->set_vm_tag(vm_tag); |
1045 sample->set_user_tag(isolate->user_tag()); | 1072 sample->set_user_tag(isolate->user_tag()); |
1046 sample->set_sp(sp); | 1073 sample->set_sp(sp); |
1047 sample->set_fp(state.fp); | 1074 sample->set_fp(fp); |
1048 sample->set_lr(state.lr); | 1075 sample->set_lr(lr); |
1049 CopyStackBuffer(sample); | 1076 CopyStackBuffer(sample); |
1050 CopyPCMarkerIfSafe(sample); | 1077 CopyPCMarkerIfSafe(sample); |
1051 | 1078 |
1052 if (FLAG_profile_vm) { | 1079 if (FLAG_profile_vm) { |
1053 // Always walk the native stack collecting both native and Dart frames. | 1080 // Always walk the native stack collecting both native and Dart frames. |
1054 ProfilerNativeStackWalker stackWalker(sample, | 1081 ProfilerNativeStackWalker stackWalker(sample, |
1055 stack_lower, | 1082 stack_lower, |
1056 stack_upper, | 1083 stack_upper, |
1057 state.pc, | 1084 pc, |
1058 state.fp, | 1085 fp, |
1059 sp); | 1086 sp); |
1060 stackWalker.walk(); | 1087 stackWalker.walk(); |
1061 } else if (exited_dart_code) { | 1088 } else if (exited_dart_code) { |
1062 // We have a valid exit frame info, use the Dart stack walker. | 1089 // We have a valid exit frame info, use the Dart stack walker. |
1063 ProfilerDartExitStackWalker stackWalker(isolate, sample); | 1090 ProfilerDartExitStackWalker stackWalker(isolate, sample); |
1064 stackWalker.walk(); | 1091 stackWalker.walk(); |
1065 } else if (in_dart_code) { | 1092 } else if (in_dart_code) { |
1066 // We are executing Dart code. We have frame pointers. | 1093 // We are executing Dart code. We have frame pointers. |
1067 ProfilerDartStackWalker stackWalker(isolate, | 1094 ProfilerDartStackWalker stackWalker(isolate, |
1068 sample, | 1095 sample, |
1069 stack_lower, | 1096 stack_lower, |
1070 stack_upper, | 1097 stack_upper, |
1071 state.pc, | 1098 pc, |
1072 state.fp, | 1099 fp, |
1073 sp); | 1100 sp); |
1074 stackWalker.walk(); | 1101 stackWalker.walk(); |
1075 } else { | 1102 } else { |
1076 sample->set_vm_tag(VMTag::kEmbedderTagId); | 1103 sample->set_vm_tag(VMTag::kEmbedderTagId); |
1077 sample->SetAt(0, state.pc); | 1104 sample->SetAt(0, pc); |
1078 } | 1105 } |
1079 } | 1106 } |
1080 | 1107 |
1081 } // namespace dart | 1108 } // namespace dart |
OLD | NEW |