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 "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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 if (message->RedirectToDeliveryFailurePort()) { | 350 if (message->RedirectToDeliveryFailurePort()) { |
351 PortMap::PostMessage(message); | 351 PortMap::PostMessage(message); |
352 } else { | 352 } else { |
353 delete message; | 353 delete message; |
354 } | 354 } |
355 return true; | 355 return true; |
356 } | 356 } |
357 } | 357 } |
358 | 358 |
359 // Parse the message. | 359 // Parse the message. |
360 SnapshotReader reader(message->data(), message->len(), Snapshot::kMessage, I); | 360 SnapshotReader reader(message->data(), message->len(), Snapshot::kMessage, |
| 361 I, zone.GetZone()); |
361 const Object& msg_obj = Object::Handle(I, reader.ReadObject()); | 362 const Object& msg_obj = Object::Handle(I, reader.ReadObject()); |
362 if (msg_obj.IsError()) { | 363 if (msg_obj.IsError()) { |
363 // An error occurred while reading the message. | 364 // An error occurred while reading the message. |
364 delete message; | 365 delete message; |
365 return ProcessUnhandledException(Error::Cast(msg_obj)); | 366 return ProcessUnhandledException(Error::Cast(msg_obj)); |
366 } | 367 } |
367 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) { | 368 if (!msg_obj.IsNull() && !msg_obj.IsInstance()) { |
368 // TODO(turnidge): We need to decide what an isolate does with | 369 // TODO(turnidge): We need to decide what an isolate does with |
369 // malformed messages. If they (eventually) come from a remote | 370 // malformed messages. If they (eventually) come from a remote |
370 // machine, then it might make sense to drop the message entirely. | 371 // machine, then it might make sense to drop the message entirely. |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 | 1215 |
1215 // Instead of directly invoking the entry point we call '_startIsolate' with | 1216 // Instead of directly invoking the entry point we call '_startIsolate' with |
1216 // the entry point as argument. | 1217 // the entry point as argument. |
1217 // Since this function ("RunIsolate") is used for both Isolate.spawn and | 1218 // Since this function ("RunIsolate") is used for both Isolate.spawn and |
1218 // Isolate.spawnUri we also send a boolean flag as argument so that the | 1219 // Isolate.spawnUri we also send a boolean flag as argument so that the |
1219 // "_startIsolate" function can act corresponding to how the isolate was | 1220 // "_startIsolate" function can act corresponding to how the isolate was |
1220 // created. | 1221 // created. |
1221 const Array& args = Array::Handle(Array::New(7)); | 1222 const Array& args = Array::Handle(Array::New(7)); |
1222 args.SetAt(0, SendPort::Handle(SendPort::New(state->parent_port()))); | 1223 args.SetAt(0, SendPort::Handle(SendPort::New(state->parent_port()))); |
1223 args.SetAt(1, Instance::Handle(func.ImplicitStaticClosure())); | 1224 args.SetAt(1, Instance::Handle(func.ImplicitStaticClosure())); |
1224 args.SetAt(2, Instance::Handle(state->BuildArgs())); | 1225 args.SetAt(2, Instance::Handle(state->BuildArgs(zone.GetZone()))); |
1225 args.SetAt(3, Instance::Handle(state->BuildMessage())); | 1226 args.SetAt(3, Instance::Handle(state->BuildMessage(zone.GetZone()))); |
1226 args.SetAt(4, is_spawn_uri ? Bool::True() : Bool::False()); | 1227 args.SetAt(4, is_spawn_uri ? Bool::True() : Bool::False()); |
1227 args.SetAt(5, ReceivePort::Handle( | 1228 args.SetAt(5, ReceivePort::Handle( |
1228 ReceivePort::New(isolate->main_port(), true /* control port */))); | 1229 ReceivePort::New(isolate->main_port(), true /* control port */))); |
1229 args.SetAt(6, capabilities); | 1230 args.SetAt(6, capabilities); |
1230 | 1231 |
1231 const Library& lib = Library::Handle(Library::IsolateLibrary()); | 1232 const Library& lib = Library::Handle(Library::IsolateLibrary()); |
1232 const String& entry_name = String::Handle(String::New("_startIsolate")); | 1233 const String& entry_name = String::Handle(String::New("_startIsolate")); |
1233 const Function& entry_point = | 1234 const Function& entry_point = |
1234 Function::Handle(lib.LookupLocalFunction(entry_name)); | 1235 Function::Handle(lib.LookupLocalFunction(entry_name)); |
1235 ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); | 1236 ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 | 1789 |
1789 template<class T> | 1790 template<class T> |
1790 T* Isolate::AllocateReusableHandle() { | 1791 T* Isolate::AllocateReusableHandle() { |
1791 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); | 1792 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); |
1792 T::initializeHandle(handle, T::null()); | 1793 T::initializeHandle(handle, T::null()); |
1793 return handle; | 1794 return handle; |
1794 } | 1795 } |
1795 | 1796 |
1796 | 1797 |
1797 static RawInstance* DeserializeObject(Isolate* isolate, | 1798 static RawInstance* DeserializeObject(Isolate* isolate, |
| 1799 Zone* zone, |
1798 uint8_t* obj_data, | 1800 uint8_t* obj_data, |
1799 intptr_t obj_len) { | 1801 intptr_t obj_len) { |
1800 if (obj_data == NULL) { | 1802 if (obj_data == NULL) { |
1801 return Instance::null(); | 1803 return Instance::null(); |
1802 } | 1804 } |
1803 SnapshotReader reader(obj_data, obj_len, Snapshot::kMessage, isolate); | 1805 SnapshotReader reader(obj_data, obj_len, Snapshot::kMessage, isolate, zone); |
1804 const Object& obj = Object::Handle(isolate, reader.ReadObject()); | 1806 const Object& obj = Object::Handle(isolate, reader.ReadObject()); |
1805 ASSERT(!obj.IsError()); | 1807 ASSERT(!obj.IsError()); |
1806 Instance& instance = Instance::Handle(isolate); | 1808 Instance& instance = Instance::Handle(isolate); |
1807 instance ^= obj.raw(); // Can't use Instance::Cast because may be null. | 1809 instance ^= obj.raw(); // Can't use Instance::Cast because may be null. |
1808 return instance.raw(); | 1810 return instance.raw(); |
1809 } | 1811 } |
1810 | 1812 |
1811 | 1813 |
1812 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, | 1814 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, |
1813 const Function& func, | 1815 const Function& func, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 const String& msg = String::Handle(String::NewFormatted( | 1954 const String& msg = String::Handle(String::NewFormatted( |
1953 "Unable to resolve static method '%s.%s' in library '%s'.", | 1955 "Unable to resolve static method '%s.%s' in library '%s'.", |
1954 class_name(), function_name(), | 1956 class_name(), function_name(), |
1955 (library_url() != NULL ? library_url() : script_url()))); | 1957 (library_url() != NULL ? library_url() : script_url()))); |
1956 return LanguageError::New(msg); | 1958 return LanguageError::New(msg); |
1957 } | 1959 } |
1958 return func.raw(); | 1960 return func.raw(); |
1959 } | 1961 } |
1960 | 1962 |
1961 | 1963 |
1962 RawInstance* IsolateSpawnState::BuildArgs() { | 1964 RawInstance* IsolateSpawnState::BuildArgs(Zone* zone) { |
1963 return DeserializeObject(isolate_, serialized_args_, serialized_args_len_); | 1965 return DeserializeObject(isolate_, zone, |
| 1966 serialized_args_, serialized_args_len_); |
1964 } | 1967 } |
1965 | 1968 |
1966 | 1969 |
1967 RawInstance* IsolateSpawnState::BuildMessage() { | 1970 RawInstance* IsolateSpawnState::BuildMessage(Zone* zone) { |
1968 return DeserializeObject(isolate_, | 1971 return DeserializeObject(isolate_, zone, |
1969 serialized_message_, serialized_message_len_); | 1972 serialized_message_, serialized_message_len_); |
1970 } | 1973 } |
1971 | 1974 |
1972 | 1975 |
1973 void IsolateSpawnState::Cleanup() { | 1976 void IsolateSpawnState::Cleanup() { |
1974 SwitchIsolateScope switch_scope(I); | 1977 SwitchIsolateScope switch_scope(I); |
1975 Dart::ShutdownIsolate(); | 1978 Dart::ShutdownIsolate(); |
1976 } | 1979 } |
1977 | 1980 |
1978 } // namespace dart | 1981 } // namespace dart |
OLD | NEW |