| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 249 |
| 250 | 250 |
| 251 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) { | 251 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) { |
| 252 Isolate* preserved_isolate = Isolate::Current(); | 252 Isolate* preserved_isolate = Isolate::Current(); |
| 253 const Instance& runnable = Instance::CheckedHandle(arguments->At(0)); | 253 const Instance& runnable = Instance::CheckedHandle(arguments->At(0)); |
| 254 const Class& runnable_class = Class::Handle(runnable.clazz()); | 254 const Class& runnable_class = Class::Handle(runnable.clazz()); |
| 255 const char* class_name = String::Handle(runnable_class.Name()).ToCString(); | 255 const char* class_name = String::Handle(runnable_class.Name()).ToCString(); |
| 256 const Library& library = Library::Handle(runnable_class.library()); | 256 const Library& library = Library::Handle(runnable_class.library()); |
| 257 ASSERT(!library.IsNull()); | 257 ASSERT(!library.IsNull()); |
| 258 const char* library_url = String::Handle(library.url()).ToCString(); | 258 const char* library_url = String::Handle(library.url()).ToCString(); |
| 259 | |
| 260 intptr_t port_id = 0; | 259 intptr_t port_id = 0; |
| 261 const char* error_msg = NULL; | 260 const char* error_msg = NULL; |
| 261 LongJump jump; |
| 262 bool init_successful = true; |
| 262 | 263 |
| 263 Isolate* spawned_isolate = | 264 Isolate* spawned_isolate = Dart::CreateIsolate(); |
| 264 Dart::CreateIsolate(NULL, preserved_isolate->init_callback_data()); | |
| 265 if (spawned_isolate != NULL) { | 265 if (spawned_isolate != NULL) { |
| 266 // First initialize the spawned isolate. |
| 267 LongJump* base = spawned_isolate->long_jump_base(); |
| 268 spawned_isolate->set_long_jump_base(&jump); |
| 269 if (setjmp(*jump.Set()) == 0) { |
| 270 Dart::InitializeIsolate(NULL, preserved_isolate->init_callback_data()); |
| 271 } else { |
| 272 init_successful = false; |
| 273 } |
| 274 spawned_isolate->set_long_jump_base(base); |
| 266 // Check arguments to see if the specified library and classes are | 275 // Check arguments to see if the specified library and classes are |
| 267 // loaded, this check will throw an exception if they are not loaded. | 276 // loaded, this check will throw an exception if they are not loaded. |
| 268 if (CheckArguments(library_url, class_name)) { | 277 if (init_successful && CheckArguments(library_url, class_name)) { |
| 269 port_id = PortMap::CreatePort(); | 278 port_id = PortMap::CreatePort(); |
| 270 uword data = reinterpret_cast<uword>( | 279 uword data = reinterpret_cast<uword>( |
| 271 new IsolateStartData(spawned_isolate, | 280 new IsolateStartData(spawned_isolate, |
| 272 strdup(library_url), | 281 strdup(library_url), |
| 273 strdup(class_name), | 282 strdup(class_name), |
| 274 port_id)); | 283 port_id)); |
| 275 new Thread(RunIsolate, data); | 284 new Thread(RunIsolate, data); |
| 276 } else { | 285 } else { |
| 277 // Error loading application into spawned isolate, shut it down and | 286 // Error spawning the isolate, maybe due to initialization errors or |
| 278 // report error. | 287 // errors while loading the application into spawned isolate, shut |
| 288 // it down and report error. |
| 279 // Make sure to grab the error message out of the isolate before it has | 289 // Make sure to grab the error message out of the isolate before it has |
| 280 // been shutdown and to allocate it in the preserved isolates zone. | 290 // been shutdown and to allocate it in the preserved isolates zone. |
| 281 { | 291 { |
| 282 Zone zone; | 292 Zone zone; |
| 283 HandleScope scope; | 293 HandleScope scope; |
| 284 const String& error = String::Handle( | 294 const String& error = String::Handle( |
| 285 spawned_isolate->object_store()->sticky_error()); | 295 spawned_isolate->object_store()->sticky_error()); |
| 286 const char* temp_error_msg = error.ToCString(); | 296 const char* temp_error_msg = error.ToCString(); |
| 287 intptr_t err_len = strlen(temp_error_msg) + 1; | 297 intptr_t err_len = strlen(temp_error_msg) + 1; |
| 288 Zone* preserved_zone = preserved_isolate->current_zone(); | 298 Zone* preserved_zone = preserved_isolate->current_zone(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); | 346 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); |
| 337 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); | 347 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); |
| 338 // TODO(iposva): Allow for arbitrary messages to be sent. | 348 // TODO(iposva): Allow for arbitrary messages to be sent. |
| 339 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); | 349 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); |
| 340 | 350 |
| 341 // TODO(turnidge): Throw an exception when the return value is false? | 351 // TODO(turnidge): Throw an exception when the return value is false? |
| 342 PortMap::PostMessage(send_id, reply_id, data); | 352 PortMap::PostMessage(send_id, reply_id, data); |
| 343 } | 353 } |
| 344 | 354 |
| 345 } // namespace dart | 355 } // namespace dart |
| OLD | NEW |