Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/assert.h" | 7 #include "vm/assert.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 class_name_(class_name), | 30 class_name_(class_name), |
| 31 port_id_(port_id) {} | 31 port_id_(port_id) {} |
| 32 | 32 |
| 33 Isolate* isolate_; | 33 Isolate* isolate_; |
| 34 char* library_url_; | 34 char* library_url_; |
| 35 char* class_name_; | 35 char* class_name_; |
| 36 intptr_t port_id_; | 36 intptr_t port_id_; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 | 39 |
| 40 static RawInstance* DeserializeMessage(void* data) { | |
| 41 // Create a snapshot object using the buffer. | |
| 42 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | |
| 43 ASSERT(snapshot->IsPartialSnapshot()); | |
| 44 | |
| 45 // Read object back from the snapshot. | |
| 46 Isolate* isolate= Isolate::Current(); | |
| 47 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store()); | |
| 48 Instance& instance = Instance::Handle(); | |
| 49 instance ^= reader.ReadObject(); | |
| 50 return instance.raw(); | |
| 51 } | |
| 52 | |
| 53 | |
| 54 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 40 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 55 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 41 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 56 return reinterpret_cast<uint8_t*>(new_ptr); | 42 return reinterpret_cast<uint8_t*>(new_ptr); |
| 57 } | 43 } |
| 58 | 44 |
| 59 | 45 |
| 60 static void* SerializeObject(const Instance& obj) { | 46 static void* SerializeObject(const Instance& obj) { |
| 61 uint8_t* result = NULL; | 47 uint8_t* result = NULL; |
| 62 SnapshotWriter writer(false, &result, &allocator); | 48 SnapshotWriter writer(false, &result, &allocator); |
| 63 writer.WriteObject(obj.raw()); | 49 writer.WriteObject(obj.raw()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 kNoArgumentNames, | 123 kNoArgumentNames, |
| 138 Resolver::kIsQualified)); | 124 Resolver::kIsQualified)); |
| 139 GrowableArray<const Object*> arguments(kNumArguments); | 125 GrowableArray<const Object*> arguments(kNumArguments); |
| 140 arguments.Add(&Integer::Handle(Integer::New(port_id))); | 126 arguments.Add(&Integer::Handle(Integer::New(port_id))); |
| 141 const Instance& result = Instance::Handle( | 127 const Instance& result = Instance::Handle( |
| 142 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 128 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
| 143 return result.raw(); | 129 return result.raw(); |
| 144 } | 130 } |
| 145 | 131 |
| 146 | 132 |
| 147 void PortMessage::Handle() { | |
| 148 const Instance& msg = Instance::Handle(DeserializeMessage(data())); | |
| 149 const String& class_name = | |
| 150 String::Handle(String::NewSymbol("ReceivePortImpl")); | |
| 151 const String& function_name = | |
| 152 String::Handle(String::NewSymbol("handleMessage_")); | |
| 153 const int kNumArguments = 3; | |
| 154 const Array& kNoArgumentNames = Array::Handle(); | |
| 155 const Function& function = Function::Handle( | |
| 156 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), | |
| 157 class_name, | |
| 158 function_name, | |
| 159 kNumArguments, | |
| 160 kNoArgumentNames, | |
| 161 Resolver::kIsQualified)); | |
| 162 GrowableArray<const Object*> arguments(kNumArguments); | |
| 163 arguments.Add(&Integer::Handle(Integer::New(dest_id()))); | |
| 164 arguments.Add(&Integer::Handle(Integer::New(reply_id()))); | |
| 165 arguments.Add(&msg); | |
| 166 const Object& result = Object::Handle( | |
| 167 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | |
| 168 if (result.IsUnhandledException()) { | |
| 169 UnhandledException& uhe = UnhandledException::Handle(); | |
| 170 uhe ^= result.raw(); | |
| 171 ProcessUnhandledException(uhe); | |
| 172 } | |
| 173 ASSERT(result.IsNull()); | |
| 174 } | |
| 175 | |
| 176 | |
| 177 static void RunIsolate(uword parameter) { | 133 static void RunIsolate(uword parameter) { |
| 178 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter); | 134 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter); |
| 179 Isolate* isolate = data->isolate_; | 135 Isolate* isolate = data->isolate_; |
| 180 char* library_url = data->library_url_; | 136 char* library_url = data->library_url_; |
| 181 char* class_name = data->class_name_; | 137 char* class_name = data->class_name_; |
| 182 intptr_t port_id = data->port_id_; | 138 intptr_t port_id = data->port_id_; |
| 183 delete data; | 139 delete data; |
| 184 | 140 |
| 185 Isolate::SetCurrent(isolate); | 141 Isolate::SetCurrent(isolate); |
| 186 // Intialize stack limit in case we are running isolate in a | 142 // Intialize stack limit in case we are running isolate in a |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 arguments, | 196 arguments, |
| 241 kNoArgumentNames); | 197 kNoArgumentNames); |
| 242 if (result.IsUnhandledException()) { | 198 if (result.IsUnhandledException()) { |
| 243 UnhandledException& uhe = UnhandledException::Handle(); | 199 UnhandledException& uhe = UnhandledException::Handle(); |
| 244 uhe ^= result.raw(); | 200 uhe ^= result.raw(); |
| 245 ProcessUnhandledException(uhe); | 201 ProcessUnhandledException(uhe); |
| 246 } | 202 } |
| 247 ASSERT(result.IsNull()); | 203 ASSERT(result.IsNull()); |
| 248 free(class_name); | 204 free(class_name); |
| 249 | 205 |
| 250 // Keep listening until there are no active receive ports. | 206 // Keep listening until there are no active receive ports. |
|
Anton Muhin
2011/10/18 17:19:58
nit: this comment can probably go away now.
turnidge
2011/10/18 17:33:40
Done.
| |
| 251 while (isolate->active_ports() > 0) { | 207 isolate->StandardRunLoop(); |
| 252 Zone zone; | |
| 253 HandleScope handle_scope; | |
| 254 | 208 |
| 255 PortMessage* message = PortMap::ReceiveMessage(0); | |
| 256 message->Handle(); | |
| 257 delete message; | |
| 258 } | |
| 259 } else { | 209 } else { |
| 260 Zone zone; | 210 Zone zone; |
| 261 HandleScope handle_scope; | 211 HandleScope handle_scope; |
| 262 const String& error = String::Handle( | 212 const String& error = String::Handle( |
| 263 Isolate::Current()->object_store()->sticky_error()); | 213 Isolate::Current()->object_store()->sticky_error()); |
| 264 const char* errmsg = error.ToCString(); | 214 const char* errmsg = error.ToCString(); |
| 265 fprintf(stderr, "%s\n", errmsg); | 215 fprintf(stderr, "%s\n", errmsg); |
| 266 exit(255); | 216 exit(255); |
| 267 } | 217 } |
| 268 isolate->set_long_jump_base(base); | 218 isolate->set_long_jump_base(base); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 PortMap::ClosePort(id); | 332 PortMap::ClosePort(id); |
| 383 } | 333 } |
| 384 | 334 |
| 385 | 335 |
| 386 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { | 336 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { |
| 387 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); | 337 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); |
| 388 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); | 338 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); |
| 389 // TODO(iposva): Allow for arbitrary messages to be sent. | 339 // TODO(iposva): Allow for arbitrary messages to be sent. |
| 390 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); | 340 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); |
| 391 | 341 |
| 392 PortMessage* message = new PortMessage(send_id, reply_id, data); | 342 // TODO(turnidge): Throw an exception when the return value is false? |
| 393 PortMap::PostMessage(message); | 343 PortMap::PostMessage(send_id, reply_id, data); |
| 394 } | 344 } |
| 395 | 345 |
| 396 } // namespace dart | 346 } // namespace dart |
| OLD | NEW |