Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: runtime/vm/isolate.cc

Issue 1177153005: Enables clean VM shutdown. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Kill isolates from the service isolate Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/json.h" 9 #include "platform/json.h"
10 #include "vm/code_observers.h" 10 #include "vm/code_observers.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 void NotifyPauseOnStart(); 149 void NotifyPauseOnStart();
150 void NotifyPauseOnExit(); 150 void NotifyPauseOnExit();
151 151
152 #if defined(DEBUG) 152 #if defined(DEBUG)
153 // Check that it is safe to access this handler. 153 // Check that it is safe to access this handler.
154 void CheckAccess(); 154 void CheckAccess();
155 #endif 155 #endif
156 bool IsCurrentIsolate() const; 156 bool IsCurrentIsolate() const;
157 virtual Isolate* isolate() const { return isolate_; } 157 virtual Isolate* isolate() const { return isolate_; }
158 158
159 private:
160 // Keep both these enums in sync with isolate_patch.dart. 159 // Keep both these enums in sync with isolate_patch.dart.
161 // The different Isolate API message types. 160 // The different Isolate API message types.
162 enum { 161 enum {
163 kPauseMsg = 1, 162 kPauseMsg = 1,
164 kResumeMsg = 2, 163 kResumeMsg = 2,
165 kPingMsg = 3, 164 kPingMsg = 3,
166 kKillMsg = 4, 165 kKillMsg = 4,
167 kAddExitMsg = 5, 166 kAddExitMsg = 5,
168 kDelExitMsg = 6, 167 kDelExitMsg = 6,
169 kAddErrorMsg = 7, 168 kAddErrorMsg = 7,
170 kDelErrorMsg = 8, 169 kDelErrorMsg = 8,
171 kErrorFatalMsg = 9, 170 kErrorFatalMsg = 9,
172 }; 171 };
173 // The different Isolate API message priorities for ping and kill messages. 172 // The different Isolate API message priorities for ping and kill messages.
174 enum { 173 enum {
175 kImmediateAction = 0, 174 kImmediateAction = 0,
176 kBeforeNextEventAction = 1, 175 kBeforeNextEventAction = 1,
177 kAsEventAction = 2 176 kAsEventAction = 2
178 }; 177 };
179 178
179 private:
180 // A result of false indicates that the isolate should terminate the 180 // A result of false indicates that the isolate should terminate the
181 // processing of further events. 181 // processing of further events.
182 bool HandleLibMessage(const Array& message); 182 bool HandleLibMessage(const Array& message);
183 183
184 bool ProcessUnhandledException(const Error& result); 184 bool ProcessUnhandledException(const Error& result);
185 Isolate* isolate_; 185 Isolate* isolate_;
186 }; 186 };
187 187
188 188
189 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) 189 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate)
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 listeners.SetAt(i + 1, Object::null_instance()); 1114 listeners.SetAt(i + 1, Object::null_instance());
1115 return; 1115 return;
1116 } 1116 }
1117 } 1117 }
1118 } 1118 }
1119 1119
1120 1120
1121 void Isolate::NotifyExitListeners() { 1121 void Isolate::NotifyExitListeners() {
1122 const GrowableObjectArray& listeners = GrowableObjectArray::Handle( 1122 const GrowableObjectArray& listeners = GrowableObjectArray::Handle(
1123 this, this->object_store()->exit_listeners()); 1123 this, this->object_store()->exit_listeners());
1124 if (listeners.IsNull()) return; 1124 if (listeners.IsNull()) {
1125 return;
1126 }
1125 1127
1126 SendPort& listener = SendPort::Handle(this); 1128 SendPort& listener = SendPort::Handle(this);
1127 Instance& response = Instance::Handle(this); 1129 Instance& response = Instance::Handle(this);
1128 for (intptr_t i = 0; i < listeners.Length(); i += 2) { 1130 for (intptr_t i = 0; i < listeners.Length(); i += 2) {
1129 listener ^= listeners.At(i); 1131 listener ^= listeners.At(i);
1130 if (!listener.IsNull()) { 1132 if (!listener.IsNull()) {
1131 Dart_Port port_id = listener.Id(); 1133 Dart_Port port_id = listener.Id();
1132 uint8_t* data = NULL; 1134 uint8_t* data = NULL;
1133 intptr_t len = 0; 1135 intptr_t len = 0;
1134 response ^= listeners.At(i + 1); 1136 response ^= listeners.At(i + 1);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 } 1322 }
1321 { 1323 {
1322 // Shut the isolate down. 1324 // Shut the isolate down.
1323 SwitchIsolateScope switch_scope(isolate); 1325 SwitchIsolateScope switch_scope(isolate);
1324 Dart::ShutdownIsolate(); 1326 Dart::ShutdownIsolate();
1325 } 1327 }
1326 } 1328 }
1327 1329
1328 1330
1329 void Isolate::Run() { 1331 void Isolate::Run() {
1330 message_handler()->Run(Dart::thread_pool(), 1332 message_handler()->Run(RunIsolate,
1331 RunIsolate,
1332 ShutdownIsolate, 1333 ShutdownIsolate,
1333 reinterpret_cast<uword>(this)); 1334 reinterpret_cast<uword>(this));
1334 } 1335 }
1335 1336
1336 1337
1337 uword Isolate::GetAndClearInterrupts() { 1338 uword Isolate::GetAndClearInterrupts() {
1338 MutexLocker ml(mutex_); 1339 MutexLocker ml(mutex_);
1339 if (stack_limit_ == saved_stack_limit_) { 1340 if (stack_limit_ == saved_stack_limit_) {
1340 return 0; // No interrupt was requested. 1341 return 0; // No interrupt was requested.
1341 } 1342 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 PortMap::ClosePorts(message_handler()); 1464 PortMap::ClosePorts(message_handler());
1464 1465
1465 // Fail fast if anybody tries to post any more messsages to this isolate. 1466 // Fail fast if anybody tries to post any more messsages to this isolate.
1466 delete message_handler(); 1467 delete message_handler();
1467 set_message_handler(NULL); 1468 set_message_handler(NULL);
1468 1469
1469 // Dump all accumulated timer data for the isolate. 1470 // Dump all accumulated timer data for the isolate.
1470 timer_list_.ReportTimers(); 1471 timer_list_.ReportTimers();
1471 1472
1472 // Write out the coverage data if collection has been enabled. 1473 // Write out the coverage data if collection has been enabled.
1473 CodeCoverage::Write(this); 1474 if (this != Dart::vm_isolate()) {
1475 CodeCoverage::Write(this);
1476 }
1474 1477
1475 // Finalize any weak persistent handles with a non-null referent. 1478 // Finalize any weak persistent handles with a non-null referent.
1476 FinalizeWeakPersistentHandlesVisitor visitor; 1479 FinalizeWeakPersistentHandlesVisitor visitor;
1477 api_state()->weak_persistent_handles().VisitHandles(&visitor); 1480 api_state()->weak_persistent_handles().VisitHandles(&visitor);
1478 api_state()->prologue_weak_persistent_handles().VisitHandles(&visitor); 1481 api_state()->prologue_weak_persistent_handles().VisitHandles(&visitor);
1479 1482
1480 if (FLAG_trace_isolates) { 1483 if (FLAG_trace_isolates) {
1481 heap()->PrintSizes(); 1484 heap()->PrintSizes();
1482 megamorphic_cache_table()->PrintSizes(); 1485 megamorphic_cache_table()->PrintSizes();
1483 Symbols::DumpStats(); 1486 Symbols::DumpStats();
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 1892
1890 1893
1891 template<class T> 1894 template<class T>
1892 T* Isolate::AllocateReusableHandle() { 1895 T* Isolate::AllocateReusableHandle() {
1893 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); 1896 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle());
1894 T::initializeHandle(handle, T::null()); 1897 T::initializeHandle(handle, T::null());
1895 return handle; 1898 return handle;
1896 } 1899 }
1897 1900
1898 1901
1902 class IsolateKillerVisitor : public IsolateVisitor {
1903 public:
1904 explicit IsolateKillerVisitor(const Array& msg)
1905 : IsolateVisitor(), msg_(Array::Handle(msg.raw())) {
1906 ASSERT(msg_.Length() == 4);
1907 msg_.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg)));
1908 msg_.SetAt(1, Smi::Handle(Smi::New(IsolateMessageHandler::kKillMsg)));
1909 msg_.SetAt(3, Smi::Handle(Smi::New(
1910 IsolateMessageHandler::kBeforeNextEventAction)));
turnidge 2015/06/30 22:15:46 We discusssed offline that it should be possible t
zra 2015/07/20 22:23:38 Acknowledged.
1911 }
1912
1913 void VisitIsolate(Isolate* isolate) {
1914 ASSERT(isolate != NULL);
1915 if ((isolate == Isolate::Current()) ||
1916 ServiceIsolate::IsServiceIsolate(isolate) ||
1917 (isolate == Dart::vm_isolate())) {
1918 return;
1919 }
1920 SendKillMessageTo(isolate);
1921 }
1922
1923 private:
1924 void SendKillMessageTo(Isolate* isolate) {
1925 // Set the capability field of the kill message with the right capability
1926 // for the isolate we are sending the message to.
1927 msg_.SetAt(2, Capability::Handle(
1928 Capability::New(isolate->terminate_capability())));
1929
1930 uint8_t* data = NULL;
1931 MessageWriter writer(&data, &allocator, false);
1932 writer.WriteMessage(msg_);
1933
1934 PortMap::PostMessage(new Message(isolate->main_port(),
1935 data, writer.BytesWritten(),
1936 Message::kOOBPriority));
1937 }
1938
1939 Array& msg_;
1940 };
1941
1942
1943 void Isolate::KillAllIsolates(Isolate* isolate) {
turnidge 2015/06/30 22:15:46 Will the "isolate" param always be the current iso
zra 2015/07/20 22:23:38 No. It should always be the service isolate. I've
1944 const Array& msg = Array::Handle(isolate, Array::New(4));
1945 IsolateKillerVisitor visitor(msg);
1946 VisitIsolates(&visitor);
1947 }
1948
1949
1899 static RawInstance* DeserializeObject(Isolate* isolate, 1950 static RawInstance* DeserializeObject(Isolate* isolate,
1900 Zone* zone, 1951 Zone* zone,
1901 uint8_t* obj_data, 1952 uint8_t* obj_data,
1902 intptr_t obj_len) { 1953 intptr_t obj_len) {
1903 if (obj_data == NULL) { 1954 if (obj_data == NULL) {
1904 return Instance::null(); 1955 return Instance::null();
1905 } 1956 }
1906 MessageSnapshotReader reader(obj_data, 1957 MessageSnapshotReader reader(obj_data,
1907 obj_len, 1958 obj_len,
1908 isolate, 1959 isolate,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 serialized_message_, serialized_message_len_); 2134 serialized_message_, serialized_message_len_);
2084 } 2135 }
2085 2136
2086 2137
2087 void IsolateSpawnState::Cleanup() { 2138 void IsolateSpawnState::Cleanup() {
2088 SwitchIsolateScope switch_scope(I); 2139 SwitchIsolateScope switch_scope(I);
2089 Dart::ShutdownIsolate(); 2140 Dart::ShutdownIsolate();
2090 } 2141 }
2091 2142
2092 } // namespace dart 2143 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698