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" |
| 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."); | |
| 20 | 23 |
| 21 | 24 |
| 22 const char* Exceptions::kCastErrorDstName = "type cast"; | 25 const char* Exceptions::kCastErrorDstName = "type cast"; |
| 23 | 26 |
| 24 | 27 |
| 25 // Iterate through the stack frames and try to find a frame with an | 28 // 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 | 29 // exception handler. Once found, set the pc, sp and fp so that execution |
| 27 // can continue in that frame. | 30 // can continue in that frame. |
| 28 static bool FindExceptionHandler(uword* handler_pc, | 31 static bool FindExceptionHandler(uword* handler_pc, |
| 29 uword* handler_sp, | 32 uword* handler_sp, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 bool handler_exists = FindExceptionHandler(&handler_pc, | 162 bool handler_exists = FindExceptionHandler(&handler_pc, |
| 160 &handler_sp, | 163 &handler_sp, |
| 161 &handler_fp, | 164 &handler_fp, |
| 162 func_list, | 165 func_list, |
| 163 code_list, | 166 code_list, |
| 164 pc_offset_list); | 167 pc_offset_list); |
| 165 if (handler_pc == 0) { | 168 if (handler_pc == 0) { |
| 166 // There are no dart invocation frames on the stack so we do not | 169 // There are no dart invocation frames on the stack so we do not |
| 167 // have a caller to return to. | 170 // have a caller to return to. |
| 168 ASSERT(!handler_exists); | 171 ASSERT(!handler_exists); |
| 172 if (FLAG_heap_profile_out_of_memory) { | |
| 173 Isolate* isolate = Isolate::Current(); | |
| 174 Instance& out_of_memory = | |
| 175 Instance::Handle(isolate->object_store()->out_of_memory()); | |
| 176 if (incoming_exception.Equals(out_of_memory)) { | |
| 177 Instance& out_of_memory = | |
| 178 Instance::Handle(isolate->object_store()->out_of_memory()); | |
| 179 if (incoming_exception.Equals(out_of_memory)) { | |
|
siva
2012/12/07 00:33:02
The handle and if check seems to be repeated twice
cshapiro
2012/12/08 07:29:46
Sorry about that. I actually caught this earlier.
| |
| 180 const char* format = "%s-out-of-memory.hprof"; | |
| 181 intptr_t len = OS::SNPrint(NULL, 0, format, isolate->name()); | |
| 182 char* filename = isolate->current_zone()->Alloc<char>(len + 1); | |
| 183 OS::SNPrint(filename, len + 1, format, isolate->name()); | |
| 184 isolate->heap()->ProfileToFile(filename); | |
|
siva
2012/12/07 00:33:02
Why not change the signature of ProfileToFile to b
cshapiro
2012/12/08 07:29:46
Good idea. Done. (Saves ~3 places, actually.)
| |
| 185 } | |
| 186 } | |
| 187 } | |
| 169 if (Isolate::UnhandledExceptionCallback() != NULL) { | 188 if (Isolate::UnhandledExceptionCallback() != NULL) { |
| 170 // Notify embedder that an unhandled exception occurred. | 189 // Notify embedder that an unhandled exception occurred. |
| 171 Dart_EnterScope(); | 190 Dart_EnterScope(); |
| 172 Dart_Handle error_handle = Api::NewHandle(Isolate::Current(), | 191 Dart_Handle error_handle = Api::NewHandle(Isolate::Current(), |
| 173 incoming_exception.raw()); | 192 incoming_exception.raw()); |
| 174 (Isolate::UnhandledExceptionCallback())(error_handle); | 193 (Isolate::UnhandledExceptionCallback())(error_handle); |
| 175 Dart_ExitScope(); | 194 Dart_ExitScope(); |
| 176 } else { | 195 } else { |
| 177 OS::PrintErr("Exception '%s' thrown:\n", exception.ToCString()); | 196 OS::PrintErr("Exception '%s' thrown:\n", exception.ToCString()); |
| 178 OS::PrintErr("Shutting down the isolate\n"); | 197 OS::PrintErr("Shutting down the isolate\n"); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 case kIsolateSpawn: | 464 case kIsolateSpawn: |
| 446 library = Library::IsolateLibrary(); | 465 library = Library::IsolateLibrary(); |
| 447 class_name = Symbols::New("IsolateSpawnException"); | 466 class_name = Symbols::New("IsolateSpawnException"); |
| 448 break; | 467 break; |
| 449 } | 468 } |
| 450 | 469 |
| 451 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); | 470 return DartLibraryCalls::ExceptionCreate(library, class_name, arguments); |
| 452 } | 471 } |
| 453 | 472 |
| 454 } // namespace dart | 473 } // namespace dart |
| OLD | NEW |