Chromium Code Reviews| 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 "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 frame = frames.NextFrame(); | 200 frame = frames.NextFrame(); |
| 201 ASSERT(frame != NULL); | 201 ASSERT(frame != NULL); |
| 202 } | 202 } |
| 203 ASSERT(frame->IsEntryFrame()); | 203 ASSERT(frame->IsEntryFrame()); |
| 204 *handler_pc = frame->pc(); | 204 *handler_pc = frame->pc(); |
| 205 *handler_sp = frame->sp(); | 205 *handler_sp = frame->sp(); |
| 206 *handler_fp = frame->fp(); | 206 *handler_fp = frame->fp(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 | 209 |
| 210 void JumpToExceptionHandler(uword program_counter, | 210 static void JumpToHandler(uword program_counter, |
| 211 uword stack_pointer, | 211 uword stack_pointer, |
| 212 uword frame_pointer, | 212 uword frame_pointer, |
| 213 const Instance& exception_object, | 213 RawObject* raw_exception, |
| 214 const Instance& stacktrace_object) { | 214 RawObject* raw_stacktrace) { |
| 215 // The no_gc StackResource is unwound through the tear down of | 215 #if defined(USING_SIMULATOR) |
| 216 // stack resources below. | 216 // Unwinding of the C++ frames and destroying of their stack resources is done |
| 217 NoGCScope no_gc; | 217 // by the simulator, because the target stack_pointer is a simulated stack |
| 218 RawInstance* exception = exception_object.raw(); | 218 // pointer and not the C++ stack pointer. |
| 219 RawInstance* stacktrace = stacktrace_object.raw(); | |
| 220 | 219 |
| 220 // Continue simulating at the given pc in the given frame after setting up the | |
| 221 // exception object in the kExceptionObjectReg register and the stacktrace | |
| 222 // object (if not NULL) in the kStackTraceObjectReg register. | |
| 223 Simulator::Current()->Longjmp(program_counter, stack_pointer, frame_pointer, | |
| 224 raw_exception, raw_stacktrace); | |
| 225 #else | |
| 221 // Prepare for unwinding frames by destroying all the stack resources | 226 // Prepare for unwinding frames by destroying all the stack resources |
| 222 // in the previous frames. | 227 // in the previous frames. |
| 223 Isolate* isolate = Isolate::Current(); | 228 Isolate* isolate = Isolate::Current(); |
| 224 while (isolate->top_resource() != NULL && | 229 while (isolate->top_resource() != NULL && |
| 225 (reinterpret_cast<uword>(isolate->top_resource()) < stack_pointer)) { | 230 (reinterpret_cast<uword>(isolate->top_resource()) < stack_pointer)) { |
| 226 isolate->top_resource()->~StackResource(); | 231 isolate->top_resource()->~StackResource(); |
| 227 } | 232 } |
| 228 | 233 |
| 229 // Set up the appropriate register state and jump to the handler. | 234 // TODO(regis): Can we safely merge both stubs and pass NULL as |
| 230 typedef void (*ExcpHandler)(uword, uword, uword, RawInstance*, RawInstance*); | 235 // stacktrace_object in the case of an error handler? |
| 231 ExcpHandler func = reinterpret_cast<ExcpHandler>( | 236 |
| 232 StubCode::JumpToExceptionHandlerEntryPoint()); | 237 if (raw_stacktrace == NULL) { |
| 233 func(program_counter, stack_pointer, frame_pointer, exception, stacktrace); | 238 // Call a stub to set up the error object in kExceptionObjectReg and to |
| 239 // continue execution at the given pc in the given frame. | |
| 240 typedef void (*ErrorHandler)(uword, uword, uword, RawObject*); | |
| 241 ErrorHandler func = reinterpret_cast<ErrorHandler>( | |
| 242 StubCode::JumpToErrorHandlerEntryPoint()); | |
| 243 func(program_counter, stack_pointer, frame_pointer, raw_exception); | |
| 244 } else { | |
| 245 // Call a stub to set up the exception object in kExceptionObjectReg, | |
| 246 // to set up the stacktrace object in kStackTraceObjectReg, and to | |
| 247 // continue execution at the given pc in the given frame. | |
| 248 typedef void (*ExcpHandler)(uword, uword, uword, RawObject*, RawObject*); | |
| 249 ExcpHandler func = reinterpret_cast<ExcpHandler>( | |
| 250 StubCode::JumpToExceptionHandlerEntryPoint()); | |
| 251 func(program_counter, stack_pointer, frame_pointer, | |
| 252 raw_exception, raw_stacktrace); | |
| 253 } | |
| 254 #endif | |
|
siva
2013/04/18 02:07:12
We not factor this code after we check and see if
regis
2013/04/18 16:18:27
Yes, I will try to factor this code after making s
| |
| 234 UNREACHABLE(); | 255 UNREACHABLE(); |
| 235 } | 256 } |
| 236 | 257 |
| 237 | 258 |
| 238 void JumpToErrorHandler(uword program_counter, | 259 static void JumpToExceptionHandler(uword program_counter, |
| 239 uword stack_pointer, | 260 uword stack_pointer, |
| 240 uword frame_pointer, | 261 uword frame_pointer, |
| 241 const Error& error) { | 262 const Instance& exception_object, |
| 263 const Instance& stacktrace_object) { | |
| 242 // The no_gc StackResource is unwound through the tear down of | 264 // The no_gc StackResource is unwound through the tear down of |
| 243 // stack resources below. | 265 // stack resources below. |
| 244 NoGCScope no_gc; | 266 NoGCScope no_gc; |
| 245 ASSERT(!error.IsNull()); | 267 RawObject* raw_exception = exception_object.raw(); |
| 246 RawError* raw_error = error.raw(); | 268 RawObject* raw_stacktrace = stacktrace_object.raw(); |
| 247 | 269 |
| 248 // Prepare for unwinding frames by destroying all the stack resources | 270 JumpToHandler(program_counter, stack_pointer, frame_pointer, |
| 249 // in the previous frames. | 271 raw_exception, raw_stacktrace); |
| 250 Isolate* isolate = Isolate::Current(); | |
| 251 while (isolate->top_resource() != NULL && | |
| 252 (reinterpret_cast<uword>(isolate->top_resource()) < stack_pointer)) { | |
| 253 isolate->top_resource()->~StackResource(); | |
| 254 } | |
| 255 | 272 |
| 256 // Set up the error object as the return value in EAX and continue | 273 UNREACHABLE(); |
| 257 // from the invocation stub. | 274 } |
| 258 typedef void (*ErrorHandler)(uword, uword, uword, RawError*); | 275 |
| 259 ErrorHandler func = reinterpret_cast<ErrorHandler>( | 276 |
| 260 StubCode::JumpToErrorHandlerEntryPoint()); | 277 static void JumpToErrorHandler(uword program_counter, |
| 261 func(program_counter, stack_pointer, frame_pointer, raw_error); | 278 uword stack_pointer, |
| 279 uword frame_pointer, | |
| 280 const Error& error_object) { | |
| 281 // The no_gc StackResource is unwound through the tear down of | |
| 282 // stack resources below. | |
| 283 NoGCScope no_gc; | |
| 284 ASSERT(!error_object.IsNull()); | |
| 285 RawObject* raw_error = error_object.raw(); | |
| 286 | |
| 287 JumpToHandler( | |
| 288 program_counter, stack_pointer, frame_pointer, raw_error, NULL); | |
| 289 | |
| 262 UNREACHABLE(); | 290 UNREACHABLE(); |
| 263 } | 291 } |
| 264 | 292 |
| 265 | 293 |
| 266 static void ThrowExceptionHelper(const Instance& incoming_exception, | 294 static void ThrowExceptionHelper(const Instance& incoming_exception, |
| 267 const Instance& existing_stacktrace) { | 295 const Instance& existing_stacktrace) { |
| 268 bool use_preallocated_stacktrace = false; | 296 bool use_preallocated_stacktrace = false; |
| 269 Isolate* isolate = Isolate::Current(); | 297 Isolate* isolate = Isolate::Current(); |
| 270 Instance& exception = Instance::Handle(isolate, incoming_exception.raw()); | 298 Instance& exception = Instance::Handle(isolate, incoming_exception.raw()); |
| 271 if (exception.IsNull()) { | 299 if (exception.IsNull()) { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 break; | 625 break; |
| 598 } | 626 } |
| 599 | 627 |
| 600 return DartLibraryCalls::ExceptionCreate(library, | 628 return DartLibraryCalls::ExceptionCreate(library, |
| 601 *class_name, | 629 *class_name, |
| 602 *constructor_name, | 630 *constructor_name, |
| 603 arguments); | 631 arguments); |
| 604 } | 632 } |
| 605 | 633 |
| 606 } // namespace dart | 634 } // namespace dart |
| OLD | NEW |