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 "include/dart_native_api.h" |
8 #include "platform/assert.h" | 9 #include "platform/assert.h" |
9 #include "platform/json.h" | 10 #include "platform/json.h" |
10 #include "vm/code_observers.h" | 11 #include "vm/code_observers.h" |
11 #include "vm/compiler_stats.h" | 12 #include "vm/compiler_stats.h" |
12 #include "vm/coverage.h" | 13 #include "vm/coverage.h" |
| 14 #include "vm/dart_api_message.h" |
13 #include "vm/dart_api_state.h" | 15 #include "vm/dart_api_state.h" |
14 #include "vm/dart_entry.h" | 16 #include "vm/dart_entry.h" |
15 #include "vm/debugger.h" | 17 #include "vm/debugger.h" |
16 #include "vm/deopt_instructions.h" | 18 #include "vm/deopt_instructions.h" |
17 #include "vm/heap.h" | 19 #include "vm/heap.h" |
18 #include "vm/lockers.h" | 20 #include "vm/lockers.h" |
19 #include "vm/log.h" | 21 #include "vm/log.h" |
20 #include "vm/message_handler.h" | 22 #include "vm/message_handler.h" |
21 #include "vm/object_id_ring.h" | 23 #include "vm/object_id_ring.h" |
22 #include "vm/object_store.h" | 24 #include "vm/object_store.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 void NotifyPauseOnStart(); | 161 void NotifyPauseOnStart(); |
160 void NotifyPauseOnExit(); | 162 void NotifyPauseOnExit(); |
161 | 163 |
162 #if defined(DEBUG) | 164 #if defined(DEBUG) |
163 // Check that it is safe to access this handler. | 165 // Check that it is safe to access this handler. |
164 void CheckAccess(); | 166 void CheckAccess(); |
165 #endif | 167 #endif |
166 bool IsCurrentIsolate() const; | 168 bool IsCurrentIsolate() const; |
167 virtual Isolate* isolate() const { return isolate_; } | 169 virtual Isolate* isolate() const { return isolate_; } |
168 | 170 |
169 private: | |
170 // Keep both these enums in sync with isolate_patch.dart. | 171 // Keep both these enums in sync with isolate_patch.dart. |
171 // The different Isolate API message types. | 172 // The different Isolate API message types. |
172 enum { | 173 enum { |
173 kPauseMsg = 1, | 174 kPauseMsg = 1, |
174 kResumeMsg = 2, | 175 kResumeMsg = 2, |
175 kPingMsg = 3, | 176 kPingMsg = 3, |
176 kKillMsg = 4, | 177 kKillMsg = 4, |
177 kAddExitMsg = 5, | 178 kAddExitMsg = 5, |
178 kDelExitMsg = 6, | 179 kDelExitMsg = 6, |
179 kAddErrorMsg = 7, | 180 kAddErrorMsg = 7, |
180 kDelErrorMsg = 8, | 181 kDelErrorMsg = 8, |
181 kErrorFatalMsg = 9, | 182 kErrorFatalMsg = 9, |
182 }; | 183 }; |
183 // The different Isolate API message priorities for ping and kill messages. | 184 // The different Isolate API message priorities for ping and kill messages. |
184 enum { | 185 enum { |
185 kImmediateAction = 0, | 186 kImmediateAction = 0, |
186 kBeforeNextEventAction = 1, | 187 kBeforeNextEventAction = 1, |
187 kAsEventAction = 2 | 188 kAsEventAction = 2 |
188 }; | 189 }; |
189 | 190 |
| 191 private: |
190 // A result of false indicates that the isolate should terminate the | 192 // A result of false indicates that the isolate should terminate the |
191 // processing of further events. | 193 // processing of further events. |
192 bool HandleLibMessage(const Array& message); | 194 bool HandleLibMessage(const Array& message); |
193 | 195 |
194 bool ProcessUnhandledException(const Error& result); | 196 bool ProcessUnhandledException(const Error& result); |
195 Isolate* isolate_; | 197 Isolate* isolate_; |
196 }; | 198 }; |
197 | 199 |
198 | 200 |
199 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) | 201 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 bool Isolate::IsIsolateOf(Thread* thread) { | 767 bool Isolate::IsIsolateOf(Thread* thread) { |
766 return this == thread->isolate(); | 768 return this == thread->isolate(); |
767 } | 769 } |
768 #endif // DEBUG | 770 #endif // DEBUG |
769 | 771 |
770 | 772 |
771 void Isolate::InitOnce() { | 773 void Isolate::InitOnce() { |
772 create_callback_ = NULL; | 774 create_callback_ = NULL; |
773 isolates_list_monitor_ = new Monitor(); | 775 isolates_list_monitor_ = new Monitor(); |
774 ASSERT(isolates_list_monitor_ != NULL); | 776 ASSERT(isolates_list_monitor_ != NULL); |
| 777 EnableIsolateCreation(); |
775 } | 778 } |
776 | 779 |
777 | 780 |
778 Isolate* Isolate::Init(const char* name_prefix, | 781 Isolate* Isolate::Init(const char* name_prefix, |
779 const Dart_IsolateFlags& api_flags, | 782 const Dart_IsolateFlags& api_flags, |
780 bool is_vm_isolate) { | 783 bool is_vm_isolate) { |
781 Isolate* result = new Isolate(api_flags); | 784 Isolate* result = new Isolate(api_flags); |
782 ASSERT(result != NULL); | 785 ASSERT(result != NULL); |
783 | 786 |
784 // Initialize metrics. | 787 // Initialize metrics. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 if (FLAG_trace_isolates) { | 846 if (FLAG_trace_isolates) { |
844 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 847 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { |
845 OS::Print("[+] Starting isolate:\n" | 848 OS::Print("[+] Starting isolate:\n" |
846 "\tisolate: %s\n", result->name()); | 849 "\tisolate: %s\n", result->name()); |
847 } | 850 } |
848 } | 851 } |
849 if (FLAG_compiler_stats) { | 852 if (FLAG_compiler_stats) { |
850 result->compiler_stats_ = new CompilerStats(result); | 853 result->compiler_stats_ = new CompilerStats(result); |
851 } | 854 } |
852 ObjectIdRing::Init(result); | 855 ObjectIdRing::Init(result); |
853 // Add to isolate list. | 856 |
854 AddIsolateTolist(result); | 857 // Add to isolate list. Shutdown and delete the isolate on failure. |
| 858 if (!AddIsolateToList(result)) { |
| 859 result->LowLevelShutdown(); |
| 860 Thread::ExitIsolate(); |
| 861 delete result; |
| 862 return NULL; |
| 863 } |
855 | 864 |
856 return result; | 865 return result; |
857 } | 866 } |
858 | 867 |
859 | 868 |
860 void Isolate::InitializeStackLimit() { | 869 void Isolate::InitializeStackLimit() { |
861 SetStackLimitFromStackBase(Isolate::GetCurrentStackPointer()); | 870 SetStackLimitFromStackBase(Isolate::GetCurrentStackPointer()); |
862 } | 871 } |
863 | 872 |
864 | 873 |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 FinalizablePersistentHandle* handle = | 1488 FinalizablePersistentHandle* handle = |
1480 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 1489 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
1481 handle->UpdateUnreachable(I); | 1490 handle->UpdateUnreachable(I); |
1482 } | 1491 } |
1483 | 1492 |
1484 private: | 1493 private: |
1485 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); | 1494 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); |
1486 }; | 1495 }; |
1487 | 1496 |
1488 | 1497 |
| 1498 void Isolate::LowLevelShutdown() { |
| 1499 // Ensure we have a zone and handle scope so that we can call VM functions, |
| 1500 // but we no longer allocate new heap objects. |
| 1501 Thread* thread = Thread::Current(); |
| 1502 StackZone stack_zone(thread); |
| 1503 HandleScope handle_scope(thread); |
| 1504 NoSafepointScope no_safepoint_scope; |
| 1505 |
| 1506 if (compiler_stats_ != NULL) { |
| 1507 OS::Print("%s", compiler_stats()->PrintToZone()); |
| 1508 } |
| 1509 |
| 1510 // Notify exit listeners that this isolate is shutting down. |
| 1511 if (object_store() != NULL) { |
| 1512 NotifyExitListeners(); |
| 1513 } |
| 1514 |
| 1515 // Clean up debugger resources. |
| 1516 debugger()->Shutdown(); |
| 1517 |
| 1518 // Close all the ports owned by this isolate. |
| 1519 PortMap::ClosePorts(message_handler()); |
| 1520 |
| 1521 // Fail fast if anybody tries to post any more messsages to this isolate. |
| 1522 delete message_handler(); |
| 1523 set_message_handler(NULL); |
| 1524 |
| 1525 // Dump all accumulated timer data for the isolate. |
| 1526 timer_list_.ReportTimers(); |
| 1527 |
| 1528 // Finalize any weak persistent handles with a non-null referent. |
| 1529 FinalizeWeakPersistentHandlesVisitor visitor; |
| 1530 api_state()->weak_persistent_handles().VisitHandles(&visitor); |
| 1531 api_state()->prologue_weak_persistent_handles().VisitHandles(&visitor); |
| 1532 |
| 1533 if (FLAG_trace_isolates) { |
| 1534 heap()->PrintSizes(); |
| 1535 megamorphic_cache_table()->PrintSizes(); |
| 1536 Symbols::DumpStats(); |
| 1537 OS::Print("[-] Stopping isolate:\n" |
| 1538 "\tisolate: %s\n", name()); |
| 1539 } |
| 1540 if (FLAG_print_metrics) { |
| 1541 LogBlock lb(this); |
| 1542 ISL_Print("Printing metrics for %s\n", name()); |
| 1543 #define ISOLATE_METRIC_PRINT(type, variable, name, unit) \ |
| 1544 ISL_Print("%s\n", metric_##variable##_.ToString()); |
| 1545 ISOLATE_METRIC_LIST(ISOLATE_METRIC_PRINT); |
| 1546 #undef ISOLATE_METRIC_PRINT |
| 1547 ISL_Print("\n"); |
| 1548 } |
| 1549 } |
| 1550 |
| 1551 |
1489 void Isolate::Shutdown() { | 1552 void Isolate::Shutdown() { |
1490 ASSERT(this == Isolate::Current()); | 1553 ASSERT(this == Isolate::Current()); |
1491 ASSERT(top_resource() == NULL); | 1554 ASSERT(top_resource() == NULL); |
1492 #if defined(DEBUG) | 1555 #if defined(DEBUG) |
1493 if (heap_ != NULL) { | 1556 if (heap_ != NULL) { |
1494 // The VM isolate keeps all objects marked. | 1557 // The VM isolate keeps all objects marked. |
1495 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); | 1558 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); |
1496 } | 1559 } |
1497 #endif // DEBUG | 1560 #endif // DEBUG |
1498 | 1561 |
1499 Thread* thread = Thread::Current(); | 1562 Thread* thread = Thread::Current(); |
1500 | 1563 |
1501 // First, perform higher-level cleanup that may need to allocate. | 1564 // First, perform higher-level cleanup that may need to allocate. |
1502 { | 1565 { |
1503 // Ensure we have a zone and handle scope so that we can call VM functions. | 1566 // Ensure we have a zone and handle scope so that we can call VM functions. |
1504 StackZone stack_zone(thread); | 1567 StackZone stack_zone(thread); |
1505 HandleScope handle_scope(thread); | 1568 HandleScope handle_scope(thread); |
1506 | 1569 |
1507 // Write out the coverage data if collection has been enabled. | 1570 // Write out the coverage data if collection has been enabled. |
1508 CodeCoverage::Write(this); | 1571 if ((this != Dart::vm_isolate()) && |
| 1572 !ServiceIsolate::IsServiceIsolateDescendant(this)) { |
| 1573 CodeCoverage::Write(this); |
| 1574 } |
1509 } | 1575 } |
1510 | 1576 |
1511 // Remove this isolate from the list *before* we start tearing it down, to | 1577 // Remove this isolate from the list *before* we start tearing it down, to |
1512 // avoid exposing it in a state of decay. | 1578 // avoid exposing it in a state of decay. |
1513 RemoveIsolateFromList(this); | 1579 RemoveIsolateFromList(this); |
1514 | 1580 |
1515 if (heap_ != NULL) { | 1581 if (heap_ != NULL) { |
1516 // Wait for any concurrent GC tasks to finish before shutting down. | 1582 // Wait for any concurrent GC tasks to finish before shutting down. |
1517 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). | 1583 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). |
1518 PageSpace* old_space = heap_->old_space(); | 1584 PageSpace* old_space = heap_->old_space(); |
1519 MonitorLocker ml(old_space->tasks_lock()); | 1585 MonitorLocker ml(old_space->tasks_lock()); |
1520 while (old_space->tasks() > 0) { | 1586 while (old_space->tasks() > 0) { |
1521 ml.Wait(); | 1587 ml.Wait(); |
1522 } | 1588 } |
1523 } | 1589 } |
1524 | 1590 |
1525 // Then, proceed with low-level teardown. | 1591 // Then, proceed with low-level teardown. |
1526 { | 1592 LowLevelShutdown(); |
1527 // Ensure we have a zone and handle scope so that we can call VM functions, | |
1528 // but we no longer allocate new heap objects. | |
1529 StackZone stack_zone(thread); | |
1530 HandleScope handle_scope(thread); | |
1531 NoSafepointScope no_safepoint_scope; | |
1532 | |
1533 if (compiler_stats_ != NULL) { | |
1534 OS::Print("%s", compiler_stats()->PrintToZone()); | |
1535 } | |
1536 | |
1537 // Notify exit listeners that this isolate is shutting down. | |
1538 if (object_store() != NULL) { | |
1539 NotifyExitListeners(); | |
1540 } | |
1541 | |
1542 // Clean up debugger resources. | |
1543 debugger()->Shutdown(); | |
1544 | |
1545 // Close all the ports owned by this isolate. | |
1546 PortMap::ClosePorts(message_handler()); | |
1547 | |
1548 // Fail fast if anybody tries to post any more messsages to this isolate. | |
1549 delete message_handler(); | |
1550 set_message_handler(NULL); | |
1551 | |
1552 // Dump all accumulated timer data for the isolate. | |
1553 timer_list_.ReportTimers(); | |
1554 | |
1555 // Finalize any weak persistent handles with a non-null referent. | |
1556 FinalizeWeakPersistentHandlesVisitor visitor; | |
1557 api_state()->weak_persistent_handles().VisitHandles(&visitor); | |
1558 api_state()->prologue_weak_persistent_handles().VisitHandles(&visitor); | |
1559 | |
1560 if (FLAG_trace_isolates) { | |
1561 heap()->PrintSizes(); | |
1562 megamorphic_cache_table()->PrintSizes(); | |
1563 Symbols::DumpStats(); | |
1564 OS::Print("[-] Stopping isolate:\n" | |
1565 "\tisolate: %s\n", name()); | |
1566 } | |
1567 if (FLAG_print_metrics) { | |
1568 LogBlock lb(this); | |
1569 ISL_Print("Printing metrics for %s\n", name()); | |
1570 #define ISOLATE_METRIC_PRINT(type, variable, name, unit) \ | |
1571 ISL_Print("%s\n", metric_##variable##_.ToString()); | |
1572 ISOLATE_METRIC_LIST(ISOLATE_METRIC_PRINT); | |
1573 #undef ISOLATE_METRIC_PRINT | |
1574 ISL_Print("\n"); | |
1575 } | |
1576 } | |
1577 | 1593 |
1578 #if defined(DEBUG) | 1594 #if defined(DEBUG) |
1579 // No concurrent sweeper tasks should be running at this point. | 1595 // No concurrent sweeper tasks should be running at this point. |
1580 if (heap_ != NULL) { | 1596 if (heap_ != NULL) { |
1581 PageSpace* old_space = heap_->old_space(); | 1597 PageSpace* old_space = heap_->old_space(); |
1582 MonitorLocker ml(old_space->tasks_lock()); | 1598 MonitorLocker ml(old_space->tasks_lock()); |
1583 ASSERT(old_space->tasks() == 0); | 1599 ASSERT(old_space->tasks() == 0); |
1584 } | 1600 } |
1585 #endif | 1601 #endif |
1586 | 1602 |
(...skipping 12 matching lines...) Expand all Loading... |
1599 Isolate::unhandled_exception_callback_ = NULL; | 1615 Isolate::unhandled_exception_callback_ = NULL; |
1600 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; | 1616 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; |
1601 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; | 1617 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; |
1602 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; | 1618 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; |
1603 Dart_FileWriteCallback Isolate::file_write_callback_ = NULL; | 1619 Dart_FileWriteCallback Isolate::file_write_callback_ = NULL; |
1604 Dart_FileCloseCallback Isolate::file_close_callback_ = NULL; | 1620 Dart_FileCloseCallback Isolate::file_close_callback_ = NULL; |
1605 Dart_EntropySource Isolate::entropy_source_callback_ = NULL; | 1621 Dart_EntropySource Isolate::entropy_source_callback_ = NULL; |
1606 | 1622 |
1607 Monitor* Isolate::isolates_list_monitor_ = NULL; | 1623 Monitor* Isolate::isolates_list_monitor_ = NULL; |
1608 Isolate* Isolate::isolates_list_head_ = NULL; | 1624 Isolate* Isolate::isolates_list_head_ = NULL; |
1609 | 1625 bool Isolate::creation_enabled_ = false; |
1610 | 1626 |
1611 void Isolate::IterateObjectPointers(ObjectPointerVisitor* visitor, | 1627 void Isolate::IterateObjectPointers(ObjectPointerVisitor* visitor, |
1612 bool visit_prologue_weak_handles, | 1628 bool visit_prologue_weak_handles, |
1613 bool validate_frames) { | 1629 bool validate_frames) { |
1614 HeapIterationScope heap_iteration_scope; | 1630 HeapIterationScope heap_iteration_scope; |
1615 VisitObjectPointers(visitor, visit_prologue_weak_handles, validate_frames); | 1631 VisitObjectPointers(visitor, visit_prologue_weak_handles, validate_frames); |
1616 } | 1632 } |
1617 | 1633 |
1618 | 1634 |
1619 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, | 1635 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 intptr_t count = 0; | 2128 intptr_t count = 0; |
2113 Isolate* current = isolates_list_head_; | 2129 Isolate* current = isolates_list_head_; |
2114 while (current != NULL) { | 2130 while (current != NULL) { |
2115 count++; | 2131 count++; |
2116 current = current->next_; | 2132 current = current->next_; |
2117 } | 2133 } |
2118 return count; | 2134 return count; |
2119 } | 2135 } |
2120 | 2136 |
2121 | 2137 |
2122 void Isolate::AddIsolateTolist(Isolate* isolate) { | 2138 bool Isolate::AddIsolateToList(Isolate* isolate) { |
2123 MonitorLocker ml(isolates_list_monitor_); | 2139 MonitorLocker ml(isolates_list_monitor_); |
| 2140 if (!creation_enabled_) { |
| 2141 return false; |
| 2142 } |
2124 ASSERT(isolate != NULL); | 2143 ASSERT(isolate != NULL); |
2125 ASSERT(isolate->next_ == NULL); | 2144 ASSERT(isolate->next_ == NULL); |
2126 isolate->next_ = isolates_list_head_; | 2145 isolate->next_ = isolates_list_head_; |
2127 isolates_list_head_ = isolate; | 2146 isolates_list_head_ = isolate; |
| 2147 return true; |
2128 } | 2148 } |
2129 | 2149 |
2130 | 2150 |
2131 void Isolate::RemoveIsolateFromList(Isolate* isolate) { | 2151 void Isolate::RemoveIsolateFromList(Isolate* isolate) { |
2132 MonitorLocker ml(isolates_list_monitor_); | 2152 MonitorLocker ml(isolates_list_monitor_); |
2133 ASSERT(isolate != NULL); | 2153 ASSERT(isolate != NULL); |
2134 if (isolate == isolates_list_head_) { | 2154 if (isolate == isolates_list_head_) { |
2135 isolates_list_head_ = isolate->next_; | 2155 isolates_list_head_ = isolate->next_; |
| 2156 if (!creation_enabled_) { |
| 2157 ml.Notify(); |
| 2158 } |
2136 return; | 2159 return; |
2137 } | 2160 } |
2138 Isolate* previous = NULL; | 2161 Isolate* previous = NULL; |
2139 Isolate* current = isolates_list_head_; | 2162 Isolate* current = isolates_list_head_; |
2140 while (current) { | 2163 while (current) { |
2141 if (current == isolate) { | 2164 if (current == isolate) { |
2142 ASSERT(previous != NULL); | 2165 ASSERT(previous != NULL); |
2143 previous->next_ = current->next_; | 2166 previous->next_ = current->next_; |
| 2167 if (!creation_enabled_) { |
| 2168 ml.Notify(); |
| 2169 } |
2144 return; | 2170 return; |
2145 } | 2171 } |
2146 previous = current; | 2172 previous = current; |
2147 current = current->next_; | 2173 current = current->next_; |
2148 } | 2174 } |
2149 UNREACHABLE(); | 2175 // If we are shutting down the VM, the isolate may not be in the list. |
| 2176 ASSERT(!creation_enabled_); |
2150 } | 2177 } |
2151 | 2178 |
2152 | 2179 |
| 2180 void Isolate::DisableIsolateCreation() { |
| 2181 MonitorLocker ml(isolates_list_monitor_); |
| 2182 creation_enabled_ = false; |
| 2183 } |
| 2184 |
| 2185 |
| 2186 void Isolate::EnableIsolateCreation() { |
| 2187 MonitorLocker ml(isolates_list_monitor_); |
| 2188 creation_enabled_ = true; |
| 2189 } |
| 2190 |
| 2191 |
2153 template<class C> | 2192 template<class C> |
2154 C* Isolate::AllocateReusableHandle() { | 2193 C* Isolate::AllocateReusableHandle() { |
2155 C* handle = reinterpret_cast<C*>(reusable_handles_.AllocateScopedHandle()); | 2194 C* handle = reinterpret_cast<C*>(reusable_handles_.AllocateScopedHandle()); |
2156 C::initializeHandle(handle, C::null()); | 2195 C::initializeHandle(handle, C::null()); |
2157 return handle; | 2196 return handle; |
2158 } | 2197 } |
2159 | 2198 |
2160 | 2199 |
| 2200 void Isolate::Kill() { |
| 2201 Dart_CObject kill_msg; |
| 2202 Dart_CObject* list_values[4]; |
| 2203 kill_msg.type = Dart_CObject_kArray; |
| 2204 kill_msg.value.as_array.length = 4; |
| 2205 kill_msg.value.as_array.values = list_values; |
| 2206 |
| 2207 Dart_CObject oob; |
| 2208 oob.type = Dart_CObject_kInt32; |
| 2209 oob.value.as_int32 = Message::kIsolateLibOOBMsg; |
| 2210 list_values[0] = &oob; |
| 2211 |
| 2212 Dart_CObject kill; |
| 2213 kill.type = Dart_CObject_kInt32; |
| 2214 kill.value.as_int32 = IsolateMessageHandler::kKillMsg; |
| 2215 list_values[1] = &kill; |
| 2216 |
| 2217 Dart_CObject cap; |
| 2218 cap.type = Dart_CObject_kCapability; |
| 2219 cap.value.as_capability.id = terminate_capability(); |
| 2220 list_values[2] = ∩ |
| 2221 |
| 2222 Dart_CObject imm; |
| 2223 imm.type = Dart_CObject_kInt32; |
| 2224 imm.value.as_int32 = IsolateMessageHandler::kImmediateAction; |
| 2225 list_values[3] = &imm; |
| 2226 |
| 2227 { |
| 2228 uint8_t* buffer = NULL; |
| 2229 ApiMessageWriter writer(&buffer, allocator); |
| 2230 bool success = writer.WriteCMessage(&kill_msg); |
| 2231 ASSERT(success); |
| 2232 |
| 2233 // Post the message at the given port. |
| 2234 success = PortMap::PostMessage(new Message(main_port(), |
| 2235 buffer, |
| 2236 writer.BytesWritten(), |
| 2237 Message::kOOBPriority)); |
| 2238 ASSERT(success); |
| 2239 } |
| 2240 } |
| 2241 |
| 2242 |
| 2243 class IsolateKillerVisitor : public IsolateVisitor { |
| 2244 public: |
| 2245 IsolateKillerVisitor() : target_(NULL) {} |
| 2246 |
| 2247 explicit IsolateKillerVisitor(Isolate* isolate) |
| 2248 : target_(isolate) { |
| 2249 ASSERT(isolate != Dart::vm_isolate()); |
| 2250 } |
| 2251 |
| 2252 virtual ~IsolateKillerVisitor() {} |
| 2253 |
| 2254 void VisitIsolate(Isolate* isolate) { |
| 2255 ASSERT(isolate != NULL); |
| 2256 if (ShouldKill(isolate)) { |
| 2257 isolate->Kill(); |
| 2258 } |
| 2259 } |
| 2260 |
| 2261 private: |
| 2262 bool ShouldKill(Isolate* isolate) { |
| 2263 // If a target_ is specified, then only kill the target_. |
| 2264 // Otherwise, don't kill the service isolate or vm isolate. |
| 2265 return (((target_ != NULL) && (isolate == target_)) || |
| 2266 ((target_ == NULL) && |
| 2267 !ServiceIsolate::IsServiceIsolateDescendant(isolate) && |
| 2268 (isolate != Dart::vm_isolate()))); |
| 2269 } |
| 2270 |
| 2271 Isolate* target_; |
| 2272 }; |
| 2273 |
| 2274 |
| 2275 void Isolate::KillAllIsolates() { |
| 2276 IsolateKillerVisitor visitor; |
| 2277 VisitIsolates(&visitor); |
| 2278 } |
| 2279 |
| 2280 |
| 2281 void Isolate::KillIfExists(Isolate* isolate) { |
| 2282 IsolateKillerVisitor visitor(isolate); |
| 2283 VisitIsolates(&visitor); |
| 2284 } |
| 2285 |
| 2286 |
2161 static RawInstance* DeserializeObject(Thread* thread, | 2287 static RawInstance* DeserializeObject(Thread* thread, |
2162 uint8_t* obj_data, | 2288 uint8_t* obj_data, |
2163 intptr_t obj_len) { | 2289 intptr_t obj_len) { |
2164 if (obj_data == NULL) { | 2290 if (obj_data == NULL) { |
2165 return Instance::null(); | 2291 return Instance::null(); |
2166 } | 2292 } |
2167 MessageSnapshotReader reader(obj_data, obj_len, thread); | 2293 MessageSnapshotReader reader(obj_data, obj_len, thread); |
2168 Zone* zone = thread->zone(); | 2294 Zone* zone = thread->zone(); |
2169 const Object& obj = Object::Handle(zone, reader.ReadObject()); | 2295 const Object& obj = Object::Handle(zone, reader.ReadObject()); |
2170 ASSERT(!obj.IsError()); | 2296 ASSERT(!obj.IsError()); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2353 serialized_message_, serialized_message_len_); | 2479 serialized_message_, serialized_message_len_); |
2354 } | 2480 } |
2355 | 2481 |
2356 | 2482 |
2357 void IsolateSpawnState::Cleanup() { | 2483 void IsolateSpawnState::Cleanup() { |
2358 SwitchIsolateScope switch_scope(I); | 2484 SwitchIsolateScope switch_scope(I); |
2359 Dart::ShutdownIsolate(); | 2485 Dart::ShutdownIsolate(); |
2360 } | 2486 } |
2361 | 2487 |
2362 } // namespace dart | 2488 } // namespace dart |
OLD | NEW |