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