Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: runtime/vm/isolate.cc

Issue 1361213003: Distinguish internal kill messages from user-initiated kill messages. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 intptr_t len = 0; 276 intptr_t len = 0;
277 SerializeObject(message, &data, &len, false); 277 SerializeObject(message, &data, &len, false);
278 this->PostMessage( 278 this->PostMessage(
279 new Message(Message::kIllegalPort, 279 new Message(Message::kIllegalPort,
280 data, len, 280 data, len,
281 Message::kNormalPriority), 281 Message::kNormalPriority),
282 priority == Isolate::kBeforeNextEventAction /* at_head */); 282 priority == Isolate::kBeforeNextEventAction /* at_head */);
283 } 283 }
284 break; 284 break;
285 } 285 }
286 case Isolate::kKillMsg: { 286 case Isolate::kKillMsg:
287 case Isolate::kInternalKillMsg: {
287 // [ OOB, kKillMsg, terminate capability, priority ] 288 // [ OOB, kKillMsg, terminate capability, priority ]
288 if (message.Length() != 4) return Error::null(); 289 if (message.Length() != 4) return Error::null();
289 Object& obj = Object::Handle(I, message.At(3)); 290 Object& obj = Object::Handle(I, message.At(3));
290 if (!obj.IsSmi()) return Error::null(); 291 if (!obj.IsSmi()) return Error::null();
291 const intptr_t priority = Smi::Cast(obj).Value(); 292 const intptr_t priority = Smi::Cast(obj).Value();
292 if (priority == Isolate::kImmediateAction) { 293 if (priority == Isolate::kImmediateAction) {
293 obj = message.At(2); 294 obj = message.At(2);
294 // Signal that the isolate should stop execution. 295 // Signal that the isolate should stop execution.
295 if (I->VerifyTerminateCapability(obj)) { 296 if (I->VerifyTerminateCapability(obj)) {
296 const String& msg = String::Handle(String::New( 297 if (msg_type == Isolate::kKillMsg) {
297 "isolate terminated by Isolate.kill")); 298 const String& msg = String::Handle(String::New(
298 return UnwindError::New(msg); 299 "isolate terminated by Isolate.kill"));
300 const UnwindError& error =
301 UnwindError::Handle(UnwindError::New(msg));
302 error.set_is_user_initiated(true);
303 return error.raw();
304 } else {
305 // TODO(turnidge): We should give the message handler a way
306 // to detect when an isolate is unwinding.
307 I->message_handler()->set_pause_on_start(false);
308 I->message_handler()->set_pause_on_exit(false);
309 const String& msg = String::Handle(String::New(
310 "isolate terminated by vm"));
311 return UnwindError::New(msg);
312 }
299 } else { 313 } else {
300 return Error::null(); 314 return Error::null();
301 } 315 }
302 } else { 316 } else {
303 ASSERT((priority == Isolate::kBeforeNextEventAction) || 317 ASSERT((priority == Isolate::kBeforeNextEventAction) ||
304 (priority == Isolate::kAsEventAction)); 318 (priority == Isolate::kAsEventAction));
305 // Update the message so that it will be handled immediately when it 319 // Update the message so that it will be handled immediately when it
306 // is picked up from the message queue the next time. 320 // is picked up from the message queue the next time.
307 message.SetAt( 321 message.SetAt(
308 0, Smi::Handle(I, Smi::New(Message::kDelayedIsolateLibOOBMsg))); 322 0, Smi::Handle(I, Smi::New(Message::kDelayedIsolateLibOOBMsg)));
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 static void ShutdownIsolate(uword parameter) { 1421 static void ShutdownIsolate(uword parameter) {
1408 Isolate* isolate = reinterpret_cast<Isolate*>(parameter); 1422 Isolate* isolate = reinterpret_cast<Isolate*>(parameter);
1409 { 1423 {
1410 // Print the error if there is one. This may execute dart code to 1424 // Print the error if there is one. This may execute dart code to
1411 // print the exception object, so we need to use a StartIsolateScope. 1425 // print the exception object, so we need to use a StartIsolateScope.
1412 Thread* thread = Thread::Current(); 1426 Thread* thread = Thread::Current();
1413 StartIsolateScope start_scope(isolate); 1427 StartIsolateScope start_scope(isolate);
1414 ASSERT(thread->isolate() == isolate); 1428 ASSERT(thread->isolate() == isolate);
1415 StackZone zone(thread); 1429 StackZone zone(thread);
1416 HandleScope handle_scope(thread); 1430 HandleScope handle_scope(thread);
1417 Error& error = Error::Handle(); 1431 const Error& error = Error::Handle(isolate->object_store()->sticky_error());
1418 error = isolate->object_store()->sticky_error();
1419 if (!error.IsNull() && !error.IsUnwindError()) { 1432 if (!error.IsNull() && !error.IsUnwindError()) {
1420 OS::PrintErr("in ShutdownIsolate: %s\n", error.ToErrorCString()); 1433 OS::PrintErr("in ShutdownIsolate: %s\n", error.ToErrorCString());
1421 } 1434 }
1422 Dart::RunShutdownCallback(); 1435 Dart::RunShutdownCallback();
1423 } 1436 }
1424 { 1437 {
1425 // Shut the isolate down. 1438 // Shut the isolate down.
1426 SwitchIsolateScope switch_scope(isolate); 1439 SwitchIsolateScope switch_scope(isolate);
1427 Dart::ShutdownIsolate(); 1440 Dart::ShutdownIsolate();
1428 } 1441 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 } 1474 }
1462 if ((interrupt_bits & kMessageInterrupt) != 0) { 1475 if ((interrupt_bits & kMessageInterrupt) != 0) {
1463 bool ok = message_handler()->HandleOOBMessages(); 1476 bool ok = message_handler()->HandleOOBMessages();
1464 if (!ok) { 1477 if (!ok) {
1465 // False result from HandleOOBMessages signals that the isolate should 1478 // False result from HandleOOBMessages signals that the isolate should
1466 // be terminating. 1479 // be terminating.
1467 if (FLAG_trace_isolates) { 1480 if (FLAG_trace_isolates) {
1468 OS::Print("[!] Terminating isolate due to OOB message:\n" 1481 OS::Print("[!] Terminating isolate due to OOB message:\n"
1469 "\tisolate: %s\n", name()); 1482 "\tisolate: %s\n", name());
1470 } 1483 }
1471 // TODO(turnidge): If the isolate is being killed by 1484 const Error& error = Error::Handle(object_store()->sticky_error());
1472 // Isolate.kill, then we probably want to respect pause_on_exit. 1485 object_store()->clear_sticky_error();
1473 // If the isolate is being killed due to vm restart we don't. 1486 ASSERT(!error.IsNull());
1474 message_handler()->set_pause_on_start(false); 1487 return error.raw();
1475 message_handler()->set_pause_on_exit(false);
1476 const String& msg = String::Handle(String::New("isolate terminated"));
1477 return UnwindError::New(msg);
1478 } 1488 }
1479 } 1489 }
1480 return Error::null(); 1490 return Error::null();
1481 } 1491 }
1482 1492
1483 1493
1484 uword Isolate::GetAndClearStackOverflowFlags() { 1494 uword Isolate::GetAndClearStackOverflowFlags() {
1485 uword stack_overflow_flags = stack_overflow_flags_; 1495 uword stack_overflow_flags = stack_overflow_flags_;
1486 stack_overflow_flags_ = 0; 1496 stack_overflow_flags_ = 0;
1487 return stack_overflow_flags; 1497 return stack_overflow_flags;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 void Isolate::LowLevelShutdown() { 1570 void Isolate::LowLevelShutdown() {
1561 // Ensure we have a zone and handle scope so that we can call VM functions, 1571 // Ensure we have a zone and handle scope so that we can call VM functions,
1562 // but we no longer allocate new heap objects. 1572 // but we no longer allocate new heap objects.
1563 Thread* thread = Thread::Current(); 1573 Thread* thread = Thread::Current();
1564 StackZone stack_zone(thread); 1574 StackZone stack_zone(thread);
1565 HandleScope handle_scope(thread); 1575 HandleScope handle_scope(thread);
1566 NoSafepointScope no_safepoint_scope; 1576 NoSafepointScope no_safepoint_scope;
1567 1577
1568 // Notify exit listeners that this isolate is shutting down. 1578 // Notify exit listeners that this isolate is shutting down.
1569 if (object_store() != NULL) { 1579 if (object_store() != NULL) {
1570 // TODO(turnidge): If the isolate is being killed by Isolate.kill, 1580 const Error& error = Error::Handle(object_store()->sticky_error());
1571 // then we want to notify event listeners. If the isolate is 1581 if (error.IsNull() ||
1572 // being killed due to vm restart we probably don't. 1582 !error.IsUnwindError() ||
1573 NotifyExitListeners(); 1583 UnwindError::Cast(error).is_user_initiated()) {
1584 NotifyExitListeners();
1585 }
1574 } 1586 }
1575 1587
1576 // Clean up debugger resources. 1588 // Clean up debugger resources.
1577 debugger()->Shutdown(); 1589 debugger()->Shutdown();
1578 1590
1579 // Close all the ports owned by this isolate. 1591 // Close all the ports owned by this isolate.
1580 PortMap::ClosePorts(message_handler()); 1592 PortMap::ClosePorts(message_handler());
1581 1593
1582 // Fail fast if anybody tries to post any more messsages to this isolate. 1594 // Fail fast if anybody tries to post any more messsages to this isolate.
1583 delete message_handler(); 1595 delete message_handler();
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 Dart_CObject* list_values[4]; 2300 Dart_CObject* list_values[4];
2289 kill_msg.type = Dart_CObject_kArray; 2301 kill_msg.type = Dart_CObject_kArray;
2290 kill_msg.value.as_array.length = 4; 2302 kill_msg.value.as_array.length = 4;
2291 kill_msg.value.as_array.values = list_values; 2303 kill_msg.value.as_array.values = list_values;
2292 2304
2293 Dart_CObject oob; 2305 Dart_CObject oob;
2294 oob.type = Dart_CObject_kInt32; 2306 oob.type = Dart_CObject_kInt32;
2295 oob.value.as_int32 = Message::kIsolateLibOOBMsg; 2307 oob.value.as_int32 = Message::kIsolateLibOOBMsg;
2296 list_values[0] = &oob; 2308 list_values[0] = &oob;
2297 2309
2298 Dart_CObject kill; 2310 Dart_CObject msg_type;
2299 kill.type = Dart_CObject_kInt32; 2311 msg_type.type = Dart_CObject_kInt32;
2300 kill.value.as_int32 = Isolate::kKillMsg; 2312 msg_type.value.as_int32 = Isolate::kInternalKillMsg;
2301 list_values[1] = &kill; 2313 list_values[1] = &msg_type;
2302 2314
2303 Dart_CObject cap; 2315 Dart_CObject cap;
2304 cap.type = Dart_CObject_kCapability; 2316 cap.type = Dart_CObject_kCapability;
2305 cap.value.as_capability.id = terminate_capability(); 2317 cap.value.as_capability.id = terminate_capability();
2306 list_values[2] = &cap; 2318 list_values[2] = &cap;
2307 2319
2308 Dart_CObject imm; 2320 Dart_CObject imm;
2309 imm.type = Dart_CObject_kInt32; 2321 imm.type = Dart_CObject_kInt32;
2310 imm.value.as_int32 = Isolate::kImmediateAction; 2322 imm.value.as_int32 = Isolate::kImmediateAction;
2311 list_values[3] = &imm; 2323 list_values[3] = &imm;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
2565 serialized_message_, serialized_message_len_); 2577 serialized_message_, serialized_message_len_);
2566 } 2578 }
2567 2579
2568 2580
2569 void IsolateSpawnState::Cleanup() { 2581 void IsolateSpawnState::Cleanup() {
2570 SwitchIsolateScope switch_scope(I); 2582 SwitchIsolateScope switch_scope(I);
2571 Dart::ShutdownIsolate(); 2583 Dart::ShutdownIsolate();
2572 } 2584 }
2573 2585
2574 } // namespace dart 2586 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/object.h » ('j') | runtime/vm/raw_object.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698