Skip to content

Commit

Permalink
Fix starting isolate directly from CoreJIT snapshot. (flutter#5798)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaranov authored Jul 19, 2018
1 parent 09ff949 commit 5d0e13a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
9 changes: 2 additions & 7 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ bool DartIsolate::PrepareForRunningFromPrecompiledCode() {
return false;
}

if (!DartVM::IsRunningPrecompiledCode()) {
return false;
}

tonic::DartState::Scope scope(this);

if (Dart_IsNull(Dart_RootLibrary())) {
Expand Down Expand Up @@ -342,9 +338,8 @@ bool DartIsolate::PrepareForRunningFromSnapshot(

tonic::DartState::Scope scope(this);

if (!Dart_IsNull(Dart_RootLibrary())) {
return false;
}
// Use root library provided by kernel in favor of one provided by snapshot.
Dart_SetRootLibrary(Dart_Null());

if (!LoadSnapshot(mapping, last_piece)) {
return false;
Expand Down
15 changes: 6 additions & 9 deletions shell/common/isolate_configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@ bool IsolateConfiguration::PrepareIsolate(
return DoPrepareIsolate(*isolate);
}

class PrecompiledIsolateConfiguration final : public IsolateConfiguration {
class AppSnapshotIsolateConfiguration final : public IsolateConfiguration {
public:
PrecompiledIsolateConfiguration() = default;
AppSnapshotIsolateConfiguration() = default;

// |shell::IsolateConfiguration|
bool DoPrepareIsolate(blink::DartIsolate& isolate) override {
if (!blink::DartVM::IsRunningPrecompiledCode()) {
return false;
}
return isolate.PrepareForRunningFromPrecompiledCode();
}

private:
FXL_DISALLOW_COPY_AND_ASSIGN(PrecompiledIsolateConfiguration);
FXL_DISALLOW_COPY_AND_ASSIGN(AppSnapshotIsolateConfiguration);
};

class SnapshotIsolateConfiguration : public IsolateConfiguration {
Expand Down Expand Up @@ -122,7 +119,7 @@ std::unique_ptr<IsolateConfiguration> IsolateConfiguration::InferFromSettings(
fml::RefPtr<blink::AssetManager> asset_manager) {
// Running in AOT mode.
if (blink::DartVM::IsRunningPrecompiledCode()) {
return CreateForPrecompiledCode();
return CreateForAppSnapshot();
}

// Run from sources.
Expand Down Expand Up @@ -193,8 +190,8 @@ std::unique_ptr<IsolateConfiguration> IsolateConfiguration::InferFromSettings(
}

std::unique_ptr<IsolateConfiguration>
IsolateConfiguration::CreateForPrecompiledCode() {
return std::make_unique<PrecompiledIsolateConfiguration>();
IsolateConfiguration::CreateForAppSnapshot() {
return std::make_unique<AppSnapshotIsolateConfiguration>();
}

std::unique_ptr<IsolateConfiguration> IsolateConfiguration::CreateForSnapshot(
Expand Down
2 changes: 1 addition & 1 deletion shell/common/isolate_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IsolateConfiguration {
const blink::Settings& settings,
fml::RefPtr<blink::AssetManager> asset_manager);

static std::unique_ptr<IsolateConfiguration> CreateForPrecompiledCode();
static std::unique_ptr<IsolateConfiguration> CreateForAppSnapshot();

static std::unique_ptr<IsolateConfiguration> CreateForSnapshot(
std::unique_ptr<fml::Mapping> snapshot);
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/android/platform_view_android_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static void SurfaceDestroyed(JNIEnv* env, jobject jcaller, jlong shell_holder) {
std::unique_ptr<IsolateConfiguration> CreateIsolateConfiguration(
const blink::AssetManager& asset_manager) {
if (blink::DartVM::IsRunningPrecompiledCode()) {
return IsolateConfiguration::CreateForPrecompiledCode();
return IsolateConfiguration::CreateForAppSnapshot();
}

const auto configuration_from_blob =
Expand All @@ -200,7 +200,8 @@ std::unique_ptr<IsolateConfiguration> CreateIsolateConfiguration(
return script;
}

return nullptr;
// This happens when starting isolate directly from CoreJIT snapshot.
return IsolateConfiguration::CreateForAppSnapshot();
}

static void RunBundleAndSnapshot(
Expand Down

0 comments on commit 5d0e13a

Please sign in to comment.