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

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

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 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
« no previous file with comments | « runtime/bin/vmservice/vmservice.dart ('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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 static RawObject* ReceivePortCreate(intptr_t port_id) { 46 static RawObject* ReceivePortCreate(intptr_t port_id) {
47 Isolate* isolate = Isolate::Current(); 47 Isolate* isolate = Isolate::Current();
48 Function& func = 48 Function& func =
49 Function::Handle(isolate, 49 Function::Handle(isolate,
50 isolate->object_store()->receive_port_create_function()); 50 isolate->object_store()->receive_port_create_function());
51 const int kNumArguments = 1; 51 const int kNumArguments = 1;
52 if (func.IsNull()) { 52 if (func.IsNull()) {
53 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); 53 Library& isolate_lib = Library::Handle(Library::IsolateLibrary());
54 ASSERT(!isolate_lib.IsNull()); 54 ASSERT(!isolate_lib.IsNull());
55 const String& class_name = 55 const String& class_name =
56 String::Handle(isolate_lib.PrivateName(Symbols::_ReceivePortImpl())); 56 String::Handle(isolate_lib.PrivateName(Symbols::_RawReceivePortImpl()));
57 const String& function_name = 57 const String& function_name =
58 String::Handle(isolate_lib.PrivateName(Symbols::_get_or_create())); 58 String::Handle(isolate_lib.PrivateName(Symbols::_get_or_create()));
59 func = Resolver::ResolveStatic(isolate_lib, 59 func = Resolver::ResolveStatic(isolate_lib,
60 class_name, 60 class_name,
61 function_name, 61 function_name,
62 kNumArguments, 62 kNumArguments,
63 Object::empty_array(), 63 Object::empty_array(),
64 Resolver::kIsQualified); 64 Resolver::kIsQualified);
65 ASSERT(!func.IsNull()); 65 ASSERT(!func.IsNull());
66 isolate->object_store()->set_receive_port_create_function(func); 66 isolate->object_store()->set_receive_port_create_function(func);
67 } 67 }
68 const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); 68 const Array& args = Array::Handle(isolate, Array::New(kNumArguments));
69 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id))); 69 args.SetAt(0, Integer::Handle(isolate, Integer::New(port_id)));
70 const Object& result = 70 const Object& result =
71 Object::Handle(isolate, DartEntry::InvokeFunction(func, args)); 71 Object::Handle(isolate, DartEntry::InvokeFunction(func, args));
72 if (!result.IsError()) { 72 if (!result.IsError()) {
73 PortMap::SetLive(port_id); 73 PortMap::SetLive(port_id);
74 } 74 }
75 return result.raw(); 75 return result.raw();
76 } 76 }
77 77
78 78
79 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { 79 DEFINE_NATIVE_ENTRY(RawReceivePortImpl_factory, 1) {
80 ASSERT(AbstractTypeArguments::CheckedHandle( 80 ASSERT(AbstractTypeArguments::CheckedHandle(
81 arguments->NativeArgAt(0)).IsNull()); 81 arguments->NativeArgAt(0)).IsNull());
82 intptr_t port_id = 82 intptr_t port_id =
83 PortMap::CreatePort(arguments->isolate()->message_handler()); 83 PortMap::CreatePort(arguments->isolate()->message_handler());
84 const Object& port = Object::Handle(ReceivePortCreate(port_id)); 84 const Object& port = Object::Handle(ReceivePortCreate(port_id));
85 if (port.IsError()) { 85 if (port.IsError()) {
86 Exceptions::PropagateError(Error::Cast(port)); 86 Exceptions::PropagateError(Error::Cast(port));
87 } 87 }
88 return port.raw(); 88 return port.raw();
89 } 89 }
90 90
91 91
92 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) { 92 DEFINE_NATIVE_ENTRY(RawReceivePortImpl_closeInternal, 1) {
93 GET_NON_NULL_NATIVE_ARGUMENT(Smi, id, arguments->NativeArgAt(0)); 93 GET_NON_NULL_NATIVE_ARGUMENT(Smi, id, arguments->NativeArgAt(0));
94 PortMap::ClosePort(id.Value()); 94 PortMap::ClosePort(id.Value());
95 return Object::null(); 95 return Object::null();
96 } 96 }
97 97
98 98
99 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { 99 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) {
100 GET_NON_NULL_NATIVE_ARGUMENT(Smi, send_id, arguments->NativeArgAt(0)); 100 GET_NON_NULL_NATIVE_ARGUMENT(Smi, send_id, arguments->NativeArgAt(0));
101 GET_NON_NULL_NATIVE_ARGUMENT(Smi, reply_id, arguments->NativeArgAt(1)); 101 GET_NON_NULL_NATIVE_ARGUMENT(Smi, reply_id, arguments->NativeArgAt(1));
102 // TODO(iposva): Allow for arbitrary messages to be sent. 102 // TODO(iposva): Allow for arbitrary messages to be sent.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 MutexLocker ml(state->isolate()->mutex()); 208 MutexLocker ml(state->isolate()->mutex());
209 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state)); 209 state->isolate()->set_spawn_data(reinterpret_cast<uword>(state));
210 if (state->isolate()->is_runnable()) { 210 if (state->isolate()->is_runnable()) {
211 state->isolate()->Run(); 211 state->isolate()->Run();
212 } 212 }
213 213
214 return port.raw(); 214 return port.raw();
215 } 215 }
216 216
217 217
218 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 2) { 218 DEFINE_NATIVE_ENTRY(isolate_spawnFunction, 1) {
219 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); 219 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0));
220 bool throw_exception = false; 220 bool throw_exception = false;
221 Function& func = Function::Handle(); 221 Function& func = Function::Handle();
222 if (closure.IsClosure()) { 222 if (closure.IsClosure()) {
223 func = Closure::function(closure); 223 func = Closure::function(closure);
224 const Class& cls = Class::Handle(func.Owner()); 224 const Class& cls = Class::Handle(func.Owner());
225 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) { 225 if (!func.IsClosureFunction() || !func.is_static() || !cls.IsTopLevel()) {
226 throw_exception = true; 226 throw_exception = true;
227 } 227 }
228 } else { 228 } else {
229 throw_exception = true; 229 throw_exception = true;
230 } 230 }
231 if (throw_exception) { 231 if (throw_exception) {
232 const String& msg = String::Handle(String::New( 232 const String& msg = String::Handle(String::New(
233 "spawnFunction expects to be passed a closure to a top-level static " 233 "Isolate.spawn expects to be passed a top-level function"));
234 "function"));
235 Exceptions::ThrowArgumentError(msg); 234 Exceptions::ThrowArgumentError(msg);
236 } 235 }
237 236
238 GET_NATIVE_ARGUMENT(Instance, callback, arguments->NativeArgAt(1));
239 Function& callback_func = Function::Handle();
240 if (callback.IsClosure()) {
241 callback_func = Closure::function(callback);
242 const Class& cls = Class::Handle(callback_func.Owner());
243 if (!callback_func.IsClosureFunction() || !callback_func.is_static() ||
244 !cls.IsTopLevel()) {
245 throw_exception = true;
246 }
247 } else if (!callback.IsNull()) {
248 throw_exception = true;
249 }
250 if (throw_exception) {
251 const String& msg = String::Handle(String::New(
252 "spawnFunction expects to be passed either a unhandled exception "
253 "callback to a top-level static function, or null"));
254 Exceptions::ThrowArgumentError(msg);
255 }
256
257 #if defined(DEBUG) 237 #if defined(DEBUG)
258 Context& ctx = Context::Handle(); 238 Context& ctx = Context::Handle();
259 ctx = Closure::context(closure); 239 ctx = Closure::context(closure);
260 ASSERT(ctx.num_variables() == 0); 240 ASSERT(ctx.num_variables() == 0);
261 if (!callback.IsNull()) {
262 ctx = Closure::context(callback);
263 ASSERT(ctx.num_variables() == 0);
264 }
265 #endif 241 #endif
266 242
267 return Spawn(arguments, new IsolateSpawnState(func, callback_func)); 243 return Spawn(arguments, new IsolateSpawnState(func));
268 } 244 }
269 245
270 246
271 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 1) { 247 DEFINE_NATIVE_ENTRY(isolate_spawnUri, 1) {
272 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); 248 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0));
273 249
274 // Canonicalize the uri with respect to the current isolate. 250 // Canonicalize the uri with respect to the current isolate.
275 char* error = NULL; 251 char* error = NULL;
276 char* canonical_uri = NULL; 252 char* canonical_uri = NULL;
277 const Library& root_lib = 253 const Library& root_lib =
(...skipping 10 matching lines...) Expand all
288 264
289 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) { 265 DEFINE_NATIVE_ENTRY(isolate_getPortInternal, 0) {
290 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port())); 266 const Object& port = Object::Handle(ReceivePortCreate(isolate->main_port()));
291 if (port.IsError()) { 267 if (port.IsError()) {
292 Exceptions::PropagateError(Error::Cast(port)); 268 Exceptions::PropagateError(Error::Cast(port));
293 } 269 }
294 return port.raw(); 270 return port.raw();
295 } 271 }
296 272
297 } // namespace dart 273 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/vmservice.dart ('k') | runtime/lib/isolate_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698