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

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
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 251
252 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) { 252 DEFINE_NATIVE_ENTRY(IsolateNatives_start, 2) {
253 Isolate* preserved_isolate = Isolate::Current(); 253 Isolate* preserved_isolate = Isolate::Current();
254 const Instance& runnable = Instance::CheckedHandle(arguments->At(0)); 254 const Instance& runnable = Instance::CheckedHandle(arguments->At(0));
255 const Class& runnable_class = Class::Handle(runnable.clazz()); 255 const Class& runnable_class = Class::Handle(runnable.clazz());
256 const char* class_name = String::Handle(runnable_class.Name()).ToCString(); 256 const char* class_name = String::Handle(runnable_class.Name()).ToCString();
257 const Library& library = Library::Handle(runnable_class.library()); 257 const Library& library = Library::Handle(runnable_class.library());
258 ASSERT(!library.IsNull()); 258 ASSERT(!library.IsNull());
259 const char* library_url = String::Handle(library.url()).ToCString(); 259 const char* library_url = String::Handle(library.url()).ToCString();
260 intptr_t port_id = 0; 260 intptr_t port_id = 0;
261 const char* error_msg = NULL; 261 static const int kEMsgLength = 256;
262 LongJump jump; 262 LongJump jump;
263 bool init_successful = true; 263 bool init_successful = true;
264 Isolate* spawned_isolate = NULL;
265 Zone* preserved_zone = preserved_isolate->current_zone();
266 void* callback_data = preserved_isolate->init_callback_data();
267 Dart_ErrorBuffer error;
268 error.buffer = reinterpret_cast<char*>(preserved_zone->Allocate(kEMsgLength));
269 error.length = kEMsgLength;
264 270
265 Isolate* spawned_isolate = Dart::CreateIsolate(); 271 if ((Isolate::CreateCallback())(callback_data, error)) {
266 if (spawned_isolate != NULL) { 272 spawned_isolate = Isolate::Current();
267 // First initialize the spawned isolate. 273 ASSERT(spawned_isolate != NULL);
268 LongJump* base = spawned_isolate->long_jump_base();
269 spawned_isolate->set_long_jump_base(&jump);
270 if (setjmp(*jump.Set()) == 0) {
271 Dart::InitializeIsolate(NULL, preserved_isolate->init_callback_data());
272 } else {
273 init_successful = false;
274 }
275 spawned_isolate->set_long_jump_base(base);
276 // Check arguments to see if the specified library and classes are 274 // Check arguments to see if the specified library and classes are
277 // loaded, this check will throw an exception if they are not loaded. 275 // loaded, this check will throw an exception if they are not loaded.
278 if (init_successful && CheckArguments(library_url, class_name)) { 276 if (init_successful && CheckArguments(library_url, class_name)) {
279 port_id = PortMap::CreatePort(); 277 port_id = PortMap::CreatePort();
280 uword data = reinterpret_cast<uword>( 278 uword data = reinterpret_cast<uword>(
281 new IsolateStartData(spawned_isolate, 279 new IsolateStartData(spawned_isolate,
282 strdup(library_url), 280 strdup(library_url),
283 strdup(class_name), 281 strdup(class_name),
284 port_id)); 282 port_id));
285 new Thread(RunIsolate, data); 283 new Thread(RunIsolate, data);
286 } else { 284 } else {
287 // Error spawning the isolate, maybe due to initialization errors or 285 // Error spawning the isolate, maybe due to initialization errors or
288 // errors while loading the application into spawned isolate, shut 286 // errors while loading the application into spawned isolate, shut
289 // it down and report error. 287 // it down and report error.
290 // Make sure to grab the error message out of the isolate before it has 288 // Make sure to grab the error message out of the isolate before it has
291 // been shutdown and to allocate it in the preserved isolates zone. 289 // been shutdown and to allocate it in the preserved isolates zone.
292 { 290 {
293 Zone zone(spawned_isolate); 291 Zone zone(spawned_isolate);
294 HandleScope scope(spawned_isolate); 292 HandleScope scope(spawned_isolate);
295 const String& error = String::Handle( 293 const String& errmsg = String::Handle(
296 spawned_isolate->object_store()->sticky_error()); 294 spawned_isolate->object_store()->sticky_error());
297 const char* temp_error_msg = error.ToCString(); 295 OS::SNPrint(const_cast<char*>(error.buffer),
298 intptr_t err_len = strlen(temp_error_msg) + 1; 296 kEMsgLength, "%s", errmsg.ToCString());
299 Zone* preserved_zone = preserved_isolate->current_zone();
300 error_msg = reinterpret_cast<char*>(preserved_zone->Allocate(err_len));
301 OS::SNPrint(
302 const_cast<char*>(error_msg), err_len, "%s", temp_error_msg);
303 } 297 }
304 Dart::ShutdownIsolate(); 298 Dart::ShutdownIsolate();
305 spawned_isolate = NULL; 299 spawned_isolate = NULL;
306 } 300 }
307 } else {
308 error_msg = "Creation of Isolate failed : ";
309 } 301 }
310 302
311 // Switch back to the original isolate and return. 303 // Switch back to the original isolate and return.
312 Isolate::SetCurrent(preserved_isolate); 304 Isolate::SetCurrent(preserved_isolate);
313 if (spawned_isolate == NULL) { 305 if (spawned_isolate == NULL) {
314 // Unable to spawn isolate correctly, throw exception. 306 // Unable to spawn isolate correctly, throw exception.
315 ASSERT(error_msg != NULL);
316 ThrowErrorException(Exceptions::kIllegalArgument, 307 ThrowErrorException(Exceptions::kIllegalArgument,
317 error_msg, 308 error.buffer,
318 library_url, 309 library_url,
319 class_name); 310 class_name);
320 } 311 }
321 const Instance& port = Instance::Handle(SendPortCreate(port_id)); 312 const Instance& port = Instance::Handle(SendPortCreate(port_id));
322 if (port.IsUnhandledException()) { 313 if (port.IsUnhandledException()) {
323 ThrowErrorException(Exceptions::kInternalError, 314 ThrowErrorException(Exceptions::kInternalError,
324 "Unable to create send port to isolate", 315 "Unable to create send port to isolate",
325 library_url, 316 library_url,
326 class_name); 317 class_name);
327 } 318 }
(...skipping 19 matching lines...) Expand all
347 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); 338 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value();
348 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); 339 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value();
349 // TODO(iposva): Allow for arbitrary messages to be sent. 340 // TODO(iposva): Allow for arbitrary messages to be sent.
350 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); 341 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2)));
351 342
352 // TODO(turnidge): Throw an exception when the return value is false? 343 // TODO(turnidge): Throw an exception when the return value is false?
353 PortMap::PostMessage(send_id, reply_id, data); 344 PortMap::PostMessage(send_id, reply_id, data);
354 } 345 }
355 346
356 } // namespace dart 347 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698