OLD | NEW |
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 "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "platform/json.h" | 9 #include "platform/json.h" |
10 #include "vm/code_observers.h" | 10 #include "vm/code_observers.h" |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 // debugging. Remove this once the vmservice becomes the standard | 952 // debugging. Remove this once the vmservice becomes the standard |
953 // way to debug. | 953 // way to debug. |
954 if (FLAG_break_at_isolate_spawn) { | 954 if (FLAG_break_at_isolate_spawn) { |
955 isolate->debugger()->OneTimeBreakAtEntry(func); | 955 isolate->debugger()->OneTimeBreakAtEntry(func); |
956 } | 956 } |
957 | 957 |
958 const Array& capabilities = Array::Handle(Array::New(2)); | 958 const Array& capabilities = Array::Handle(Array::New(2)); |
959 Capability& capability = Capability::Handle(); | 959 Capability& capability = Capability::Handle(); |
960 capability = Capability::New(isolate->pause_capability()); | 960 capability = Capability::New(isolate->pause_capability()); |
961 capabilities.SetAt(0, capability); | 961 capabilities.SetAt(0, capability); |
| 962 // Check whether this isolate should be started in paused state. |
| 963 if (state->paused()) { |
| 964 bool added = isolate->AddResumeCapability(capability); |
| 965 ASSERT(added); // There should be no pending resume capabilities. |
| 966 isolate->message_handler()->increment_paused(); |
| 967 } |
962 capability = Capability::New(isolate->terminate_capability()); | 968 capability = Capability::New(isolate->terminate_capability()); |
963 capabilities.SetAt(1, capability); | 969 capabilities.SetAt(1, capability); |
964 | 970 |
965 // Instead of directly invoking the entry point we call '_startIsolate' with | 971 // Instead of directly invoking the entry point we call '_startIsolate' with |
966 // the entry point as argument. | 972 // the entry point as argument. |
967 // Since this function ("RunIsolate") is used for both Isolate.spawn and | 973 // Since this function ("RunIsolate") is used for both Isolate.spawn and |
968 // Isolate.spawnUri we also send a boolean flag as argument so that the | 974 // Isolate.spawnUri we also send a boolean flag as argument so that the |
969 // "_startIsolate" function can act corresponding to how the isolate was | 975 // "_startIsolate" function can act corresponding to how the isolate was |
970 // created. | 976 // created. |
971 const Array& args = Array::Handle(Array::New(7)); | 977 const Array& args = Array::Handle(Array::New(7)); |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 const Object& obj = Object::Handle(isolate, reader.ReadObject()); | 1535 const Object& obj = Object::Handle(isolate, reader.ReadObject()); |
1530 ASSERT(!obj.IsError()); | 1536 ASSERT(!obj.IsError()); |
1531 Instance& instance = Instance::Handle(isolate); | 1537 Instance& instance = Instance::Handle(isolate); |
1532 instance ^= obj.raw(); // Can't use Instance::Cast because may be null. | 1538 instance ^= obj.raw(); // Can't use Instance::Cast because may be null. |
1533 return instance.raw(); | 1539 return instance.raw(); |
1534 } | 1540 } |
1535 | 1541 |
1536 | 1542 |
1537 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, | 1543 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, |
1538 const Function& func, | 1544 const Function& func, |
1539 const Instance& message) | 1545 const Instance& message, |
| 1546 bool paused) |
1540 : isolate_(NULL), | 1547 : isolate_(NULL), |
1541 parent_port_(parent_port), | 1548 parent_port_(parent_port), |
1542 script_url_(NULL), | 1549 script_url_(NULL), |
1543 package_root_(NULL), | 1550 package_root_(NULL), |
1544 library_url_(NULL), | 1551 library_url_(NULL), |
1545 class_name_(NULL), | 1552 class_name_(NULL), |
1546 function_name_(NULL), | 1553 function_name_(NULL), |
1547 exception_callback_name_(NULL), | 1554 exception_callback_name_(NULL), |
1548 serialized_args_(NULL), | 1555 serialized_args_(NULL), |
1549 serialized_args_len_(0), | 1556 serialized_args_len_(0), |
1550 serialized_message_(NULL), | 1557 serialized_message_(NULL), |
1551 serialized_message_len_(0) { | 1558 serialized_message_len_(0), |
| 1559 paused_(paused) { |
1552 script_url_ = NULL; | 1560 script_url_ = NULL; |
1553 const Class& cls = Class::Handle(func.Owner()); | 1561 const Class& cls = Class::Handle(func.Owner()); |
1554 const Library& lib = Library::Handle(cls.library()); | 1562 const Library& lib = Library::Handle(cls.library()); |
1555 const String& lib_url = String::Handle(lib.url()); | 1563 const String& lib_url = String::Handle(lib.url()); |
1556 library_url_ = strdup(lib_url.ToCString()); | 1564 library_url_ = strdup(lib_url.ToCString()); |
1557 | 1565 |
1558 const String& func_name = String::Handle(func.name()); | 1566 const String& func_name = String::Handle(func.name()); |
1559 function_name_ = strdup(func_name.ToCString()); | 1567 function_name_ = strdup(func_name.ToCString()); |
1560 if (!cls.IsTopLevel()) { | 1568 if (!cls.IsTopLevel()) { |
1561 const String& class_name = String::Handle(cls.Name()); | 1569 const String& class_name = String::Handle(cls.Name()); |
1562 class_name_ = strdup(class_name.ToCString()); | 1570 class_name_ = strdup(class_name.ToCString()); |
1563 } | 1571 } |
1564 exception_callback_name_ = strdup("_unhandledExceptionCallback"); | 1572 exception_callback_name_ = strdup("_unhandledExceptionCallback"); |
1565 SerializeObject(message, &serialized_message_, &serialized_message_len_); | 1573 SerializeObject(message, &serialized_message_, &serialized_message_len_); |
1566 } | 1574 } |
1567 | 1575 |
1568 | 1576 |
1569 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, | 1577 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, |
1570 const char* script_url, | 1578 const char* script_url, |
1571 const char* package_root, | 1579 const char* package_root, |
1572 const Instance& args, | 1580 const Instance& args, |
1573 const Instance& message) | 1581 const Instance& message, |
| 1582 bool paused) |
1574 : isolate_(NULL), | 1583 : isolate_(NULL), |
1575 parent_port_(parent_port), | 1584 parent_port_(parent_port), |
1576 package_root_(NULL), | 1585 package_root_(NULL), |
1577 library_url_(NULL), | 1586 library_url_(NULL), |
1578 class_name_(NULL), | 1587 class_name_(NULL), |
1579 function_name_(NULL), | 1588 function_name_(NULL), |
1580 exception_callback_name_(NULL), | 1589 exception_callback_name_(NULL), |
1581 serialized_args_(NULL), | 1590 serialized_args_(NULL), |
1582 serialized_args_len_(0), | 1591 serialized_args_len_(0), |
1583 serialized_message_(NULL), | 1592 serialized_message_(NULL), |
1584 serialized_message_len_(0) { | 1593 serialized_message_len_(0), |
| 1594 paused_(paused) { |
1585 script_url_ = strdup(script_url); | 1595 script_url_ = strdup(script_url); |
1586 if (package_root != NULL) { | 1596 if (package_root != NULL) { |
1587 package_root_ = strdup(package_root); | 1597 package_root_ = strdup(package_root); |
1588 } | 1598 } |
1589 library_url_ = NULL; | 1599 library_url_ = NULL; |
1590 function_name_ = strdup("main"); | 1600 function_name_ = strdup("main"); |
1591 exception_callback_name_ = strdup("_unhandledExceptionCallback"); | 1601 exception_callback_name_ = strdup("_unhandledExceptionCallback"); |
1592 SerializeObject(args, &serialized_args_, &serialized_args_len_); | 1602 SerializeObject(args, &serialized_args_, &serialized_args_len_); |
1593 SerializeObject(message, &serialized_message_, &serialized_message_len_); | 1603 SerializeObject(message, &serialized_message_, &serialized_message_len_); |
1594 } | 1604 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 serialized_message_, serialized_message_len_); | 1679 serialized_message_, serialized_message_len_); |
1670 } | 1680 } |
1671 | 1681 |
1672 | 1682 |
1673 void IsolateSpawnState::Cleanup() { | 1683 void IsolateSpawnState::Cleanup() { |
1674 SwitchIsolateScope switch_scope(I); | 1684 SwitchIsolateScope switch_scope(I); |
1675 Dart::ShutdownIsolate(); | 1685 Dart::ShutdownIsolate(); |
1676 } | 1686 } |
1677 | 1687 |
1678 } // namespace dart | 1688 } // namespace dart |
OLD | NEW |