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

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

Issue 8297004: Allow embedders to provide custom message delivery for an isolate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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_api.h ('k') | runtime/vm/assert.h » ('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) 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 19 matching lines...) Expand all
30 class_name_(class_name), 30 class_name_(class_name),
31 port_id_(port_id) {} 31 port_id_(port_id) {}
32 32
33 Isolate* isolate_; 33 Isolate* isolate_;
34 char* library_url_; 34 char* library_url_;
35 char* class_name_; 35 char* class_name_;
36 intptr_t port_id_; 36 intptr_t port_id_;
37 }; 37 };
38 38
39 39
40 static RawInstance* DeserializeMessage(void* data) {
41 // Create a snapshot object using the buffer.
42 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data);
43 ASSERT(snapshot->IsPartialSnapshot());
44
45 // Read object back from the snapshot.
46 Isolate* isolate= Isolate::Current();
47 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
48 Instance& instance = Instance::Handle();
49 instance ^= reader.ReadObject();
50 return instance.raw();
51 }
52
53
54 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 40 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
55 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 41 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
56 return reinterpret_cast<uint8_t*>(new_ptr); 42 return reinterpret_cast<uint8_t*>(new_ptr);
57 } 43 }
58 44
59 45
60 static void* SerializeObject(const Instance& obj) { 46 static void* SerializeObject(const Instance& obj) {
61 uint8_t* result = NULL; 47 uint8_t* result = NULL;
62 SnapshotWriter writer(false, &result, &allocator); 48 SnapshotWriter writer(false, &result, &allocator);
63 writer.WriteObject(obj.raw()); 49 writer.WriteObject(obj.raw());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 kNoArgumentNames, 123 kNoArgumentNames,
138 Resolver::kIsQualified)); 124 Resolver::kIsQualified));
139 GrowableArray<const Object*> arguments(kNumArguments); 125 GrowableArray<const Object*> arguments(kNumArguments);
140 arguments.Add(&Integer::Handle(Integer::New(port_id))); 126 arguments.Add(&Integer::Handle(Integer::New(port_id)));
141 const Instance& result = Instance::Handle( 127 const Instance& result = Instance::Handle(
142 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); 128 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
143 return result.raw(); 129 return result.raw();
144 } 130 }
145 131
146 132
147 void PortMessage::Handle() {
148 const Instance& msg = Instance::Handle(DeserializeMessage(data()));
149 const String& class_name =
150 String::Handle(String::NewSymbol("ReceivePortImpl"));
151 const String& function_name =
152 String::Handle(String::NewSymbol("handleMessage_"));
153 const int kNumArguments = 3;
154 const Array& kNoArgumentNames = Array::Handle();
155 const Function& function = Function::Handle(
156 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()),
157 class_name,
158 function_name,
159 kNumArguments,
160 kNoArgumentNames,
161 Resolver::kIsQualified));
162 GrowableArray<const Object*> arguments(kNumArguments);
163 arguments.Add(&Integer::Handle(Integer::New(dest_id())));
164 arguments.Add(&Integer::Handle(Integer::New(reply_id())));
165 arguments.Add(&msg);
166 const Object& result = Object::Handle(
167 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
168 if (result.IsUnhandledException()) {
169 UnhandledException& uhe = UnhandledException::Handle();
170 uhe ^= result.raw();
171 ProcessUnhandledException(uhe);
172 }
173 ASSERT(result.IsNull());
174 }
175
176
177 static void RunIsolate(uword parameter) { 133 static void RunIsolate(uword parameter) {
178 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter); 134 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter);
179 Isolate* isolate = data->isolate_; 135 Isolate* isolate = data->isolate_;
180 char* library_url = data->library_url_; 136 char* library_url = data->library_url_;
181 char* class_name = data->class_name_; 137 char* class_name = data->class_name_;
182 intptr_t port_id = data->port_id_; 138 intptr_t port_id = data->port_id_;
183 delete data; 139 delete data;
184 140
185 Isolate::SetCurrent(isolate); 141 Isolate::SetCurrent(isolate);
186 // Intialize stack limit in case we are running isolate in a 142 // Intialize stack limit in case we are running isolate in a
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 target_function, 195 target_function,
240 arguments, 196 arguments,
241 kNoArgumentNames); 197 kNoArgumentNames);
242 if (result.IsUnhandledException()) { 198 if (result.IsUnhandledException()) {
243 UnhandledException& uhe = UnhandledException::Handle(); 199 UnhandledException& uhe = UnhandledException::Handle();
244 uhe ^= result.raw(); 200 uhe ^= result.raw();
245 ProcessUnhandledException(uhe); 201 ProcessUnhandledException(uhe);
246 } 202 }
247 ASSERT(result.IsNull()); 203 ASSERT(result.IsNull());
248 free(class_name); 204 free(class_name);
205 isolate->StandardRunLoop();
249 206
250 // Keep listening until there are no active receive ports.
251 while (isolate->active_ports() > 0) {
252 Zone zone;
253 HandleScope handle_scope;
254
255 PortMessage* message = PortMap::ReceiveMessage(0);
256 message->Handle();
257 delete message;
258 }
259 } else { 207 } else {
260 Zone zone; 208 Zone zone;
261 HandleScope handle_scope; 209 HandleScope handle_scope;
262 const String& error = String::Handle( 210 const String& error = String::Handle(
263 Isolate::Current()->object_store()->sticky_error()); 211 Isolate::Current()->object_store()->sticky_error());
264 const char* errmsg = error.ToCString(); 212 const char* errmsg = error.ToCString();
265 fprintf(stderr, "%s\n", errmsg); 213 fprintf(stderr, "%s\n", errmsg);
266 exit(255); 214 exit(255);
267 } 215 }
268 isolate->set_long_jump_base(base); 216 isolate->set_long_jump_base(base);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 PortMap::ClosePort(id); 330 PortMap::ClosePort(id);
383 } 331 }
384 332
385 333
386 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { 334 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) {
387 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); 335 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value();
388 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); 336 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value();
389 // TODO(iposva): Allow for arbitrary messages to be sent. 337 // TODO(iposva): Allow for arbitrary messages to be sent.
390 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); 338 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2)));
391 339
392 PortMessage* message = new PortMessage(send_id, reply_id, data); 340 // TODO(turnidge): Throw an exception when the return value is false?
393 PortMap::PostMessage(message); 341 PortMap::PostMessage(send_id, reply_id, data);
394 } 342 }
395 343
396 } // namespace dart 344 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/assert.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698