Chromium Code Reviews| Index: runtime/vm/isolate.cc |
| diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc |
| index 97ac51f4e68f5048276e6914a594f94175c20daf..1a66ef2c66f9dbf4913022dbe77ed12cf7c9fb7d 100644 |
| --- a/runtime/vm/isolate.cc |
| +++ b/runtime/vm/isolate.cc |
| @@ -177,7 +177,7 @@ class IsolateMessageHandler : public MessageHandler { |
| const char* name() const; |
| void MessageNotify(Message::Priority priority); |
| - bool HandleMessage(Message* message); |
| + MessageStatus HandleMessage(Message* message); |
| void NotifyPauseOnStart(); |
| void NotifyPauseOnExit(); |
| @@ -193,7 +193,7 @@ class IsolateMessageHandler : public MessageHandler { |
| // processing of further events. |
| RawError* HandleLibMessage(const Array& message); |
| - bool ProcessUnhandledException(const Error& result); |
| + MessageStatus ProcessUnhandledException(const Error& result); |
| Isolate* isolate_; |
| }; |
| @@ -284,7 +284,8 @@ RawError* IsolateMessageHandler::HandleLibMessage(const Array& message) { |
| break; |
| } |
| case Isolate::kKillMsg: |
| - case Isolate::kInternalKillMsg: { |
| + case Isolate::kInternalKillMsg: |
| + case Isolate::kVMRestartMsg: { |
| // [ OOB, kKillMsg, terminate capability, priority ] |
| if (message.Length() != 4) return Error::null(); |
| Object& obj = Object::Handle(I, message.At(3)); |
| @@ -301,14 +302,19 @@ RawError* IsolateMessageHandler::HandleLibMessage(const Array& message) { |
| UnwindError::Handle(UnwindError::New(msg)); |
| error.set_is_user_initiated(true); |
| return error.raw(); |
| - } else { |
| - // TODO(turnidge): We should give the message handler a way |
| - // to detect when an isolate is unwinding. |
| - I->message_handler()->set_pause_on_start(false); |
| - I->message_handler()->set_pause_on_exit(false); |
| + } else if (msg_type == Isolate::kInternalKillMsg) { |
| const String& msg = String::Handle(String::New( |
| "isolate terminated by vm")); |
| return UnwindError::New(msg); |
| + } else if (msg_type == Isolate::kVMRestartMsg) { |
| + const String& msg = String::Handle(String::New( |
|
Cutch
2015/10/05 18:10:46
Maybe a comment here that this path kills the curr
turnidge
2015/10/05 22:18:24
Done.
|
| + "isolate terminated for vm restart")); |
| + const UnwindError& error = |
| + UnwindError::Handle(UnwindError::New(msg)); |
| + error.set_is_vm_restart(true); |
| + return error.raw(); |
| + } else { |
| + UNREACHABLE(); |
| } |
| } else { |
| return Error::null(); |
| @@ -420,7 +426,8 @@ void IsolateMessageHandler::MessageNotify(Message::Priority priority) { |
| } |
| -bool IsolateMessageHandler::HandleMessage(Message* message) { |
| +MessageHandler::MessageStatus IsolateMessageHandler::HandleMessage( |
| + Message* message) { |
| ASSERT(IsCurrentIsolate()); |
| Thread* thread = Thread::Current(); |
| StackZone stack_zone(thread); |
| @@ -449,7 +456,7 @@ bool IsolateMessageHandler::HandleMessage(Message* message) { |
| } else { |
| delete message; |
| } |
| - return true; |
| + return kOK; |
| } |
| } |
| @@ -473,7 +480,7 @@ bool IsolateMessageHandler::HandleMessage(Message* message) { |
| Instance& msg = Instance::Handle(zone); |
| msg ^= msg_obj.raw(); // Can't use Instance::Cast because may be null. |
| - bool success = true; |
| + MessageStatus status = kOK; |
| if (message->IsOOB()) { |
| // OOB messages are expected to be fixed length arrays where the first |
| // element is a Smi describing the OOB destination. Messages that do not |
| @@ -491,7 +498,7 @@ bool IsolateMessageHandler::HandleMessage(Message* message) { |
| case Message::kIsolateLibOOBMsg: { |
| const Error& error = Error::Handle(HandleLibMessage(oob_msg)); |
| if (!error.IsNull()) { |
| - success = ProcessUnhandledException(error); |
| + status = ProcessUnhandledException(error); |
| } |
| break; |
| } |
| @@ -518,7 +525,7 @@ bool IsolateMessageHandler::HandleMessage(Message* message) { |
| (Smi::Cast(oob_tag).Value() == Message::kDelayedIsolateLibOOBMsg)) { |
| const Error& error = Error::Handle(HandleLibMessage(msg_arr)); |
| if (!error.IsNull()) { |
| - success = ProcessUnhandledException(error); |
| + status = ProcessUnhandledException(error); |
| } |
| } |
| } |
| @@ -527,22 +534,22 @@ bool IsolateMessageHandler::HandleMessage(Message* message) { |
| const Object& result = Object::Handle(zone, |
| DartLibraryCalls::HandleMessage(msg_handler, msg)); |
| if (result.IsError()) { |
| - success = ProcessUnhandledException(Error::Cast(result)); |
| + status = ProcessUnhandledException(Error::Cast(result)); |
| } else { |
| ASSERT(result.IsNull()); |
| } |
| } |
| delete message; |
| - if (success) { |
| + if (status == kOK) { |
| const Object& result = |
| Object::Handle(zone, I->InvokePendingServiceExtensionCalls()); |
| if (result.IsError()) { |
| - success = ProcessUnhandledException(Error::Cast(result)); |
| + status = ProcessUnhandledException(Error::Cast(result)); |
| } else { |
| ASSERT(result.IsNull()); |
| } |
| } |
| - return success; |
| + return status; |
| } |
| @@ -586,7 +593,8 @@ bool IsolateMessageHandler::IsCurrentIsolate() const { |
| } |
| -bool IsolateMessageHandler::ProcessUnhandledException(const Error& result) { |
| +MessageHandler::MessageStatus IsolateMessageHandler::ProcessUnhandledException( |
| + const Error& result) { |
| // Notify the debugger about specific unhandled exceptions which are withheld |
| // when being thrown. |
| if (result.IsUnhandledException()) { |
| @@ -632,7 +640,14 @@ bool IsolateMessageHandler::ProcessUnhandledException(const Error& result) { |
| if (result.IsUnwindError()) { |
| // Unwind errors are always fatal and don't notify listeners. |
|
zra
2015/10/05 16:56:47
Is this comment still correct?
turnidge
2015/10/05 22:18:24
Updated.
|
| I->object_store()->set_sticky_error(result); |
| - return false; |
| + const UnwindError& unwind = UnwindError::Cast(result); |
| + if (unwind.is_user_initiated()) { |
| + return kError; |
| + } else if (unwind.is_vm_restart()) { |
| + return kRestart; |
| + } else { |
| + return kShutdown; |
| + } |
| } else { |
| bool has_listener = I->NotifyErrorListeners(exc_str, stacktrace_str); |
| if (I->ErrorsFatal()) { |
| @@ -641,10 +656,10 @@ bool IsolateMessageHandler::ProcessUnhandledException(const Error& result) { |
| } else { |
| I->object_store()->set_sticky_error(result); |
| } |
| - return false; |
| + return kError; |
| } |
| } |
| - return true; |
| + return kOK; |
| } |
| @@ -1303,13 +1318,24 @@ bool Isolate::NotifyErrorListeners(const String& msg, |
| } |
| -static void StoreError(Isolate* isolate, const Object& obj) { |
| - ASSERT(obj.IsError()); |
| - isolate->object_store()->set_sticky_error(Error::Cast(obj)); |
| +static |
|
zra
2015/10/05 16:56:47
It looks like we'd usually break the long line in
turnidge
2015/10/05 22:18:24
Done.
|
| +MessageHandler::MessageStatus StoreError(Isolate* isolate, const Error& error) { |
| + isolate->object_store()->set_sticky_error(error); |
| + if (error.IsUnwindError()) { |
| + const UnwindError& unwind = UnwindError::Cast(error); |
| + if (!unwind.is_user_initiated()) { |
| + if (unwind.is_vm_restart()) { |
| + return MessageHandler::kRestart; |
| + } else { |
| + return MessageHandler::kShutdown; |
| + } |
| + } |
| + } |
| + return MessageHandler::kError; |
| } |
| -static bool RunIsolate(uword parameter) { |
| +static MessageHandler::MessageStatus RunIsolate(uword parameter) { |
| Isolate* isolate = reinterpret_cast<Isolate*>(parameter); |
| IsolateSpawnState* state = NULL; |
| Thread* thread = Thread::Current(); |
| @@ -1343,15 +1369,19 @@ static bool RunIsolate(uword parameter) { |
| if (!ClassFinalizer::ProcessPendingClasses()) { |
| // Error is in sticky error already. |
| - return false; |
| +#if defined(DEBUG) |
| + const Error& error = |
| + Error::Handle(isolate->object_store()->sticky_error()); |
| + ASSERT(!error.IsUnwindError()); |
| +#endif |
| + return MessageHandler::kError; |
| } |
| Object& result = Object::Handle(); |
| result = state->ResolveFunction(); |
| bool is_spawn_uri = state->is_spawn_uri(); |
| if (result.IsError()) { |
| - StoreError(isolate, result); |
| - return false; |
| + return StoreError(isolate, Error::Cast(result)); |
| } |
| ASSERT(result.IsFunction()); |
| Function& func = Function::Handle(isolate); |
| @@ -1406,11 +1436,10 @@ static bool RunIsolate(uword parameter) { |
| result = DartEntry::InvokeFunction(entry_point, args); |
| if (result.IsError()) { |
| - StoreError(isolate, result); |
| - return false; |
| + return StoreError(isolate, Error::Cast(result)); |
| } |
| } |
| - return true; |
| + return MessageHandler::kOK; |
| } |
| @@ -1469,8 +1498,9 @@ RawError* Isolate::HandleInterrupts() { |
| } |
| } |
| if ((interrupt_bits & kMessageInterrupt) != 0) { |
| - bool ok = message_handler()->HandleOOBMessages(); |
| - if (!ok) { |
| + MessageHandler::MessageStatus status = |
| + message_handler()->HandleOOBMessages(); |
| + if (status != MessageHandler::kOK) { |
| // False result from HandleOOBMessages signals that the isolate should |
| // be terminating. |
| if (FLAG_trace_isolates) { |
| @@ -1478,8 +1508,8 @@ RawError* Isolate::HandleInterrupts() { |
| "\tisolate: %s\n", name()); |
| } |
| const Error& error = Error::Handle(object_store()->sticky_error()); |
| + ASSERT(!error.IsNull() && error.IsUnwindError()); |
| object_store()->clear_sticky_error(); |
| - ASSERT(!error.IsNull()); |
| return error.raw(); |
| } |
| } |
| @@ -2276,7 +2306,7 @@ C* Isolate::AllocateReusableHandle() { |
| } |
| -void Isolate::KillLocked() { |
| +void Isolate::KillLocked(LibMsgId msg_id) { |
| Dart_CObject kill_msg; |
| Dart_CObject* list_values[4]; |
| kill_msg.type = Dart_CObject_kArray; |
| @@ -2290,7 +2320,7 @@ void Isolate::KillLocked() { |
| Dart_CObject msg_type; |
| msg_type.type = Dart_CObject_kInt32; |
| - msg_type.value.as_int32 = Isolate::kInternalKillMsg; |
| + msg_type.value.as_int32 = msg_id; |
| list_values[1] = &msg_type; |
| Dart_CObject cap; |