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

Side by Side Diff: lib/isolate.cc

Issue 8673002: - Refactor the isolate callback mechanism to also include creation of the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/dart_api.h ('k') | vm/bootstrap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) { 255 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) {
256 Isolate* preserved_isolate = Isolate::Current(); 256 Isolate* preserved_isolate = Isolate::Current();
257 const Instance& runnable = Instance::CheckedHandle(arguments->At(0)); 257 const Instance& runnable = Instance::CheckedHandle(arguments->At(0));
258 const Class& runnable_class = Class::Handle(runnable.clazz()); 258 const Class& runnable_class = Class::Handle(runnable.clazz());
259 const char* class_name = String::Handle(runnable_class.Name()).ToCString(); 259 const char* class_name = String::Handle(runnable_class.Name()).ToCString();
260 const Library& library = Library::Handle(runnable_class.library()); 260 const Library& library = Library::Handle(runnable_class.library());
261 ASSERT(!library.IsNull()); 261 ASSERT(!library.IsNull());
262 const char* library_url = String::Handle(library.url()).ToCString(); 262 const char* library_url = String::Handle(library.url()).ToCString();
263 intptr_t port_id = 0; 263 intptr_t port_id = 0;
264 const char* error_msg = NULL;
265 LongJump jump; 264 LongJump jump;
266 bool init_successful = true; 265 bool init_successful = true;
267 266 Isolate* spawned_isolate = NULL;
268 Isolate* spawned_isolate = Dart::CreateIsolate(); 267 void* callback_data = preserved_isolate->init_callback_data();
269 if (spawned_isolate != NULL) { 268 char* error = NULL;
270 // First initialize the spawned isolate. 269 Dart_IsolateCreateCallback callback = Isolate::CreateCallback();
271 LongJump* base = spawned_isolate->long_jump_base(); 270 if (callback == NULL) {
272 spawned_isolate->set_long_jump_base(&jump); 271 error = strdup("Null callback specified for isolate creation\n");
273 if (setjmp(*jump.Set()) == 0) { 272 } else if (callback(callback_data, &error)) {
274 Dart::InitializeIsolate(NULL, preserved_isolate->init_callback_data()); 273 spawned_isolate = Isolate::Current();
275 } else { 274 ASSERT(spawned_isolate != NULL);
276 init_successful = false;
277 }
278 spawned_isolate->set_long_jump_base(base);
279 // Check arguments to see if the specified library and classes are 275 // Check arguments to see if the specified library and classes are
280 // 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.
281 if (init_successful && CheckArguments(library_url, class_name)) { 277 if (init_successful && CheckArguments(library_url, class_name)) {
282 port_id = spawned_isolate->main_port(); 278 port_id = spawned_isolate->main_port();
283 uword data = reinterpret_cast<uword>( 279 uword data = reinterpret_cast<uword>(
284 new IsolateStartData(spawned_isolate, 280 new IsolateStartData(spawned_isolate,
285 strdup(library_url), 281 strdup(library_url),
286 strdup(class_name), 282 strdup(class_name),
287 port_id)); 283 port_id));
288 new Thread(RunIsolate, data); 284 new Thread(RunIsolate, data);
289 } else { 285 } else {
290 // Error spawning the isolate, maybe due to initialization errors or 286 // Error spawning the isolate, maybe due to initialization errors or
291 // errors while loading the application into spawned isolate, shut 287 // errors while loading the application into spawned isolate, shut
292 // it down and report error. 288 // it down and report error.
293 // 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
294 // been shutdown and to allocate it in the preserved isolates zone. 290 // been shutdown and to allocate it in the preserved isolates zone.
295 { 291 {
296 Zone zone(spawned_isolate); 292 Zone zone(spawned_isolate);
297 HandleScope scope(spawned_isolate); 293 HandleScope scope(spawned_isolate);
298 const String& error = String::Handle( 294 const String& errmsg = String::Handle(
299 spawned_isolate->object_store()->sticky_error()); 295 spawned_isolate->object_store()->sticky_error());
300 const char* temp_error_msg = error.ToCString(); 296 error = strdup(errmsg.ToCString());
301 intptr_t err_len = strlen(temp_error_msg) + 1;
302 Zone* preserved_zone = preserved_isolate->current_zone();
303 error_msg = reinterpret_cast<char*>(preserved_zone->Allocate(err_len));
304 OS::SNPrint(
305 const_cast<char*>(error_msg), err_len, "%s", temp_error_msg);
306 } 297 }
307 Dart::ShutdownIsolate(); 298 Dart::ShutdownIsolate();
308 spawned_isolate = NULL; 299 spawned_isolate = NULL;
309 } 300 }
310 } else {
311 error_msg = "Creation of Isolate failed : ";
312 } 301 }
313 302
314 // Switch back to the original isolate and return. 303 // Switch back to the original isolate and return.
315 Isolate::SetCurrent(preserved_isolate); 304 Isolate::SetCurrent(preserved_isolate);
316 if (spawned_isolate == NULL) { 305 if (spawned_isolate == NULL) {
317 // Unable to spawn isolate correctly, throw exception. 306 // Unable to spawn isolate correctly, throw exception.
318 ASSERT(error_msg != NULL);
319 ThrowErrorException(Exceptions::kIllegalArgument, 307 ThrowErrorException(Exceptions::kIllegalArgument,
320 error_msg, 308 error,
321 library_url, 309 library_url,
322 class_name); 310 class_name);
323 } 311 }
324 const Instance& port = Instance::Handle(SendPortCreate(port_id)); 312 const Instance& port = Instance::Handle(SendPortCreate(port_id));
325 if (port.IsUnhandledException()) { 313 if (port.IsUnhandledException()) {
326 ThrowErrorException(Exceptions::kInternalError, 314 ThrowErrorException(Exceptions::kInternalError,
327 "Unable to create send port to isolate", 315 "Unable to create send port to isolate",
328 library_url, 316 library_url,
329 class_name); 317 class_name);
330 } 318 }
(...skipping 19 matching lines...) Expand all
350 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); 338 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value();
351 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); 339 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value();
352 // TODO(iposva): Allow for arbitrary messages to be sent. 340 // TODO(iposva): Allow for arbitrary messages to be sent.
353 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); 341 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2)));
354 342
355 // TODO(turnidge): Throw an exception when the return value is false? 343 // TODO(turnidge): Throw an exception when the return value is false?
356 PortMap::PostMessage(send_id, reply_id, data); 344 PortMap::PostMessage(send_id, reply_id, data);
357 } 345 }
358 346
359 } // namespace dart 347 } // namespace dart
OLDNEW
« no previous file with comments | « include/dart_api.h ('k') | vm/bootstrap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698