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" | |
9 #include "platform/assert.h" | 8 #include "platform/assert.h" |
10 #include "platform/json.h" | 9 #include "platform/json.h" |
11 #include "vm/code_observers.h" | 10 #include "vm/code_observers.h" |
12 #include "vm/compiler_stats.h" | 11 #include "vm/compiler_stats.h" |
13 #include "vm/coverage.h" | 12 #include "vm/coverage.h" |
14 #include "vm/dart_api_message.h" | |
15 #include "vm/dart_api_state.h" | 13 #include "vm/dart_api_state.h" |
16 #include "vm/dart_entry.h" | 14 #include "vm/dart_entry.h" |
17 #include "vm/debugger.h" | 15 #include "vm/debugger.h" |
18 #include "vm/deopt_instructions.h" | 16 #include "vm/deopt_instructions.h" |
19 #include "vm/heap.h" | 17 #include "vm/heap.h" |
20 #include "vm/lockers.h" | 18 #include "vm/lockers.h" |
21 #include "vm/log.h" | 19 #include "vm/log.h" |
22 #include "vm/message_handler.h" | 20 #include "vm/message_handler.h" |
23 #include "vm/object_id_ring.h" | 21 #include "vm/object_id_ring.h" |
24 #include "vm/object_store.h" | 22 #include "vm/object_store.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 void NotifyPauseOnStart(); | 158 void NotifyPauseOnStart(); |
161 void NotifyPauseOnExit(); | 159 void NotifyPauseOnExit(); |
162 | 160 |
163 #if defined(DEBUG) | 161 #if defined(DEBUG) |
164 // Check that it is safe to access this handler. | 162 // Check that it is safe to access this handler. |
165 void CheckAccess(); | 163 void CheckAccess(); |
166 #endif | 164 #endif |
167 bool IsCurrentIsolate() const; | 165 bool IsCurrentIsolate() const; |
168 virtual Isolate* isolate() const { return isolate_; } | 166 virtual Isolate* isolate() const { return isolate_; } |
169 | 167 |
| 168 private: |
170 // Keep both these enums in sync with isolate_patch.dart. | 169 // Keep both these enums in sync with isolate_patch.dart. |
171 // The different Isolate API message types. | 170 // The different Isolate API message types. |
172 enum { | 171 enum { |
173 kPauseMsg = 1, | 172 kPauseMsg = 1, |
174 kResumeMsg = 2, | 173 kResumeMsg = 2, |
175 kPingMsg = 3, | 174 kPingMsg = 3, |
176 kKillMsg = 4, | 175 kKillMsg = 4, |
177 kAddExitMsg = 5, | 176 kAddExitMsg = 5, |
178 kDelExitMsg = 6, | 177 kDelExitMsg = 6, |
179 kAddErrorMsg = 7, | 178 kAddErrorMsg = 7, |
180 kDelErrorMsg = 8, | 179 kDelErrorMsg = 8, |
181 kErrorFatalMsg = 9, | 180 kErrorFatalMsg = 9, |
182 }; | 181 }; |
183 // The different Isolate API message priorities for ping and kill messages. | 182 // The different Isolate API message priorities for ping and kill messages. |
184 enum { | 183 enum { |
185 kImmediateAction = 0, | 184 kImmediateAction = 0, |
186 kBeforeNextEventAction = 1, | 185 kBeforeNextEventAction = 1, |
187 kAsEventAction = 2 | 186 kAsEventAction = 2 |
188 }; | 187 }; |
189 | 188 |
190 private: | |
191 // A result of false indicates that the isolate should terminate the | 189 // A result of false indicates that the isolate should terminate the |
192 // processing of further events. | 190 // processing of further events. |
193 bool HandleLibMessage(const Array& message); | 191 bool HandleLibMessage(const Array& message); |
194 | 192 |
195 bool ProcessUnhandledException(const Error& result); | 193 bool ProcessUnhandledException(const Error& result); |
196 Isolate* isolate_; | 194 Isolate* isolate_; |
197 }; | 195 }; |
198 | 196 |
199 | 197 |
200 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) | 198 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 bool Isolate::IsIsolateOf(Thread* thread) { | 742 bool Isolate::IsIsolateOf(Thread* thread) { |
745 return this == thread->isolate(); | 743 return this == thread->isolate(); |
746 } | 744 } |
747 #endif // DEBUG | 745 #endif // DEBUG |
748 | 746 |
749 | 747 |
750 void Isolate::InitOnce() { | 748 void Isolate::InitOnce() { |
751 create_callback_ = NULL; | 749 create_callback_ = NULL; |
752 isolates_list_monitor_ = new Monitor(); | 750 isolates_list_monitor_ = new Monitor(); |
753 ASSERT(isolates_list_monitor_ != NULL); | 751 ASSERT(isolates_list_monitor_ != NULL); |
754 EnableIsolateCreation(); | |
755 } | 752 } |
756 | 753 |
757 | 754 |
758 Isolate* Isolate::Init(const char* name_prefix, | 755 Isolate* Isolate::Init(const char* name_prefix, |
759 const Dart_IsolateFlags& api_flags, | 756 const Dart_IsolateFlags& api_flags, |
760 bool is_vm_isolate) { | 757 bool is_vm_isolate) { |
761 Isolate* result = new Isolate(api_flags); | 758 Isolate* result = new Isolate(api_flags); |
762 ASSERT(result != NULL); | 759 ASSERT(result != NULL); |
763 | 760 |
764 // Initialize metrics. | 761 // Initialize metrics. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 if (FLAG_trace_isolates) { | 820 if (FLAG_trace_isolates) { |
824 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 821 if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { |
825 OS::Print("[+] Starting isolate:\n" | 822 OS::Print("[+] Starting isolate:\n" |
826 "\tisolate: %s\n", result->name()); | 823 "\tisolate: %s\n", result->name()); |
827 } | 824 } |
828 } | 825 } |
829 if (FLAG_compiler_stats) { | 826 if (FLAG_compiler_stats) { |
830 result->compiler_stats_ = new CompilerStats(result); | 827 result->compiler_stats_ = new CompilerStats(result); |
831 } | 828 } |
832 ObjectIdRing::Init(result); | 829 ObjectIdRing::Init(result); |
833 | 830 // Add to isolate list. |
834 // Add to isolate list. Shutdown and delete the isolate on failure. | 831 AddIsolateTolist(result); |
835 if (!AddIsolateToList(result)) { | |
836 result->LowLevelShutdown(); | |
837 Thread::ExitIsolate(); | |
838 delete result; | |
839 return NULL; | |
840 } | |
841 | 832 |
842 return result; | 833 return result; |
843 } | 834 } |
844 | 835 |
845 | 836 |
846 void Isolate::InitializeStackLimit() { | 837 void Isolate::InitializeStackLimit() { |
847 SetStackLimitFromStackBase(Isolate::GetCurrentStackPointer()); | 838 SetStackLimitFromStackBase(Isolate::GetCurrentStackPointer()); |
848 } | 839 } |
849 | 840 |
850 | 841 |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 FinalizablePersistentHandle* handle = | 1447 FinalizablePersistentHandle* handle = |
1457 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 1448 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
1458 handle->UpdateUnreachable(I); | 1449 handle->UpdateUnreachable(I); |
1459 } | 1450 } |
1460 | 1451 |
1461 private: | 1452 private: |
1462 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); | 1453 DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); |
1463 }; | 1454 }; |
1464 | 1455 |
1465 | 1456 |
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 | |
1510 void Isolate::Shutdown() { | 1457 void Isolate::Shutdown() { |
1511 ASSERT(this == Isolate::Current()); | 1458 ASSERT(this == Isolate::Current()); |
1512 ASSERT(top_resource() == NULL); | 1459 ASSERT(top_resource() == NULL); |
1513 #if defined(DEBUG) | 1460 #if defined(DEBUG) |
1514 if (heap_ != NULL) { | 1461 if (heap_ != NULL) { |
1515 // The VM isolate keeps all objects marked. | 1462 // The VM isolate keeps all objects marked. |
1516 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); | 1463 heap_->Verify(this == Dart::vm_isolate() ? kRequireMarked : kForbidMarked); |
1517 } | 1464 } |
1518 #endif // DEBUG | 1465 #endif // DEBUG |
1519 | 1466 |
1520 // First, perform higher-level cleanup that may need to allocate. | 1467 // First, perform higher-level cleanup that may need to allocate. |
1521 { | 1468 { |
1522 // Ensure we have a zone and handle scope so that we can call VM functions. | 1469 // Ensure we have a zone and handle scope so that we can call VM functions. |
1523 StackZone stack_zone(this); | 1470 StackZone stack_zone(this); |
1524 HandleScope handle_scope(this); | 1471 HandleScope handle_scope(this); |
1525 | 1472 |
1526 // Write out the coverage data if collection has been enabled. | 1473 // Write out the coverage data if collection has been enabled. |
1527 if ((this != Dart::vm_isolate()) && | 1474 CodeCoverage::Write(this); |
1528 !ServiceIsolate::IsServiceIsolateDescendant(this)) { | |
1529 CodeCoverage::Write(this); | |
1530 } | |
1531 | 1475 |
1532 if ((timeline_event_recorder_ != NULL) && | 1476 if ((timeline_event_recorder_ != NULL) && |
1533 (FLAG_timeline_trace_dir != NULL)) { | 1477 (FLAG_timeline_trace_dir != NULL)) { |
1534 timeline_event_recorder_->WriteTo(FLAG_timeline_trace_dir); | 1478 timeline_event_recorder_->WriteTo(FLAG_timeline_trace_dir); |
1535 } | 1479 } |
1536 } | 1480 } |
1537 | 1481 |
1538 // Remove this isolate from the list *before* we start tearing it down, to | 1482 // Remove this isolate from the list *before* we start tearing it down, to |
1539 // avoid exposing it in a state of decay. | 1483 // avoid exposing it in a state of decay. |
1540 RemoveIsolateFromList(this); | 1484 RemoveIsolateFromList(this); |
1541 | 1485 |
1542 if (heap_ != NULL) { | 1486 if (heap_ != NULL) { |
1543 // Wait for any concurrent GC tasks to finish before shutting down. | 1487 // Wait for any concurrent GC tasks to finish before shutting down. |
1544 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). | 1488 // TODO(koda): Support faster sweeper shutdown (e.g., after current page). |
1545 PageSpace* old_space = heap_->old_space(); | 1489 PageSpace* old_space = heap_->old_space(); |
1546 MonitorLocker ml(old_space->tasks_lock()); | 1490 MonitorLocker ml(old_space->tasks_lock()); |
1547 while (old_space->tasks() > 0) { | 1491 while (old_space->tasks() > 0) { |
1548 ml.Wait(); | 1492 ml.Wait(); |
1549 } | 1493 } |
1550 } | 1494 } |
1551 | 1495 |
1552 // Then, proceed with low-level teardown. | 1496 // Then, proceed with low-level teardown. |
1553 LowLevelShutdown(); | 1497 { |
| 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 } |
1554 | 1539 |
1555 #if defined(DEBUG) | 1540 #if defined(DEBUG) |
1556 // No concurrent sweeper tasks should be running at this point. | 1541 // No concurrent sweeper tasks should be running at this point. |
1557 if (heap_ != NULL) { | 1542 if (heap_ != NULL) { |
1558 PageSpace* old_space = heap_->old_space(); | 1543 PageSpace* old_space = heap_->old_space(); |
1559 MonitorLocker ml(old_space->tasks_lock()); | 1544 MonitorLocker ml(old_space->tasks_lock()); |
1560 ASSERT(old_space->tasks() == 0); | 1545 ASSERT(old_space->tasks() == 0); |
1561 } | 1546 } |
1562 #endif | 1547 #endif |
1563 | 1548 |
(...skipping 12 matching lines...) Expand all Loading... |
1576 Isolate::unhandled_exception_callback_ = NULL; | 1561 Isolate::unhandled_exception_callback_ = NULL; |
1577 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; | 1562 Dart_IsolateShutdownCallback Isolate::shutdown_callback_ = NULL; |
1578 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; | 1563 Dart_FileOpenCallback Isolate::file_open_callback_ = NULL; |
1579 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; | 1564 Dart_FileReadCallback Isolate::file_read_callback_ = NULL; |
1580 Dart_FileWriteCallback Isolate::file_write_callback_ = NULL; | 1565 Dart_FileWriteCallback Isolate::file_write_callback_ = NULL; |
1581 Dart_FileCloseCallback Isolate::file_close_callback_ = NULL; | 1566 Dart_FileCloseCallback Isolate::file_close_callback_ = NULL; |
1582 Dart_EntropySource Isolate::entropy_source_callback_ = NULL; | 1567 Dart_EntropySource Isolate::entropy_source_callback_ = NULL; |
1583 | 1568 |
1584 Monitor* Isolate::isolates_list_monitor_ = NULL; | 1569 Monitor* Isolate::isolates_list_monitor_ = NULL; |
1585 Isolate* Isolate::isolates_list_head_ = NULL; | 1570 Isolate* Isolate::isolates_list_head_ = NULL; |
1586 bool Isolate::creation_enabled_ = false; | 1571 |
1587 | 1572 |
1588 void Isolate::IterateObjectPointers(ObjectPointerVisitor* visitor, | 1573 void Isolate::IterateObjectPointers(ObjectPointerVisitor* visitor, |
1589 bool visit_prologue_weak_handles, | 1574 bool visit_prologue_weak_handles, |
1590 bool validate_frames) { | 1575 bool validate_frames) { |
1591 HeapIterationScope heap_iteration_scope; | 1576 HeapIterationScope heap_iteration_scope; |
1592 VisitObjectPointers(visitor, visit_prologue_weak_handles, validate_frames); | 1577 VisitObjectPointers(visitor, visit_prologue_weak_handles, validate_frames); |
1593 } | 1578 } |
1594 | 1579 |
1595 | 1580 |
1596 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, | 1581 void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor, |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 intptr_t count = 0; | 1910 intptr_t count = 0; |
1926 Isolate* current = isolates_list_head_; | 1911 Isolate* current = isolates_list_head_; |
1927 while (current != NULL) { | 1912 while (current != NULL) { |
1928 count++; | 1913 count++; |
1929 current = current->next_; | 1914 current = current->next_; |
1930 } | 1915 } |
1931 return count; | 1916 return count; |
1932 } | 1917 } |
1933 | 1918 |
1934 | 1919 |
1935 bool Isolate::AddIsolateToList(Isolate* isolate) { | 1920 void Isolate::AddIsolateTolist(Isolate* isolate) { |
1936 MonitorLocker ml(isolates_list_monitor_); | 1921 MonitorLocker ml(isolates_list_monitor_); |
1937 if (!creation_enabled_) { | |
1938 return false; | |
1939 } | |
1940 ASSERT(isolate != NULL); | 1922 ASSERT(isolate != NULL); |
1941 ASSERT(isolate->next_ == NULL); | 1923 ASSERT(isolate->next_ == NULL); |
1942 isolate->next_ = isolates_list_head_; | 1924 isolate->next_ = isolates_list_head_; |
1943 isolates_list_head_ = isolate; | 1925 isolates_list_head_ = isolate; |
1944 return true; | |
1945 } | 1926 } |
1946 | 1927 |
1947 | 1928 |
1948 void Isolate::RemoveIsolateFromList(Isolate* isolate) { | 1929 void Isolate::RemoveIsolateFromList(Isolate* isolate) { |
1949 MonitorLocker ml(isolates_list_monitor_); | 1930 MonitorLocker ml(isolates_list_monitor_); |
1950 ASSERT(isolate != NULL); | 1931 ASSERT(isolate != NULL); |
1951 if (isolate == isolates_list_head_) { | 1932 if (isolate == isolates_list_head_) { |
1952 isolates_list_head_ = isolate->next_; | 1933 isolates_list_head_ = isolate->next_; |
1953 return; | 1934 return; |
1954 } | 1935 } |
1955 Isolate* previous = NULL; | 1936 Isolate* previous = NULL; |
1956 Isolate* current = isolates_list_head_; | 1937 Isolate* current = isolates_list_head_; |
1957 while (current) { | 1938 while (current) { |
1958 if (current == isolate) { | 1939 if (current == isolate) { |
1959 ASSERT(previous != NULL); | 1940 ASSERT(previous != NULL); |
1960 previous->next_ = current->next_; | 1941 previous->next_ = current->next_; |
1961 return; | 1942 return; |
1962 } | 1943 } |
1963 previous = current; | 1944 previous = current; |
1964 current = current->next_; | 1945 current = current->next_; |
1965 } | 1946 } |
1966 // If we are shutting down the VM, the isolate may not be in the list. | 1947 UNREACHABLE(); |
1967 ASSERT(!creation_enabled_); | |
1968 } | 1948 } |
1969 | 1949 |
1970 | 1950 |
1971 #if defined(DEBUG) | 1951 #if defined(DEBUG) |
1972 void Isolate::CheckForDuplicateThreadState(InterruptableThreadState* state) { | 1952 void Isolate::CheckForDuplicateThreadState(InterruptableThreadState* state) { |
1973 MonitorLocker ml(isolates_list_monitor_); | 1953 MonitorLocker ml(isolates_list_monitor_); |
1974 ASSERT(state != NULL); | 1954 ASSERT(state != NULL); |
1975 Isolate* current = isolates_list_head_; | 1955 Isolate* current = isolates_list_head_; |
1976 while (current) { | 1956 while (current) { |
1977 ASSERT(current->thread_state() != state); | 1957 ASSERT(current->thread_state() != state); |
1978 current = current->next_; | 1958 current = current->next_; |
1979 } | 1959 } |
1980 } | 1960 } |
1981 #endif | 1961 #endif |
1982 | 1962 |
1983 | 1963 |
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 | |
1996 template<class T> | 1964 template<class T> |
1997 T* Isolate::AllocateReusableHandle() { | 1965 T* Isolate::AllocateReusableHandle() { |
1998 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); | 1966 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); |
1999 T::initializeHandle(handle, T::null()); | 1967 T::initializeHandle(handle, T::null()); |
2000 return handle; | 1968 return handle; |
2001 } | 1969 } |
2002 | 1970 |
2003 | 1971 |
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 | |
2071 static RawInstance* DeserializeObject(Isolate* isolate, | 1972 static RawInstance* DeserializeObject(Isolate* isolate, |
2072 Zone* zone, | 1973 Zone* zone, |
2073 uint8_t* obj_data, | 1974 uint8_t* obj_data, |
2074 intptr_t obj_len) { | 1975 intptr_t obj_len) { |
2075 if (obj_data == NULL) { | 1976 if (obj_data == NULL) { |
2076 return Instance::null(); | 1977 return Instance::null(); |
2077 } | 1978 } |
2078 MessageSnapshotReader reader(obj_data, | 1979 MessageSnapshotReader reader(obj_data, |
2079 obj_len, | 1980 obj_len, |
2080 isolate, | 1981 isolate, |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2267 serialized_message_, serialized_message_len_); | 2168 serialized_message_, serialized_message_len_); |
2268 } | 2169 } |
2269 | 2170 |
2270 | 2171 |
2271 void IsolateSpawnState::Cleanup() { | 2172 void IsolateSpawnState::Cleanup() { |
2272 SwitchIsolateScope switch_scope(I); | 2173 SwitchIsolateScope switch_scope(I); |
2273 Dart::ShutdownIsolate(); | 2174 Dart::ShutdownIsolate(); |
2274 } | 2175 } |
2275 | 2176 |
2276 } // namespace dart | 2177 } // namespace dart |
OLD | NEW |