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