OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/exceptions.h" | 5 #include "vm/exceptions.h" |
6 | 6 |
7 #include "platform/address_sanitizer.h" | 7 #include "platform/address_sanitizer.h" |
8 | 8 |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
11 #include "vm/debugger.h" | 11 #include "vm/debugger.h" |
12 #include "vm/flags.h" | 12 #include "vm/flags.h" |
13 #include "vm/log.h" | 13 #include "vm/log.h" |
14 #include "vm/longjump.h" | 14 #include "vm/longjump.h" |
15 #include "vm/object.h" | 15 #include "vm/object.h" |
16 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
17 #include "vm/stack_frame.h" | 17 #include "vm/stack_frame.h" |
18 #include "vm/stub_code.h" | 18 #include "vm/stub_code.h" |
19 #include "vm/symbols.h" | 19 #include "vm/symbols.h" |
20 #include "vm/tags.h" | 20 #include "vm/tags.h" |
21 | 21 |
22 namespace dart { | 22 namespace dart { |
23 | 23 |
| 24 DECLARE_FLAG(bool, trace_deoptimization); |
24 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, | 25 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, |
25 "Prints a stack trace everytime a throw occurs."); | 26 "Prints a stack trace everytime a throw occurs."); |
26 | 27 |
27 | 28 |
28 class StacktraceBuilder : public ValueObject { | 29 class StacktraceBuilder : public ValueObject { |
29 public: | 30 public: |
30 StacktraceBuilder() { } | 31 StacktraceBuilder() { } |
31 virtual ~StacktraceBuilder() { } | 32 virtual ~StacktraceBuilder() { } |
32 | 33 |
33 virtual void AddFrame(const Code& code, const Smi& offset) = 0; | 34 virtual void AddFrame(const Code& code, const Smi& offset) = 0; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 122 |
122 static void BuildStackTrace(StacktraceBuilder* builder) { | 123 static void BuildStackTrace(StacktraceBuilder* builder) { |
123 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); | 124 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); |
124 StackFrame* frame = frames.NextFrame(); | 125 StackFrame* frame = frames.NextFrame(); |
125 ASSERT(frame != NULL); // We expect to find a dart invocation frame. | 126 ASSERT(frame != NULL); // We expect to find a dart invocation frame. |
126 Code& code = Code::Handle(); | 127 Code& code = Code::Handle(); |
127 Smi& offset = Smi::Handle(); | 128 Smi& offset = Smi::Handle(); |
128 while (frame != NULL) { | 129 while (frame != NULL) { |
129 if (frame->IsDartFrame()) { | 130 if (frame->IsDartFrame()) { |
130 code = frame->LookupDartCode(); | 131 code = frame->LookupDartCode(); |
| 132 ASSERT(code.ContainsInstructionAt(frame->pc())); |
131 offset = Smi::New(frame->pc() - code.PayloadStart()); | 133 offset = Smi::New(frame->pc() - code.PayloadStart()); |
132 builder->AddFrame(code, offset); | 134 builder->AddFrame(code, offset); |
133 } | 135 } |
134 frame = frames.NextFrame(); | 136 frame = frames.NextFrame(); |
135 } | 137 } |
136 } | 138 } |
137 | 139 |
138 | 140 |
139 // Iterate through the stack frames and try to find a frame with an | 141 // Iterate through the stack frames and try to find a frame with an |
140 // exception handler. Once found, set the pc, sp and fp so that execution | 142 // exception handler. Once found, set the pc, sp and fp so that execution |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 uword stack_pointer, | 209 uword stack_pointer, |
208 uword frame_pointer, | 210 uword frame_pointer, |
209 const Object& exception_object, | 211 const Object& exception_object, |
210 const Object& stacktrace_object) { | 212 const Object& stacktrace_object) { |
211 // The no_gc StackResource is unwound through the tear down of | 213 // The no_gc StackResource is unwound through the tear down of |
212 // stack resources below. | 214 // stack resources below. |
213 NoSafepointScope no_safepoint; | 215 NoSafepointScope no_safepoint; |
214 RawObject* raw_exception = exception_object.raw(); | 216 RawObject* raw_exception = exception_object.raw(); |
215 RawObject* raw_stacktrace = stacktrace_object.raw(); | 217 RawObject* raw_stacktrace = stacktrace_object.raw(); |
216 | 218 |
| 219 #if !defined(TARGET_ARCH_DBC) |
| 220 MallocGrowableArray<PendingLazyDeopt>* pending_deopts = |
| 221 thread->isolate()->pending_deopts(); |
| 222 for (intptr_t i = pending_deopts->length() - 1; i >= 0; i--) { |
| 223 if ((*pending_deopts)[i].fp() == frame_pointer) { |
| 224 // Frame is scheduled for lazy deopt. |
| 225 |
| 226 // Deopt should now resume in the catch handler instead of after the call. |
| 227 (*pending_deopts)[i].set_pc(program_counter); |
| 228 |
| 229 // Jump to the deopt stub instead of the catch handler. |
| 230 program_counter = |
| 231 StubCode::DeoptimizeLazyFromThrow_entry()->EntryPoint(); |
| 232 if (FLAG_trace_deoptimization) { |
| 233 THR_Print("Throwing to frame scheduled for lazy deopt fp=%" Pp "\n", |
| 234 frame_pointer); |
| 235 } |
| 236 break; |
| 237 } |
| 238 } |
| 239 for (intptr_t i = pending_deopts->length() - 1; i >= 0; i--) { |
| 240 // Leave the mapping at fp itself for use in DeoptimizeCopyFrame. |
| 241 if ((*pending_deopts)[i].fp() < frame_pointer) { |
| 242 pending_deopts->RemoveAt(i); |
| 243 } |
| 244 } |
| 245 #endif // !DBC |
| 246 |
| 247 |
217 #if defined(USING_SIMULATOR) | 248 #if defined(USING_SIMULATOR) |
218 // Unwinding of the C++ frames and destroying of their stack resources is done | 249 // Unwinding of the C++ frames and destroying of their stack resources is done |
219 // by the simulator, because the target stack_pointer is a simulated stack | 250 // by the simulator, because the target stack_pointer is a simulated stack |
220 // pointer and not the C++ stack pointer. | 251 // pointer and not the C++ stack pointer. |
221 | 252 |
222 // Continue simulating at the given pc in the given frame after setting up the | 253 // Continue simulating at the given pc in the given frame after setting up the |
223 // exception object in the kExceptionObjectReg register and the stacktrace | 254 // exception object in the kExceptionObjectReg register and the stacktrace |
224 // object (may be raw null) in the kStackTraceObjectReg register. | 255 // object (may be raw null) in the kStackTraceObjectReg register. |
225 | 256 |
226 Simulator::Current()->Longjmp(program_counter, stack_pointer, frame_pointer, | 257 Simulator::Current()->Longjmp(program_counter, stack_pointer, frame_pointer, |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 } | 769 } |
739 | 770 |
740 return DartLibraryCalls::InstanceCreate(library, | 771 return DartLibraryCalls::InstanceCreate(library, |
741 *class_name, | 772 *class_name, |
742 *constructor_name, | 773 *constructor_name, |
743 arguments); | 774 arguments); |
744 } | 775 } |
745 | 776 |
746 | 777 |
747 } // namespace dart | 778 } // namespace dart |
OLD | NEW |