Skip to content

Commit

Permalink
Wait for Dart VM initialization before the letting the service isolat…
Browse files Browse the repository at this point in the history
…e constructor access the VM object. (flutter#6028)

The service isolate creation callback may occur on a background thread before
the call the Dart_Initialize within the DartVM construtor can finish. We store
pointers to various snapshots within the DartVM object. These snapshots are
necessary for to successfully create the service isolate. The isolate creation
callback access the global object within the ForProcessIfInitialized method.
This method can return null if the VM object has not been initialized. This
leads to the service protocol failing to start in a non-deterministic manner.
This patch moves the creation and access of the DartVM object within a critical
section.
  • Loading branch information
chinmaygarde authored Aug 15, 2018
1 parent 9c0c620 commit 2f19645
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions runtime/dart_vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,15 @@ fml::RefPtr<DartVM> DartVM::ForProcess(Settings settings) {
}

static std::once_flag gVMInitialization;
static std::mutex gVMMutex;
static fml::RefPtr<DartVM> gVM;

fml::RefPtr<DartVM> DartVM::ForProcess(
Settings settings,
fml::RefPtr<DartSnapshot> vm_snapshot,
fml::RefPtr<DartSnapshot> isolate_snapshot,
fml::RefPtr<DartSnapshot> shared_snapshot) {
std::lock_guard<std::mutex> lock(gVMMutex);
std::call_once(gVMInitialization, [settings, //
vm_snapshot, //
isolate_snapshot, //
Expand Down Expand Up @@ -296,6 +298,7 @@ fml::RefPtr<DartVM> DartVM::ForProcess(
}

fml::RefPtr<DartVM> DartVM::ForProcessIfInitialized() {
std::lock_guard<std::mutex> lock(gVMMutex);
return gVM;
}

Expand Down

0 comments on commit 2f19645

Please sign in to comment.