Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/isolate.h" | 5 #include "vm/isolate.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "lib/mirrors.h" | 9 #include "lib/mirrors.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 | 35 |
| 36 class IsolateMessageHandler : public MessageHandler { | 36 class IsolateMessageHandler : public MessageHandler { |
| 37 public: | 37 public: |
| 38 explicit IsolateMessageHandler(Isolate* isolate); | 38 explicit IsolateMessageHandler(Isolate* isolate); |
| 39 ~IsolateMessageHandler(); | 39 ~IsolateMessageHandler(); |
| 40 | 40 |
| 41 const char* name() const; | 41 const char* name() const; |
| 42 void MessageNotify(Message::Priority priority); | 42 void MessageNotify(Message::Priority priority); |
| 43 bool HandleMessage(Message* message); | 43 bool HandleMessage(Message* message); |
| 44 | |
| 45 #if defined(DEBUG) | 44 #if defined(DEBUG) |
| 46 // Check that it is safe to access this handler. | 45 // Check that it is safe to access this handler. |
| 47 void CheckAccess(); | 46 void CheckAccess(); |
| 48 #endif | 47 #endif |
| 49 bool IsCurrentIsolate() const; | 48 bool IsCurrentIsolate() const; |
| 50 virtual Isolate* GetIsolate() const { return isolate_; } | 49 virtual Isolate* GetIsolate() const { return isolate_; } |
| 50 bool UnhandledExceptionCallbackHandler(const Object& message, | |
| 51 const UnhandledException& error); | |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 Isolate* isolate_; | 54 Isolate* isolate_; |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 | 57 |
| 57 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) | 58 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) |
| 58 : isolate_(isolate) { | 59 : isolate_(isolate) { |
| 59 } | 60 } |
| 60 | 61 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 // malformed messages. If they (eventually) come from a remote | 95 // malformed messages. If they (eventually) come from a remote |
| 95 // machine, then it might make sense to drop the message entirely. | 96 // machine, then it might make sense to drop the message entirely. |
| 96 // In the case that the message originated locally, which is | 97 // In the case that the message originated locally, which is |
| 97 // always true for now, then this should never occur. | 98 // always true for now, then this should never occur. |
| 98 UNREACHABLE(); | 99 UNREACHABLE(); |
| 99 } | 100 } |
| 100 | 101 |
| 101 Instance& msg = Instance::Handle(); | 102 Instance& msg = Instance::Handle(); |
| 102 msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. | 103 msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. |
| 103 | 104 |
| 105 bool success = true; | |
| 104 if (message->IsOOB()) { | 106 if (message->IsOOB()) { |
| 105 // For now the only OOB messages are Mirrors messages. | 107 // For now the only OOB messages are Mirrors messages. |
| 106 HandleMirrorsMessage(isolate_, message->reply_port(), msg); | 108 HandleMirrorsMessage(isolate_, message->reply_port(), msg); |
| 107 delete message; | |
| 108 } else { | 109 } else { |
| 109 const Object& result = Object::Handle( | 110 const Object& result = Object::Handle( |
| 110 DartLibraryCalls::HandleMessage( | 111 DartLibraryCalls::HandleMessage( |
| 111 message->dest_port(), message->reply_port(), msg)); | 112 message->dest_port(), message->reply_port(), msg)); |
| 112 delete message; | |
| 113 if (result.IsError()) { | 113 if (result.IsError()) { |
| 114 isolate_->object_store()->set_sticky_error(Error::Cast(result)); | 114 isolate_->object_store()->set_sticky_error(Error::Cast(result)); |
| 115 return false; | 115 if (result.IsUnhandledException()) { |
| 116 const UnhandledException& error = UnhandledException::Cast(result); | |
| 117 RawInstance* exception = error.exception(); | |
| 118 if ((exception != isolate_->object_store()->out_of_memory()) && | |
| 119 (exception != isolate_->object_store()->stack_overflow())) { | |
| 120 success = UnhandledExceptionCallbackHandler(msg, error); | |
| 121 if (!success && (Isolate::UnhandledExceptionCallback() != NULL)) { | |
| 122 // Notify embedder that an unhandled exception occurred. | |
| 123 Dart_EnterScope(); | |
| 124 Dart_Handle error_handle = Api::NewHandle(isolate_, error.raw()); | |
| 125 (Isolate::UnhandledExceptionCallback())(error_handle); | |
| 126 // TODO(tball): add some sort of blocker to ensure embedder | |
| 127 // doesn't run any more code on this isolate. | |
| 128 Dart_ExitScope(); | |
| 129 } | |
| 130 } | |
| 131 } | |
|
siva
2012/11/21 00:45:04
I presume a return of success == true would keep t
Tom Ball
2012/11/21 05:22:38
PTAL -- I refactored it and fixed when the Unhandl
| |
| 132 } else { | |
| 133 ASSERT(result.IsNull()); | |
| 116 } | 134 } |
| 117 ASSERT(result.IsNull()); | |
| 118 } | 135 } |
| 119 return true; | 136 delete message; |
| 137 return success; | |
| 120 } | 138 } |
| 121 | 139 |
| 122 | 140 |
| 141 bool IsolateMessageHandler::UnhandledExceptionCallbackHandler( | |
| 142 const Object& message, const UnhandledException& error) { | |
| 143 RawInstance* callback = | |
| 144 isolate_->object_store()->unhandled_exception_closure(); | |
| 145 Instance& closure = Instance::Handle(callback); | |
| 146 if (closure.IsNull()) { | |
| 147 return false; // Error wasn't handled by callback. | |
| 148 } | |
| 149 const Instance& stacktrace = | |
| 150 Instance::Handle(isolate_, error.stacktrace()); | |
| 151 | |
| 152 // Wrap these args into an IsolateUncaughtException object. | |
| 153 GrowableArray<const Object*> exception_args(3); | |
| 154 exception_args.Add(&message); | |
| 155 exception_args.Add(&error); | |
| 156 exception_args.Add(&stacktrace); | |
| 157 Object& exception = Object::Handle(); | |
| 158 exception = Exceptions::Create(Exceptions::kIsolateUnhandledException, | |
| 159 exception_args); | |
| 160 if (exception.IsError()) { | |
| 161 return false; | |
| 162 } | |
| 163 | |
| 164 // Invoke script's callback closure. | |
| 165 GrowableArray<const Object*> callback_args(1); | |
| 166 callback_args.Add(&exception); | |
| 167 const Array& kNoArgumentNames = Array::Handle(isolate_); | |
| 168 RawObject* response = DartEntry::InvokeClosure(closure, | |
| 169 callback_args, | |
| 170 kNoArgumentNames); | |
| 171 // TODO(tball): log any nested exceptions. | |
| 172 return (response == Bool::True()); | |
| 173 } | |
| 174 | |
| 175 | |
| 123 #if defined(DEBUG) | 176 #if defined(DEBUG) |
| 124 void IsolateMessageHandler::CheckAccess() { | 177 void IsolateMessageHandler::CheckAccess() { |
| 125 ASSERT(IsCurrentIsolate()); | 178 ASSERT(IsCurrentIsolate()); |
| 126 } | 179 } |
| 127 #endif | 180 #endif |
| 128 | 181 |
| 129 | 182 |
| 130 bool IsolateMessageHandler::IsCurrentIsolate() const { | 183 bool IsolateMessageHandler::IsCurrentIsolate() const { |
| 131 return (isolate_ == Isolate::Current()); | 184 return (isolate_ == Isolate::Current()); |
| 132 } | 185 } |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 "\tisolate: %s\n", name()); | 492 "\tisolate: %s\n", name()); |
| 440 } | 493 } |
| 441 // TODO(5411455): For now just make sure there are no current isolates | 494 // TODO(5411455): For now just make sure there are no current isolates |
| 442 // as we are shutting down the isolate. | 495 // as we are shutting down the isolate. |
| 443 SetCurrent(NULL); | 496 SetCurrent(NULL); |
| 444 } | 497 } |
| 445 | 498 |
| 446 | 499 |
| 447 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; | 500 Dart_IsolateCreateCallback Isolate::create_callback_ = NULL; |
| 448 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; | 501 Dart_IsolateInterruptCallback Isolate::interrupt_callback_ = NULL; |
| 502 Dart_IsolateUnhandledExceptionCallback | |
| 503 Isolate::unhandled_exception_callback_ = NULL; | |
| 449 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; | 504 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; |
| 450 | 505 |
| 451 | 506 |
| 452 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, | 507 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
| 453 bool visit_prologue_weak_handles, | 508 bool visit_prologue_weak_handles, |
| 454 bool validate_frames) { | 509 bool validate_frames) { |
| 455 ASSERT(visitor != NULL); | 510 ASSERT(visitor != NULL); |
| 456 | 511 |
| 457 // Visit objects in the object store. | 512 // Visit objects in the object store. |
| 458 object_store()->VisitObjectPointers(visitor); | 513 object_store()->VisitObjectPointers(visitor); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 | 546 |
| 492 | 547 |
| 493 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, | 548 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, |
| 494 bool visit_prologue_weak_handles) { | 549 bool visit_prologue_weak_handles) { |
| 495 if (api_state() != NULL) { | 550 if (api_state() != NULL) { |
| 496 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); | 551 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); |
| 497 } | 552 } |
| 498 } | 553 } |
| 499 | 554 |
| 500 } // namespace dart | 555 } // namespace dart |
| OLD | NEW |