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

Side by Side Diff: runtime/lib/isolate.cc

Issue 834233003: Fix for issue 21398 (only send "literal like" objects across isolates spawned using spawnURI (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/include/dart_native_api.h ('k') | runtime/lib/isolate_patch.dart » ('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) 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 "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart.h" 8 #include "vm/dart.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return Smi::New(hash); 95 return Smi::New(hash);
96 } 96 }
97 97
98 98
99 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 2) { 99 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 2) {
100 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); 100 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
101 // TODO(iposva): Allow for arbitrary messages to be sent. 101 // TODO(iposva): Allow for arbitrary messages to be sent.
102 GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1)); 102 GET_NON_NULL_NATIVE_ARGUMENT(Instance, obj, arguments->NativeArgAt(1));
103 103
104 uint8_t* data = NULL; 104 uint8_t* data = NULL;
105 MessageWriter writer(&data, &allocator); 105 bool can_send_any_object = (isolate->origin_id() == port.origin_id());
106 MessageWriter writer(&data, &allocator, can_send_any_object);
106 writer.WriteMessage(obj); 107 writer.WriteMessage(obj);
107 108
108 // TODO(turnidge): Throw an exception when the return value is false? 109 // TODO(turnidge): Throw an exception when the return value is false?
109 PortMap::PostMessage(new Message(port.Id(), 110 PortMap::PostMessage(new Message(port.Id(),
110 data, writer.BytesWritten(), 111 data, writer.BytesWritten(),
111 Message::kNormalPriority)); 112 Message::kNormalPriority));
112 return Object::null(); 113 return Object::null();
113 } 114 }
114 115
115 116
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 Isolate* child_isolate = reinterpret_cast<Isolate*>( 172 Isolate* child_isolate = reinterpret_cast<Isolate*>(
172 (callback)(state->script_url(), 173 (callback)(state->script_url(),
173 state->function_name(), 174 state->function_name(),
174 state->package_root(), 175 state->package_root(),
175 init_data, 176 init_data,
176 error)); 177 error));
177 if (child_isolate == NULL) { 178 if (child_isolate == NULL) {
178 Isolate::SetCurrent(parent_isolate); 179 Isolate::SetCurrent(parent_isolate);
179 return false; 180 return false;
180 } 181 }
182 if (!state->is_spawn_uri()) {
183 // For isolates spawned using the spawnFunction semantics we set
184 // the origin_id to the origin_id of the parent isolate.
185 child_isolate->set_origin_id(parent_isolate->origin_id());
186 }
181 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); 187 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate));
182 188
183 Isolate::SetCurrent(parent_isolate); 189 Isolate::SetCurrent(parent_isolate);
184 return true; 190 return true;
185 } 191 }
186 192
187 193
188 static RawObject* Spawn(Isolate* parent_isolate, 194 static void Spawn(Isolate* parent_isolate, IsolateSpawnState* state) {
189 IsolateSpawnState* state) {
190 // Create a new isolate. 195 // Create a new isolate.
191 char* error = NULL; 196 char* error = NULL;
192 if (!CreateIsolate(parent_isolate, state, &error)) { 197 if (!CreateIsolate(parent_isolate, state, &error)) {
193 delete state; 198 delete state;
194 const String& msg = String::Handle(String::New(error)); 199 const String& msg = String::Handle(String::New(error));
195 free(error); 200 free(error);
196 ThrowIsolateSpawnException(msg); 201 ThrowIsolateSpawnException(msg);
197 } 202 }
198 203
199 // Create a SendPort for the new isolate. 204 // Start the new isolate if it is already marked as runnable.
200 Isolate* spawned_isolate = state->isolate(); 205 Isolate* spawned_isolate = state->isolate();
201 const SendPort& port = SendPort::Handle(
202 SendPort::New(spawned_isolate->main_port()));
203
204 // Start the new isolate if it is already marked as runnable.
205 MutexLocker ml(spawned_isolate->mutex()); 206 MutexLocker ml(spawned_isolate->mutex());
206 spawned_isolate->set_spawn_state(state); 207 spawned_isolate->set_spawn_state(state);
207 if (spawned_isolate->is_runnable()) { 208 if (spawned_isolate->is_runnable()) {
208 spawned_isolate->Run(); 209 spawned_isolate->Run();
209 } 210 }
210
211 return port.raw();
212 } 211 }
213 212
214 213
215 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 4) { 214 DEFINE_NATIVE_ENTRY(Isolate_spawnFunction, 4) {
216 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); 215 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
217 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(1)); 216 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(1));
218 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(2)); 217 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(2));
219 GET_NON_NULL_NATIVE_ARGUMENT(Bool, paused, arguments->NativeArgAt(3)); 218 GET_NON_NULL_NATIVE_ARGUMENT(Bool, paused, arguments->NativeArgAt(3));
220 if (closure.IsClosure()) { 219 if (closure.IsClosure()) {
221 Function& func = Function::Handle(); 220 Function& func = Function::Handle();
222 func = Closure::function(closure); 221 func = Closure::function(closure);
223 if (func.IsImplicitClosureFunction() && func.is_static()) { 222 if (func.IsImplicitClosureFunction() && func.is_static()) {
224 #if defined(DEBUG) 223 #if defined(DEBUG)
225 Context& ctx = Context::Handle(); 224 Context& ctx = Context::Handle();
226 ctx = Closure::context(closure); 225 ctx = Closure::context(closure);
227 ASSERT(ctx.num_variables() == 0); 226 ASSERT(ctx.num_variables() == 0);
228 #endif 227 #endif
229 return Spawn(isolate, new IsolateSpawnState( 228 Spawn(isolate, new IsolateSpawnState(port.Id(),
230 port.Id(), func, message, paused.value())); 229 func,
230 message,
231 paused.value()));
232 return Object::null();
231 } 233 }
232 } 234 }
233 const String& msg = String::Handle(String::New( 235 const String& msg = String::Handle(String::New(
234 "Isolate.spawn expects to be passed a static or top-level function")); 236 "Isolate.spawn expects to be passed a static or top-level function"));
235 Exceptions::ThrowArgumentError(msg); 237 Exceptions::ThrowArgumentError(msg);
236 return Object::null(); 238 return Object::null();
237 } 239 }
238 240
239 241
240 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 6) { 242 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 6) {
(...skipping 17 matching lines...) Expand all
258 260
259 char* utf8_package_root = NULL; 261 char* utf8_package_root = NULL;
260 if (!package_root.IsNull()) { 262 if (!package_root.IsNull()) {
261 const intptr_t len = Utf8::Length(package_root); 263 const intptr_t len = Utf8::Length(package_root);
262 Zone* zone = isolate->current_zone(); 264 Zone* zone = isolate->current_zone();
263 utf8_package_root = zone->Alloc<char>(len + 1); 265 utf8_package_root = zone->Alloc<char>(len + 1);
264 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len); 266 package_root.ToUTF8(reinterpret_cast<uint8_t*>(utf8_package_root), len);
265 utf8_package_root[len] = '\0'; 267 utf8_package_root[len] = '\0';
266 } 268 }
267 269
268 return Spawn(isolate, new IsolateSpawnState(port.Id(), 270 Spawn(isolate, new IsolateSpawnState(port.Id(),
269 canonical_uri, 271 canonical_uri,
270 utf8_package_root, 272 utf8_package_root,
271 args, 273 args,
272 message, 274 message,
273 paused.value())); 275 paused.value()));
276 return Object::null();
274 } 277 }
275 278
276 279
277 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0) { 280 DEFINE_NATIVE_ENTRY(Isolate_getPortAndCapabilitiesOfCurrentIsolate, 0) {
278 const Array& result = Array::Handle(Array::New(3)); 281 const Array& result = Array::Handle(Array::New(3));
279 result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port()))); 282 result.SetAt(0, SendPort::Handle(SendPort::New(isolate->main_port())));
280 result.SetAt(1, Capability::Handle( 283 result.SetAt(1, Capability::Handle(
281 Capability::New(isolate->pause_capability()))); 284 Capability::New(isolate->pause_capability())));
282 result.SetAt(2, Capability::Handle( 285 result.SetAt(2, Capability::Handle(
283 Capability::New(isolate->terminate_capability()))); 286 Capability::New(isolate->terminate_capability())));
284 return result.raw(); 287 return result.raw();
285 } 288 }
286 289
287 290
288 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) { 291 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) {
289 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); 292 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
290 GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1)); 293 GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1));
291 294
292 // Make sure to route this request to the isolate library OOB mesage handler. 295 // Make sure to route this request to the isolate library OOB mesage handler.
293 msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg))); 296 msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg)));
294 297
295 uint8_t* data = NULL; 298 uint8_t* data = NULL;
296 MessageWriter writer(&data, &allocator); 299 MessageWriter writer(&data, &allocator, false);
297 writer.WriteMessage(msg); 300 writer.WriteMessage(msg);
298 301
299 PortMap::PostMessage(new Message(port.Id(), 302 PortMap::PostMessage(new Message(port.Id(),
300 data, writer.BytesWritten(), 303 data, writer.BytesWritten(),
301 Message::kOOBPriority)); 304 Message::kOOBPriority));
302 return Object::null(); 305 return Object::null();
303 } 306 }
304 307
305 } // namespace dart 308 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_native_api.h ('k') | runtime/lib/isolate_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698