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

Side by Side Diff: runtime/vm/service_isolate.cc

Issue 1422753005: Minimize enter/exit isolate calls during startup and shutdown of service isolate. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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/service_isolate.h" 5 #include "vm/service_isolate.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 // Service isolate already exists. 248 // Service isolate already exists.
249 return; 249 return;
250 } 250 }
251 SetServiceIsolate(I); 251 SetServiceIsolate(I);
252 } 252 }
253 253
254 254
255 void ServiceIsolate::ConstructExitMessageAndCache(Isolate* I) { 255 void ServiceIsolate::ConstructExitMessageAndCache(Isolate* I) {
256 // Construct and cache exit message here so we can send it without needing an 256 // Construct and cache exit message here so we can send it without needing an
257 // isolate. 257 // isolate.
258 StartIsolateScope iso_scope(I);
259 Thread* T = Thread::Current(); 258 Thread* T = Thread::Current();
260 ASSERT(I == T->isolate()); 259 ASSERT(I == T->isolate());
261 ASSERT(I != NULL); 260 ASSERT(I != NULL);
262 StackZone zone(T); 261 StackZone zone(T);
263 HANDLESCOPE(T); 262 HANDLESCOPE(T);
264 ASSERT(exit_message_ == NULL); 263 ASSERT(exit_message_ == NULL);
265 ASSERT(exit_message_length_ == 0); 264 ASSERT(exit_message_length_ == 0);
266 const Array& list = Array::Handle(Z, MakeServiceExitMessage()); 265 const Array& list = Array::Handle(Z, MakeServiceExitMessage());
267 ASSERT(!list.IsNull()); 266 ASSERT(!list.IsNull());
268 MessageWriter writer(&exit_message_, &allocator, false); 267 MessageWriter writer(&exit_message_, &allocator, false);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 &api_flags, 316 &api_flags,
318 NULL, 317 NULL,
319 &error)); 318 &error));
320 if (isolate == NULL) { 319 if (isolate == NULL) {
321 OS::PrintErr("vm-service: Isolate creation error: %s\n", error); 320 OS::PrintErr("vm-service: Isolate creation error: %s\n", error);
322 ServiceIsolate::SetServiceIsolate(NULL); 321 ServiceIsolate::SetServiceIsolate(NULL);
323 ServiceIsolate::FinishedInitializing(); 322 ServiceIsolate::FinishedInitializing();
324 return; 323 return;
325 } 324 }
326 325
327 326 {
328 Thread::ExitIsolate(); 327 ASSERT(Isolate::Current() == NULL);
329 328 StartIsolateScope start_scope(isolate);
330 ServiceIsolate::ConstructExitMessageAndCache(isolate); 329 ServiceIsolate::ConstructExitMessageAndCache(isolate);
331 330 RunMain(isolate);
332 RunMain(isolate); 331 }
333 332
334 ServiceIsolate::FinishedInitializing(); 333 ServiceIsolate::FinishedInitializing();
335 334
336 isolate->message_handler()->Run(Dart::thread_pool(), 335 isolate->message_handler()->Run(Dart::thread_pool(),
337 NULL, 336 NULL,
338 ShutdownIsolate, 337 ShutdownIsolate,
339 reinterpret_cast<uword>(isolate)); 338 reinterpret_cast<uword>(isolate));
340 } 339 }
341 340
342 protected: 341 protected:
343 static void ShutdownIsolate(uword parameter) { 342 static void ShutdownIsolate(uword parameter) {
344 Isolate* I = reinterpret_cast<Isolate*>(parameter); 343 Isolate* I = reinterpret_cast<Isolate*>(parameter);
345 ASSERT(ServiceIsolate::IsServiceIsolate(I)); 344 ASSERT(ServiceIsolate::IsServiceIsolate(I));
346 ServiceIsolate::SetServiceIsolate(NULL); 345 ServiceIsolate::SetServiceIsolate(NULL);
347 ServiceIsolate::SetServicePort(ILLEGAL_PORT); 346 ServiceIsolate::SetServicePort(ILLEGAL_PORT);
348 { 347 {
349 // Print the error if there is one. This may execute dart code to 348 // Print the error if there is one. This may execute dart code to
350 // print the exception object, so we need to use a StartIsolateScope. 349 // print the exception object, so we need to use a StartIsolateScope.
350 ASSERT(Isolate::Current() == NULL);
351 StartIsolateScope start_scope(I); 351 StartIsolateScope start_scope(I);
352 Thread* T = Thread::Current(); 352 Thread* T = Thread::Current();
353 ASSERT(I == T->isolate()); 353 ASSERT(I == T->isolate());
354 StackZone zone(T); 354 StackZone zone(T);
355 HandleScope handle_scope(T); 355 HandleScope handle_scope(T);
zra 2015/10/30 04:47:50 Calling Dart::ShutdownIsolate() inside of a Handle
356 Error& error = Error::Handle(Z); 356 Error& error = Error::Handle(Z);
357 error = I->object_store()->sticky_error(); 357 error = I->object_store()->sticky_error();
358 if (!error.IsNull() && !error.IsUnwindError()) { 358 if (!error.IsNull() && !error.IsUnwindError()) {
359 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString()); 359 OS::PrintErr("vm-service: Error: %s\n", error.ToErrorCString());
360 } 360 }
361 Dart::RunShutdownCallback(); 361 Dart::RunShutdownCallback();
362 } 362
363 {
364 // Shut the isolate down. 363 // Shut the isolate down.
365 SwitchIsolateScope switch_scope(I);
366 Dart::ShutdownIsolate(); 364 Dart::ShutdownIsolate();
367 } 365 }
368 if (FLAG_trace_service) { 366 if (FLAG_trace_service) {
369 OS::Print("vm-service: Shutdown.\n"); 367 OS::Print("vm-service: Shutdown.\n");
370 } 368 }
371 ServiceIsolate::FinishedExiting(); 369 ServiceIsolate::FinishedExiting();
372 } 370 }
373 371
374 void RunMain(Isolate* I) { 372 void RunMain(Isolate* I) {
375 if (Dart::IsRunningPrecompiledCode()) { 373 if (Dart::IsRunningPrecompiledCode()) {
376 // TODO(24651): Remove this. 374 // TODO(24651): Remove this.
377 return; 375 return;
378 } 376 }
379
380 StartIsolateScope iso_scope(I);
381 Thread* T = Thread::Current(); 377 Thread* T = Thread::Current();
382 ASSERT(I == T->isolate()); 378 ASSERT(I == T->isolate());
383 StackZone zone(T); 379 StackZone zone(T);
384 HANDLESCOPE(T); 380 HANDLESCOPE(T);
385 // Invoke main which will return the loadScriptPort. 381 // Invoke main which will return the loadScriptPort.
386 const Library& root_library = Library::Handle(Z, 382 const Library& root_library = Library::Handle(Z,
387 I->object_store()->root_library()); 383 I->object_store()->root_library());
388 if (root_library.IsNull()) { 384 if (root_library.IsNull()) {
389 if (FLAG_trace_service) { 385 if (FLAG_trace_service) {
390 OS::Print("vm-service: Embedder did not install a script."); 386 OS::Print("vm-service: Embedder did not install a script.");
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 ASSERT(!result.IsNull()); 489 ASSERT(!result.IsNull());
494 Dart_Port port = ILLEGAL_PORT; 490 Dart_Port port = ILLEGAL_PORT;
495 if (result.IsReceivePort()) { 491 if (result.IsReceivePort()) {
496 port = ReceivePort::Cast(result).Id(); 492 port = ReceivePort::Cast(result).Id();
497 } 493 }
498 ASSERT(port != ILLEGAL_PORT); 494 ASSERT(port != ILLEGAL_PORT);
499 ServiceIsolate::SetServicePort(port); 495 ServiceIsolate::SetServicePort(port);
500 } 496 }
501 497
502 } // namespace dart 498 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698