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

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

Powered by Google App Engine
This is Rietveld 408576698