| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 454 |
| 455 void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { | 455 void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { |
| 456 // Visit the roots from the top for a given thread. | 456 // Visit the roots from the top for a given thread. |
| 457 Object* pending; | 457 Object* pending; |
| 458 // The pending exception can sometimes be a failure. We can't show | 458 // The pending exception can sometimes be a failure. We can't show |
| 459 // that to the GC, which only understands objects. | 459 // that to the GC, which only understands objects. |
| 460 if (thread->pending_exception_->ToObject(&pending)) { | 460 if (thread->pending_exception_->ToObject(&pending)) { |
| 461 v->VisitPointer(&pending); | 461 v->VisitPointer(&pending); |
| 462 thread->pending_exception_ = pending; // In case GC updated it. | 462 thread->pending_exception_ = pending; // In case GC updated it. |
| 463 } | 463 } |
| 464 |
| 465 v->VisitPointer(&(thread->last_traced_exception_)); |
| 466 v->VisitPointer(BitCast<Object**>(&(thread->last_stack_trace_))); |
| 464 v->VisitPointer(&(thread->pending_message_obj_)); | 467 v->VisitPointer(&(thread->pending_message_obj_)); |
| 465 v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); | 468 v->VisitPointer(BitCast<Object**>(&(thread->pending_message_script_))); |
| 466 v->VisitPointer(BitCast<Object**>(&(thread->context_))); | 469 v->VisitPointer(BitCast<Object**>(&(thread->context_))); |
| 467 Object* scheduled; | 470 Object* scheduled; |
| 468 if (thread->scheduled_exception_->ToObject(&scheduled)) { | 471 if (thread->scheduled_exception_->ToObject(&scheduled)) { |
| 469 v->VisitPointer(&scheduled); | 472 v->VisitPointer(&scheduled); |
| 470 thread->scheduled_exception_ = scheduled; | 473 thread->scheduled_exception_ = scheduled; |
| 471 } | 474 } |
| 472 | 475 |
| 473 for (v8::TryCatch* block = thread->TryCatchHandler(); | 476 for (v8::TryCatch* block = thread->TryCatchHandler(); |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 Handle<Object> exception_handle(exception_object); | 1049 Handle<Object> exception_handle(exception_object); |
| 1047 | 1050 |
| 1048 // Determine reporting and whether the exception is caught externally. | 1051 // Determine reporting and whether the exception is caught externally. |
| 1049 bool catchable_by_javascript = is_catchable_by_javascript(exception); | 1052 bool catchable_by_javascript = is_catchable_by_javascript(exception); |
| 1050 // Only real objects can be caught by JS. | 1053 // Only real objects can be caught by JS. |
| 1051 ASSERT(!catchable_by_javascript || is_object); | 1054 ASSERT(!catchable_by_javascript || is_object); |
| 1052 bool can_be_caught_externally = false; | 1055 bool can_be_caught_externally = false; |
| 1053 bool should_report_exception = | 1056 bool should_report_exception = |
| 1054 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); | 1057 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); |
| 1055 bool report_exception = catchable_by_javascript && should_report_exception; | 1058 bool report_exception = catchable_by_javascript && should_report_exception; |
| 1059 bool try_catch_needs_message = |
| 1060 can_be_caught_externally && try_catch_handler()->capture_message_; |
| 1061 bool exception_rethrown = |
| 1062 (thread_local_top_.last_traced_exception_ == exception_object); |
| 1063 bool bootstrapping = bootstrapper()->IsActive(); |
| 1056 | 1064 |
| 1057 #ifdef ENABLE_DEBUGGER_SUPPORT | 1065 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1058 // Notify debugger of exception. | 1066 // Notify debugger of exception. |
| 1059 if (catchable_by_javascript) { | 1067 if (catchable_by_javascript) { |
| 1060 debugger_->OnException(exception_handle, report_exception); | 1068 debugger_->OnException(exception_handle, report_exception); |
| 1061 } | 1069 } |
| 1062 #endif | 1070 #endif |
| 1063 | 1071 |
| 1064 // Generate the message. | 1072 // Generate message. |
| 1065 Handle<Object> message_obj; | 1073 Handle<Object> message_obj; |
| 1066 MessageLocation potential_computed_location; | 1074 Handle<JSArray> stack_trace_object; |
| 1067 bool try_catch_needs_message = | 1075 if (capture_stack_trace_for_uncaught_exceptions_ && !bootstrapping) { |
| 1068 can_be_caught_externally && | 1076 if (exception_rethrown) { |
| 1069 try_catch_handler()->capture_message_; | 1077 // We already have the stack trace for this exception. |
| 1078 stack_trace_object = Handle<JSArray>(thread_local_top_.last_stack_trace_); |
| 1079 } else { |
| 1080 // Hang on to this exception and its stack trace even if it's not an |
| 1081 // uncaught exception just in case it is rethrown later. |
| 1082 stack_trace_object = CaptureCurrentStackTrace( |
| 1083 stack_trace_for_uncaught_exceptions_frame_limit_, |
| 1084 stack_trace_for_uncaught_exceptions_options_); |
| 1085 thread_local_top_.last_traced_exception_ = exception_object; |
| 1086 thread_local_top_.last_stack_trace_ = *stack_trace_object; |
| 1087 } |
| 1088 } |
| 1089 |
| 1070 if (report_exception || try_catch_needs_message) { | 1090 if (report_exception || try_catch_needs_message) { |
| 1091 MessageLocation potential_computed_location; |
| 1071 if (location == NULL) { | 1092 if (location == NULL) { |
| 1072 // If no location was specified we use a computed one instead | 1093 // If no location was specified we use a computed one instead. |
| 1073 ComputeLocation(&potential_computed_location); | 1094 ComputeLocation(&potential_computed_location); |
| 1074 location = &potential_computed_location; | 1095 location = &potential_computed_location; |
| 1075 } | 1096 } |
| 1076 if (!bootstrapper()->IsActive()) { | 1097 // It's not safe to try to make message objects or collect stack traces |
| 1077 // It's not safe to try to make message objects or collect stack | 1098 // while the bootstrapper is active since the infrastructure may not have |
| 1078 // traces while the bootstrapper is active since the infrastructure | 1099 // been properly initialized. |
| 1079 // may not have been properly initialized. | 1100 if (!bootstrapping) { |
| 1080 Handle<String> stack_trace; | 1101 Handle<String> stack_trace; |
| 1081 if (FLAG_trace_exception) stack_trace = StackTraceString(); | 1102 if (FLAG_trace_exception) stack_trace = StackTraceString(); |
| 1082 Handle<JSArray> stack_trace_object; | 1103 message_obj = MessageHandler::MakeMessageObject( |
| 1083 if (report_exception && capture_stack_trace_for_uncaught_exceptions_) { | 1104 "uncaught_exception", |
| 1084 stack_trace_object = CaptureCurrentStackTrace( | 1105 location, |
| 1085 stack_trace_for_uncaught_exceptions_frame_limit_, | 1106 HandleVector<Object>(&exception_handle, 1), |
| 1086 stack_trace_for_uncaught_exceptions_options_); | 1107 stack_trace, |
| 1108 stack_trace_object); |
| 1109 thread_local_top()->pending_message_obj_ = *message_obj; |
| 1110 if (location != NULL) { |
| 1111 thread_local_top()->pending_message_script_ = *location->script(); |
| 1112 thread_local_top()->pending_message_start_pos_ = location->start_pos(); |
| 1113 thread_local_top()->pending_message_end_pos_ = location->end_pos(); |
| 1087 } | 1114 } |
| 1088 ASSERT(is_object); // Can't use the handle unless there's a real object. | |
| 1089 message_obj = MessageHandler::MakeMessageObject("uncaught_exception", | |
| 1090 location, HandleVector<Object>(&exception_handle, 1), stack_trace, | |
| 1091 stack_trace_object); | |
| 1092 } else if (location != NULL && !location->script().is_null()) { | 1115 } else if (location != NULL && !location->script().is_null()) { |
| 1093 // We are bootstrapping and caught an error where the location is set | 1116 // We are bootstrapping and caught an error where the location is set |
| 1094 // and we have a script for the location. | 1117 // and we have a script for the location. |
| 1095 // In this case we could have an extension (or an internal error | 1118 // In this case we could have an extension (or an internal error |
| 1096 // somewhere) and we print out the line number at which the error occured | 1119 // somewhere) and we print out the line number at which the error occured |
| 1097 // to the console for easier debugging. | 1120 // to the console for easier debugging. |
| 1098 int line_number = GetScriptLineNumberSafe(location->script(), | 1121 int line_number = GetScriptLineNumberSafe(location->script(), |
| 1099 location->start_pos()); | 1122 location->start_pos()); |
| 1100 OS::PrintError("Extension or internal compilation error at line %d.\n", | 1123 OS::PrintError("Extension or internal compilation error at line %d.\n", |
| 1101 line_number); | 1124 line_number); |
| 1102 } | 1125 } |
| 1103 } | 1126 } |
| 1104 | 1127 |
| 1105 // Save the message for reporting if the the exception remains uncaught. | 1128 // Save the message for reporting if the the exception remains uncaught. |
| 1106 thread_local_top()->has_pending_message_ = report_exception; | 1129 thread_local_top()->has_pending_message_ = report_exception; |
| 1107 if (!message_obj.is_null()) { | |
| 1108 thread_local_top()->pending_message_obj_ = *message_obj; | |
| 1109 if (location != NULL) { | |
| 1110 thread_local_top()->pending_message_script_ = *location->script(); | |
| 1111 thread_local_top()->pending_message_start_pos_ = location->start_pos(); | |
| 1112 thread_local_top()->pending_message_end_pos_ = location->end_pos(); | |
| 1113 } | |
| 1114 } | |
| 1115 | 1130 |
| 1116 // Do not forget to clean catcher_ if currently thrown exception cannot | 1131 // Do not forget to clean catcher_ if currently thrown exception cannot |
| 1117 // be caught. If necessary, ReThrow will update the catcher. | 1132 // be caught. If necessary, ReThrow will update the catcher. |
| 1118 thread_local_top()->catcher_ = can_be_caught_externally ? | 1133 thread_local_top()->catcher_ = can_be_caught_externally ? |
| 1119 try_catch_handler() : NULL; | 1134 try_catch_handler() : NULL; |
| 1120 | 1135 |
| 1121 // NOTE: Notifying the debugger or generating the message | 1136 // NOTE: Notifying the debugger or generating the message |
| 1122 // may have caused new exceptions. For now, we just ignore | 1137 // may have caused new exceptions. For now, we just ignore |
| 1123 // that and set the pending exception to the original one. | 1138 // that and set the pending exception to the original one. |
| 1124 if (is_object) { | 1139 if (is_object) { |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1807 stub_cache_->Initialize(create_heap_objects); | 1822 stub_cache_->Initialize(create_heap_objects); |
| 1808 | 1823 |
| 1809 // If we are deserializing, read the state into the now-empty heap. | 1824 // If we are deserializing, read the state into the now-empty heap. |
| 1810 if (des != NULL) { | 1825 if (des != NULL) { |
| 1811 des->Deserialize(); | 1826 des->Deserialize(); |
| 1812 stub_cache_->Initialize(true); | 1827 stub_cache_->Initialize(true); |
| 1813 } | 1828 } |
| 1814 | 1829 |
| 1815 // Finish initialization of ThreadLocal after deserialization is done. | 1830 // Finish initialization of ThreadLocal after deserialization is done. |
| 1816 clear_pending_exception(); | 1831 clear_pending_exception(); |
| 1832 clear_last_stack_trace(); |
| 1817 clear_pending_message(); | 1833 clear_pending_message(); |
| 1818 clear_scheduled_exception(); | 1834 clear_scheduled_exception(); |
| 1819 | 1835 |
| 1820 // Deserializing may put strange things in the root array's copy of the | 1836 // Deserializing may put strange things in the root array's copy of the |
| 1821 // stack guard. | 1837 // stack guard. |
| 1822 heap_.SetStackLimits(); | 1838 heap_.SetStackLimits(); |
| 1823 | 1839 |
| 1824 deoptimizer_data_ = new DeoptimizerData; | 1840 deoptimizer_data_ = new DeoptimizerData; |
| 1825 runtime_profiler_ = new RuntimeProfiler(this); | 1841 runtime_profiler_ = new RuntimeProfiler(this); |
| 1826 runtime_profiler_->SetUp(); | 1842 runtime_profiler_->SetUp(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1919 | 1935 |
| 1920 #ifdef DEBUG | 1936 #ifdef DEBUG |
| 1921 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 1937 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 1922 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 1938 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
| 1923 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 1939 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 1924 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 1940 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 1925 #undef ISOLATE_FIELD_OFFSET | 1941 #undef ISOLATE_FIELD_OFFSET |
| 1926 #endif | 1942 #endif |
| 1927 | 1943 |
| 1928 } } // namespace v8::internal | 1944 } } // namespace v8::internal |
| OLD | NEW |