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

Unified Diff: runtime/lib/isolate.cc

Issue 456983002: Refactor isolate startup code in preparation for making isolate spawning more truly non-blocking. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: portmap changes, fixed hang Created 6 years, 4 months 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/isolate.cc
diff --git a/runtime/lib/isolate.cc b/runtime/lib/isolate.cc
index e36fbf00f779af60b153d013af4aad4d408a7922..e9ec176e2d1e68027604aad7294407f14eed82b6 100644
--- a/runtime/lib/isolate.cc
+++ b/runtime/lib/isolate.cc
@@ -38,7 +38,7 @@ DEFINE_NATIVE_ENTRY(RawReceivePortImpl_factory, 1) {
ASSERT(TypeArguments::CheckedHandle(arguments->NativeArgAt(0)).IsNull());
Dart_Port port_id =
PortMap::CreatePort(arguments->isolate()->message_handler());
- return ReceivePort::New(port_id);
+ return ReceivePort::New(port_id, false /* not control port */);
}
@@ -176,20 +176,10 @@ static RawObject* Spawn(NativeArguments* arguments, IsolateSpawnState* state) {
ThrowIsolateSpawnException(msg);
}
- // The result of spawning an Isolate is an array with 3 elements:
- // [main_port, pause_capability, terminate_capability]
- const Array& result = Array::Handle(Array::New(3));
-
// Create a SendPort for the new isolate.
Isolate* spawned_isolate = state->isolate();
const SendPort& port = SendPort::Handle(
SendPort::New(spawned_isolate->main_port()));
- result.SetAt(0, port);
- Capability& capability = Capability::Handle();
- capability = Capability::New(spawned_isolate->pause_capability());
- result.SetAt(1, capability); // pauseCapability
- capability = Capability::New(spawned_isolate->terminate_capability());
- result.SetAt(2, capability); // terminateCapability
// Start the new isolate if it is already marked as runnable.
MutexLocker ml(spawned_isolate->mutex());
@@ -198,12 +188,14 @@ static RawObject* Spawn(NativeArguments* arguments, IsolateSpawnState* state) {
spawned_isolate->Run();
}
- return result.raw();
+ return port.raw();
}
-DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 1) {
- GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0));
+DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 3) {
+ GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
+ GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(1));
+ GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(2));
if (closure.IsClosure()) {
Function& func = Function::Handle();
func = Closure::function(closure);
@@ -213,7 +205,7 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 1) {
ctx = Closure::context(closure);
ASSERT(ctx.num_variables() == 0);
#endif
- return Spawn(arguments, new IsolateSpawnState(func));
+ return Spawn(arguments, new IsolateSpawnState(port.Id(), func, message));
}
}
const String& msg = String::Handle(String::New(
@@ -223,8 +215,11 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 1) {
}
-DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) {
- GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0));
+DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 4) {
+ GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
+ GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(1));
+ GET_NON_NULL_NATIVE_ARGUMENT(Instance, args, arguments->NativeArgAt(2));
+ GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(3));
// Canonicalize the uri with respect to the current isolate.
char* error = NULL;
@@ -237,7 +232,8 @@ DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) {
ThrowIsolateSpawnException(msg);
}
- return Spawn(arguments, new IsolateSpawnState(canonical_uri));
+ return Spawn(arguments, new IsolateSpawnState(port.Id(), canonical_uri,
+ args, message));
}
@@ -258,14 +254,4 @@ DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) {
return Object::null();
}
-
-DEFINE_NATIVE_ENTRY(Isolate_mainPort, 0) {
- // The control port is being accessed as a regular port from Dart code. This
- // is most likely due to the _startIsolate code in dart:isolate. Account for
- // this by increasing the number of open control ports.
- isolate->message_handler()->increment_control_ports();
-
- return ReceivePort::New(isolate->main_port());
-}
-
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698