-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shut down and restart the Dart VM as needed. #7832
Conversation
Thanks to @a-siva & @jason-simmons for helping to arrive at this approach. The stuff in dart_vm_lifecycle.cc has the implementation details about thread safety that are important and ought to be closely reviewed. |
The shell was already designed to cleanly shut down the VM but it couldnt earlier as Dart_Initialize could never be called after a Dart_Cleanup. This meant that shutting down an engine instance could not shut down the VM to save memory because newly created engines in the process after that point couldn't restart the VM. There can only be one VM running in a process at a time.
9894648
to
d210788
Compare
@@ -0,0 +1,79 @@ | |||
// Copyright 2013 The Flutter Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New file, I guess we should move the copyright year to 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All our files apparently need to have this preamble. @Hixie knows the details.
@@ -0,0 +1,47 @@ | |||
// Copyright 2013 The Flutter Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
|
||
const Settings& GetSettings() const; | ||
|
||
const DartSnapshot& GetVMSnapshot() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are treating this snapshot differently and not returning a fml::RefPtr I suppose because it is used only in Dart_Init(). You might be starting a new VM again after deleting the previous VM, is it guaranteed that these calls to Dart_Init will always happen on the same thread?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. There is no such guarantee. However, all the constructors and destructors of the DartVM are guaranteed to be guarded by a single global mutex. Also, the the new vm_data_ is owned by the DartVM object so the second launch should get the updated VM data.
@@ -0,0 +1,106 @@ | |||
// Copyright 2013 The Flutter Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm modulo a couple nits.
flutter/engine@033f207...163a2fd git log 033f207..163a2fd --no-merges --oneline 163a2fd Revert "Android embedding refactor pr3 add remaining systemchannels (#7738)" (flutter/engine#7849) 0d6ff16 Shut down and restart the Dart VM as needed. (flutter/engine#7832) 256db4b Android embedding refactor pr3 add remaining systemchannels (flutter/engine#7738) 02d7ca3 Don't call static method from instance variable (flutter/engine#7841) 10cee61 Delete GL textures when they are released from the texture registry. (flutter/engine#7836) 69e4606 Fix NullPointerException in SurfaceTextureRegistryEntry (flutter/engine#7837) 9a965bc Fix NullPointerException in ResourceCleaner (flutter/engine#7838) 2acd794 Add fml::FileExists implementation for Windows (flutter/engine#7845) fa38a98 Update buildroot to 7f64ff4928e to unblock Mac builds. (flutter/engine#7846) 1ba3295 Add support for calling into other plugins from a background context on iOS (flutter/engine#7843) df2fc97 Roll src/third_party/skia 154acd7a1374..be9aff25bddc (13 commits) (flutter/engine#7842) 0ca1d1f Remove the Dart JIT snapshot data from AOT builds of the embedder library (flutter/engine#7806) c51ea41 Roll src/third_party/skia 7a74c7cb6da0..154acd7a1374 (1 commits) (flutter/engine#7840) ecbaea1 Ensure to pass dill file after VM options for gen_snapshot (flutter/engine#7839) 5d3f714 Roll src/third_party/skia b00f7b34751b..7a74c7cb6da0 (1 commits) (flutter/engine#7835) 7337399 Roll src/third_party/skia 9a88bee122f1..b00f7b34751b (24 commits) (flutter/engine#7831) 6f318ef Move up ndk version that is being downloaded(old one no longer available) (flutter/engine#7830) a8aa1ee Track flow id (flutter/engine#7826) b1ce6b7 Roll src/third_party/skia a0dcd29f536b..9a88bee122f1 (4 commits) (flutter/engine#7825) dbc1663 Roll src/third_party/skia 6152470dc69e..a0dcd29f536b (2 commits) (flutter/engine#7824) 9426776 Roll src/third_party/skia 4037f7f5d8b4..6152470dc69e (1 commits) (flutter/engine#7823) e2394ad Add flow events connecting pointer events to frames (flutter/engine#7807) 0a5a7c5 Roll src/third_party/skia 09c01e9df260..4037f7f5d8b4 (3 commits) (flutter/engine#7821) b867f48 Roll src/third_party/skia 186669c4128b..09c01e9df260 (5 commits) (flutter/engine#7820) af39e22 Fix tests that were committed after cirrus ran (flutter/engine#7819) 1f2cbf7 Roll src/third_party/dart 0a7dcf17eb..c92d5ca288 (64 commits) The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md If the roll is causing failures, please contact the current sheriff (liyuqian@google.com), and stop the roller if necessary.
This reverts commit 572fea3.
The shell was already designed to cleanly shut down the VM but it couldnt
earlier as |Dart_Initialize| could never be called after a |Dart_Cleanup|. This
meant that shutting down an engine instance could not shut down the VM to save
memory because newly created engines in the process after that point couldn't
restart the VM. There can only be one VM running in a process at a time.
This patch separate the previous DartVM object into one that references a
running instance of the DartVM and a set of immutable dependencies that
components can reference even as the VM is shutting down.
Unit tests have been added to assert that non-overlapping engine launches use
difference VM instances.