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" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 frame = frames.NextFrame(); | 197 frame = frames.NextFrame(); |
198 ASSERT(frame != NULL); | 198 ASSERT(frame != NULL); |
199 } | 199 } |
200 ASSERT(frame->IsEntryFrame()); | 200 ASSERT(frame->IsEntryFrame()); |
201 *handler_pc = frame->pc(); | 201 *handler_pc = frame->pc(); |
202 *handler_sp = frame->sp(); | 202 *handler_sp = frame->sp(); |
203 *handler_fp = frame->fp(); | 203 *handler_fp = frame->fp(); |
204 } | 204 } |
205 | 205 |
206 | 206 |
207 static void JumpToExceptionHandler(Thread* thread, | 207 static uword RemapExceptionPCForDeopt(Thread* thread, |
208 uword program_counter, | 208 uword program_counter, |
209 uword stack_pointer, | 209 uword frame_pointer) { |
210 uword frame_pointer, | |
211 const Object& exception_object, | |
212 const Object& stacktrace_object) { | |
213 // The no_gc StackResource is unwound through the tear down of | |
214 // stack resources below. | |
215 NoSafepointScope no_safepoint; | |
216 RawObject* raw_exception = exception_object.raw(); | |
217 RawObject* raw_stacktrace = stacktrace_object.raw(); | |
218 | |
219 #if !defined(TARGET_ARCH_DBC) | 210 #if !defined(TARGET_ARCH_DBC) |
220 MallocGrowableArray<PendingLazyDeopt>* pending_deopts = | 211 MallocGrowableArray<PendingLazyDeopt>* pending_deopts = |
221 thread->isolate()->pending_deopts(); | 212 thread->isolate()->pending_deopts(); |
222 if (pending_deopts->length() > 0) { | 213 if (pending_deopts->length() > 0) { |
223 // Check if the target frame is scheduled for lazy deopt. | 214 // Check if the target frame is scheduled for lazy deopt. |
224 for (intptr_t i = 0; i < pending_deopts->length(); i++) { | 215 for (intptr_t i = 0; i < pending_deopts->length(); i++) { |
225 if ((*pending_deopts)[i].fp() == frame_pointer) { | 216 if ((*pending_deopts)[i].fp() == frame_pointer) { |
226 // Deopt should now resume in the catch handler instead of after the | 217 // Deopt should now resume in the catch handler instead of after the |
227 // call. | 218 // call. |
228 (*pending_deopts)[i].set_pc(program_counter); | 219 (*pending_deopts)[i].set_pc(program_counter); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 257 } |
267 pending_deopts->RemoveAt(i); | 258 pending_deopts->RemoveAt(i); |
268 } | 259 } |
269 } | 260 } |
270 | 261 |
271 #if defined(DEBUG) | 262 #if defined(DEBUG) |
272 ValidateFrames(); | 263 ValidateFrames(); |
273 #endif | 264 #endif |
274 } | 265 } |
275 #endif // !DBC | 266 #endif // !DBC |
| 267 return program_counter; |
| 268 } |
276 | 269 |
277 | 270 |
| 271 static void JumpToExceptionHandler(Thread* thread, |
| 272 uword program_counter, |
| 273 uword stack_pointer, |
| 274 uword frame_pointer, |
| 275 const Object& exception_object, |
| 276 const Object& stacktrace_object) { |
| 277 uword remapped_pc = |
| 278 RemapExceptionPCForDeopt(thread, program_counter, frame_pointer); |
| 279 thread->set_active_exception(exception_object); |
| 280 thread->set_active_stacktrace(stacktrace_object); |
| 281 thread->set_resume_pc(remapped_pc); |
| 282 uword run_exception_pc = StubCode::RunExceptionHandler_entry()->EntryPoint(); |
| 283 Exceptions::JumpToFrame(thread, run_exception_pc, stack_pointer, |
| 284 frame_pointer); |
| 285 } |
| 286 |
| 287 |
| 288 void Exceptions::JumpToFrame(Thread* thread, |
| 289 uword program_counter, |
| 290 uword stack_pointer, |
| 291 uword frame_pointer) { |
278 #if defined(USING_SIMULATOR) | 292 #if defined(USING_SIMULATOR) |
279 // Unwinding of the C++ frames and destroying of their stack resources is done | 293 // Unwinding of the C++ frames and destroying of their stack resources is done |
280 // by the simulator, because the target stack_pointer is a simulated stack | 294 // by the simulator, because the target stack_pointer is a simulated stack |
281 // pointer and not the C++ stack pointer. | 295 // pointer and not the C++ stack pointer. |
282 | 296 |
283 // Continue simulating at the given pc in the given frame after setting up the | 297 // Continue simulating at the given pc in the given frame after setting up the |
284 // exception object in the kExceptionObjectReg register and the stacktrace | 298 // exception object in the kExceptionObjectReg register and the stacktrace |
285 // object (may be raw null) in the kStackTraceObjectReg register. | 299 // object (may be raw null) in the kStackTraceObjectReg register. |
286 | 300 |
287 Simulator::Current()->Longjmp(program_counter, stack_pointer, frame_pointer, | 301 Simulator::Current()->JumpToFrame(program_counter, stack_pointer, |
288 raw_exception, raw_stacktrace, thread); | 302 frame_pointer, thread); |
289 #else | 303 #else |
290 // Prepare for unwinding frames by destroying all the stack resources | 304 // Prepare for unwinding frames by destroying all the stack resources |
291 // in the previous frames. | 305 // in the previous frames. |
292 StackResource::Unwind(thread); | 306 StackResource::Unwind(thread); |
293 | 307 |
294 // Call a stub to set up the exception object in kExceptionObjectReg, | 308 // Call a stub to set up the exception object in kExceptionObjectReg, |
295 // to set up the stacktrace object in kStackTraceObjectReg, and to | 309 // to set up the stacktrace object in kStackTraceObjectReg, and to |
296 // continue execution at the given pc in the given frame. | 310 // continue execution at the given pc in the given frame. |
297 typedef void (*ExcpHandler)(uword, uword, uword, RawObject*, RawObject*, | 311 typedef void (*ExcpHandler)(uword, uword, uword, Thread*); |
298 Thread*); | |
299 ExcpHandler func = reinterpret_cast<ExcpHandler>( | 312 ExcpHandler func = reinterpret_cast<ExcpHandler>( |
300 StubCode::JumpToExceptionHandler_entry()->EntryPoint()); | 313 StubCode::JumpToFrame_entry()->EntryPoint()); |
301 | 314 |
302 // Unpoison the stack before we tear it down in the generated stub code. | 315 // Unpoison the stack before we tear it down in the generated stub code. |
303 uword current_sp = Thread::GetCurrentStackPointer() - 1024; | 316 uword current_sp = Thread::GetCurrentStackPointer() - 1024; |
304 ASAN_UNPOISON(reinterpret_cast<void*>(current_sp), | 317 ASAN_UNPOISON(reinterpret_cast<void*>(current_sp), |
305 stack_pointer - current_sp); | 318 stack_pointer - current_sp); |
306 | 319 |
307 func(program_counter, stack_pointer, frame_pointer, raw_exception, | 320 func(program_counter, stack_pointer, frame_pointer, thread); |
308 raw_stacktrace, thread); | |
309 #endif | 321 #endif |
310 UNREACHABLE(); | 322 UNREACHABLE(); |
311 } | 323 } |
312 | 324 |
313 | 325 |
314 static RawField* LookupStacktraceField(const Instance& instance) { | 326 static RawField* LookupStacktraceField(const Instance& instance) { |
315 if (instance.GetClassId() < kNumPredefinedCids) { | 327 if (instance.GetClassId() < kNumPredefinedCids) { |
316 // 'class Error' is not a predefined class. | 328 // 'class Error' is not a predefined class. |
317 return Field::null(); | 329 return Field::null(); |
318 } | 330 } |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 class_name = &Symbols::_CompileTimeError(); | 795 class_name = &Symbols::_CompileTimeError(); |
784 break; | 796 break; |
785 } | 797 } |
786 | 798 |
787 return DartLibraryCalls::InstanceCreate(library, *class_name, | 799 return DartLibraryCalls::InstanceCreate(library, *class_name, |
788 *constructor_name, arguments); | 800 *constructor_name, arguments); |
789 } | 801 } |
790 | 802 |
791 | 803 |
792 } // namespace dart | 804 } // namespace dart |
OLD | NEW |