Generate an app snapshot even if the training run does a hard exit.

(As the analyzer and pub do.)

R=asiva@google.com

Review URL: https://codereview.chromium.org/2426843002 .
This commit is contained in:
Ryan Macnak 2016-10-19 09:37:47 -07:00
parent 8a909671e6
commit 5ee94eb837
3 changed files with 32 additions and 1 deletions

View file

@ -16,6 +16,8 @@ namespace bin {
class EventHandler;
class Loader;
typedef void (*ExitHook)(int64_t exit_code);
// Data associated with every isolate in the standalone VM
// embedding. This is used to free external resources for each isolate
// when the isolate shuts down.
@ -29,7 +31,8 @@ class IsolateData {
packages_file(NULL),
udp_receive_buffer(NULL),
builtin_lib_(NULL),
loader_(NULL) {
loader_(NULL),
exit_hook_(NULL) {
if (package_root != NULL) {
ASSERT(packages_file == NULL);
this->package_root = strdup(package_root);
@ -64,6 +67,9 @@ class IsolateData {
builtin_lib_ = Dart_NewPersistentHandle(lib);
}
ExitHook exit_hook() const { return exit_hook_; }
void set_exit_hook(ExitHook hook) { exit_hook_ = hook; }
char* script_url;
char* package_root;
char* packages_file;
@ -83,6 +89,7 @@ class IsolateData {
private:
Dart_Handle builtin_lib_;
Loader* loader_;
ExitHook exit_hook_;
DISALLOW_COPY_AND_ASSIGN(IsolateData);
};

View file

@ -775,6 +775,9 @@ static Dart_Handle EnvironmentCallback(Dart_Handle name) {
} \
static void SnapshotOnExitHook(int64_t exit_code);
// Returns true on success, false on failure.
static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
const char* main,
@ -801,6 +804,10 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
IsolateData* isolate_data = new IsolateData(script_uri,
package_root,
packages_config);
if ((gen_snapshot_kind == kAppAfterRun) ||
(gen_snapshot_kind == kAppJITAfterRun)) {
isolate_data->set_exit_hook(SnapshotOnExitHook);
}
Dart_Isolate isolate = Dart_CreateIsolate(script_uri,
main,
isolate_snapshot_buffer,
@ -1521,6 +1528,18 @@ static void GenerateFullSnapshot() {
}
static void SnapshotOnExitHook(int64_t exit_code) {
if (exit_code == 0) {
if (gen_snapshot_kind == kAppAfterRun) {
GenerateFullSnapshot();
} else {
Dart_PrecompileJIT();
GeneratePrecompiledJITSnapshot();
}
}
}
bool RunMainIsolate(const char* script_name,
CommandLineOptions* dart_options) {
// Call CreateIsolateAndSetup which creates an isolate and loads up

View file

@ -246,6 +246,11 @@ void FUNCTION_NAME(Process_Exit)(Dart_NativeArguments args) {
int64_t status = 0;
// Ignore result if passing invalid argument and just exit 0.
DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
IsolateData* isolate_data =
reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData());
if (isolate_data->exit_hook() != NULL) {
isolate_data->exit_hook()(status);
}
Dart_ExitIsolate();
Platform::Exit(static_cast<int>(status));
}