Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "include/dart_native_api.h" | 5 #include "include/dart_native_api.h" |
| 6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.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_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| 11 #include "vm/dart_entry.h" | 11 #include "vm/dart_entry.h" |
| 12 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
| 13 #include "vm/lockers.h" | 13 #include "vm/lockers.h" |
| 14 #include "vm/longjump.h" | 14 #include "vm/longjump.h" |
| 15 #include "vm/message_handler.h" | 15 #include "vm/message_handler.h" |
| 16 #include "vm/object.h" | 16 #include "vm/object.h" |
| 17 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
| 18 #include "vm/port.h" | 18 #include "vm/port.h" |
| 19 #include "vm/resolver.h" | 19 #include "vm/resolver.h" |
| 20 #include "vm/service.h" | 20 #include "vm/service.h" |
| 21 #include "vm/snapshot.h" | 21 #include "vm/snapshot.h" |
| 22 #include "vm/symbols.h" | 22 #include "vm/symbols.h" |
| 23 #include "vm/unicode.h" | 23 #include "vm/unicode.h" |
| 24 | 24 |
| 25 namespace dart { | 25 namespace dart { |
| 26 | 26 |
| 27 DEFINE_FLAG(bool, i_like_slow_isolate_spawn, false, | |
| 28 "Block the parent thread when loading spawned isolates."); | |
| 29 | |
| 27 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 30 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 28 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 31 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 29 return reinterpret_cast<uint8_t*>(new_ptr); | 32 return reinterpret_cast<uint8_t*>(new_ptr); |
| 30 } | 33 } |
| 31 | 34 |
| 32 | 35 |
| 33 DEFINE_NATIVE_ENTRY(CapabilityImpl_factory, 1) { | 36 DEFINE_NATIVE_ENTRY(CapabilityImpl_factory, 1) { |
| 34 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); | 37 ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull()); |
| 35 uint64_t id = isolate->random()->NextUInt64(); | 38 uint64_t id = isolate->random()->NextUInt64(); |
| 36 return Capability::New(id); | 39 return Capability::New(id); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 ctx = Closure::context(closure); | 213 ctx = Closure::context(closure); |
| 211 ASSERT(ctx.num_variables() == 0); | 214 ASSERT(ctx.num_variables() == 0); |
| 212 #endif | 215 #endif |
| 213 // Get the parent function so that we get the right function name. | 216 // Get the parent function so that we get the right function name. |
| 214 func = func.parent_function(); | 217 func = func.parent_function(); |
| 215 | 218 |
| 216 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value(); | 219 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value(); |
| 217 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id(); | 220 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id(); |
| 218 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id(); | 221 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id(); |
| 219 | 222 |
| 220 Dart::thread_pool()->Run(new SpawnIsolateTask( | 223 ThreadPool::Task* spawn_task = |
| 221 new IsolateSpawnState(port.Id(), | 224 new SpawnIsolateTask( |
| 222 isolate->origin_id(), | 225 new IsolateSpawnState(port.Id(), |
| 223 isolate->init_callback_data(), | 226 isolate->origin_id(), |
| 224 func, | 227 isolate->init_callback_data(), |
| 225 message, | 228 func, |
| 226 paused.value(), | 229 message, |
| 227 fatal_errors, | 230 paused.value(), |
| 228 on_exit_port, | 231 fatal_errors, |
| 229 on_error_port))); | 232 on_exit_port, |
| 233 on_error_port)); | |
| 234 if (FLAG_i_like_slow_isolate_spawn) { | |
| 235 // We block the parent isolate while the child isolate loads. | |
| 236 Isolate* saved = Isolate::Current(); | |
|
siva
2015/11/23 20:56:01
I think
Isolate* saved = isolate;
should also work
| |
| 237 Thread::ExitIsolate(); | |
| 238 spawn_task->Run(); | |
| 239 delete spawn_task; | |
| 240 spawn_task = NULL; | |
| 241 Thread::EnterIsolate(saved); | |
| 242 } else { | |
| 243 Dart::thread_pool()->Run(spawn_task); | |
| 244 } | |
| 230 return Object::null(); | 245 return Object::null(); |
| 231 } | 246 } |
| 232 } | 247 } |
| 233 const String& msg = String::Handle(String::New( | 248 const String& msg = String::Handle(String::New( |
| 234 "Isolate.spawn expects to be passed a static or top-level function")); | 249 "Isolate.spawn expects to be passed a static or top-level function")); |
| 235 Exceptions::ThrowArgumentError(msg); | 250 Exceptions::ThrowArgumentError(msg); |
| 236 return Object::null(); | 251 return Object::null(); |
| 237 } | 252 } |
| 238 | 253 |
| 239 | 254 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 utf8_package_map[i] = String2UTF8(String::Cast(entry)); | 347 utf8_package_map[i] = String2UTF8(String::Cast(entry)); |
| 333 } | 348 } |
| 334 // NULL terminated array. | 349 // NULL terminated array. |
| 335 utf8_package_map[len] = NULL; | 350 utf8_package_map[len] = NULL; |
| 336 } | 351 } |
| 337 | 352 |
| 338 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value(); | 353 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value(); |
| 339 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id(); | 354 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id(); |
| 340 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id(); | 355 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id(); |
| 341 | 356 |
| 342 IsolateSpawnState* state = new IsolateSpawnState( | 357 IsolateSpawnState* state = |
| 343 port.Id(), | 358 new IsolateSpawnState( |
| 344 isolate->init_callback_data(), | 359 port.Id(), |
| 345 canonical_uri, | 360 isolate->init_callback_data(), |
| 346 utf8_package_root, | 361 canonical_uri, |
| 347 const_cast<const char**>(utf8_package_map), | 362 utf8_package_root, |
| 348 args, | 363 const_cast<const char**>(utf8_package_map), |
| 349 message, | 364 args, |
| 350 paused.value(), | 365 message, |
| 351 fatal_errors, | 366 paused.value(), |
| 352 on_exit_port, | 367 fatal_errors, |
| 353 on_error_port); | 368 on_exit_port, |
| 369 on_error_port); | |
| 370 | |
| 354 // If we were passed a value then override the default flags state for | 371 // If we were passed a value then override the default flags state for |
| 355 // checked mode. | 372 // checked mode. |
| 356 if (!checked.IsNull()) { | 373 if (!checked.IsNull()) { |
| 357 state->isolate_flags()->set_checked(checked.value()); | 374 state->isolate_flags()->set_checked(checked.value()); |
| 358 } | 375 } |
| 359 | 376 |
| 360 Dart::thread_pool()->Run(new SpawnIsolateTask(state)); | 377 ThreadPool::Task* spawn_task = new SpawnIsolateTask(state); |
| 378 if (FLAG_i_like_slow_isolate_spawn) { | |
| 379 // We block the parent isolate while the child isolate loads. | |
| 380 Isolate* saved = Isolate::Current(); | |
|
siva
2015/11/23 20:56:01
Ditto.
| |
| 381 Thread::ExitIsolate(); | |
| 382 spawn_task->Run(); | |
| 383 delete spawn_task; | |
| 384 spawn_task = NULL; | |
| 385 Thread::EnterIsolate(saved); | |
| 386 } else { | |
| 387 Dart::thread_pool()->Run(spawn_task); | |
| 388 } | |
| 361 return Object::null(); | 389 return Object::null(); |
| 362 } | 390 } |
| 363 | 391 |
| 364 | 392 |
| 365 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0) { | 393 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0) { |
| 366 const Array& result = Array::Handle(Array::New(3)); | 394 const Array& result = Array::Handle(Array::New(3)); |
| 367 result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port()))); | 395 result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port()))); |
| 368 result.SetAt(1, Capability::Handle( | 396 result.SetAt(1, Capability::Handle( |
| 369 Capability::New(isolate->pause_capability()))); | 397 Capability::New(isolate->pause_capability()))); |
| 370 result.SetAt(2, Capability::Handle( | 398 result.SetAt(2, Capability::Handle( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 384 MessageWriter writer(&data, &allocator, false); | 412 MessageWriter writer(&data, &allocator, false); |
| 385 writer.WriteMessage(msg); | 413 writer.WriteMessage(msg); |
| 386 | 414 |
| 387 PortMap::PostMessage(new Message(port.Id(), | 415 PortMap::PostMessage(new Message(port.Id(), |
| 388 data, writer.BytesWritten(), | 416 data, writer.BytesWritten(), |
| 389 Message::kOOBPriority)); | 417 Message::kOOBPriority)); |
| 390 return Object::null(); | 418 return Object::null(); |
| 391 } | 419 } |
| 392 | 420 |
| 393 } // namespace dart | 421 } // namespace dart |
| OLD | NEW |