| 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" |
| 11 #include "vm/object.h" | 11 #include "vm/object.h" |
| 12 #include "vm/object_store.h" |
| 12 #include "vm/stack_frame.h" | 13 #include "vm/stack_frame.h" |
| 13 #include "vm/stub_code.h" | 14 #include "vm/stub_code.h" |
| 14 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
| 15 | 16 |
| 16 namespace dart { | 17 namespace dart { |
| 17 | 18 |
| 18 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, | 19 DEFINE_FLAG(bool, print_stacktrace_at_throw, false, |
| 19 "Prints a stack trace everytime a throw occurs."); | 20 "Prints a stack trace everytime a throw occurs."); |
| 21 DEFINE_FLAG(bool, heap_profile_out_of_memory, false, |
| 22 "Writes a heap profile on unhandled out-of-memory exceptions."); |
| 23 DECLARE_FLAG(bool, heap_profile_out_of_memory); |
| 20 | 24 |
| 21 | 25 |
| 22 const char* Exceptions::kCastErrorDstName = "type cast"; | 26 const char* Exceptions::kCastErrorDstName = "type cast"; |
| 23 | 27 |
| 24 | 28 |
| 25 // Iterate through the stack frames and try to find a frame with an | 29 // Iterate through the stack frames and try to find a frame with an |
| 26 // exception handler. Once found, set the pc, sp and fp so that execution | 30 // exception handler. Once found, set the pc, sp and fp so that execution |
| 27 // can continue in that frame. | 31 // can continue in that frame. |
| 28 static bool FindExceptionHandler(uword* handler_pc, | 32 static bool FindExceptionHandler(uword* handler_pc, |
| 29 uword* handler_sp, | 33 uword* handler_sp, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 OS::Print("%s\n", stacktrace.ToCString()); | 187 OS::Print("%s\n", stacktrace.ToCString()); |
| 184 } | 188 } |
| 185 if (handler_exists) { | 189 if (handler_exists) { |
| 186 // Found a dart handler for the exception, jump to it. | 190 // Found a dart handler for the exception, jump to it. |
| 187 JumpToExceptionHandler(handler_pc, | 191 JumpToExceptionHandler(handler_pc, |
| 188 handler_sp, | 192 handler_sp, |
| 189 handler_fp, | 193 handler_fp, |
| 190 exception, | 194 exception, |
| 191 stacktrace); | 195 stacktrace); |
| 192 } else { | 196 } else { |
| 197 if (FLAG_heap_profile_out_of_memory) { |
| 198 Isolate* isolate = Isolate::Current(); |
| 199 if (exception.raw() == isolate->object_store()->out_of_memory()) { |
| 200 isolate->heap()->ProfileToFile("out-of-memory"); |
| 201 } |
| 202 } |
| 193 // No dart exception handler found in this invocation sequence, | 203 // No dart exception handler found in this invocation sequence, |
| 194 // so we create an unhandled exception object and return to the | 204 // so we create an unhandled exception object and return to the |
| 195 // invocation stub so that it returns this unhandled exception | 205 // invocation stub so that it returns this unhandled exception |
| 196 // object. The C++ code which invoked this dart sequence can check | 206 // object. The C++ code which invoked this dart sequence can check |
| 197 // and do the appropriate thing (rethrow the exception to the | 207 // and do the appropriate thing (rethrow the exception to the |
| 198 // dart invocation sequence above it, print diagnostics and terminate | 208 // dart invocation sequence above it, print diagnostics and terminate |
| 199 // the isolate etc.). | 209 // the isolate etc.). |
| 200 const UnhandledException& unhandled_exception = UnhandledException::Handle( | 210 const UnhandledException& unhandled_exception = UnhandledException::Handle( |
| 201 UnhandledException::New(exception, stacktrace)); | 211 UnhandledException::New(exception, stacktrace)); |
| 202 JumpToErrorHandler(handler_pc, handler_sp, handler_fp, unhandled_exception); | 212 JumpToErrorHandler(handler_pc, handler_sp, handler_fp, unhandled_exception); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 case kIsolateSpawn: | 440 case kIsolateSpawn: |
| 431 library = Library::IsolateLibrary(); | 441 library = Library::IsolateLibrary(); |
| 432 class_name = Symbols::New("IsolateSpawnException"); | 442 class_name = Symbols::New("IsolateSpawnException"); |
| 433 break; | 443 break; |
| 434 } | 444 } |
| 435 | 445 |
| 436 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); | 446 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); |
| 437 } | 447 } |
| 438 | 448 |
| 439 } // namespace dart | 449 } // namespace dart |
| OLD | NEW |