| 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 "include/dart_native_api.h" | 
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" | 
| 10 #include "platform/text_buffer.h" | 10 #include "platform/text_buffer.h" | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 57 DECLARE_FLAG(bool, trace_service); | 57 DECLARE_FLAG(bool, trace_service); | 
| 58 DECLARE_FLAG(bool, warn_on_pause_with_no_debugger); | 58 DECLARE_FLAG(bool, warn_on_pause_with_no_debugger); | 
| 59 | 59 | 
| 60 // Reload flags. | 60 // Reload flags. | 
| 61 DECLARE_FLAG(bool, check_reloaded); | 61 DECLARE_FLAG(bool, check_reloaded); | 
| 62 DECLARE_FLAG(int, reload_every); | 62 DECLARE_FLAG(int, reload_every); | 
| 63 DECLARE_FLAG(bool, reload_every_back_off); | 63 DECLARE_FLAG(bool, reload_every_back_off); | 
| 64 DECLARE_FLAG(bool, trace_reload); | 64 DECLARE_FLAG(bool, trace_reload); | 
| 65 | 65 | 
| 66 | 66 | 
| 67 NOT_IN_PRODUCT( | 67 #if !defined(PRODUCT) | 
| 68 static void CheckedModeHandler(bool value) { | 68 static void CheckedModeHandler(bool value) { | 
| 69   FLAG_enable_asserts = value; | 69   FLAG_enable_asserts = value; | 
| 70   FLAG_enable_type_checks = value; | 70   FLAG_enable_type_checks = value; | 
| 71 } | 71 } | 
| 72 | 72 | 
| 73 // --enable-checked-mode and --checked both enable checked mode which is | 73 // --enable-checked-mode and --checked both enable checked mode which is | 
| 74 // equivalent to setting --enable-asserts and --enable-type-checks. | 74 // equivalent to setting --enable-asserts and --enable-type-checks. | 
| 75 DEFINE_FLAG_HANDLER(CheckedModeHandler, | 75 DEFINE_FLAG_HANDLER(CheckedModeHandler, | 
| 76                     enable_checked_mode, | 76                     enable_checked_mode, | 
| 77                     "Enable checked mode."); | 77                     "Enable checked mode."); | 
| 78 | 78 | 
| 79 DEFINE_FLAG_HANDLER(CheckedModeHandler, | 79 DEFINE_FLAG_HANDLER(CheckedModeHandler, checked, "Enable checked mode."); | 
| 80                     checked, | 80 #endif  // !defined(PRODUCT) | 
| 81                     "Enable checked mode."); |  | 
| 82 ) |  | 
| 83 | 81 | 
| 84 | 82 | 
| 85 // Quick access to the locally defined thread() and isolate() methods. | 83 // Quick access to the locally defined thread() and isolate() methods. | 
| 86 #define T (thread()) | 84 #define T (thread()) | 
| 87 #define I (isolate()) | 85 #define I (isolate()) | 
| 88 | 86 | 
| 89 #if defined(DEBUG) | 87 #if defined(DEBUG) | 
| 90 // Helper class to ensure that a live origin_id is never reused | 88 // Helper class to ensure that a live origin_id is never reused | 
| 91 // and assigned to an isolate. | 89 // and assigned to an isolate. | 
| 92 class VerifyOriginId : public IsolateVisitor { | 90 class VerifyOriginId : public IsolateVisitor { | 
| 93  public: | 91  public: | 
| 94   explicit VerifyOriginId(Dart_Port id) : id_(id) {} | 92   explicit VerifyOriginId(Dart_Port id) : id_(id) {} | 
| 95 | 93 | 
| 96   void VisitIsolate(Isolate* isolate) { | 94   void VisitIsolate(Isolate* isolate) { ASSERT(isolate->origin_id() != id_); } | 
| 97     ASSERT(isolate->origin_id() != id_); |  | 
| 98   } |  | 
| 99 | 95 | 
| 100  private: | 96  private: | 
| 101   Dart_Port id_; | 97   Dart_Port id_; | 
| 102   DISALLOW_COPY_AND_ASSIGN(VerifyOriginId); | 98   DISALLOW_COPY_AND_ASSIGN(VerifyOriginId); | 
| 103 }; | 99 }; | 
| 104 #endif | 100 #endif | 
| 105 | 101 | 
| 106 | 102 | 
| 107 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 103 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 
| 108   void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 104   void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 
| 109   return reinterpret_cast<uint8_t*>(new_ptr); | 105   return reinterpret_cast<uint8_t*>(new_ptr); | 
| 110 } | 106 } | 
| 111 | 107 | 
| 112 | 108 | 
| 113 static void SerializeObject(const Instance& obj, | 109 static void SerializeObject(const Instance& obj, | 
| 114                             uint8_t** obj_data, | 110                             uint8_t** obj_data, | 
| 115                             intptr_t* obj_len, | 111                             intptr_t* obj_len, | 
| 116                             bool allow_any_object) { | 112                             bool allow_any_object) { | 
| 117   MessageWriter writer(obj_data, &allocator, allow_any_object); | 113   MessageWriter writer(obj_data, &allocator, allow_any_object); | 
| 118   writer.WriteMessage(obj); | 114   writer.WriteMessage(obj); | 
| 119   *obj_len = writer.BytesWritten(); | 115   *obj_len = writer.BytesWritten(); | 
| 120 } | 116 } | 
| 121 | 117 | 
| 122 // TODO(zra): Allocation of Message objects should be centralized. | 118 // TODO(zra): Allocation of Message objects should be centralized. | 
| 123 static Message* SerializeMessage( | 119 static Message* SerializeMessage(Dart_Port dest_port, const Instance& obj) { | 
| 124     Dart_Port dest_port, const Instance& obj) { |  | 
| 125   if (ApiObjectConverter::CanConvert(obj.raw())) { | 120   if (ApiObjectConverter::CanConvert(obj.raw())) { | 
| 126     return new Message(dest_port, obj.raw(), Message::kNormalPriority); | 121     return new Message(dest_port, obj.raw(), Message::kNormalPriority); | 
| 127   } else { | 122   } else { | 
| 128     uint8_t* obj_data; | 123     uint8_t* obj_data; | 
| 129     intptr_t obj_len; | 124     intptr_t obj_len; | 
| 130     SerializeObject(obj, &obj_data, &obj_len, false); | 125     SerializeObject(obj, &obj_data, &obj_len, false); | 
| 131     return new Message(dest_port, obj_data, obj_len, Message::kNormalPriority); | 126     return new Message(dest_port, obj_data, obj_len, Message::kNormalPriority); | 
| 132   } | 127   } | 
| 133 } | 128 } | 
| 134 | 129 | 
| 135 | 130 | 
| 136 NoOOBMessageScope::NoOOBMessageScope(Thread* thread) : StackResource(thread) { | 131 NoOOBMessageScope::NoOOBMessageScope(Thread* thread) : StackResource(thread) { | 
| 137   thread->DeferOOBMessageInterrupts(); | 132   thread->DeferOOBMessageInterrupts(); | 
| 138 } | 133 } | 
| 139 | 134 | 
| 140 | 135 | 
| 141 NoOOBMessageScope::~NoOOBMessageScope() { | 136 NoOOBMessageScope::~NoOOBMessageScope() { | 
| 142   thread()->RestoreOOBMessageInterrupts(); | 137   thread()->RestoreOOBMessageInterrupts(); | 
| 143 } | 138 } | 
| 144 | 139 | 
| 145 | 140 | 
| 146 NoReloadScope::NoReloadScope(Isolate* isolate, Thread* thread) | 141 NoReloadScope::NoReloadScope(Isolate* isolate, Thread* thread) | 
| 147     : StackResource(thread), | 142     : StackResource(thread), isolate_(isolate) { | 
| 148       isolate_(isolate) { |  | 
| 149   ASSERT(isolate_ != NULL); | 143   ASSERT(isolate_ != NULL); | 
| 150   AtomicOperations::FetchAndIncrement(&(isolate_->no_reload_scope_depth_)); | 144   AtomicOperations::FetchAndIncrement(&(isolate_->no_reload_scope_depth_)); | 
| 151   ASSERT( | 145   ASSERT(AtomicOperations::LoadRelaxed(&(isolate_->no_reload_scope_depth_)) >= | 
| 152       AtomicOperations::LoadRelaxed(&(isolate_->no_reload_scope_depth_)) >= 0); | 146          0); | 
| 153 } | 147 } | 
| 154 | 148 | 
| 155 | 149 | 
| 156 NoReloadScope::~NoReloadScope() { | 150 NoReloadScope::~NoReloadScope() { | 
| 157   AtomicOperations::FetchAndDecrement(&(isolate_->no_reload_scope_depth_)); | 151   AtomicOperations::FetchAndDecrement(&(isolate_->no_reload_scope_depth_)); | 
| 158   ASSERT( | 152   ASSERT(AtomicOperations::LoadRelaxed(&(isolate_->no_reload_scope_depth_)) >= | 
| 159       AtomicOperations::LoadRelaxed(&(isolate_->no_reload_scope_depth_)) >= 0); | 153          0); | 
| 160 } | 154 } | 
| 161 | 155 | 
| 162 | 156 | 
| 163 void Isolate::RegisterClass(const Class& cls) { | 157 void Isolate::RegisterClass(const Class& cls) { | 
| 164   NOT_IN_PRODUCT( | 158 #if !defined(PRODUCT) | 
| 165     if (IsReloading()) { | 159   if (IsReloading()) { | 
| 166       reload_context()->RegisterClass(cls); | 160     reload_context()->RegisterClass(cls); | 
| 167       return; | 161     return; | 
| 168     } | 162   } | 
| 169   ) | 163 #endif  // !defined(PRODUCT) | 
| 170   class_table()->Register(cls); | 164   class_table()->Register(cls); | 
| 171 } | 165 } | 
| 172 | 166 | 
| 173 | 167 | 
| 174 void Isolate::RegisterClassAt(intptr_t index, const Class& cls) { | 168 void Isolate::RegisterClassAt(intptr_t index, const Class& cls) { | 
| 175   class_table()->RegisterAt(index, cls); | 169   class_table()->RegisterAt(index, cls); | 
| 176 } | 170 } | 
| 177 | 171 | 
| 178 | 172 | 
| 179 void Isolate::ValidateClassTable() { | 173 void Isolate::ValidateClassTable() { | 
| 180   class_table()->Validate(); | 174   class_table()->Validate(); | 
| 181 } | 175 } | 
| 182 | 176 | 
| 183 | 177 | 
| 184 void Isolate::SendInternalLibMessage(LibMsgId msg_id, uint64_t capability) { | 178 void Isolate::SendInternalLibMessage(LibMsgId msg_id, uint64_t capability) { | 
| 185   const Array& msg = Array::Handle(Array::New(3)); | 179   const Array& msg = Array::Handle(Array::New(3)); | 
| 186   Object& element = Object::Handle(); | 180   Object& element = Object::Handle(); | 
| 187 | 181 | 
| 188   element = Smi::New(Message::kIsolateLibOOBMsg); | 182   element = Smi::New(Message::kIsolateLibOOBMsg); | 
| 189   msg.SetAt(0, element); | 183   msg.SetAt(0, element); | 
| 190   element = Smi::New(msg_id); | 184   element = Smi::New(msg_id); | 
| 191   msg.SetAt(1, element); | 185   msg.SetAt(1, element); | 
| 192   element = Capability::New(capability); | 186   element = Capability::New(capability); | 
| 193   msg.SetAt(2, element); | 187   msg.SetAt(2, element); | 
| 194 | 188 | 
| 195   uint8_t* data = NULL; | 189   uint8_t* data = NULL; | 
| 196   MessageWriter writer(&data, &allocator, false); | 190   MessageWriter writer(&data, &allocator, false); | 
| 197   writer.WriteMessage(msg); | 191   writer.WriteMessage(msg); | 
| 198 | 192 | 
| 199   PortMap::PostMessage(new Message(main_port(), | 193   PortMap::PostMessage(new Message(main_port(), data, writer.BytesWritten(), | 
| 200                                    data, writer.BytesWritten(), |  | 
| 201                                    Message::kOOBPriority)); | 194                                    Message::kOOBPriority)); | 
| 202 } | 195 } | 
| 203 | 196 | 
| 204 | 197 | 
| 205 class IsolateMessageHandler : public MessageHandler { | 198 class IsolateMessageHandler : public MessageHandler { | 
| 206  public: | 199  public: | 
| 207   explicit IsolateMessageHandler(Isolate* isolate); | 200   explicit IsolateMessageHandler(Isolate* isolate); | 
| 208   ~IsolateMessageHandler(); | 201   ~IsolateMessageHandler(); | 
| 209 | 202 | 
| 210   const char* name() const; | 203   const char* name() const; | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 226   // A result of false indicates that the isolate should terminate the | 219   // A result of false indicates that the isolate should terminate the | 
| 227   // processing of further events. | 220   // processing of further events. | 
| 228   RawError* HandleLibMessage(const Array& message); | 221   RawError* HandleLibMessage(const Array& message); | 
| 229 | 222 | 
| 230   MessageStatus ProcessUnhandledException(const Error& result); | 223   MessageStatus ProcessUnhandledException(const Error& result); | 
| 231   Isolate* isolate_; | 224   Isolate* isolate_; | 
| 232 }; | 225 }; | 
| 233 | 226 | 
| 234 | 227 | 
| 235 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) | 228 IsolateMessageHandler::IsolateMessageHandler(Isolate* isolate) | 
| 236     : isolate_(isolate) { | 229     : isolate_(isolate) {} | 
| 237 } |  | 
| 238 | 230 | 
| 239 | 231 | 
| 240 IsolateMessageHandler::~IsolateMessageHandler() { | 232 IsolateMessageHandler::~IsolateMessageHandler() {} | 
| 241 } |  | 
| 242 | 233 | 
| 243 const char* IsolateMessageHandler::name() const { | 234 const char* IsolateMessageHandler::name() const { | 
| 244   return isolate_->name(); | 235   return isolate_->name(); | 
| 245 } | 236 } | 
| 246 | 237 | 
| 247 | 238 | 
| 248 // Isolate library OOB messages are fixed sized arrays which have the | 239 // Isolate library OOB messages are fixed sized arrays which have the | 
| 249 // following format: | 240 // following format: | 
| 250 // [ OOB dispatch, Isolate library dispatch, <message specific data> ] | 241 // [ OOB dispatch, Isolate library dispatch, <message specific data> ] | 
| 251 RawError* IsolateMessageHandler::HandleLibMessage(const Array& message) { | 242 RawError* IsolateMessageHandler::HandleLibMessage(const Array& message) { | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 286       if (!obj2.IsSendPort()) return Error::null(); | 277       if (!obj2.IsSendPort()) return Error::null(); | 
| 287       const SendPort& send_port = SendPort::Cast(obj2); | 278       const SendPort& send_port = SendPort::Cast(obj2); | 
| 288       const Object& obj3 = Object::Handle(zone, message.At(3)); | 279       const Object& obj3 = Object::Handle(zone, message.At(3)); | 
| 289       if (!obj3.IsSmi()) return Error::null(); | 280       if (!obj3.IsSmi()) return Error::null(); | 
| 290       const intptr_t priority = Smi::Cast(obj3).Value(); | 281       const intptr_t priority = Smi::Cast(obj3).Value(); | 
| 291       const Object& obj4 = Object::Handle(zone, message.At(4)); | 282       const Object& obj4 = Object::Handle(zone, message.At(4)); | 
| 292       if (!obj4.IsInstance() && !obj4.IsNull()) return Error::null(); | 283       if (!obj4.IsInstance() && !obj4.IsNull()) return Error::null(); | 
| 293       const Instance& response = | 284       const Instance& response = | 
| 294           obj4.IsNull() ? Instance::null_instance() : Instance::Cast(obj4); | 285           obj4.IsNull() ? Instance::null_instance() : Instance::Cast(obj4); | 
| 295       if (priority == Isolate::kImmediateAction) { | 286       if (priority == Isolate::kImmediateAction) { | 
| 296         PortMap::PostMessage(SerializeMessage( | 287         PortMap::PostMessage(SerializeMessage(send_port.Id(), response)); | 
| 297             send_port.Id(), response)); |  | 
| 298       } else { | 288       } else { | 
| 299         ASSERT((priority == Isolate::kBeforeNextEventAction) || | 289         ASSERT((priority == Isolate::kBeforeNextEventAction) || | 
| 300                (priority == Isolate::kAsEventAction)); | 290                (priority == Isolate::kAsEventAction)); | 
| 301         // Update the message so that it will be handled immediately when it | 291         // Update the message so that it will be handled immediately when it | 
| 302         // is picked up from the message queue the next time. | 292         // is picked up from the message queue the next time. | 
| 303         message.SetAt(0, Smi::Handle(zone, | 293         message.SetAt( | 
| 304             Smi::New(Message::kDelayedIsolateLibOOBMsg))); | 294             0, Smi::Handle(zone, Smi::New(Message::kDelayedIsolateLibOOBMsg))); | 
| 305         message.SetAt(3, Smi::Handle(zone, | 295         message.SetAt(3, | 
| 306             Smi::New(Isolate::kImmediateAction))); | 296                       Smi::Handle(zone, Smi::New(Isolate::kImmediateAction))); | 
| 307         this->PostMessage(SerializeMessage( | 297         this->PostMessage( | 
| 308             Message::kIllegalPort, message), | 298             SerializeMessage(Message::kIllegalPort, message), | 
| 309             priority == Isolate::kBeforeNextEventAction /* at_head */); | 299             priority == Isolate::kBeforeNextEventAction /* at_head */); | 
| 310       } | 300       } | 
| 311       break; | 301       break; | 
| 312     } | 302     } | 
| 313     case Isolate::kKillMsg: | 303     case Isolate::kKillMsg: | 
| 314     case Isolate::kInternalKillMsg: | 304     case Isolate::kInternalKillMsg: | 
| 315     case Isolate::kVMRestartMsg: { | 305     case Isolate::kVMRestartMsg: { | 
| 316       // [ OOB, kKillMsg, terminate capability, priority ] | 306       // [ OOB, kKillMsg, terminate capability, priority ] | 
| 317       if (message.Length() != 4) return Error::null(); | 307       if (message.Length() != 4) return Error::null(); | 
| 318       Object& obj = Object::Handle(zone, message.At(3)); | 308       Object& obj = Object::Handle(zone, message.At(3)); | 
| 319       if (!obj.IsSmi()) return Error::null(); | 309       if (!obj.IsSmi()) return Error::null(); | 
| 320       const intptr_t priority = Smi::Cast(obj).Value(); | 310       const intptr_t priority = Smi::Cast(obj).Value(); | 
| 321       if (priority == Isolate::kImmediateAction) { | 311       if (priority == Isolate::kImmediateAction) { | 
| 322         obj = message.At(2); | 312         obj = message.At(2); | 
| 323         if (I->VerifyTerminateCapability(obj)) { | 313         if (I->VerifyTerminateCapability(obj)) { | 
| 324           // We will kill the current isolate by returning an UnwindError. | 314           // We will kill the current isolate by returning an UnwindError. | 
| 325           if (msg_type == Isolate::kKillMsg) { | 315           if (msg_type == Isolate::kKillMsg) { | 
| 326             const String& msg = String::Handle(String::New( | 316             const String& msg = String::Handle( | 
| 327                 "isolate terminated by Isolate.kill")); | 317                 String::New("isolate terminated by Isolate.kill")); | 
| 328             const UnwindError& error = | 318             const UnwindError& error = | 
| 329                 UnwindError::Handle(UnwindError::New(msg)); | 319                 UnwindError::Handle(UnwindError::New(msg)); | 
| 330             error.set_is_user_initiated(true); | 320             error.set_is_user_initiated(true); | 
| 331             return error.raw(); | 321             return error.raw(); | 
| 332           } else if (msg_type == Isolate::kInternalKillMsg) { | 322           } else if (msg_type == Isolate::kInternalKillMsg) { | 
| 333             const String& msg = String::Handle(String::New( | 323             const String& msg = | 
| 334                 "isolate terminated by vm")); | 324                 String::Handle(String::New("isolate terminated by vm")); | 
| 335             return UnwindError::New(msg); | 325             return UnwindError::New(msg); | 
| 336           } else if (msg_type == Isolate::kVMRestartMsg) { | 326           } else if (msg_type == Isolate::kVMRestartMsg) { | 
| 337             // If this is the main isolate, this request to restart | 327             // If this is the main isolate, this request to restart | 
| 338             // will be caught and handled in the embedder.  Otherwise | 328             // will be caught and handled in the embedder.  Otherwise | 
| 339             // this unwind error will cause the isolate to exit. | 329             // this unwind error will cause the isolate to exit. | 
| 340             const String& msg = String::Handle(String::New( | 330             const String& msg = String::Handle( | 
| 341                 "isolate terminated for vm restart")); | 331                 String::New("isolate terminated for vm restart")); | 
| 342             const UnwindError& error = | 332             const UnwindError& error = | 
| 343                 UnwindError::Handle(UnwindError::New(msg)); | 333                 UnwindError::Handle(UnwindError::New(msg)); | 
| 344             error.set_is_vm_restart(true); | 334             error.set_is_vm_restart(true); | 
| 345             return error.raw(); | 335             return error.raw(); | 
| 346           } else { | 336           } else { | 
| 347             UNREACHABLE(); | 337             UNREACHABLE(); | 
| 348           } | 338           } | 
| 349         } else { | 339         } else { | 
| 350           return Error::null(); | 340           return Error::null(); | 
| 351         } | 341         } | 
| 352       } else { | 342       } else { | 
| 353         ASSERT((priority == Isolate::kBeforeNextEventAction) || | 343         ASSERT((priority == Isolate::kBeforeNextEventAction) || | 
| 354                (priority == Isolate::kAsEventAction)); | 344                (priority == Isolate::kAsEventAction)); | 
| 355         // Update the message so that it will be handled immediately when it | 345         // Update the message so that it will be handled immediately when it | 
| 356         // is picked up from the message queue the next time. | 346         // is picked up from the message queue the next time. | 
| 357         message.SetAt(0, Smi::Handle(zone, | 347         message.SetAt( | 
| 358             Smi::New(Message::kDelayedIsolateLibOOBMsg))); | 348             0, Smi::Handle(zone, Smi::New(Message::kDelayedIsolateLibOOBMsg))); | 
| 359         message.SetAt(3, Smi::Handle(zone, | 349         message.SetAt(3, | 
| 360             Smi::New(Isolate::kImmediateAction))); | 350                       Smi::Handle(zone, Smi::New(Isolate::kImmediateAction))); | 
| 361         this->PostMessage(SerializeMessage( | 351         this->PostMessage( | 
| 362             Message::kIllegalPort, message), | 352             SerializeMessage(Message::kIllegalPort, message), | 
| 363             priority == Isolate::kBeforeNextEventAction /* at_head */); | 353             priority == Isolate::kBeforeNextEventAction /* at_head */); | 
| 364       } | 354       } | 
| 365       break; | 355       break; | 
| 366     } | 356     } | 
| 367     case Isolate::kInterruptMsg: { | 357     case Isolate::kInterruptMsg: { | 
| 368       // [ OOB, kInterruptMsg, pause capability ] | 358       // [ OOB, kInterruptMsg, pause capability ] | 
| 369       if (message.Length() != 3) return Error::null(); | 359       if (message.Length() != 3) return Error::null(); | 
| 370       Object& obj = Object::Handle(zone, message.At(2)); | 360       Object& obj = Object::Handle(zone, message.At(2)); | 
| 371       if (!I->VerifyPauseCapability(obj)) return Error::null(); | 361       if (!I->VerifyPauseCapability(obj)) return Error::null(); | 
| 372 | 362 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 387       if (!obj.IsSendPort()) return Error::null(); | 377       if (!obj.IsSendPort()) return Error::null(); | 
| 388       const SendPort& listener = SendPort::Cast(obj); | 378       const SendPort& listener = SendPort::Cast(obj); | 
| 389       switch (msg_type) { | 379       switch (msg_type) { | 
| 390         case Isolate::kAddExitMsg: { | 380         case Isolate::kAddExitMsg: { | 
| 391           if (message.Length() != 4) return Error::null(); | 381           if (message.Length() != 4) return Error::null(); | 
| 392           // [ OOB, msg, listener port, response object ] | 382           // [ OOB, msg, listener port, response object ] | 
| 393           const Object& response = Object::Handle(zone, message.At(3)); | 383           const Object& response = Object::Handle(zone, message.At(3)); | 
| 394           if (!response.IsInstance() && !response.IsNull()) { | 384           if (!response.IsInstance() && !response.IsNull()) { | 
| 395             return Error::null(); | 385             return Error::null(); | 
| 396           } | 386           } | 
| 397           I->AddExitListener(listener, | 387           I->AddExitListener(listener, response.IsNull() | 
| 398                              response.IsNull() ? Instance::null_instance() | 388                                            ? Instance::null_instance() | 
| 399                                                : Instance::Cast(response)); | 389                                            : Instance::Cast(response)); | 
| 400           break; | 390           break; | 
| 401         } | 391         } | 
| 402         case Isolate::kDelExitMsg: | 392         case Isolate::kDelExitMsg: | 
| 403           if (message.Length() != 3) return Error::null(); | 393           if (message.Length() != 3) return Error::null(); | 
| 404           I->RemoveExitListener(listener); | 394           I->RemoveExitListener(listener); | 
| 405           break; | 395           break; | 
| 406         case Isolate::kAddErrorMsg: | 396         case Isolate::kAddErrorMsg: | 
| 407           if (message.Length() != 3) return Error::null(); | 397           if (message.Length() != 3) return Error::null(); | 
| 408           I->AddErrorListener(listener); | 398           I->AddErrorListener(listener); | 
| 409           break; | 399           break; | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 453 | 443 | 
| 454 | 444 | 
| 455 MessageHandler::MessageStatus IsolateMessageHandler::HandleMessage( | 445 MessageHandler::MessageStatus IsolateMessageHandler::HandleMessage( | 
| 456     Message* message) { | 446     Message* message) { | 
| 457   ASSERT(IsCurrentIsolate()); | 447   ASSERT(IsCurrentIsolate()); | 
| 458   Thread* thread = Thread::Current(); | 448   Thread* thread = Thread::Current(); | 
| 459   StackZone stack_zone(thread); | 449   StackZone stack_zone(thread); | 
| 460   Zone* zone = stack_zone.GetZone(); | 450   Zone* zone = stack_zone.GetZone(); | 
| 461   HandleScope handle_scope(thread); | 451   HandleScope handle_scope(thread); | 
| 462 #ifndef PRODUCT | 452 #ifndef PRODUCT | 
| 463   TimelineDurationScope tds(thread, | 453   TimelineDurationScope tds(thread, Timeline::GetIsolateStream(), | 
| 464                             Timeline::GetIsolateStream(), |  | 
| 465                             "HandleMessage"); | 454                             "HandleMessage"); | 
| 466   tds.SetNumArguments(1); | 455   tds.SetNumArguments(1); | 
| 467   tds.CopyArgument(0, "isolateName", I->name()); | 456   tds.CopyArgument(0, "isolateName", I->name()); | 
| 468 #endif | 457 #endif | 
| 469 | 458 | 
| 470   // If the message is in band we lookup the handler to dispatch to.  If the | 459   // If the message is in band we lookup the handler to dispatch to.  If the | 
| 471   // receive port was closed, we drop the message without deserializing it. | 460   // receive port was closed, we drop the message without deserializing it. | 
| 472   // Illegal port is a special case for artificially enqueued isolate library | 461   // Illegal port is a special case for artificially enqueued isolate library | 
| 473   // messages which are handled in C++ code below. | 462   // messages which are handled in C++ code below. | 
| 474   Object& msg_handler = Object::Handle(zone); | 463   Object& msg_handler = Object::Handle(zone); | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 564         if (oob_tag.IsSmi() && | 553         if (oob_tag.IsSmi() && | 
| 565             (Smi::Cast(oob_tag).Value() == Message::kDelayedIsolateLibOOBMsg)) { | 554             (Smi::Cast(oob_tag).Value() == Message::kDelayedIsolateLibOOBMsg)) { | 
| 566           const Error& error = Error::Handle(HandleLibMessage(msg_arr)); | 555           const Error& error = Error::Handle(HandleLibMessage(msg_arr)); | 
| 567           if (!error.IsNull()) { | 556           if (!error.IsNull()) { | 
| 568             status = ProcessUnhandledException(error); | 557             status = ProcessUnhandledException(error); | 
| 569           } | 558           } | 
| 570         } | 559         } | 
| 571       } | 560       } | 
| 572     } | 561     } | 
| 573   } else { | 562   } else { | 
| 574     const Object& result = Object::Handle(zone, | 563     const Object& result = | 
| 575         DartLibraryCalls::HandleMessage(msg_handler, msg)); | 564         Object::Handle(zone, DartLibraryCalls::HandleMessage(msg_handler, msg)); | 
| 576     if (result.IsError()) { | 565     if (result.IsError()) { | 
| 577       status = ProcessUnhandledException(Error::Cast(result)); | 566       status = ProcessUnhandledException(Error::Cast(result)); | 
| 578     } else { | 567     } else { | 
| 579       ASSERT(result.IsNull()); | 568       ASSERT(result.IsNull()); | 
| 580     } | 569     } | 
| 581   } | 570   } | 
| 582   delete message; | 571   delete message; | 
| 583 #ifndef PRODUCT | 572 #ifndef PRODUCT | 
| 584   if (status == kOK) { | 573   if (status == kOK) { | 
| 585     const Object& result = | 574     const Object& result = | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 617   if (!FLAG_support_service) { | 606   if (!FLAG_support_service) { | 
| 618     return; | 607     return; | 
| 619   } | 608   } | 
| 620   if (Service::debug_stream.enabled() || FLAG_warn_on_pause_with_no_debugger) { | 609   if (Service::debug_stream.enabled() || FLAG_warn_on_pause_with_no_debugger) { | 
| 621     StartIsolateScope start_isolate(I); | 610     StartIsolateScope start_isolate(I); | 
| 622     StackZone zone(T); | 611     StackZone zone(T); | 
| 623     HandleScope handle_scope(T); | 612     HandleScope handle_scope(T); | 
| 624     ServiceEvent pause_event(I, ServiceEvent::kPauseExit); | 613     ServiceEvent pause_event(I, ServiceEvent::kPauseExit); | 
| 625     Service::HandleEvent(&pause_event); | 614     Service::HandleEvent(&pause_event); | 
| 626   } else if (FLAG_trace_service) { | 615   } else if (FLAG_trace_service) { | 
| 627     OS::Print("vm-service: Dropping event of type PauseExit (%s)\n", | 616     OS::Print("vm-service: Dropping event of type PauseExit (%s)\n", I->name()); | 
| 628               I->name()); |  | 
| 629   } | 617   } | 
| 630 } | 618 } | 
| 631 #endif  // !PRODUCT | 619 #endif  // !PRODUCT | 
| 632 | 620 | 
| 633 | 621 | 
| 634 #if defined(DEBUG) | 622 #if defined(DEBUG) | 
| 635 void IsolateMessageHandler::CheckAccess() { | 623 void IsolateMessageHandler::CheckAccess() { | 
| 636   ASSERT(IsCurrentIsolate()); | 624   ASSERT(IsCurrentIsolate()); | 
| 637 } | 625 } | 
| 638 #endif | 626 #endif | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 730 | 718 | 
| 731 void Isolate::FlagsCopyTo(Dart_IsolateFlags* api_flags) const { | 719 void Isolate::FlagsCopyTo(Dart_IsolateFlags* api_flags) const { | 
| 732   api_flags->version = DART_FLAGS_CURRENT_VERSION; | 720   api_flags->version = DART_FLAGS_CURRENT_VERSION; | 
| 733   api_flags->enable_type_checks = type_checks(); | 721   api_flags->enable_type_checks = type_checks(); | 
| 734   api_flags->enable_asserts = asserts(); | 722   api_flags->enable_asserts = asserts(); | 
| 735   api_flags->enable_error_on_bad_type = error_on_bad_type(); | 723   api_flags->enable_error_on_bad_type = error_on_bad_type(); | 
| 736   api_flags->enable_error_on_bad_override = error_on_bad_override(); | 724   api_flags->enable_error_on_bad_override = error_on_bad_override(); | 
| 737 } | 725 } | 
| 738 | 726 | 
| 739 | 727 | 
| 740 NOT_IN_PRODUCT( | 728 #if !defined(PRODUCT) | 
| 741 void Isolate::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) { | 729 void Isolate::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) { | 
| 742   type_checks_ = api_flags.enable_type_checks; | 730   type_checks_ = api_flags.enable_type_checks; | 
| 743   asserts_ = api_flags.enable_asserts; | 731   asserts_ = api_flags.enable_asserts; | 
| 744   error_on_bad_type_ = api_flags.enable_error_on_bad_type; | 732   error_on_bad_type_ = api_flags.enable_error_on_bad_type; | 
| 745   error_on_bad_override_ = api_flags.enable_error_on_bad_override; | 733   error_on_bad_override_ = api_flags.enable_error_on_bad_override; | 
| 746   // Leave others at defaults. | 734   // Leave others at defaults. | 
| 747 }) | 735 } | 
|  | 736 #endif  // !defined(PRODUCT) | 
| 748 | 737 | 
| 749 | 738 | 
| 750 DEBUG_ONLY( | 739 #if defined(DEBUG) | 
| 751 // static | 740 // static | 
| 752 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { | 741 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { | 
| 753   ASSERT(isolate == Isolate::Current()); | 742   ASSERT(isolate == Isolate::Current()); | 
| 754 } | 743 } | 
| 755 | 744 | 
| 756 void BaseIsolate::AssertCurrentThreadIsMutator() const { | 745 void BaseIsolate::AssertCurrentThreadIsMutator() const { | 
| 757   ASSERT(Isolate::Current() == this); | 746   ASSERT(Isolate::Current() == this); | 
| 758   ASSERT(Thread::Current()->IsMutatorThread()); | 747   ASSERT(Thread::Current()->IsMutatorThread()); | 
| 759 } | 748 } | 
| 760 ) | 749 #endif  // defined(DEBUG) | 
| 761 | 750 | 
| 762 #if defined(DEBUG) | 751 #if defined(DEBUG) | 
| 763 #define REUSABLE_HANDLE_SCOPE_INIT(object)                                     \ | 752 #define REUSABLE_HANDLE_SCOPE_INIT(object)                                     \ | 
| 764   reusable_##object##_handle_scope_active_(false), | 753   reusable_##object##_handle_scope_active_(false), | 
| 765 #else | 754 #else | 
| 766 #define REUSABLE_HANDLE_SCOPE_INIT(object) | 755 #define REUSABLE_HANDLE_SCOPE_INIT(object) | 
| 767 #endif  // defined(DEBUG) | 756 #endif  // defined(DEBUG) | 
| 768 | 757 | 
| 769 #define REUSABLE_HANDLE_INITIALIZERS(object)                                   \ | 758 #define REUSABLE_HANDLE_INITIALIZERS(object) object##_handle_(NULL), | 
| 770   object##_handle_(NULL), |  | 
| 771 | 759 | 
| 772 // TODO(srdjan): Some Isolate monitors can be shared. Replace their usage with | 760 // TODO(srdjan): Some Isolate monitors can be shared. Replace their usage with | 
| 773 // that shared monitor. | 761 // that shared monitor. | 
| 774 Isolate::Isolate(const Dart_IsolateFlags& api_flags) | 762 Isolate::Isolate(const Dart_IsolateFlags& api_flags) | 
| 775   :   store_buffer_(new StoreBuffer()), | 763     : store_buffer_(new StoreBuffer()), | 
| 776       heap_(NULL), | 764       heap_(NULL), | 
| 777       user_tag_(0), | 765       user_tag_(0), | 
| 778       current_tag_(UserTag::null()), | 766       current_tag_(UserTag::null()), | 
| 779       default_tag_(UserTag::null()), | 767       default_tag_(UserTag::null()), | 
| 780       object_store_(NULL), | 768       object_store_(NULL), | 
| 781       class_table_(), | 769       class_table_(), | 
| 782       single_step_(false), | 770       single_step_(false), | 
| 783       thread_registry_(new ThreadRegistry()), | 771       thread_registry_(new ThreadRegistry()), | 
| 784       safepoint_handler_(new SafepointHandler(this)), | 772       safepoint_handler_(new SafepointHandler(this)), | 
| 785       message_notify_callback_(NULL), | 773       message_notify_callback_(NULL), | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 830       all_classes_finalized_(false), | 818       all_classes_finalized_(false), | 
| 831       next_(NULL), | 819       next_(NULL), | 
| 832       pause_loop_monitor_(NULL), | 820       pause_loop_monitor_(NULL), | 
| 833       loading_invalidation_gen_(kInvalidGen), | 821       loading_invalidation_gen_(kInvalidGen), | 
| 834       top_level_parsing_count_(0), | 822       top_level_parsing_count_(0), | 
| 835       field_list_mutex_(new Mutex()), | 823       field_list_mutex_(new Mutex()), | 
| 836       boxed_field_list_(GrowableObjectArray::null()), | 824       boxed_field_list_(GrowableObjectArray::null()), | 
| 837       spawn_count_monitor_(new Monitor()), | 825       spawn_count_monitor_(new Monitor()), | 
| 838       spawn_count_(0), | 826       spawn_count_(0), | 
| 839 #define ISOLATE_METRIC_CONSTRUCTORS(type, variable, name, unit)                \ | 827 #define ISOLATE_METRIC_CONSTRUCTORS(type, variable, name, unit)                \ | 
| 840       metric_##variable##_(), | 828   metric_##variable##_(), | 
| 841       ISOLATE_METRIC_LIST(ISOLATE_METRIC_CONSTRUCTORS) | 829       ISOLATE_METRIC_LIST(ISOLATE_METRIC_CONSTRUCTORS) | 
| 842 #undef ISOLATE_METRIC_CONSTRUCTORS | 830 #undef ISOLATE_METRIC_CONSTRUCTORS | 
| 843       has_attempted_reload_(false), | 831           has_attempted_reload_(false), | 
| 844       no_reload_scope_depth_(0), | 832       no_reload_scope_depth_(0), | 
| 845       reload_every_n_stack_overflow_checks_(FLAG_reload_every), | 833       reload_every_n_stack_overflow_checks_(FLAG_reload_every), | 
| 846       reload_context_(NULL), | 834       reload_context_(NULL), | 
| 847       last_reload_timestamp_(OS::GetCurrentTimeMillis()), | 835       last_reload_timestamp_(OS::GetCurrentTimeMillis()), | 
| 848       should_pause_post_service_request_(false) { | 836       should_pause_post_service_request_(false) { | 
| 849   NOT_IN_PRODUCT(FlagsCopyFrom(api_flags)); | 837   NOT_IN_PRODUCT(FlagsCopyFrom(api_flags)); | 
| 850   // TODO(asiva): A Thread is not available here, need to figure out | 838   // TODO(asiva): A Thread is not available here, need to figure out | 
| 851   // how the vm_tag (kEmbedderTagId) can be set, these tags need to | 839   // how the vm_tag (kEmbedderTagId) can be set, these tags need to | 
| 852   // move to the OSThread structure. | 840   // move to the OSThread structure. | 
| 853   set_user_tag(UserTags::kDefaultUserTag); | 841   set_user_tag(UserTags::kDefaultUserTag); | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 911   EnableIsolateCreation(); | 899   EnableIsolateCreation(); | 
| 912 } | 900 } | 
| 913 | 901 | 
| 914 | 902 | 
| 915 Isolate* Isolate::Init(const char* name_prefix, | 903 Isolate* Isolate::Init(const char* name_prefix, | 
| 916                        const Dart_IsolateFlags& api_flags, | 904                        const Dart_IsolateFlags& api_flags, | 
| 917                        bool is_vm_isolate) { | 905                        bool is_vm_isolate) { | 
| 918   Isolate* result = new Isolate(api_flags); | 906   Isolate* result = new Isolate(api_flags); | 
| 919   ASSERT(result != NULL); | 907   ASSERT(result != NULL); | 
| 920 | 908 | 
| 921   // Initialize metrics. | 909 // Initialize metrics. | 
| 922 #define ISOLATE_METRIC_INIT(type, variable, name, unit)                        \ | 910 #define ISOLATE_METRIC_INIT(type, variable, name, unit)                        \ | 
| 923   result->metric_##variable##_.Init(result, name, NULL, Metric::unit); | 911   result->metric_##variable##_.Init(result, name, NULL, Metric::unit); | 
| 924   ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); | 912   ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); | 
| 925 #undef ISOLATE_METRIC_INIT | 913 #undef ISOLATE_METRIC_INIT | 
| 926 | 914 | 
| 927   Heap::Init(result, | 915   Heap::Init(result, | 
| 928              is_vm_isolate | 916              is_vm_isolate | 
| 929                  ? 0  // New gen size 0; VM isolate should only allocate in old. | 917                  ? 0  // New gen size 0; VM isolate should only allocate in old. | 
| 930                  : FLAG_new_gen_semi_max_size * MBInWords, | 918                  : FLAG_new_gen_semi_max_size * MBInWords, | 
| 931              FLAG_old_gen_heap_size * MBInWords, | 919              FLAG_old_gen_heap_size * MBInWords, | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 960   result->set_pause_capability(result->random()->NextUInt64()); | 948   result->set_pause_capability(result->random()->NextUInt64()); | 
| 961   result->set_terminate_capability(result->random()->NextUInt64()); | 949   result->set_terminate_capability(result->random()->NextUInt64()); | 
| 962 | 950 | 
| 963   result->BuildName(name_prefix); | 951   result->BuildName(name_prefix); | 
| 964   if (FLAG_support_debugger) { | 952   if (FLAG_support_debugger) { | 
| 965     result->debugger_ = new Debugger(); | 953     result->debugger_ = new Debugger(); | 
| 966     result->debugger_->Initialize(result); | 954     result->debugger_->Initialize(result); | 
| 967   } | 955   } | 
| 968   if (FLAG_trace_isolates) { | 956   if (FLAG_trace_isolates) { | 
| 969     if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 957     if (name_prefix == NULL || strcmp(name_prefix, "vm-isolate") != 0) { | 
| 970       OS::Print("[+] Starting isolate:\n" | 958       OS::Print( | 
| 971                 "\tisolate:    %s\n", result->name()); | 959           "[+] Starting isolate:\n" | 
|  | 960           "\tisolate:    %s\n", | 
|  | 961           result->name()); | 
| 972     } | 962     } | 
| 973   } | 963   } | 
| 974 | 964 | 
| 975 #ifndef PRODUCT | 965 #ifndef PRODUCT | 
| 976   if (FLAG_support_service) { | 966   if (FLAG_support_service) { | 
| 977     ObjectIdRing::Init(result); | 967     ObjectIdRing::Init(result); | 
| 978   } | 968   } | 
| 979 #endif  // !PRODUCT | 969 #endif  // !PRODUCT | 
| 980 | 970 | 
| 981   // Add to isolate list. Shutdown and delete the isolate on failure. | 971   // Add to isolate list. Shutdown and delete the isolate on failure. | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 997 | 987 | 
| 998 | 988 | 
| 999 void Isolate::SetupInstructionsSnapshotPage( | 989 void Isolate::SetupInstructionsSnapshotPage( | 
| 1000     const uint8_t* instructions_snapshot_buffer) { | 990     const uint8_t* instructions_snapshot_buffer) { | 
| 1001   InstructionsSnapshot snapshot(instructions_snapshot_buffer); | 991   InstructionsSnapshot snapshot(instructions_snapshot_buffer); | 
| 1002 #if defined(DEBUG) | 992 #if defined(DEBUG) | 
| 1003   if (FLAG_trace_isolates) { | 993   if (FLAG_trace_isolates) { | 
| 1004     OS::Print("Precompiled instructions are at [0x%" Px ", 0x%" Px ")\n", | 994     OS::Print("Precompiled instructions are at [0x%" Px ", 0x%" Px ")\n", | 
| 1005               reinterpret_cast<uword>(snapshot.instructions_start()), | 995               reinterpret_cast<uword>(snapshot.instructions_start()), | 
| 1006               reinterpret_cast<uword>(snapshot.instructions_start()) + | 996               reinterpret_cast<uword>(snapshot.instructions_start()) + | 
| 1007               snapshot.instructions_size()); | 997                   snapshot.instructions_size()); | 
| 1008   } | 998   } | 
| 1009 #endif | 999 #endif | 
| 1010   heap_->SetupExternalPage(snapshot.instructions_start(), | 1000   heap_->SetupExternalPage(snapshot.instructions_start(), | 
| 1011                            snapshot.instructions_size(), | 1001                            snapshot.instructions_size(), | 
| 1012                            /* is_executable = */ true); | 1002                            /* is_executable = */ true); | 
| 1013 } | 1003 } | 
| 1014 | 1004 | 
| 1015 | 1005 | 
| 1016 void Isolate::SetupDataSnapshotPage(const uint8_t* data_snapshot_buffer) { | 1006 void Isolate::SetupDataSnapshotPage(const uint8_t* data_snapshot_buffer) { | 
| 1017   DataSnapshot snapshot(data_snapshot_buffer); | 1007   DataSnapshot snapshot(data_snapshot_buffer); | 
| 1018 #if defined(DEBUG) | 1008 #if defined(DEBUG) | 
| 1019   if (FLAG_trace_isolates) { | 1009   if (FLAG_trace_isolates) { | 
| 1020     OS::Print("Precompiled rodata are at [0x%" Px ", 0x%" Px ")\n", | 1010     OS::Print( | 
| 1021               reinterpret_cast<uword>(snapshot.data_start()), | 1011         "Precompiled rodata are at [0x%" Px ", 0x%" Px ")\n", | 
| 1022               reinterpret_cast<uword>(snapshot.data_start()) + | 1012         reinterpret_cast<uword>(snapshot.data_start()), | 
| 1023               snapshot.data_size()); | 1013         reinterpret_cast<uword>(snapshot.data_start()) + snapshot.data_size()); | 
| 1024   } | 1014   } | 
| 1025 #endif | 1015 #endif | 
| 1026   heap_->SetupExternalPage(snapshot.data_start(), | 1016   heap_->SetupExternalPage(snapshot.data_start(), snapshot.data_size(), | 
| 1027                            snapshot.data_size(), |  | 
| 1028                            /* is_executable = */ false); | 1017                            /* is_executable = */ false); | 
| 1029 } | 1018 } | 
| 1030 | 1019 | 
| 1031 | 1020 | 
| 1032 void Isolate::ScheduleMessageInterrupts() { | 1021 void Isolate::ScheduleMessageInterrupts() { | 
| 1033   // We take the threads lock here to ensure that the mutator thread does not | 1022   // We take the threads lock here to ensure that the mutator thread does not | 
| 1034   // exit the isolate while we are trying to schedule interrupts on it. | 1023   // exit the isolate while we are trying to schedule interrupts on it. | 
| 1035   MonitorLocker ml(threads_lock()); | 1024   MonitorLocker ml(threads_lock()); | 
| 1036   Thread* mthread = mutator_thread(); | 1025   Thread* mthread = mutator_thread(); | 
| 1037   if (mthread != NULL) { | 1026   if (mthread != NULL) { | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1074   set_debugger_name(name_prefix); | 1063   set_debugger_name(name_prefix); | 
| 1075   if (ServiceIsolate::NameEquals(name_prefix)) { | 1064   if (ServiceIsolate::NameEquals(name_prefix)) { | 
| 1076     name_ = strdup(name_prefix); | 1065     name_ = strdup(name_prefix); | 
| 1077     return; | 1066     return; | 
| 1078   } | 1067   } | 
| 1079   name_ = OS::SCreate(NULL, "%s-%" Pd64 "", name_prefix, main_port()); | 1068   name_ = OS::SCreate(NULL, "%s-%" Pd64 "", name_prefix, main_port()); | 
| 1080 } | 1069 } | 
| 1081 | 1070 | 
| 1082 | 1071 | 
| 1083 void Isolate::DoneLoading() { | 1072 void Isolate::DoneLoading() { | 
| 1084   GrowableObjectArray& libs = GrowableObjectArray::Handle(current_zone(), | 1073   GrowableObjectArray& libs = | 
| 1085       object_store()->libraries()); | 1074       GrowableObjectArray::Handle(current_zone(), object_store()->libraries()); | 
| 1086   Library& lib = Library::Handle(current_zone()); | 1075   Library& lib = Library::Handle(current_zone()); | 
| 1087   intptr_t num_libs = libs.Length(); | 1076   intptr_t num_libs = libs.Length(); | 
| 1088   for (intptr_t i = 0; i < num_libs; i++) { | 1077   for (intptr_t i = 0; i < num_libs; i++) { | 
| 1089     lib ^= libs.At(i); | 1078     lib ^= libs.At(i); | 
| 1090     // If this library was loaded with Dart_LoadLibrary, it was marked | 1079     // If this library was loaded with Dart_LoadLibrary, it was marked | 
| 1091     // as 'load in progres'. Set the status to 'loaded'. | 1080     // as 'load in progres'. Set the status to 'loaded'. | 
| 1092     if (lib.LoadInProgress()) { | 1081     if (lib.LoadInProgress()) { | 
| 1093       lib.SetLoaded(); | 1082       lib.SetLoaded(); | 
| 1094     } | 1083     } | 
| 1095     lib.InitExportedNamesCache(); | 1084     lib.InitExportedNamesCache(); | 
| 1096   } | 1085   } | 
| 1097   TokenStream::CloseSharedTokenList(this); | 1086   TokenStream::CloseSharedTokenList(this); | 
| 1098 } | 1087 } | 
| 1099 | 1088 | 
| 1100 | 1089 | 
| 1101 bool Isolate::CanReload() const { | 1090 bool Isolate::CanReload() const { | 
| 1102 #ifndef PRODUCT | 1091 #ifndef PRODUCT | 
| 1103   return !ServiceIsolate::IsServiceIsolateDescendant(this) && | 1092   return !ServiceIsolate::IsServiceIsolateDescendant(this) && is_runnable() && | 
| 1104          is_runnable() && !IsReloading() && | 1093          !IsReloading() && | 
| 1105          (AtomicOperations::LoadRelaxed(&no_reload_scope_depth_) == 0) && | 1094          (AtomicOperations::LoadRelaxed(&no_reload_scope_depth_) == 0) && | 
| 1106          IsolateCreationEnabled(); | 1095          IsolateCreationEnabled(); | 
| 1107 #else | 1096 #else | 
| 1108   return false; | 1097   return false; | 
| 1109 #endif | 1098 #endif | 
| 1110 } | 1099 } | 
| 1111 | 1100 | 
| 1112 | 1101 | 
| 1113 #ifndef PRODUCT | 1102 #ifndef PRODUCT | 
| 1114 bool Isolate::ReloadSources(JSONStream* js, | 1103 bool Isolate::ReloadSources(JSONStream* js, | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 1141   Thread* thread = Thread::Current(); | 1130   Thread* thread = Thread::Current(); | 
| 1142   SafepointOperationScope safepoint_scope(thread); | 1131   SafepointOperationScope safepoint_scope(thread); | 
| 1143 | 1132 | 
| 1144   delete reload_context_; | 1133   delete reload_context_; | 
| 1145   reload_context_ = NULL; | 1134   reload_context_ = NULL; | 
| 1146 } | 1135 } | 
| 1147 #endif  // !PRODUCT | 1136 #endif  // !PRODUCT | 
| 1148 | 1137 | 
| 1149 | 1138 | 
| 1150 void Isolate::DoneFinalizing() { | 1139 void Isolate::DoneFinalizing() { | 
| 1151   NOT_IN_PRODUCT( | 1140 #if !defined(PRODUCT) | 
| 1152     if (IsReloading()) { | 1141   if (IsReloading()) { | 
| 1153       reload_context_->FinalizeLoading(); | 1142     reload_context_->FinalizeLoading(); | 
| 1154     } | 1143   } | 
| 1155   ) | 1144 #endif  // !defined(PRODUCT) | 
| 1156 } | 1145 } | 
| 1157 | 1146 | 
| 1158 | 1147 | 
| 1159 |  | 
| 1160 bool Isolate::MakeRunnable() { | 1148 bool Isolate::MakeRunnable() { | 
| 1161   ASSERT(Isolate::Current() == NULL); | 1149   ASSERT(Isolate::Current() == NULL); | 
| 1162 | 1150 | 
| 1163   MutexLocker ml(mutex_); | 1151   MutexLocker ml(mutex_); | 
| 1164   // Check if we are in a valid state to make the isolate runnable. | 1152   // Check if we are in a valid state to make the isolate runnable. | 
| 1165   if (is_runnable() == true) { | 1153   if (is_runnable() == true) { | 
| 1166     return false;  // Already runnable. | 1154     return false;  // Already runnable. | 
| 1167   } | 1155   } | 
| 1168   // Set the isolate as runnable and if we are being spawned schedule | 1156   // Set the isolate as runnable and if we are being spawned schedule | 
| 1169   // isolate on thread pool for execution. | 1157   // isolate on thread pool for execution. | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 1194   if (FLAG_support_service && Service::isolate_stream.enabled()) { | 1182   if (FLAG_support_service && Service::isolate_stream.enabled()) { | 
| 1195     ServiceEvent runnableEvent(this, ServiceEvent::kIsolateRunnable); | 1183     ServiceEvent runnableEvent(this, ServiceEvent::kIsolateRunnable); | 
| 1196     Service::HandleEvent(&runnableEvent); | 1184     Service::HandleEvent(&runnableEvent); | 
| 1197   } | 1185   } | 
| 1198 #endif  // !PRODUCT | 1186 #endif  // !PRODUCT | 
| 1199   return true; | 1187   return true; | 
| 1200 } | 1188 } | 
| 1201 | 1189 | 
| 1202 | 1190 | 
| 1203 bool Isolate::VerifyPauseCapability(const Object& capability) const { | 1191 bool Isolate::VerifyPauseCapability(const Object& capability) const { | 
| 1204   return !capability.IsNull() && | 1192   return !capability.IsNull() && capability.IsCapability() && | 
| 1205       capability.IsCapability() && | 1193          (pause_capability() == Capability::Cast(capability).Id()); | 
| 1206       (pause_capability() == Capability::Cast(capability).Id()); |  | 
| 1207 } | 1194 } | 
| 1208 | 1195 | 
| 1209 | 1196 | 
| 1210 bool Isolate::VerifyTerminateCapability(const Object& capability) const { | 1197 bool Isolate::VerifyTerminateCapability(const Object& capability) const { | 
| 1211   return !capability.IsNull() && | 1198   return !capability.IsNull() && capability.IsCapability() && | 
| 1212       capability.IsCapability() && | 1199          (terminate_capability() == Capability::Cast(capability).Id()); | 
| 1213       (terminate_capability() == Capability::Cast(capability).Id()); |  | 
| 1214 } | 1200 } | 
| 1215 | 1201 | 
| 1216 | 1202 | 
| 1217 bool Isolate::AddResumeCapability(const Capability& capability) { | 1203 bool Isolate::AddResumeCapability(const Capability& capability) { | 
| 1218   // Ensure a limit for the number of resume capabilities remembered. | 1204   // Ensure a limit for the number of resume capabilities remembered. | 
| 1219   static const intptr_t kMaxResumeCapabilities = kSmiMax / (6 * kWordSize); | 1205   static const intptr_t kMaxResumeCapabilities = kSmiMax / (6 * kWordSize); | 
| 1220 | 1206 | 
| 1221   const GrowableObjectArray& caps = GrowableObjectArray::Handle( | 1207   const GrowableObjectArray& caps = GrowableObjectArray::Handle( | 
| 1222       current_zone(), object_store()->resume_capabilities()); | 1208       current_zone(), object_store()->resume_capabilities()); | 
| 1223   Capability& current = Capability::Handle(current_zone()); | 1209   Capability& current = Capability::Handle(current_zone()); | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 1242     caps.Add(capability); | 1228     caps.Add(capability); | 
| 1243   } else { | 1229   } else { | 
| 1244     caps.SetAt(insertion_index, capability); | 1230     caps.SetAt(insertion_index, capability); | 
| 1245   } | 1231   } | 
| 1246   return true; | 1232   return true; | 
| 1247 } | 1233 } | 
| 1248 | 1234 | 
| 1249 | 1235 | 
| 1250 bool Isolate::RemoveResumeCapability(const Capability& capability) { | 1236 bool Isolate::RemoveResumeCapability(const Capability& capability) { | 
| 1251   const GrowableObjectArray& caps = GrowableObjectArray::Handle( | 1237   const GrowableObjectArray& caps = GrowableObjectArray::Handle( | 
| 1252        current_zone(), object_store()->resume_capabilities()); | 1238       current_zone(), object_store()->resume_capabilities()); | 
| 1253   Capability& current = Capability::Handle(current_zone()); | 1239   Capability& current = Capability::Handle(current_zone()); | 
| 1254   for (intptr_t i = 0; i < caps.Length(); i++) { | 1240   for (intptr_t i = 0; i < caps.Length(); i++) { | 
| 1255     current ^= caps.At(i); | 1241     current ^= caps.At(i); | 
| 1256     if (!current.IsNull() && (current.Id() == capability.Id())) { | 1242     if (!current.IsNull() && (current.Id() == capability.Id())) { | 
| 1257       // Remove the matching capability from the list. | 1243       // Remove the matching capability from the list. | 
| 1258       current = Capability::null(); | 1244       current = Capability::null(); | 
| 1259       caps.SetAt(i, current); | 1245       caps.SetAt(i, current); | 
| 1260       return true; | 1246       return true; | 
| 1261     } | 1247     } | 
| 1262   } | 1248   } | 
| 1263   return false; | 1249   return false; | 
| 1264 } | 1250 } | 
| 1265 | 1251 | 
| 1266 | 1252 | 
| 1267 // TODO(iposva): Remove duplicated code and start using some hash based | 1253 // TODO(iposva): Remove duplicated code and start using some hash based | 
| 1268 // structure instead of these linear lookups. | 1254 // structure instead of these linear lookups. | 
| 1269 void Isolate::AddExitListener(const SendPort& listener, | 1255 void Isolate::AddExitListener(const SendPort& listener, | 
| 1270                               const Instance& response) { | 1256                               const Instance& response) { | 
| 1271   // Ensure a limit for the number of listeners remembered. | 1257   // Ensure a limit for the number of listeners remembered. | 
| 1272   static const intptr_t kMaxListeners = kSmiMax / (12 * kWordSize); | 1258   static const intptr_t kMaxListeners = kSmiMax / (12 * kWordSize); | 
| 1273 | 1259 | 
| 1274   const GrowableObjectArray& listeners = GrowableObjectArray::Handle( | 1260   const GrowableObjectArray& listeners = GrowableObjectArray::Handle( | 
| 1275        current_zone(), object_store()->exit_listeners()); | 1261       current_zone(), object_store()->exit_listeners()); | 
| 1276   SendPort& current = SendPort::Handle(current_zone()); | 1262   SendPort& current = SendPort::Handle(current_zone()); | 
| 1277   intptr_t insertion_index = -1; | 1263   intptr_t insertion_index = -1; | 
| 1278   for (intptr_t i = 0; i < listeners.Length(); i += 2) { | 1264   for (intptr_t i = 0; i < listeners.Length(); i += 2) { | 
| 1279     current ^= listeners.At(i); | 1265     current ^= listeners.At(i); | 
| 1280     if (current.IsNull()) { | 1266     if (current.IsNull()) { | 
| 1281       if (insertion_index < 0) { | 1267       if (insertion_index < 0) { | 
| 1282         insertion_index = i; | 1268         insertion_index = i; | 
| 1283       } | 1269       } | 
| 1284     } else if (current.Id() == listener.Id()) { | 1270     } else if (current.Id() == listener.Id()) { | 
| 1285       listeners.SetAt(i + 1, response); | 1271       listeners.SetAt(i + 1, response); | 
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1432     if (state->on_error_port() != ILLEGAL_PORT) { | 1418     if (state->on_error_port() != ILLEGAL_PORT) { | 
| 1433       const SendPort& listener = | 1419       const SendPort& listener = | 
| 1434           SendPort::Handle(SendPort::New(state->on_error_port())); | 1420           SendPort::Handle(SendPort::New(state->on_error_port())); | 
| 1435       isolate->AddErrorListener(listener); | 1421       isolate->AddErrorListener(listener); | 
| 1436     } | 1422     } | 
| 1437 | 1423 | 
| 1438     // Switch back to spawning isolate. | 1424     // Switch back to spawning isolate. | 
| 1439 | 1425 | 
| 1440 | 1426 | 
| 1441     if (!ClassFinalizer::ProcessPendingClasses()) { | 1427     if (!ClassFinalizer::ProcessPendingClasses()) { | 
| 1442       // Error is in sticky error already. | 1428 // Error is in sticky error already. | 
| 1443 #if defined(DEBUG) | 1429 #if defined(DEBUG) | 
| 1444       const Error& error = Error::Handle(thread->sticky_error()); | 1430       const Error& error = Error::Handle(thread->sticky_error()); | 
| 1445       ASSERT(!error.IsUnwindError()); | 1431       ASSERT(!error.IsUnwindError()); | 
| 1446 #endif | 1432 #endif | 
| 1447       return MessageHandler::kError; | 1433       return MessageHandler::kError; | 
| 1448     } | 1434     } | 
| 1449 | 1435 | 
| 1450     Object& result = Object::Handle(); | 1436     Object& result = Object::Handle(); | 
| 1451     result = state->ResolveFunction(); | 1437     result = state->ResolveFunction(); | 
| 1452     bool is_spawn_uri = state->is_spawn_uri(); | 1438     bool is_spawn_uri = state->is_spawn_uri(); | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1487     // Since this function ("RunIsolate") is used for both Isolate.spawn and | 1473     // Since this function ("RunIsolate") is used for both Isolate.spawn and | 
| 1488     // Isolate.spawnUri we also send a boolean flag as argument so that the | 1474     // Isolate.spawnUri we also send a boolean flag as argument so that the | 
| 1489     // "_startIsolate" function can act corresponding to how the isolate was | 1475     // "_startIsolate" function can act corresponding to how the isolate was | 
| 1490     // created. | 1476     // created. | 
| 1491     const Array& args = Array::Handle(Array::New(7)); | 1477     const Array& args = Array::Handle(Array::New(7)); | 
| 1492     args.SetAt(0, SendPort::Handle(SendPort::New(state->parent_port()))); | 1478     args.SetAt(0, SendPort::Handle(SendPort::New(state->parent_port()))); | 
| 1493     args.SetAt(1, Instance::Handle(func.ImplicitStaticClosure())); | 1479     args.SetAt(1, Instance::Handle(func.ImplicitStaticClosure())); | 
| 1494     args.SetAt(2, Instance::Handle(state->BuildArgs(thread))); | 1480     args.SetAt(2, Instance::Handle(state->BuildArgs(thread))); | 
| 1495     args.SetAt(3, Instance::Handle(state->BuildMessage(thread))); | 1481     args.SetAt(3, Instance::Handle(state->BuildMessage(thread))); | 
| 1496     args.SetAt(4, is_spawn_uri ? Bool::True() : Bool::False()); | 1482     args.SetAt(4, is_spawn_uri ? Bool::True() : Bool::False()); | 
| 1497     args.SetAt(5, ReceivePort::Handle( | 1483     args.SetAt(5, ReceivePort::Handle(ReceivePort::New( | 
| 1498         ReceivePort::New(isolate->main_port(), true /* control port */))); | 1484                       isolate->main_port(), true /* control port */))); | 
| 1499     args.SetAt(6, capabilities); | 1485     args.SetAt(6, capabilities); | 
| 1500 | 1486 | 
| 1501     const Library& lib = Library::Handle(Library::IsolateLibrary()); | 1487     const Library& lib = Library::Handle(Library::IsolateLibrary()); | 
| 1502     const String& entry_name = String::Handle(String::New("_startIsolate")); | 1488     const String& entry_name = String::Handle(String::New("_startIsolate")); | 
| 1503     const Function& entry_point = | 1489     const Function& entry_point = | 
| 1504         Function::Handle(lib.LookupLocalFunction(entry_name)); | 1490         Function::Handle(lib.LookupLocalFunction(entry_name)); | 
| 1505     ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); | 1491     ASSERT(entry_point.IsFunction() && !entry_point.IsNull()); | 
| 1506 | 1492 | 
| 1507     result = DartEntry::InvokeFunction(entry_point, args); | 1493     result = DartEntry::InvokeFunction(entry_point, args); | 
| 1508     if (result.IsError()) { | 1494     if (result.IsError()) { | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 1519   // running the shutdown callback. | 1505   // running the shutdown callback. | 
| 1520   isolate->WaitForOutstandingSpawns(); | 1506   isolate->WaitForOutstandingSpawns(); | 
| 1521   { | 1507   { | 
| 1522     // Print the error if there is one.  This may execute dart code to | 1508     // Print the error if there is one.  This may execute dart code to | 
| 1523     // print the exception object, so we need to use a StartIsolateScope. | 1509     // print the exception object, so we need to use a StartIsolateScope. | 
| 1524     StartIsolateScope start_scope(isolate); | 1510     StartIsolateScope start_scope(isolate); | 
| 1525     Thread* thread = Thread::Current(); | 1511     Thread* thread = Thread::Current(); | 
| 1526     ASSERT(thread->isolate() == isolate); | 1512     ASSERT(thread->isolate() == isolate); | 
| 1527     StackZone zone(thread); | 1513     StackZone zone(thread); | 
| 1528     HandleScope handle_scope(thread); | 1514     HandleScope handle_scope(thread); | 
| 1529     // TODO(27003): Enable for precompiled. | 1515 // TODO(27003): Enable for precompiled. | 
| 1530 #if defined(DEBUG) && !defined(DART_PRECOMPILED_RUNTIME) | 1516 #if defined(DEBUG) && !defined(DART_PRECOMPILED_RUNTIME) | 
| 1531     if (!isolate->HasAttemptedReload()) { | 1517     if (!isolate->HasAttemptedReload()) { | 
| 1532       // For this verification we need to stop the background compiler earlier. | 1518       // For this verification we need to stop the background compiler earlier. | 
| 1533       // This would otherwise happen in Dart::ShowdownIsolate. | 1519       // This would otherwise happen in Dart::ShowdownIsolate. | 
| 1534       isolate->StopBackgroundCompiler(); | 1520       isolate->StopBackgroundCompiler(); | 
| 1535       isolate->heap()->CollectAllGarbage(); | 1521       isolate->heap()->CollectAllGarbage(); | 
| 1536       VerifyCanonicalVisitor check_canonical(thread); | 1522       VerifyCanonicalVisitor check_canonical(thread); | 
| 1537       isolate->heap()->IterateObjects(&check_canonical); | 1523       isolate->heap()->IterateObjects(&check_canonical); | 
| 1538     } | 1524     } | 
| 1539 #endif  // DEBUG | 1525 #endif  // DEBUG | 
| 1540     const Error& error = Error::Handle(thread->sticky_error()); | 1526     const Error& error = Error::Handle(thread->sticky_error()); | 
| 1541     if (!error.IsNull() && !error.IsUnwindError()) { | 1527     if (!error.IsNull() && !error.IsUnwindError()) { | 
| 1542       OS::PrintErr("in ShutdownIsolate: %s\n", error.ToErrorCString()); | 1528       OS::PrintErr("in ShutdownIsolate: %s\n", error.ToErrorCString()); | 
| 1543     } | 1529     } | 
| 1544     Dart::RunShutdownCallback(); | 1530     Dart::RunShutdownCallback(); | 
| 1545   } | 1531   } | 
| 1546   // Shut the isolate down. | 1532   // Shut the isolate down. | 
| 1547   Dart::ShutdownIsolate(isolate); | 1533   Dart::ShutdownIsolate(isolate); | 
| 1548 } | 1534 } | 
| 1549 | 1535 | 
| 1550 | 1536 | 
| 1551 void Isolate::SetStickyError(RawError* sticky_error) { | 1537 void Isolate::SetStickyError(RawError* sticky_error) { | 
| 1552   ASSERT(((sticky_error_ == Error::null()) || | 1538   ASSERT( | 
| 1553          (sticky_error == Error::null())) && | 1539       ((sticky_error_ == Error::null()) || (sticky_error == Error::null())) && | 
| 1554          (sticky_error != sticky_error_)); | 1540       (sticky_error != sticky_error_)); | 
| 1555   sticky_error_ = sticky_error; | 1541   sticky_error_ = sticky_error; | 
| 1556 } | 1542 } | 
| 1557 | 1543 | 
| 1558 | 1544 | 
| 1559 void Isolate::Run() { | 1545 void Isolate::Run() { | 
| 1560   message_handler()->Run(Dart::thread_pool(), | 1546   message_handler()->Run(Dart::thread_pool(), RunIsolate, ShutdownIsolate, | 
| 1561                          RunIsolate, |  | 
| 1562                          ShutdownIsolate, |  | 
| 1563                          reinterpret_cast<uword>(this)); | 1547                          reinterpret_cast<uword>(this)); | 
| 1564 } | 1548 } | 
| 1565 | 1549 | 
| 1566 | 1550 | 
| 1567 void Isolate::AddClosureFunction(const Function& function) const { | 1551 void Isolate::AddClosureFunction(const Function& function) const { | 
| 1568   ASSERT(!Compiler::IsBackgroundCompilation()); | 1552   ASSERT(!Compiler::IsBackgroundCompilation()); | 
| 1569   GrowableObjectArray& closures = | 1553   GrowableObjectArray& closures = | 
| 1570       GrowableObjectArray::Handle(object_store()->closure_functions()); | 1554       GrowableObjectArray::Handle(object_store()->closure_functions()); | 
| 1571   ASSERT(!closures.IsNull()); | 1555   ASSERT(!closures.IsNull()); | 
| 1572   ASSERT(function.IsNonImplicitClosureFunction()); | 1556   ASSERT(function.IsNonImplicitClosureFunction()); | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1616       GrowableObjectArray::Handle(object_store()->closure_functions()); | 1600       GrowableObjectArray::Handle(object_store()->closure_functions()); | 
| 1617   if ((idx < 0) || (idx >= closures_array.Length())) { | 1601   if ((idx < 0) || (idx >= closures_array.Length())) { | 
| 1618     return Function::null(); | 1602     return Function::null(); | 
| 1619   } | 1603   } | 
| 1620   return Function::RawCast(closures_array.At(idx)); | 1604   return Function::RawCast(closures_array.At(idx)); | 
| 1621 } | 1605 } | 
| 1622 | 1606 | 
| 1623 | 1607 | 
| 1624 class FinalizeWeakPersistentHandlesVisitor : public HandleVisitor { | 1608 class FinalizeWeakPersistentHandlesVisitor : public HandleVisitor { | 
| 1625  public: | 1609  public: | 
| 1626   FinalizeWeakPersistentHandlesVisitor() : HandleVisitor(Thread::Current()) { | 1610   FinalizeWeakPersistentHandlesVisitor() : HandleVisitor(Thread::Current()) {} | 
| 1627   } |  | 
| 1628 | 1611 | 
| 1629   void VisitHandle(uword addr) { | 1612   void VisitHandle(uword addr) { | 
| 1630     FinalizablePersistentHandle* handle = | 1613     FinalizablePersistentHandle* handle = | 
| 1631         reinterpret_cast<FinalizablePersistentHandle*>(addr); | 1614         reinterpret_cast<FinalizablePersistentHandle*>(addr); | 
| 1632     FinalizationQueue* queue = NULL;  // Finalize in the foreground. | 1615     FinalizationQueue* queue = NULL;  // Finalize in the foreground. | 
| 1633     handle->UpdateUnreachable(thread()->isolate(), queue); | 1616     handle->UpdateUnreachable(thread()->isolate(), queue); | 
| 1634   } | 1617   } | 
| 1635 | 1618 | 
| 1636  private: | 1619  private: | 
| 1637   DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); | 1620   DISALLOW_COPY_AND_ASSIGN(FinalizeWeakPersistentHandlesVisitor); | 
| 1638 }; | 1621 }; | 
| 1639 | 1622 | 
| 1640 | 1623 | 
| 1641 void Isolate::LowLevelShutdown() { | 1624 void Isolate::LowLevelShutdown() { | 
| 1642   // Ensure we have a zone and handle scope so that we can call VM functions, | 1625   // Ensure we have a zone and handle scope so that we can call VM functions, | 
| 1643   // but we no longer allocate new heap objects. | 1626   // but we no longer allocate new heap objects. | 
| 1644   Thread* thread = Thread::Current(); | 1627   Thread* thread = Thread::Current(); | 
| 1645   StackZone stack_zone(thread); | 1628   StackZone stack_zone(thread); | 
| 1646   HandleScope handle_scope(thread); | 1629   HandleScope handle_scope(thread); | 
| 1647   NoSafepointScope no_safepoint_scope; | 1630   NoSafepointScope no_safepoint_scope; | 
| 1648 | 1631 | 
| 1649   // Notify exit listeners that this isolate is shutting down. | 1632   // Notify exit listeners that this isolate is shutting down. | 
| 1650   if (object_store() != NULL) { | 1633   if (object_store() != NULL) { | 
| 1651     const Error& error = Error::Handle(thread->sticky_error()); | 1634     const Error& error = Error::Handle(thread->sticky_error()); | 
| 1652     if (error.IsNull() || | 1635     if (error.IsNull() || !error.IsUnwindError() || | 
| 1653         !error.IsUnwindError() || |  | 
| 1654         UnwindError::Cast(error).is_user_initiated()) { | 1636         UnwindError::Cast(error).is_user_initiated()) { | 
| 1655       NotifyExitListeners(); | 1637       NotifyExitListeners(); | 
| 1656     } | 1638     } | 
| 1657   } | 1639   } | 
| 1658 | 1640 | 
| 1659   // Clean up debugger resources. | 1641   // Clean up debugger resources. | 
| 1660   if (FLAG_support_debugger) { | 1642   if (FLAG_support_debugger) { | 
| 1661     debugger()->Shutdown(); | 1643     debugger()->Shutdown(); | 
| 1662   } | 1644   } | 
| 1663 | 1645 | 
| 1664 | 1646 | 
| 1665   // Close all the ports owned by this isolate. | 1647   // Close all the ports owned by this isolate. | 
| 1666   PortMap::ClosePorts(message_handler()); | 1648   PortMap::ClosePorts(message_handler()); | 
| 1667 | 1649 | 
| 1668   // Fail fast if anybody tries to post any more messsages to this isolate. | 1650   // Fail fast if anybody tries to post any more messsages to this isolate. | 
| 1669   delete message_handler(); | 1651   delete message_handler(); | 
| 1670   set_message_handler(NULL); | 1652   set_message_handler(NULL); | 
| 1671   if (FLAG_support_timeline) { | 1653   if (FLAG_support_timeline) { | 
| 1672     // Before analyzing the isolate's timeline blocks- reclaim all cached | 1654     // Before analyzing the isolate's timeline blocks- reclaim all cached | 
| 1673     // blocks. | 1655     // blocks. | 
| 1674     Timeline::ReclaimCachedBlocksFromThreads(); | 1656     Timeline::ReclaimCachedBlocksFromThreads(); | 
| 1675   } | 1657   } | 
| 1676 | 1658 | 
| 1677   // Dump all timing data for the isolate. | 1659 // Dump all timing data for the isolate. | 
| 1678 #ifndef PRODUCT | 1660 #ifndef PRODUCT | 
| 1679   if (FLAG_support_timeline && FLAG_timing) { | 1661   if (FLAG_support_timeline && FLAG_timing) { | 
| 1680     TimelinePauseTrace tpt; | 1662     TimelinePauseTrace tpt; | 
| 1681     tpt.Print(); | 1663     tpt.Print(); | 
| 1682   } | 1664   } | 
| 1683 #endif  // !PRODUCT | 1665 #endif  // !PRODUCT | 
| 1684 | 1666 | 
| 1685   // Finalize any weak persistent handles with a non-null referent. | 1667   // Finalize any weak persistent handles with a non-null referent. | 
| 1686   FinalizeWeakPersistentHandlesVisitor visitor; | 1668   FinalizeWeakPersistentHandlesVisitor visitor; | 
| 1687   api_state()->weak_persistent_handles().VisitHandles(&visitor); | 1669   api_state()->weak_persistent_handles().VisitHandles(&visitor); | 
| 1688 | 1670 | 
| 1689   if (FLAG_dump_megamorphic_stats) { | 1671   if (FLAG_dump_megamorphic_stats) { | 
| 1690     MegamorphicCacheTable::PrintSizes(this); | 1672     MegamorphicCacheTable::PrintSizes(this); | 
| 1691   } | 1673   } | 
| 1692   if (FLAG_trace_isolates) { | 1674   if (FLAG_trace_isolates) { | 
| 1693     heap()->PrintSizes(); | 1675     heap()->PrintSizes(); | 
| 1694     Symbols::DumpStats(); | 1676     Symbols::DumpStats(); | 
| 1695     OS::Print("[-] Stopping isolate:\n" | 1677     OS::Print( | 
| 1696               "\tisolate:    %s\n", name()); | 1678         "[-] Stopping isolate:\n" | 
|  | 1679         "\tisolate:    %s\n", | 
|  | 1680         name()); | 
| 1697   } | 1681   } | 
| 1698   if (FLAG_print_metrics) { | 1682   if (FLAG_print_metrics) { | 
| 1699     LogBlock lb; | 1683     LogBlock lb; | 
| 1700     OS::PrintErr("Printing metrics for %s\n", name()); | 1684     OS::PrintErr("Printing metrics for %s\n", name()); | 
| 1701 #define ISOLATE_METRIC_PRINT(type, variable, name, unit)                       \ | 1685 #define ISOLATE_METRIC_PRINT(type, variable, name, unit)                       \ | 
| 1702   OS::PrintErr("%s\n", metric_##variable##_.ToString()); | 1686   OS::PrintErr("%s\n", metric_##variable##_.ToString()); | 
| 1703 | 1687 | 
| 1704     ISOLATE_METRIC_LIST(ISOLATE_METRIC_PRINT); | 1688     ISOLATE_METRIC_LIST(ISOLATE_METRIC_PRINT); | 
| 1705 #undef ISOLATE_METRIC_PRINT | 1689 #undef ISOLATE_METRIC_PRINT | 
| 1706     OS::PrintErr("\n"); | 1690     OS::PrintErr("\n"); | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1747   // Don't allow anymore dart code to execution on this isolate. | 1731   // Don't allow anymore dart code to execution on this isolate. | 
| 1748   thread->ClearStackLimit(); | 1732   thread->ClearStackLimit(); | 
| 1749 | 1733 | 
| 1750   // First, perform higher-level cleanup that may need to allocate. | 1734   // First, perform higher-level cleanup that may need to allocate. | 
| 1751   { | 1735   { | 
| 1752     // Ensure we have a zone and handle scope so that we can call VM functions. | 1736     // Ensure we have a zone and handle scope so that we can call VM functions. | 
| 1753     StackZone stack_zone(thread); | 1737     StackZone stack_zone(thread); | 
| 1754     HandleScope handle_scope(thread); | 1738     HandleScope handle_scope(thread); | 
| 1755 | 1739 | 
| 1756     // Write compiler stats data if enabled. | 1740     // Write compiler stats data if enabled. | 
| 1757     if (FLAG_support_compiler_stats && FLAG_compiler_stats | 1741     if (FLAG_support_compiler_stats && FLAG_compiler_stats && | 
| 1758         && !ServiceIsolate::IsServiceIsolateDescendant(this) | 1742         !ServiceIsolate::IsServiceIsolateDescendant(this) && | 
| 1759         && (this != Dart::vm_isolate())) { | 1743         (this != Dart::vm_isolate())) { | 
| 1760       OS::Print("%s", aggregate_compiler_stats()->PrintToZone()); | 1744       OS::Print("%s", aggregate_compiler_stats()->PrintToZone()); | 
| 1761     } | 1745     } | 
| 1762   } | 1746   } | 
| 1763 | 1747 | 
| 1764   // Remove this isolate from the list *before* we start tearing it down, to | 1748   // Remove this isolate from the list *before* we start tearing it down, to | 
| 1765   // avoid exposing it in a state of decay. | 1749   // avoid exposing it in a state of decay. | 
| 1766   RemoveIsolateFromList(this); | 1750   RemoveIsolateFromList(this); | 
| 1767 | 1751 | 
| 1768   if (heap_ != NULL) { | 1752   if (heap_ != NULL) { | 
| 1769     // Wait for any concurrent GC tasks to finish before shutting down. | 1753     // Wait for any concurrent GC tasks to finish before shutting down. | 
| 1770     // TODO(koda): Support faster sweeper shutdown (e.g., after current page). | 1754     // TODO(koda): Support faster sweeper shutdown (e.g., after current page). | 
| 1771     PageSpace* old_space = heap_->old_space(); | 1755     PageSpace* old_space = heap_->old_space(); | 
| 1772     MonitorLocker ml(old_space->tasks_lock()); | 1756     MonitorLocker ml(old_space->tasks_lock()); | 
| 1773     while (old_space->tasks() > 0) { | 1757     while (old_space->tasks() > 0) { | 
| 1774       ml.Wait(); | 1758       ml.Wait(); | 
| 1775     } | 1759     } | 
| 1776   } | 1760   } | 
| 1777 | 1761 | 
| 1778   if (FLAG_check_reloaded && is_runnable() && | 1762   if (FLAG_check_reloaded && is_runnable() && (this != Dart::vm_isolate()) && | 
| 1779       (this != Dart::vm_isolate()) && |  | 
| 1780       !ServiceIsolate::IsServiceIsolateDescendant(this)) { | 1763       !ServiceIsolate::IsServiceIsolateDescendant(this)) { | 
| 1781     if (!HasAttemptedReload()) { | 1764     if (!HasAttemptedReload()) { | 
| 1782       FATAL("Isolate did not reload before exiting and " | 1765       FATAL( | 
| 1783             "--check-reloaded is enabled.\n"); | 1766           "Isolate did not reload before exiting and " | 
|  | 1767           "--check-reloaded is enabled.\n"); | 
| 1784     } | 1768     } | 
| 1785   } | 1769   } | 
| 1786 | 1770 | 
| 1787   // Then, proceed with low-level teardown. | 1771   // Then, proceed with low-level teardown. | 
| 1788   LowLevelShutdown(); | 1772   LowLevelShutdown(); | 
| 1789 | 1773 | 
| 1790 #if defined(DEBUG) | 1774 #if defined(DEBUG) | 
| 1791   // No concurrent sweeper tasks should be running at this point. | 1775   // No concurrent sweeper tasks should be running at this point. | 
| 1792   if (heap_ != NULL) { | 1776   if (heap_ != NULL) { | 
| 1793     PageSpace* old_space = heap_->old_space(); | 1777     PageSpace* old_space = heap_->old_space(); | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1844   visitor->VisitPointer(reinterpret_cast<RawObject**>(&tag_table_)); | 1828   visitor->VisitPointer(reinterpret_cast<RawObject**>(&tag_table_)); | 
| 1845 | 1829 | 
| 1846   if (background_compiler() != NULL) { | 1830   if (background_compiler() != NULL) { | 
| 1847     background_compiler()->VisitPointers(visitor); | 1831     background_compiler()->VisitPointers(visitor); | 
| 1848   } | 1832   } | 
| 1849 | 1833 | 
| 1850   // Visit the deoptimized code array which is stored in the isolate. | 1834   // Visit the deoptimized code array which is stored in the isolate. | 
| 1851   visitor->VisitPointer( | 1835   visitor->VisitPointer( | 
| 1852       reinterpret_cast<RawObject**>(&deoptimized_code_array_)); | 1836       reinterpret_cast<RawObject**>(&deoptimized_code_array_)); | 
| 1853 | 1837 | 
| 1854   visitor->VisitPointer( | 1838   visitor->VisitPointer(reinterpret_cast<RawObject**>(&sticky_error_)); | 
| 1855         reinterpret_cast<RawObject**>(&sticky_error_)); |  | 
| 1856 | 1839 | 
| 1857   // Visit the pending service extension calls. | 1840   // Visit the pending service extension calls. | 
| 1858   visitor->VisitPointer( | 1841   visitor->VisitPointer( | 
| 1859       reinterpret_cast<RawObject**>(&pending_service_extension_calls_)); | 1842       reinterpret_cast<RawObject**>(&pending_service_extension_calls_)); | 
| 1860 | 1843 | 
| 1861   // Visit the registered service extension handlers. | 1844   // Visit the registered service extension handlers. | 
| 1862   visitor->VisitPointer( | 1845   visitor->VisitPointer( | 
| 1863       reinterpret_cast<RawObject**>(®istered_service_extension_handlers_)); | 1846       reinterpret_cast<RawObject**>(®istered_service_extension_handlers_)); | 
| 1864 | 1847 | 
| 1865   // Visit the boxed_field_list_. | 1848   // Visit the boxed_field_list_. | 
| 1866   // 'boxed_field_list_' access via mutator and background compilation threads | 1849   // 'boxed_field_list_' access via mutator and background compilation threads | 
| 1867   // is guarded with a monitor. This means that we can visit it only | 1850   // is guarded with a monitor. This means that we can visit it only | 
| 1868   // when at safepoint or the field_list_mutex_ lock has been taken. | 1851   // when at safepoint or the field_list_mutex_ lock has been taken. | 
| 1869   visitor->VisitPointer(reinterpret_cast<RawObject**>(&boxed_field_list_)); | 1852   visitor->VisitPointer(reinterpret_cast<RawObject**>(&boxed_field_list_)); | 
| 1870 | 1853 | 
| 1871   // Visit objects in the debugger. | 1854   // Visit objects in the debugger. | 
| 1872   if (FLAG_support_debugger) { | 1855   if (FLAG_support_debugger) { | 
| 1873     debugger()->VisitObjectPointers(visitor); | 1856     debugger()->VisitObjectPointers(visitor); | 
| 1874   } | 1857   } | 
| 1875 | 1858 | 
| 1876   NOT_IN_PRODUCT( | 1859 #if !defined(PRODUCT) | 
| 1877     // Visit objects that are being used for isolate reload. | 1860   // Visit objects that are being used for isolate reload. | 
| 1878     if (reload_context() != NULL) { | 1861   if (reload_context() != NULL) { | 
| 1879       reload_context()->VisitObjectPointers(visitor); | 1862     reload_context()->VisitObjectPointers(visitor); | 
| 1880     } | 1863   } | 
| 1881     if (ServiceIsolate::IsServiceIsolate(this)) { | 1864   if (ServiceIsolate::IsServiceIsolate(this)) { | 
| 1882       ServiceIsolate::VisitObjectPointers(visitor); | 1865     ServiceIsolate::VisitObjectPointers(visitor); | 
| 1883     } | 1866   } | 
| 1884   ) | 1867 #endif  // !defined(PRODUCT) | 
| 1885 | 1868 | 
| 1886   // Visit objects that are being used for deoptimization. | 1869   // Visit objects that are being used for deoptimization. | 
| 1887   if (deopt_context() != NULL) { | 1870   if (deopt_context() != NULL) { | 
| 1888     deopt_context()->VisitObjectPointers(visitor); | 1871     deopt_context()->VisitObjectPointers(visitor); | 
| 1889   } | 1872   } | 
| 1890 | 1873 | 
| 1891   // Visit objects in all threads (e.g., Dart stack, handles in zones). | 1874   // Visit objects in all threads (e.g., Dart stack, handles in zones). | 
| 1892   thread_registry()->VisitObjectPointers(visitor, validate_frames); | 1875   thread_registry()->VisitObjectPointers(visitor, validate_frames); | 
| 1893 } | 1876 } | 
| 1894 | 1877 | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 1922   ASSERT(raw_class->ptr()->id_ == cid); | 1905   ASSERT(raw_class->ptr()->id_ == cid); | 
| 1923 #endif | 1906 #endif | 
| 1924   return raw_class; | 1907   return raw_class; | 
| 1925 } | 1908 } | 
| 1926 | 1909 | 
| 1927 | 1910 | 
| 1928 void Isolate::AddPendingDeopt(uword fp, uword pc) { | 1911 void Isolate::AddPendingDeopt(uword fp, uword pc) { | 
| 1929   // GrowableArray::Add is not atomic and may be interrupt by a profiler | 1912   // GrowableArray::Add is not atomic and may be interrupt by a profiler | 
| 1930   // stack walk. | 1913   // stack walk. | 
| 1931   MallocGrowableArray<PendingLazyDeopt>* old_pending_deopts = pending_deopts_; | 1914   MallocGrowableArray<PendingLazyDeopt>* old_pending_deopts = pending_deopts_; | 
| 1932   MallocGrowableArray<PendingLazyDeopt>* new_pending_deopts | 1915   MallocGrowableArray<PendingLazyDeopt>* new_pending_deopts = | 
| 1933       = new MallocGrowableArray<PendingLazyDeopt>( | 1916       new MallocGrowableArray<PendingLazyDeopt>(old_pending_deopts->length() + | 
| 1934           old_pending_deopts->length() + 1); | 1917                                                 1); | 
| 1935   for (intptr_t i = 0; i < old_pending_deopts->length(); i++) { | 1918   for (intptr_t i = 0; i < old_pending_deopts->length(); i++) { | 
| 1936     ASSERT((*old_pending_deopts)[i].fp() != fp); | 1919     ASSERT((*old_pending_deopts)[i].fp() != fp); | 
| 1937     new_pending_deopts->Add((*old_pending_deopts)[i]); | 1920     new_pending_deopts->Add((*old_pending_deopts)[i]); | 
| 1938   } | 1921   } | 
| 1939   PendingLazyDeopt deopt(fp, pc); | 1922   PendingLazyDeopt deopt(fp, pc); | 
| 1940   new_pending_deopts->Add(deopt); | 1923   new_pending_deopts->Add(deopt); | 
| 1941 | 1924 | 
| 1942   pending_deopts_ = new_pending_deopts; | 1925   pending_deopts_ = new_pending_deopts; | 
| 1943   delete old_pending_deopts; | 1926   delete old_pending_deopts; | 
| 1944 } | 1927 } | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1983 void Isolate::PrintJSON(JSONStream* stream, bool ref) { | 1966 void Isolate::PrintJSON(JSONStream* stream, bool ref) { | 
| 1984   if (!FLAG_support_service) { | 1967   if (!FLAG_support_service) { | 
| 1985     return; | 1968     return; | 
| 1986   } | 1969   } | 
| 1987   JSONObject jsobj(stream); | 1970   JSONObject jsobj(stream); | 
| 1988   jsobj.AddProperty("type", (ref ? "@Isolate" : "Isolate")); | 1971   jsobj.AddProperty("type", (ref ? "@Isolate" : "Isolate")); | 
| 1989   jsobj.AddFixedServiceId("isolates/%" Pd64 "", | 1972   jsobj.AddFixedServiceId("isolates/%" Pd64 "", | 
| 1990                           static_cast<int64_t>(main_port())); | 1973                           static_cast<int64_t>(main_port())); | 
| 1991 | 1974 | 
| 1992   jsobj.AddProperty("name", debugger_name()); | 1975   jsobj.AddProperty("name", debugger_name()); | 
| 1993   jsobj.AddPropertyF("number", "%" Pd64 "", | 1976   jsobj.AddPropertyF("number", "%" Pd64 "", static_cast<int64_t>(main_port())); | 
| 1994                      static_cast<int64_t>(main_port())); |  | 
| 1995   if (ref) { | 1977   if (ref) { | 
| 1996     return; | 1978     return; | 
| 1997   } | 1979   } | 
| 1998   jsobj.AddPropertyF("_originNumber", "%" Pd64 "", | 1980   jsobj.AddPropertyF("_originNumber", "%" Pd64 "", | 
| 1999                      static_cast<int64_t>(origin_id())); | 1981                      static_cast<int64_t>(origin_id())); | 
| 2000   int64_t start_time_millis = start_time() / kMicrosecondsPerMillisecond; | 1982   int64_t start_time_millis = start_time() / kMicrosecondsPerMillisecond; | 
| 2001   jsobj.AddPropertyTimeMillis("startTime", start_time_millis); | 1983   jsobj.AddPropertyTimeMillis("startTime", start_time_millis); | 
| 2002   { | 1984   { | 
| 2003     JSONObject jsheap(&jsobj, "_heaps"); | 1985     JSONObject jsheap(&jsobj, "_heaps"); | 
| 2004     heap()->PrintToJSONObject(Heap::kNew, &jsheap); | 1986     heap()->PrintToJSONObject(Heap::kNew, &jsheap); | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 2017     jsobj.AddProperty("pauseEvent", &pause_event); | 1999     jsobj.AddProperty("pauseEvent", &pause_event); | 
| 2018   } else if (message_handler()->is_paused_on_start() || | 2000   } else if (message_handler()->is_paused_on_start() || | 
| 2019              message_handler()->should_pause_on_start()) { | 2001              message_handler()->should_pause_on_start()) { | 
| 2020     ASSERT((debugger() == NULL) || (debugger()->PauseEvent() == NULL)); | 2002     ASSERT((debugger() == NULL) || (debugger()->PauseEvent() == NULL)); | 
| 2021     ServiceEvent pause_event(this, ServiceEvent::kPauseStart); | 2003     ServiceEvent pause_event(this, ServiceEvent::kPauseStart); | 
| 2022     jsobj.AddProperty("pauseEvent", &pause_event); | 2004     jsobj.AddProperty("pauseEvent", &pause_event); | 
| 2023   } else if (message_handler()->is_paused_on_exit() && | 2005   } else if (message_handler()->is_paused_on_exit() && | 
| 2024              ((debugger() == NULL) || (debugger()->PauseEvent() == NULL))) { | 2006              ((debugger() == NULL) || (debugger()->PauseEvent() == NULL))) { | 
| 2025     ServiceEvent pause_event(this, ServiceEvent::kPauseExit); | 2007     ServiceEvent pause_event(this, ServiceEvent::kPauseExit); | 
| 2026     jsobj.AddProperty("pauseEvent", &pause_event); | 2008     jsobj.AddProperty("pauseEvent", &pause_event); | 
| 2027   } else if ((debugger() != NULL) && | 2009   } else if ((debugger() != NULL) && (debugger()->PauseEvent() != NULL) && | 
| 2028              (debugger()->PauseEvent() != NULL) && |  | 
| 2029              !resume_request_) { | 2010              !resume_request_) { | 
| 2030     jsobj.AddProperty("pauseEvent", debugger()->PauseEvent()); | 2011     jsobj.AddProperty("pauseEvent", debugger()->PauseEvent()); | 
| 2031   } else { | 2012   } else { | 
| 2032     ServiceEvent pause_event(this, ServiceEvent::kResume); | 2013     ServiceEvent pause_event(this, ServiceEvent::kResume); | 
| 2033 | 2014 | 
| 2034     if (debugger() != NULL) { | 2015     if (debugger() != NULL) { | 
| 2035       // TODO(turnidge): Don't compute a full stack trace. | 2016       // TODO(turnidge): Don't compute a full stack trace. | 
| 2036       DebuggerStackTrace* stack = debugger()->StackTrace(); | 2017       DebuggerStackTrace* stack = debugger()->StackTrace(); | 
| 2037       if (stack->Length() > 0) { | 2018       if (stack->Length() > 0) { | 
| 2038         pause_event.set_top_frame(stack->FrameAt(0)); | 2019         pause_event.set_top_frame(stack->FrameAt(0)); | 
| 2039       } | 2020       } | 
| 2040     } | 2021     } | 
| 2041     jsobj.AddProperty("pauseEvent", &pause_event); | 2022     jsobj.AddProperty("pauseEvent", &pause_event); | 
| 2042   } | 2023   } | 
| 2043 | 2024 | 
| 2044   const Library& lib = | 2025   const Library& lib = Library::Handle(object_store()->root_library()); | 
| 2045       Library::Handle(object_store()->root_library()); |  | 
| 2046   if (!lib.IsNull()) { | 2026   if (!lib.IsNull()) { | 
| 2047     jsobj.AddProperty("rootLib", lib); | 2027     jsobj.AddProperty("rootLib", lib); | 
| 2048   } | 2028   } | 
| 2049 | 2029 | 
| 2050   if (FLAG_profiler) { | 2030   if (FLAG_profiler) { | 
| 2051     JSONObject tagCounters(&jsobj, "_tagCounters"); | 2031     JSONObject tagCounters(&jsobj, "_tagCounters"); | 
| 2052     vm_tag_counters()->PrintToJSONObject(&tagCounters); | 2032     vm_tag_counters()->PrintToJSONObject(&tagCounters); | 
| 2053   } | 2033   } | 
| 2054   if (Thread::Current()->sticky_error() != Object::null()) { | 2034   if (Thread::Current()->sticky_error() != Object::null()) { | 
| 2055     Error& error = Error::Handle(Thread::Current()->sticky_error()); | 2035     Error& error = Error::Handle(Thread::Current()->sticky_error()); | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 2076   } | 2056   } | 
| 2077 | 2057 | 
| 2078   { | 2058   { | 
| 2079     JSONArray breakpoints(&jsobj, "breakpoints"); | 2059     JSONArray breakpoints(&jsobj, "breakpoints"); | 
| 2080     if (debugger() != NULL) { | 2060     if (debugger() != NULL) { | 
| 2081       debugger()->PrintBreakpointsToJSONArray(&breakpoints); | 2061       debugger()->PrintBreakpointsToJSONArray(&breakpoints); | 
| 2082     } | 2062     } | 
| 2083   } | 2063   } | 
| 2084 | 2064 | 
| 2085   Dart_ExceptionPauseInfo pause_info = (debugger() != NULL) | 2065   Dart_ExceptionPauseInfo pause_info = (debugger() != NULL) | 
| 2086       ? debugger()->GetExceptionPauseInfo() | 2066                                            ? debugger()->GetExceptionPauseInfo() | 
| 2087       : kNoPauseOnExceptions; | 2067                                            : kNoPauseOnExceptions; | 
| 2088   jsobj.AddProperty("exceptionPauseMode", | 2068   jsobj.AddProperty("exceptionPauseMode", | 
| 2089                     ExceptionPauseInfoToServiceEnum(pause_info)); | 2069                     ExceptionPauseInfoToServiceEnum(pause_info)); | 
| 2090 | 2070 | 
| 2091   if (debugger() != NULL) { | 2071   if (debugger() != NULL) { | 
| 2092     JSONObject settings(&jsobj, "_debuggerSettings"); | 2072     JSONObject settings(&jsobj, "_debuggerSettings"); | 
| 2093     debugger()->PrintSettingsToJSONObject(&settings); | 2073     debugger()->PrintSettingsToJSONObject(&settings); | 
| 2094   } | 2074   } | 
| 2095 | 2075 | 
| 2096   { | 2076   { | 
| 2097     GrowableObjectArray& handlers = | 2077     GrowableObjectArray& handlers = | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2150   deoptimized_code.Add(code); | 2130   deoptimized_code.Add(code); | 
| 2151 } | 2131 } | 
| 2152 | 2132 | 
| 2153 | 2133 | 
| 2154 void Isolate::clear_sticky_error() { | 2134 void Isolate::clear_sticky_error() { | 
| 2155   sticky_error_ = Error::null(); | 2135   sticky_error_ = Error::null(); | 
| 2156 } | 2136 } | 
| 2157 | 2137 | 
| 2158 | 2138 | 
| 2159 void Isolate::set_pending_service_extension_calls( | 2139 void Isolate::set_pending_service_extension_calls( | 
| 2160       const GrowableObjectArray& value) { | 2140     const GrowableObjectArray& value) { | 
| 2161   pending_service_extension_calls_ = value.raw(); | 2141   pending_service_extension_calls_ = value.raw(); | 
| 2162 } | 2142 } | 
| 2163 | 2143 | 
| 2164 | 2144 | 
| 2165 void Isolate::set_registered_service_extension_handlers( | 2145 void Isolate::set_registered_service_extension_handlers( | 
| 2166     const GrowableObjectArray& value) { | 2146     const GrowableObjectArray& value) { | 
| 2167   registered_service_extension_handlers_ = value.raw(); | 2147   registered_service_extension_handlers_ = value.raw(); | 
| 2168 } | 2148 } | 
| 2169 | 2149 | 
| 2170 | 2150 | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2239     ASSERT(!parameter_values.IsNull()); | 2219     ASSERT(!parameter_values.IsNull()); | 
| 2240     arguments.SetAt(kPendingValuesIndex, parameter_values); | 2220     arguments.SetAt(kPendingValuesIndex, parameter_values); | 
| 2241     reply_port ^= calls.At(i + kPendingReplyPortIndex); | 2221     reply_port ^= calls.At(i + kPendingReplyPortIndex); | 
| 2242     ASSERT(!reply_port.IsNull()); | 2222     ASSERT(!reply_port.IsNull()); | 
| 2243     arguments.SetAt(kPendingReplyPortIndex, reply_port); | 2223     arguments.SetAt(kPendingReplyPortIndex, reply_port); | 
| 2244     id ^= calls.At(i + kPendingIdIndex); | 2224     id ^= calls.At(i + kPendingIdIndex); | 
| 2245     arguments.SetAt(kPendingIdIndex, id); | 2225     arguments.SetAt(kPendingIdIndex, id); | 
| 2246     arguments.SetAt(kPendingEntrySize, Bool::Get(FLAG_trace_service)); | 2226     arguments.SetAt(kPendingEntrySize, Bool::Get(FLAG_trace_service)); | 
| 2247 | 2227 | 
| 2248     if (FLAG_trace_service) { | 2228     if (FLAG_trace_service) { | 
| 2249       OS::Print( | 2229       OS::Print("[+%" Pd64 "ms] Isolate %s invoking _runExtension for %s\n", | 
| 2250           "[+%" Pd64 "ms] Isolate %s invoking _runExtension for %s\n", | 2230                 Dart::timestamp(), name(), method_name.ToCString()); | 
| 2251           Dart::timestamp(), name(), method_name.ToCString()); |  | 
| 2252     } | 2231     } | 
| 2253     result = DartEntry::InvokeFunction(run_extension, arguments); | 2232     result = DartEntry::InvokeFunction(run_extension, arguments); | 
| 2254     if (FLAG_trace_service) { | 2233     if (FLAG_trace_service) { | 
| 2255       OS::Print( | 2234       OS::Print("[+%" Pd64 "ms] Isolate %s : _runExtension complete for %s\n", | 
| 2256           "[+%" Pd64 "ms] Isolate %s : _runExtension complete for %s\n", | 2235                 Dart::timestamp(), name(), method_name.ToCString()); | 
| 2257           Dart::timestamp(), name(), method_name.ToCString()); |  | 
| 2258     } | 2236     } | 
| 2259     // Propagate the error. | 2237     // Propagate the error. | 
| 2260     if (result.IsError()) { | 2238     if (result.IsError()) { | 
| 2261       // Remaining service extension calls are dropped. | 2239       // Remaining service extension calls are dropped. | 
| 2262       if (!result.IsUnwindError()) { | 2240       if (!result.IsUnwindError()) { | 
| 2263         // Send error back over the protocol. | 2241         // Send error back over the protocol. | 
| 2264         Service::PostError(method_name, | 2242         Service::PostError(method_name, parameter_keys, parameter_values, | 
| 2265                            parameter_keys, | 2243                            reply_port, id, Error::Cast(result)); | 
| 2266                            parameter_values, |  | 
| 2267                            reply_port, |  | 
| 2268                            id, |  | 
| 2269                            Error::Cast(result)); |  | 
| 2270       } | 2244       } | 
| 2271       return result.raw(); | 2245       return result.raw(); | 
| 2272     } | 2246     } | 
| 2273     // Drain the microtask queue. | 2247     // Drain the microtask queue. | 
| 2274     result = DartLibraryCalls::DrainMicrotaskQueue(); | 2248     result = DartLibraryCalls::DrainMicrotaskQueue(); | 
| 2275     // Propagate the error. | 2249     // Propagate the error. | 
| 2276     if (result.IsError()) { | 2250     if (result.IsError()) { | 
| 2277       // Remaining service extension calls are dropped. | 2251       // Remaining service extension calls are dropped. | 
| 2278       return result.raw(); | 2252       return result.raw(); | 
| 2279     } | 2253     } | 
| 2280   } | 2254   } | 
| 2281   return Object::null(); | 2255   return Object::null(); | 
| 2282 } | 2256 } | 
| 2283 | 2257 | 
| 2284 | 2258 | 
| 2285 RawGrowableObjectArray* Isolate::GetAndClearPendingServiceExtensionCalls() { | 2259 RawGrowableObjectArray* Isolate::GetAndClearPendingServiceExtensionCalls() { | 
| 2286   RawGrowableObjectArray* r = pending_service_extension_calls_; | 2260   RawGrowableObjectArray* r = pending_service_extension_calls_; | 
| 2287   pending_service_extension_calls_ = GrowableObjectArray::null(); | 2261   pending_service_extension_calls_ = GrowableObjectArray::null(); | 
| 2288   return r; | 2262   return r; | 
| 2289 } | 2263 } | 
| 2290 | 2264 | 
| 2291 | 2265 | 
| 2292 void Isolate::AppendServiceExtensionCall(const Instance& closure, | 2266 void Isolate::AppendServiceExtensionCall(const Instance& closure, | 
| 2293                                          const String& method_name, | 2267                                          const String& method_name, | 
| 2294                                          const Array& parameter_keys, | 2268                                          const Array& parameter_keys, | 
| 2295                                          const Array& parameter_values, | 2269                                          const Array& parameter_values, | 
| 2296                                          const Instance& reply_port, | 2270                                          const Instance& reply_port, | 
| 2297                                          const Instance& id) { | 2271                                          const Instance& id) { | 
| 2298   if (FLAG_trace_service) { | 2272   if (FLAG_trace_service) { | 
| 2299     OS::Print( | 2273     OS::Print("[+%" Pd64 "ms] Isolate %s ENQUEUING request for extension %s\n", | 
| 2300         "[+%" Pd64 "ms] Isolate %s ENQUEUING request for extension %s\n", | 2274               Dart::timestamp(), name(), method_name.ToCString()); | 
| 2301         Dart::timestamp(), name(), method_name.ToCString()); |  | 
| 2302   } | 2275   } | 
| 2303   GrowableObjectArray& calls = | 2276   GrowableObjectArray& calls = | 
| 2304       GrowableObjectArray::Handle(pending_service_extension_calls()); | 2277       GrowableObjectArray::Handle(pending_service_extension_calls()); | 
| 2305   if (calls.IsNull()) { | 2278   if (calls.IsNull()) { | 
| 2306     calls ^= GrowableObjectArray::New(); | 2279     calls ^= GrowableObjectArray::New(); | 
| 2307     ASSERT(!calls.IsNull()); | 2280     ASSERT(!calls.IsNull()); | 
| 2308     set_pending_service_extension_calls(calls); | 2281     set_pending_service_extension_calls(calls); | 
| 2309   } | 2282   } | 
| 2310   ASSERT(kPendingHandlerIndex == 0); | 2283   ASSERT(kPendingHandlerIndex == 0); | 
| 2311   calls.Add(closure); | 2284   calls.Add(closure); | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2396   // embedder.  We don't know what kind of thread we are on -- it | 2369   // embedder.  We don't know what kind of thread we are on -- it | 
| 2397   // could be from our thread pool or it could be a thread from the | 2370   // could be from our thread pool or it could be a thread from the | 
| 2398   // embedder.  Sit on the current thread handling service events | 2371   // embedder.  Sit on the current thread handling service events | 
| 2399   // until we are told to resume. | 2372   // until we are told to resume. | 
| 2400   if (pause_loop_monitor_ == NULL) { | 2373   if (pause_loop_monitor_ == NULL) { | 
| 2401     pause_loop_monitor_ = new Monitor(); | 2374     pause_loop_monitor_ = new Monitor(); | 
| 2402   } | 2375   } | 
| 2403   Dart_EnterScope(); | 2376   Dart_EnterScope(); | 
| 2404   MonitorLocker ml(pause_loop_monitor_); | 2377   MonitorLocker ml(pause_loop_monitor_); | 
| 2405 | 2378 | 
| 2406   Dart_MessageNotifyCallback saved_notify_callback = | 2379   Dart_MessageNotifyCallback saved_notify_callback = message_notify_callback(); | 
| 2407       message_notify_callback(); |  | 
| 2408   set_message_notify_callback(Isolate::WakePauseEventHandler); | 2380   set_message_notify_callback(Isolate::WakePauseEventHandler); | 
| 2409 | 2381 | 
| 2410   const bool had_isolate_reload_context = reload_context() != NULL; | 2382   const bool had_isolate_reload_context = reload_context() != NULL; | 
| 2411   const int64_t start_time_micros = | 2383   const int64_t start_time_micros = | 
| 2412       !had_isolate_reload_context ? 0 : reload_context()->start_time_micros(); | 2384       !had_isolate_reload_context ? 0 : reload_context()->start_time_micros(); | 
| 2413   bool resume = false; | 2385   bool resume = false; | 
| 2414   while (true) { | 2386   while (true) { | 
| 2415     // Handle all available vm service messages, up to a resume | 2387     // Handle all available vm service messages, up to a resume | 
| 2416     // request. | 2388     // request. | 
| 2417     while (!resume && Dart_HasServiceMessages()) { | 2389     while (!resume && Dart_HasServiceMessages()) { | 
| 2418       ml.Exit(); | 2390       ml.Exit(); | 
| 2419       resume = Dart_HandleServiceMessages(); | 2391       resume = Dart_HandleServiceMessages(); | 
| 2420       ml.Enter(); | 2392       ml.Enter(); | 
| 2421     } | 2393     } | 
| 2422     if (resume) { | 2394     if (resume) { | 
| 2423       break; | 2395       break; | 
| 2424     } | 2396     } | 
| 2425 | 2397 | 
| 2426     if (had_isolate_reload_context && (reload_context() == NULL)) { | 2398     if (had_isolate_reload_context && (reload_context() == NULL)) { | 
| 2427       if (FLAG_trace_reload) { | 2399       if (FLAG_trace_reload) { | 
| 2428         const int64_t reload_time_micros = | 2400         const int64_t reload_time_micros = | 
| 2429             OS::GetCurrentMonotonicMicros() - start_time_micros; | 2401             OS::GetCurrentMonotonicMicros() - start_time_micros; | 
| 2430         double reload_millis = | 2402         double reload_millis = MicrosecondsToMilliseconds(reload_time_micros); | 
| 2431             MicrosecondsToMilliseconds(reload_time_micros); |  | 
| 2432         OS::Print("Reloading has finished! (%.2f ms)\n", reload_millis); | 2403         OS::Print("Reloading has finished! (%.2f ms)\n", reload_millis); | 
| 2433       } | 2404       } | 
| 2434       break; | 2405       break; | 
| 2435     } | 2406     } | 
| 2436 | 2407 | 
| 2437     // Wait for more service messages. | 2408     // Wait for more service messages. | 
| 2438     Monitor::WaitResult res = ml.Wait(); | 2409     Monitor::WaitResult res = ml.Wait(); | 
| 2439     ASSERT(res == Monitor::kNotified); | 2410     ASSERT(res == Monitor::kNotified); | 
| 2440   } | 2411   } | 
| 2441   set_message_notify_callback(saved_notify_callback); | 2412   set_message_notify_callback(saved_notify_callback); | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2557   imm.value.as_int32 = Isolate::kImmediateAction; | 2528   imm.value.as_int32 = Isolate::kImmediateAction; | 
| 2558   list_values[3] = &imm; | 2529   list_values[3] = &imm; | 
| 2559 | 2530 | 
| 2560   { | 2531   { | 
| 2561     uint8_t* buffer = NULL; | 2532     uint8_t* buffer = NULL; | 
| 2562     ApiMessageWriter writer(&buffer, allocator); | 2533     ApiMessageWriter writer(&buffer, allocator); | 
| 2563     bool success = writer.WriteCMessage(&kill_msg); | 2534     bool success = writer.WriteCMessage(&kill_msg); | 
| 2564     ASSERT(success); | 2535     ASSERT(success); | 
| 2565 | 2536 | 
| 2566     // Post the message at the given port. | 2537     // Post the message at the given port. | 
| 2567     success = PortMap::PostMessage(new Message(main_port(), | 2538     success = PortMap::PostMessage(new Message( | 
| 2568                                                buffer, | 2539         main_port(), buffer, writer.BytesWritten(), Message::kOOBPriority)); | 
| 2569                                                writer.BytesWritten(), |  | 
| 2570                                                Message::kOOBPriority)); |  | 
| 2571     ASSERT(success); | 2540     ASSERT(success); | 
| 2572   } | 2541   } | 
| 2573 } | 2542 } | 
| 2574 | 2543 | 
| 2575 | 2544 | 
| 2576 class IsolateKillerVisitor : public IsolateVisitor { | 2545 class IsolateKillerVisitor : public IsolateVisitor { | 
| 2577  public: | 2546  public: | 
| 2578   explicit IsolateKillerVisitor(Isolate::LibMsgId msg_id) | 2547   explicit IsolateKillerVisitor(Isolate::LibMsgId msg_id) | 
| 2579       : target_(NULL), msg_id_(msg_id) {} | 2548       : target_(NULL), msg_id_(msg_id) {} | 
| 2580 | 2549 | 
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2798 | 2767 | 
| 2799   String& func_name = String::Handle(); | 2768   String& func_name = String::Handle(); | 
| 2800   func_name ^= func.name(); | 2769   func_name ^= func.name(); | 
| 2801   func_name ^= String::ScrubName(func_name); | 2770   func_name ^= String::ScrubName(func_name); | 
| 2802   function_name_ = NewConstChar(func_name.ToCString()); | 2771   function_name_ = NewConstChar(func_name.ToCString()); | 
| 2803   if (!cls.IsTopLevel()) { | 2772   if (!cls.IsTopLevel()) { | 
| 2804     const String& class_name = String::Handle(cls.Name()); | 2773     const String& class_name = String::Handle(cls.Name()); | 
| 2805     class_name_ = NewConstChar(class_name.ToCString()); | 2774     class_name_ = NewConstChar(class_name.ToCString()); | 
| 2806   } | 2775   } | 
| 2807   bool can_send_any_object = true; | 2776   bool can_send_any_object = true; | 
| 2808   SerializeObject(message, | 2777   SerializeObject(message, &serialized_message_, &serialized_message_len_, | 
| 2809                   &serialized_message_, |  | 
| 2810                   &serialized_message_len_, |  | 
| 2811                   can_send_any_object); | 2778                   can_send_any_object); | 
| 2812   // Inherit flags from spawning isolate. | 2779   // Inherit flags from spawning isolate. | 
| 2813   Isolate::Current()->FlagsCopyTo(isolate_flags()); | 2780   Isolate::Current()->FlagsCopyTo(isolate_flags()); | 
| 2814 } | 2781 } | 
| 2815 | 2782 | 
| 2816 | 2783 | 
| 2817 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, | 2784 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, | 
| 2818                                      void* init_data, | 2785                                      void* init_data, | 
| 2819                                      const char* script_url, | 2786                                      const char* script_url, | 
| 2820                                      const char* package_root, | 2787                                      const char* package_root, | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 2843       serialized_args_len_(0), | 2810       serialized_args_len_(0), | 
| 2844       serialized_message_(NULL), | 2811       serialized_message_(NULL), | 
| 2845       serialized_message_len_(0), | 2812       serialized_message_len_(0), | 
| 2846       spawn_count_monitor_(spawn_count_monitor), | 2813       spawn_count_monitor_(spawn_count_monitor), | 
| 2847       spawn_count_(spawn_count), | 2814       spawn_count_(spawn_count), | 
| 2848       isolate_flags_(), | 2815       isolate_flags_(), | 
| 2849       paused_(paused), | 2816       paused_(paused), | 
| 2850       errors_are_fatal_(errors_are_fatal) { | 2817       errors_are_fatal_(errors_are_fatal) { | 
| 2851   function_name_ = NewConstChar("main"); | 2818   function_name_ = NewConstChar("main"); | 
| 2852   bool can_send_any_object = false; | 2819   bool can_send_any_object = false; | 
| 2853   SerializeObject(args, | 2820   SerializeObject(args, &serialized_args_, &serialized_args_len_, | 
| 2854                   &serialized_args_, |  | 
| 2855                   &serialized_args_len_, |  | 
| 2856                   can_send_any_object); | 2821                   can_send_any_object); | 
| 2857   SerializeObject(message, | 2822   SerializeObject(message, &serialized_message_, &serialized_message_len_, | 
| 2858                   &serialized_message_, |  | 
| 2859                   &serialized_message_len_, |  | 
| 2860                   can_send_any_object); | 2823                   can_send_any_object); | 
| 2861   // By default inherit flags from spawning isolate. These can be overridden | 2824   // By default inherit flags from spawning isolate. These can be overridden | 
| 2862   // from the calling code. | 2825   // from the calling code. | 
| 2863   Isolate::Current()->FlagsCopyTo(isolate_flags()); | 2826   Isolate::Current()->FlagsCopyTo(isolate_flags()); | 
| 2864 } | 2827 } | 
| 2865 | 2828 | 
| 2866 | 2829 | 
| 2867 IsolateSpawnState::~IsolateSpawnState() { | 2830 IsolateSpawnState::~IsolateSpawnState() { | 
| 2868   delete[] script_url_; | 2831   delete[] script_url_; | 
| 2869   delete[] package_root_; | 2832   delete[] package_root_; | 
| 2870   delete[] package_config_; | 2833   delete[] package_config_; | 
| 2871   delete[] library_url_; | 2834   delete[] library_url_; | 
| 2872   delete[] class_name_; | 2835   delete[] class_name_; | 
| 2873   delete[] function_name_; | 2836   delete[] function_name_; | 
| 2874   free(serialized_args_); | 2837   free(serialized_args_); | 
| 2875   free(serialized_message_); | 2838   free(serialized_message_); | 
| 2876 } | 2839 } | 
| 2877 | 2840 | 
| 2878 | 2841 | 
| 2879 RawObject* IsolateSpawnState::ResolveFunction() { | 2842 RawObject* IsolateSpawnState::ResolveFunction() { | 
| 2880   Thread* thread = Thread::Current(); | 2843   Thread* thread = Thread::Current(); | 
| 2881   Zone* zone = thread->zone(); | 2844   Zone* zone = thread->zone(); | 
| 2882 | 2845 | 
| 2883   const String& func_name = String::Handle(zone, String::New(function_name())); | 2846   const String& func_name = String::Handle(zone, String::New(function_name())); | 
| 2884 | 2847 | 
| 2885   if (library_url() == NULL) { | 2848   if (library_url() == NULL) { | 
| 2886     // Handle spawnUri lookup rules. | 2849     // Handle spawnUri lookup rules. | 
| 2887     // Check whether the root library defines a main function. | 2850     // Check whether the root library defines a main function. | 
| 2888     const Library& lib = Library::Handle(zone, | 2851     const Library& lib = | 
| 2889                                          I->object_store()->root_library()); | 2852         Library::Handle(zone, I->object_store()->root_library()); | 
| 2890     Function& func = Function::Handle(zone, lib.LookupLocalFunction(func_name)); | 2853     Function& func = Function::Handle(zone, lib.LookupLocalFunction(func_name)); | 
| 2891     if (func.IsNull()) { | 2854     if (func.IsNull()) { | 
| 2892       // Check whether main is reexported from the root library. | 2855       // Check whether main is reexported from the root library. | 
| 2893       const Object& obj = Object::Handle(zone, lib.LookupReExport(func_name)); | 2856       const Object& obj = Object::Handle(zone, lib.LookupReExport(func_name)); | 
| 2894       if (obj.IsFunction()) { | 2857       if (obj.IsFunction()) { | 
| 2895         func ^= obj.raw(); | 2858         func ^= obj.raw(); | 
| 2896       } | 2859       } | 
| 2897     } | 2860     } | 
| 2898     if (func.IsNull()) { | 2861     if (func.IsNull()) { | 
| 2899       const String& msg = String::Handle(zone, String::NewFormatted( | 2862       const String& msg = String::Handle( | 
| 2900           "Unable to resolve function '%s' in script '%s'.", | 2863           zone, String::NewFormatted( | 
| 2901           function_name(), script_url())); | 2864                     "Unable to resolve function '%s' in script '%s'.", | 
|  | 2865                     function_name(), script_url())); | 
| 2902       return LanguageError::New(msg); | 2866       return LanguageError::New(msg); | 
| 2903     } | 2867     } | 
| 2904     return func.raw(); | 2868     return func.raw(); | 
| 2905   } | 2869   } | 
| 2906 | 2870 | 
| 2907   // Lookup the to be spawned function for the Isolate.spawn implementation. | 2871   // Lookup the to be spawned function for the Isolate.spawn implementation. | 
| 2908   // Resolve the library. | 2872   // Resolve the library. | 
| 2909   const String& lib_url = String::Handle(zone, String::New(library_url())); | 2873   const String& lib_url = String::Handle(zone, String::New(library_url())); | 
| 2910   const Library& lib = Library::Handle(zone, | 2874   const Library& lib = | 
| 2911                                        Library::LookupLibrary(thread, lib_url)); | 2875       Library::Handle(zone, Library::LookupLibrary(thread, lib_url)); | 
| 2912   if (lib.IsNull() || lib.IsError()) { | 2876   if (lib.IsNull() || lib.IsError()) { | 
| 2913     const String& msg = String::Handle(zone, String::NewFormatted( | 2877     const String& msg = String::Handle( | 
| 2914         "Unable to find library '%s'.", library_url())); | 2878         zone, | 
|  | 2879         String::NewFormatted("Unable to find library '%s'.", library_url())); | 
| 2915     return LanguageError::New(msg); | 2880     return LanguageError::New(msg); | 
| 2916   } | 2881   } | 
| 2917 | 2882 | 
| 2918   // Resolve the function. | 2883   // Resolve the function. | 
| 2919   if (class_name() == NULL) { | 2884   if (class_name() == NULL) { | 
| 2920     const Function& func = Function::Handle(zone, | 2885     const Function& func = | 
| 2921                                             lib.LookupLocalFunction(func_name)); | 2886         Function::Handle(zone, lib.LookupLocalFunction(func_name)); | 
| 2922     if (func.IsNull()) { | 2887     if (func.IsNull()) { | 
| 2923       const String& msg = String::Handle(zone, String::NewFormatted( | 2888       const String& msg = String::Handle( | 
| 2924           "Unable to resolve function '%s' in library '%s'.", | 2889           zone, String::NewFormatted( | 
| 2925           function_name(), library_url())); | 2890                     "Unable to resolve function '%s' in library '%s'.", | 
|  | 2891                     function_name(), library_url())); | 
| 2926       return LanguageError::New(msg); | 2892       return LanguageError::New(msg); | 
| 2927     } | 2893     } | 
| 2928     return func.raw(); | 2894     return func.raw(); | 
| 2929   } | 2895   } | 
| 2930 | 2896 | 
| 2931   const String& cls_name = String::Handle(zone, String::New(class_name())); | 2897   const String& cls_name = String::Handle(zone, String::New(class_name())); | 
| 2932   const Class& cls = Class::Handle(zone, lib.LookupLocalClass(cls_name)); | 2898   const Class& cls = Class::Handle(zone, lib.LookupLocalClass(cls_name)); | 
| 2933   if (cls.IsNull()) { | 2899   if (cls.IsNull()) { | 
| 2934     const String& msg = String::Handle(zone, String::NewFormatted( | 2900     const String& msg = String::Handle( | 
| 2935           "Unable to resolve class '%s' in library '%s'.", | 2901         zone, String::NewFormatted( | 
| 2936           class_name(), | 2902                   "Unable to resolve class '%s' in library '%s'.", class_name(), | 
| 2937           (library_url() != NULL ? library_url() : script_url()))); | 2903                   (library_url() != NULL ? library_url() : script_url()))); | 
| 2938     return LanguageError::New(msg); | 2904     return LanguageError::New(msg); | 
| 2939   } | 2905   } | 
| 2940   const Function& func = | 2906   const Function& func = | 
| 2941       Function::Handle(zone, cls.LookupStaticFunctionAllowPrivate(func_name)); | 2907       Function::Handle(zone, cls.LookupStaticFunctionAllowPrivate(func_name)); | 
| 2942   if (func.IsNull()) { | 2908   if (func.IsNull()) { | 
| 2943     const String& msg = String::Handle(zone, String::NewFormatted( | 2909     const String& msg = String::Handle( | 
| 2944           "Unable to resolve static method '%s.%s' in library '%s'.", | 2910         zone, String::NewFormatted( | 
| 2945           class_name(), function_name(), | 2911                   "Unable to resolve static method '%s.%s' in library '%s'.", | 
| 2946           (library_url() != NULL ? library_url() : script_url()))); | 2912                   class_name(), function_name(), | 
|  | 2913                   (library_url() != NULL ? library_url() : script_url()))); | 
| 2947     return LanguageError::New(msg); | 2914     return LanguageError::New(msg); | 
| 2948   } | 2915   } | 
| 2949   return func.raw(); | 2916   return func.raw(); | 
| 2950 } | 2917 } | 
| 2951 | 2918 | 
| 2952 | 2919 | 
| 2953 RawInstance* IsolateSpawnState::BuildArgs(Thread* thread) { | 2920 RawInstance* IsolateSpawnState::BuildArgs(Thread* thread) { | 
| 2954   return DeserializeObject(thread, serialized_args_, serialized_args_len_); | 2921   return DeserializeObject(thread, serialized_args_, serialized_args_len_); | 
| 2955 } | 2922 } | 
| 2956 | 2923 | 
| 2957 | 2924 | 
| 2958 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) { | 2925 RawInstance* IsolateSpawnState::BuildMessage(Thread* thread) { | 
| 2959   return DeserializeObject(thread, | 2926   return DeserializeObject(thread, serialized_message_, | 
| 2960                            serialized_message_, serialized_message_len_); | 2927                            serialized_message_len_); | 
| 2961 } | 2928 } | 
| 2962 | 2929 | 
| 2963 | 2930 | 
| 2964 void IsolateSpawnState::DecrementSpawnCount() { | 2931 void IsolateSpawnState::DecrementSpawnCount() { | 
| 2965   ASSERT(spawn_count_monitor_ != NULL); | 2932   ASSERT(spawn_count_monitor_ != NULL); | 
| 2966   ASSERT(spawn_count_ != NULL); | 2933   ASSERT(spawn_count_ != NULL); | 
| 2967   MonitorLocker ml(spawn_count_monitor_); | 2934   MonitorLocker ml(spawn_count_monitor_); | 
| 2968   ASSERT(*spawn_count_ > 0); | 2935   ASSERT(*spawn_count_ > 0); | 
| 2969   *spawn_count_ = *spawn_count_ - 1; | 2936   *spawn_count_ = *spawn_count_ - 1; | 
| 2970   ml.Notify(); | 2937   ml.Notify(); | 
| 2971 } | 2938 } | 
| 2972 | 2939 | 
| 2973 }  // namespace dart | 2940 }  // namespace dart | 
| OLD | NEW | 
|---|