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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 bool Isolate::IsIsolateOf(Thread* thread) { | 744 bool Isolate::IsIsolateOf(Thread* thread) { |
743 return this == thread->isolate(); | 745 return this == thread->isolate(); |
744 } | 746 } |
745 #endif // DEBUG | 747 #endif // DEBUG |
746 | 748 |
747 | 749 |
748 void Isolate::InitOnce() { | 750 void Isolate::InitOnce() { |
749 create_callback_ = NULL; | 751 create_callback_ = NULL; |
750 isolates_list_monitor_ = new Monitor(); | 752 isolates_list_monitor_ = new Monitor(); |
751 ASSERT(isolates_list_monitor_ != NULL); | 753 ASSERT(isolates_list_monitor_ != NULL); |
| 754 EnableIsolateCreation(); |
752 } | 755 } |
753 | 756 |
754 | 757 |
755 Isolate* Isolate::Init(const char* name_prefix, | 758 Isolate* Isolate::Init(const char* name_prefix, |
756 const Dart_IsolateFlags& api_flags, | 759 const Dart_IsolateFlags& api_flags, |
757 bool is_vm_isolate) { | 760 bool is_vm_isolate) { |
758 Isolate* result = new Isolate(api_flags); | 761 Isolate* result = new Isolate(api_flags); |
759 ASSERT(result != NULL); | 762 ASSERT(result != NULL); |
760 | 763 |
761 // Initialize metrics. | 764 // Initialize metrics. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 if (FLAG_trace_isolates) { | 823 if (FLAG_trace_isolates) { |
821 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 824 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { |
822 OS::Print("[+] Starting isolate:\n" | 825 OS::Print("[+] Starting isolate:\n" |
823 "\tisolate: %s\n", result->name()); | 826 "\tisolate: %s\n", result->name()); |
824 } | 827 } |
825 } | 828 } |
826 if (FLAG_compiler_stats) { | 829 if (FLAG_compiler_stats) { |
827 result->compiler_stats_ = new CompilerStats(result); | 830 result->compiler_stats_ = new CompilerStats(result); |
828 } | 831 } |
829 ObjectIdRing::Init(result); | 832 ObjectIdRing::Init(result); |
830 // Add to isolate list. | 833 |
831 AddIsolateTolist(result); | 834 // Add to isolate list. Shutdown and delete the isolate on failure. |
| 835 if (!AddIsolateToList(result)) { |
| 836 result->LowLevelShutdown(); |
| 837 Thread::ExitIsolate(); |
| 838 delete result; |
| 839 return NULL; |
| 840 } |
832 | 841 |
833 return result; | 842 return result; |
834 } | 843 } |
835 | 844 |
836 | 845 |
837 void Isolate::InitializeStackLimit() { | 846 void Isolate::InitializeStackLimit() { |
838 SetStackLimitFromStackBase(Isolate::GetCurrentStackPointer()); | 847 SetStackLimitFromStackBase(Isolate::GetCurrentStackPointer()); |
839 } | 848 } |
840 | 849 |
841 | 850 |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 FinalizablePersistentHandle* handle = | 1456 FinalizablePersistentHandle* handle = |
1448 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 1457 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
1449 handle->UpdateUnreachable(I); | 1458 handle->UpdateUnreachable(I); |
1450 } | 1459 } |
1451 | 1460 |
1452 private: | 1461 private: |
1453 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); | 1462 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); |
1454 }; | 1463 }; |
1455 | 1464 |
1456 | 1465 |
| 1466 void Isolate::LowLevelShutdown() { |
| 1467 // Ensure we have a zone and handle scope so that we can call VM functions, |
| 1468 // but we no longer allocate new heap objects. |
| 1469 StackZone stack_zone(this); |
| 1470 HandleScope handle_scope(this); |
| 1471 NoSafepointScope no_safepoint_scope; |
| 1472 |
| 1473 if (compiler_stats_ != NULL) { |
| 1474 compiler_stats()->Print(); |
| 1475 } |
| 1476 |
| 1477 // Notify exit listeners that this isolate is shutting down. |
| 1478 if (object_store() != NULL) { |
| 1479 NotifyExitListeners(); |
| 1480 } |
| 1481 |
| 1482 // Clean up debugger resources. |
| 1483 debugger()->Shutdown(); |
| 1484 |
| 1485 // Close all the ports owned by this isolate. |
| 1486 PortMap::ClosePorts(message_handler()); |
| 1487 |
| 1488 // Fail fast if anybody tries to post any more messsages to this isolate. |
| 1489 delete message_handler(); |
| 1490 set_message_handler(NULL); |
| 1491 |
| 1492 // Dump all accumulated timer data for the isolate. |
| 1493 timer_list_.ReportTimers(); |
| 1494 |
| 1495 // Finalize any weak persistent handles with a non-null referent. |
| 1496 FinalizeWeakPersistentHandlesVisitor visitor; |
| 1497 api_state()->weak_persistent_handles().VisitHandles(&visitor); |
| 1498 api_state()->prologue_weak_persistent_handles().VisitHandles(&visitor); |
| 1499 |
| 1500 if (FLAG_trace_isolates) { |
| 1501 heap()->PrintSizes(); |
| 1502 megamorphic_cache_table()->PrintSizes(); |
| 1503 Symbols::DumpStats(); |
| 1504 OS::Print("[-] Stopping isolate:\n" |
| 1505 "\tisolate: %s\n", name()); |
| 1506 } |
| 1507 } |
| 1508 |
| 1509 |
1457 void Isolate::Shutdown() { | 1510 void Isolate::Shutdown() { |
1458 ASSERT(this == Isolate::Current()); | 1511 ASSERT(this == Isolate::Current()); |
1459 ASSERT(top_resource() == NULL); | 1512 ASSERT(top_resource() == NULL); |
1460 #if defined(DEBUG) | 1513 #if defined(DEBUG) |
1461 if (heap_ != NULL) { | 1514 if (heap_ != NULL) { |
1462 // The VM isolate keeps all objects marked. | 1515 // The VM isolate keeps all objects marked. |
1463 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); | 1516 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); |
1464 } | 1517 } |
1465 #endif // DEBUG | 1518 #endif // DEBUG |
1466 | 1519 |
1467 // First, perform higher-level cleanup that may need to allocate. | 1520 // First, perform higher-level cleanup that may need to allocate. |
1468 { | 1521 { |
1469 // Ensure we have a zone and handle scope so that we can call VM functions. | 1522 // Ensure we have a zone and handle scope so that we can call VM functions. |
1470 StackZone stack_zone(this); | 1523 StackZone stack_zone(this); |
1471 HandleScope handle_scope(this); | 1524 HandleScope handle_scope(this); |
1472 | 1525 |
1473 // Write out the coverage data if collection has been enabled. | 1526 // Write out the coverage data if collection has been enabled. |
1474 CodeCoverage::Write(this); | 1527 if ((this != Dart::vm_isolate()) && |
| 1528 !ServiceIsolate::IsServiceIsolateDescendant(this)) { |
| 1529 CodeCoverage::Write(this); |
| 1530 } |
1475 | 1531 |
1476 if ((timeline_event_recorder_ != NULL) && | 1532 if ((timeline_event_recorder_ != NULL) && |
1477 (FLAG_timeline_trace_dir != NULL)) { | 1533 (FLAG_timeline_trace_dir != NULL)) { |
1478 timeline_event_recorder_->WriteTo(FLAG_timeline_trace_dir); | 1534 timeline_event_recorder_->WriteTo(FLAG_timeline_trace_dir); |
1479 } | 1535 } |
1480 } | 1536 } |
1481 | 1537 |
1482 // Remove this isolate from the list *before* we start tearing it down, to | 1538 // Remove this isolate from the list *before* we start tearing it down, to |
1483 // avoid exposing it in a state of decay. | 1539 // avoid exposing it in a state of decay. |
1484 RemoveIsolateFromList(this); | 1540 RemoveIsolateFromList(this); |
1485 | 1541 |
1486 if (heap_ != NULL) { | 1542 if (heap_ != NULL) { |
1487 // Wait for any concurrent GC tasks to finish before shutting down. | 1543 // Wait for any concurrent GC tasks to finish before shutting down. |
1488 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). | 1544 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). |
1489 PageSpace* old_space = heap_->old_space(); | 1545 PageSpace* old_space = heap_->old_space(); |
1490 MonitorLocker ml(old_space->tasks_lock()); | 1546 MonitorLocker ml(old_space->tasks_lock()); |
1491 while (old_space->tasks() > 0) { | 1547 while (old_space->tasks() > 0) { |
1492 ml.Wait(); | 1548 ml.Wait(); |
1493 } | 1549 } |
1494 } | 1550 } |
1495 | 1551 |
1496 // Then, proceed with low-level teardown. | 1552 // Then, proceed with low-level teardown. |
1497 { | 1553 LowLevelShutdown(); |
1498 // Ensure we have a zone and handle scope so that we can call VM functions, | |
1499 // but we no longer allocate new heap objects. | |
1500 StackZone stack_zone(this); | |
1501 HandleScope handle_scope(this); | |
1502 NoSafepointScope no_safepoint_scope; | |
1503 | |
1504 if (compiler_stats_ != NULL) { | |
1505 compiler_stats()->Print(); | |
1506 } | |
1507 | |
1508 // Notify exit listeners that this isolate is shutting down. | |
1509 if (object_store() != NULL) { | |
1510 NotifyExitListeners(); | |
1511 } | |
1512 | |
1513 // Clean up debugger resources. | |
1514 debugger()->Shutdown(); | |
1515 | |
1516 // Close all the ports owned by this isolate. | |
1517 PortMap::ClosePorts(message_handler()); | |
1518 | |
1519 // Fail fast if anybody tries to post any more messsages to this isolate. | |
1520 delete message_handler(); | |
1521 set_message_handler(NULL); | |
1522 | |
1523 // Dump all accumulated timer data for the isolate. | |
1524 timer_list_.ReportTimers(); | |
1525 | |
1526 // Finalize any weak persistent handles with a non-null referent. | |
1527 FinalizeWeakPersistentHandlesVisitor visitor; | |
1528 api_state()->weak_persistent_handles().VisitHandles(&visitor); | |
1529 api_state()->prologue_weak_persistent_handles().VisitHandles(&visitor); | |
1530 | |
1531 if (FLAG_trace_isolates) { | |
1532 heap()->PrintSizes(); | |
1533 megamorphic_cache_table()->PrintSizes(); | |
1534 Symbols::DumpStats(); | |
1535 OS::Print("[-] Stopping isolate:\n" | |
1536 "\tisolate: %s\n", name()); | |
1537 } | |
1538 } | |
1539 | 1554 |
1540 #if defined(DEBUG) | 1555 #if defined(DEBUG) |
1541 // No concurrent sweeper tasks should be running at this point. | 1556 // No concurrent sweeper tasks should be running at this point. |
1542 if (heap_ != NULL) { | 1557 if (heap_ != NULL) { |
1543 PageSpace* old_space = heap_->old_space(); | 1558 PageSpace* old_space = heap_->old_space(); |
1544 MonitorLocker ml(old_space->tasks_lock()); | 1559 MonitorLocker ml(old_space->tasks_lock()); |
1545 ASSERT(old_space->tasks() == 0); | 1560 ASSERT(old_space->tasks() == 0); |
1546 } | 1561 } |
1547 #endif | 1562 #endif |
1548 | 1563 |
(...skipping 12 matching lines...) Expand all Loading... |
1561 Isolate::unhandled_exception_callback_ = NULL; | 1576 Isolate::unhandled_exception_callback_ = NULL; |
1562 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; | 1577 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; |
1563 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; | 1578 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; |
1564 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; | 1579 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; |
1565 Dart_FileWriteCallback Isolate::file_write_callback_ = NULL; | 1580 Dart_FileWriteCallback Isolate::file_write_callback_ = NULL; |
1566 Dart_FileCloseCallback Isolate::file_close_callback_ = NULL; | 1581 Dart_FileCloseCallback Isolate::file_close_callback_ = NULL; |
1567 Dart_EntropySource Isolate::entropy_source_callback_ = NULL; | 1582 Dart_EntropySource Isolate::entropy_source_callback_ = NULL; |
1568 | 1583 |
1569 Monitor* Isolate::isolates_list_monitor_ = NULL; | 1584 Monitor* Isolate::isolates_list_monitor_ = NULL; |
1570 Isolate* Isolate::isolates_list_head_ = NULL; | 1585 Isolate* Isolate::isolates_list_head_ = NULL; |
1571 | 1586 bool Isolate::creation_enabled_ = false; |
1572 | 1587 |
1573 void Isolate::IterateObjectPointers(ObjectPointerVisitor* visitor, | 1588 void Isolate::IterateObjectPointers(ObjectPointerVisitor* visitor, |
1574 bool visit_prologue_weak_handles, | 1589 bool visit_prologue_weak_handles, |
1575 bool validate_frames) { | 1590 bool validate_frames) { |
1576 HeapIterationScope heap_iteration_scope; | 1591 HeapIterationScope heap_iteration_scope; |
1577 VisitObjectPointers(visitor, visit_prologue_weak_handles, validate_frames); | 1592 VisitObjectPointers(visitor, visit_prologue_weak_handles, validate_frames); |
1578 } | 1593 } |
1579 | 1594 |
1580 | 1595 |
1581 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, | 1596 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1910 intptr_t count = 0; | 1925 intptr_t count = 0; |
1911 Isolate* current = isolates_list_head_; | 1926 Isolate* current = isolates_list_head_; |
1912 while (current != NULL) { | 1927 while (current != NULL) { |
1913 count++; | 1928 count++; |
1914 current = current->next_; | 1929 current = current->next_; |
1915 } | 1930 } |
1916 return count; | 1931 return count; |
1917 } | 1932 } |
1918 | 1933 |
1919 | 1934 |
1920 void Isolate::AddIsolateTolist(Isolate* isolate) { | 1935 bool Isolate::AddIsolateToList(Isolate* isolate) { |
1921 MonitorLocker ml(isolates_list_monitor_); | 1936 MonitorLocker ml(isolates_list_monitor_); |
| 1937 if (!creation_enabled_) { |
| 1938 return false; |
| 1939 } |
1922 ASSERT(isolate != NULL); | 1940 ASSERT(isolate != NULL); |
1923 ASSERT(isolate->next_ == NULL); | 1941 ASSERT(isolate->next_ == NULL); |
1924 isolate->next_ = isolates_list_head_; | 1942 isolate->next_ = isolates_list_head_; |
1925 isolates_list_head_ = isolate; | 1943 isolates_list_head_ = isolate; |
| 1944 return true; |
1926 } | 1945 } |
1927 | 1946 |
1928 | 1947 |
1929 void Isolate::RemoveIsolateFromList(Isolate* isolate) { | 1948 void Isolate::RemoveIsolateFromList(Isolate* isolate) { |
1930 MonitorLocker ml(isolates_list_monitor_); | 1949 MonitorLocker ml(isolates_list_monitor_); |
1931 ASSERT(isolate != NULL); | 1950 ASSERT(isolate != NULL); |
1932 if (isolate == isolates_list_head_) { | 1951 if (isolate == isolates_list_head_) { |
1933 isolates_list_head_ = isolate->next_; | 1952 isolates_list_head_ = isolate->next_; |
1934 return; | 1953 return; |
1935 } | 1954 } |
1936 Isolate* previous = NULL; | 1955 Isolate* previous = NULL; |
1937 Isolate* current = isolates_list_head_; | 1956 Isolate* current = isolates_list_head_; |
1938 while (current) { | 1957 while (current) { |
1939 if (current == isolate) { | 1958 if (current == isolate) { |
1940 ASSERT(previous != NULL); | 1959 ASSERT(previous != NULL); |
1941 previous->next_ = current->next_; | 1960 previous->next_ = current->next_; |
1942 return; | 1961 return; |
1943 } | 1962 } |
1944 previous = current; | 1963 previous = current; |
1945 current = current->next_; | 1964 current = current->next_; |
1946 } | 1965 } |
1947 UNREACHABLE(); | 1966 // If we are shutting down the VM, the isolate may not be in the list. |
| 1967 ASSERT(!creation_enabled_); |
1948 } | 1968 } |
1949 | 1969 |
1950 | 1970 |
1951 #if defined(DEBUG) | 1971 #if defined(DEBUG) |
1952 void Isolate::CheckForDuplicateThreadState(InterruptableThreadState* state) { | 1972 void Isolate::CheckForDuplicateThreadState(InterruptableThreadState* state) { |
1953 MonitorLocker ml(isolates_list_monitor_); | 1973 MonitorLocker ml(isolates_list_monitor_); |
1954 ASSERT(state != NULL); | 1974 ASSERT(state != NULL); |
1955 Isolate* current = isolates_list_head_; | 1975 Isolate* current = isolates_list_head_; |
1956 while (current) { | 1976 while (current) { |
1957 ASSERT(current->thread_state() != state); | 1977 ASSERT(current->thread_state() != state); |
1958 current = current->next_; | 1978 current = current->next_; |
1959 } | 1979 } |
1960 } | 1980 } |
1961 #endif | 1981 #endif |
1962 | 1982 |
1963 | 1983 |
| 1984 void Isolate::DisableIsolateCreation() { |
| 1985 MonitorLocker ml(isolates_list_monitor_); |
| 1986 creation_enabled_ = false; |
| 1987 } |
| 1988 |
| 1989 |
| 1990 void Isolate::EnableIsolateCreation() { |
| 1991 MonitorLocker ml(isolates_list_monitor_); |
| 1992 creation_enabled_ = true; |
| 1993 } |
| 1994 |
| 1995 |
1964 template<class T> | 1996 template<class T> |
1965 T* Isolate::AllocateReusableHandle() { | 1997 T* Isolate::AllocateReusableHandle() { |
1966 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); | 1998 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); |
1967 T::initializeHandle(handle, T::null()); | 1999 T::initializeHandle(handle, T::null()); |
1968 return handle; | 2000 return handle; |
1969 } | 2001 } |
1970 | 2002 |
1971 | 2003 |
| 2004 void Isolate::KillIsolate(Isolate* isolate) { |
| 2005 Dart_CObject kill_msg; |
| 2006 Dart_CObject* list_values[4]; |
| 2007 kill_msg.type = Dart_CObject_kArray; |
| 2008 kill_msg.value.as_array.length = 4; |
| 2009 kill_msg.value.as_array.values = list_values; |
| 2010 |
| 2011 Dart_CObject oob; |
| 2012 oob.type = Dart_CObject_kInt32; |
| 2013 oob.value.as_int32 = Message::kIsolateLibOOBMsg; |
| 2014 list_values[0] = &oob; |
| 2015 |
| 2016 Dart_CObject kill; |
| 2017 kill.type = Dart_CObject_kInt32; |
| 2018 kill.value.as_int32 = IsolateMessageHandler::kKillMsg; |
| 2019 list_values[1] = &kill; |
| 2020 |
| 2021 Dart_CObject cap; |
| 2022 cap.type = Dart_CObject_kCapability; |
| 2023 cap.value.as_capability.id = isolate->terminate_capability(); |
| 2024 list_values[2] = ∩ |
| 2025 |
| 2026 Dart_CObject imm; |
| 2027 imm.type = Dart_CObject_kInt32; |
| 2028 imm.value.as_int32 = IsolateMessageHandler::kImmediateAction; |
| 2029 list_values[3] = &imm; |
| 2030 |
| 2031 isolate->ScheduleInterrupts(Isolate::kMessageInterrupt); |
| 2032 { |
| 2033 uint8_t* buffer = NULL; |
| 2034 ApiMessageWriter writer(&buffer, allocator); |
| 2035 bool success = writer.WriteCMessage(&kill_msg); |
| 2036 ASSERT(success); |
| 2037 |
| 2038 // Post the message at the given port. |
| 2039 success = PortMap::PostMessage(new Message(isolate->main_port(), |
| 2040 buffer, |
| 2041 writer.BytesWritten(), |
| 2042 Message::kOOBPriority)); |
| 2043 ASSERT(success); |
| 2044 } |
| 2045 } |
| 2046 |
| 2047 |
| 2048 class IsolateKillerVisitor : public IsolateVisitor { |
| 2049 public: |
| 2050 IsolateKillerVisitor() {} |
| 2051 |
| 2052 virtual ~IsolateKillerVisitor() {} |
| 2053 |
| 2054 void VisitIsolate(Isolate* isolate) { |
| 2055 ASSERT(isolate != NULL); |
| 2056 if (ServiceIsolate::IsServiceIsolateDescendant(isolate) || |
| 2057 (isolate == Dart::vm_isolate())) { |
| 2058 return; |
| 2059 } |
| 2060 Isolate::KillIsolate(isolate); |
| 2061 } |
| 2062 }; |
| 2063 |
| 2064 |
| 2065 void Isolate::KillAllIsolates() { |
| 2066 IsolateKillerVisitor visitor; |
| 2067 VisitIsolates(&visitor); |
| 2068 } |
| 2069 |
| 2070 |
1972 static RawInstance* DeserializeObject(Isolate* isolate, | 2071 static RawInstance* DeserializeObject(Isolate* isolate, |
1973 Zone* zone, | 2072 Zone* zone, |
1974 uint8_t* obj_data, | 2073 uint8_t* obj_data, |
1975 intptr_t obj_len) { | 2074 intptr_t obj_len) { |
1976 if (obj_data == NULL) { | 2075 if (obj_data == NULL) { |
1977 return Instance::null(); | 2076 return Instance::null(); |
1978 } | 2077 } |
1979 MessageSnapshotReader reader(obj_data, | 2078 MessageSnapshotReader reader(obj_data, |
1980 obj_len, | 2079 obj_len, |
1981 isolate, | 2080 isolate, |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 serialized_message_, serialized_message_len_); | 2267 serialized_message_, serialized_message_len_); |
2169 } | 2268 } |
2170 | 2269 |
2171 | 2270 |
2172 void IsolateSpawnState::Cleanup() { | 2271 void IsolateSpawnState::Cleanup() { |
2173 SwitchIsolateScope switch_scope(I); | 2272 SwitchIsolateScope switch_scope(I); |
2174 Dart::ShutdownIsolate(); | 2273 Dart::ShutdownIsolate(); |
2175 } | 2274 } |
2176 | 2275 |
2177 } // namespace dart | 2276 } // namespace dart |
OLD | NEW |