Skip to content

Commit

Permalink
Eliminate support for Dart 1 (flutter#5504)
Browse files Browse the repository at this point in the history
Eliminates support for running directly from sources or script snapshots. In
debug mode, we run from a kernel snapshot; in profile and release modes, we
link in AOT-compiled code.

Renames --dart-non-checked-mode to --disable-dart-asserts since checked mode
does not make sense in Dart 2.
  • Loading branch information
cbracken authored Jun 12, 2018
1 parent 036443d commit 0ea93c3
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 244 deletions.
2 changes: 0 additions & 2 deletions common/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace blink {
std::string Settings::ToString() const {
std::stringstream stream;
stream << "Settings: " << std::endl;
stream << "script_snapshot_path: " << script_snapshot_path << std::endl;
stream << "vm_snapshot_data_path: " << vm_snapshot_data_path << std::endl;
stream << "vm_snapshot_instr_path: " << vm_snapshot_instr_path << std::endl;
stream << "isolate_snapshot_data_path: " << isolate_snapshot_data_path
Expand All @@ -32,7 +31,6 @@ std::string Settings::ToString() const {
stream << "trace_startup: " << trace_startup << std::endl;
stream << "endless_trace_buffer: " << endless_trace_buffer << std::endl;
stream << "enable_dart_profiling: " << enable_dart_profiling << std::endl;
stream << "dart_non_checked_mode: " << dart_non_checked_mode << std::endl;
stream << "enable_observatory: " << enable_observatory << std::endl;
stream << "observatory_port: " << observatory_port << std::endl;
stream << "ipv6: " << ipv6 << std::endl;
Expand Down
2 changes: 0 additions & 2 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ using TaskObserverRemove = std::function<void(intptr_t /* key */)>;

struct Settings {
// VM settings
std::string script_snapshot_path;
std::string platform_kernel_path;

std::string vm_snapshot_data_path;
Expand All @@ -47,7 +46,6 @@ struct Settings {
bool trace_startup = false;
bool endless_trace_buffer = false;
bool enable_dart_profiling = false;
bool dart_non_checked_mode = false;
// Used as the script URI in debug messages. Does not affect how the Dart code
// is executed.
std::string advisory_script_uri = "main.dart";
Expand Down
33 changes: 3 additions & 30 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,9 @@ bool DartIsolate::PrepareForRunningFromPrecompiledCode() {
return true;
}

static bool LoadScriptSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
FXL_CHECK(last_piece) << "Script snapshots cannot be divided";
if (tonic::LogIfError(Dart_LoadScriptFromSnapshot(mapping->GetMapping(),
mapping->GetSize()))) {
return false;
}
return true;
}

static bool LoadKernelSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
FXL_DCHECK(Dart_IsKernel(mapping->GetMapping(), mapping->GetSize())) << "Only kernel snapshots are supported";
Dart_Handle library =
Dart_LoadLibraryFromKernel(mapping->GetMapping(), mapping->GetSize());
if (tonic::LogIfError(library)) {
Expand All @@ -307,16 +298,6 @@ static bool LoadKernelSnapshot(std::shared_ptr<const fml::Mapping> mapping,
return true;
}

static bool LoadSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
if (Dart_IsKernel(mapping->GetMapping(), mapping->GetSize())) {
return LoadKernelSnapshot(std::move(mapping), last_piece);
} else {
return LoadScriptSnapshot(std::move(mapping), last_piece);
}
return false;
}

FXL_WARN_UNUSED_RESULT
bool DartIsolate::PrepareForRunningFromSnapshot(
std::shared_ptr<const fml::Mapping> mapping,
Expand All @@ -340,7 +321,7 @@ bool DartIsolate::PrepareForRunningFromSnapshot(
return false;
}

if (!LoadSnapshot(mapping, last_piece)) {
if (!LoadKernelSnapshot(mapping, last_piece)) {
return false;
}

Expand Down Expand Up @@ -566,20 +547,12 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(
// thread.
service_isolate->ResetWeakPtrFactory();

const bool isolate_snapshot_is_dart_2 = Dart_IsDart2Snapshot(
vm->GetIsolateSnapshot()->GetData()->GetSnapshotPointer());
const bool is_preview_dart2 =
(vm->GetPlatformKernel().GetSize() > 0) || isolate_snapshot_is_dart_2;
const bool running_from_sources =
!DartVM::IsRunningPrecompiledCode() && !is_preview_dart2;

tonic::DartState::Scope scope(service_isolate);
if (!DartServiceIsolate::Startup(
settings.ipv6 ? "::1" : "127.0.0.1", // server IP address
settings.observatory_port, // server observatory port
tonic::DartState::HandleLibraryTag, // embedder library tag handler
running_from_sources, // running from source code
false, // disable websocket origin check
false, // disable websocket origin check
error // error (out)
)) {
// Error is populated by call to startup.
Expand Down
98 changes: 9 additions & 89 deletions runtime/dart_service_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
}

#define kLibrarySourceNamePrefix "/vmservice"
static const char* kServiceIsolateScript = "vmservice_io.dart";

namespace flutter {
namespace runtime {
Expand Down Expand Up @@ -84,7 +83,6 @@ void DartServiceIsolate::Shutdown(Dart_NativeArguments args) {
bool DartServiceIsolate::Startup(std::string server_ip,
intptr_t server_port,
Dart_LibraryTagHandler embedder_tag_handler,
bool running_from_sources,
bool disable_origin_check,
char** error) {
Dart_Isolate isolate = Dart_CurrentIsolate();
Expand All @@ -108,31 +106,14 @@ bool DartServiceIsolate::Startup(std::string server_ip,
&flutter::runtime::__flutter_embedded_service_isolate_resources_[0]);
}

Dart_Handle result;

if (running_from_sources) {
// Use our own library tag handler when loading service isolate sources.
Dart_SetLibraryTagHandler(DartServiceIsolate::LibraryTagHandler);
// Load main script.
Dart_Handle library = LoadScript(kServiceIsolateScript);
FXL_DCHECK(library != Dart_Null());
SHUTDOWN_ON_ERROR(library);
// Setup native entry resolution.
result = Dart_SetNativeResolver(library, GetNativeFunction, GetSymbol);

SHUTDOWN_ON_ERROR(result);
// Finalize loading.
result = Dart_FinalizeLoading(false);
SHUTDOWN_ON_ERROR(result);
} else {
Dart_Handle uri = Dart_NewStringFromCString("dart:vmservice_io");
Dart_Handle library = Dart_LookupLibrary(uri);
SHUTDOWN_ON_ERROR(library);
result = Dart_SetRootLibrary(library);
SHUTDOWN_ON_ERROR(result);
result = Dart_SetNativeResolver(library, GetNativeFunction, GetSymbol);
SHUTDOWN_ON_ERROR(result);
}
// Set the root library for the isolate.
Dart_Handle uri = Dart_NewStringFromCString("dart:vmservice_io");
Dart_Handle library = Dart_LookupLibrary(uri);
SHUTDOWN_ON_ERROR(library);
Dart_Handle result = Dart_SetRootLibrary(library);
SHUTDOWN_ON_ERROR(result);
result = Dart_SetNativeResolver(library, GetNativeFunction, GetSymbol);
SHUTDOWN_ON_ERROR(result);

// Make runnable.
Dart_ExitScope();
Expand All @@ -146,7 +127,7 @@ bool DartServiceIsolate::Startup(std::string server_ip,
Dart_EnterIsolate(isolate);
Dart_EnterScope();

Dart_Handle library = Dart_RootLibrary();
library = Dart_RootLibrary();
SHUTDOWN_ON_ERROR(library);

// Set the HTTP server's ip.
Expand Down Expand Up @@ -174,30 +155,6 @@ bool DartServiceIsolate::Startup(std::string server_ip,
return true;
}

Dart_Handle DartServiceIsolate::GetSource(const char* name) {
const intptr_t kBufferSize = 512;
char buffer[kBufferSize];
snprintf(&buffer[0], kBufferSize - 1, "%s/%s", kLibrarySourceNamePrefix,
name);
const char* vmservice_source = NULL;
int r = g_resources->ResourceLookup(buffer, &vmservice_source);
FXL_DCHECK(r != EmbedderResources::kNoSuchInstance);
return Dart_NewStringFromCString(vmservice_source);
}

Dart_Handle DartServiceIsolate::LoadScript(const char* name) {
Dart_Handle url = Dart_NewStringFromCString("dart:vmservice_io");
Dart_Handle source = GetSource(name);
return Dart_LoadScript(url, Dart_Null(), source, 0, 0);
}

Dart_Handle DartServiceIsolate::LoadSource(Dart_Handle library,
const char* name) {
Dart_Handle url = Dart_NewStringFromCString(name);
Dart_Handle source = GetSource(name);
return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0);
}

Dart_Handle DartServiceIsolate::LoadResource(Dart_Handle library,
const char* resource_name) {
// Prepare for invoke call.
Expand Down Expand Up @@ -248,41 +205,4 @@ Dart_Handle DartServiceIsolate::LoadResources(Dart_Handle library) {
return result;
}

Dart_Handle DartServiceIsolate::LibraryTagHandler(Dart_LibraryTag tag,
Dart_Handle library,
Dart_Handle url) {
if (!Dart_IsLibrary(library)) {
return Dart_NewApiError("not a library");
}
if (!Dart_IsString(url)) {
return Dart_NewApiError("url is not a string");
}
const char* url_string = NULL;
Dart_Handle result = Dart_StringToCString(url, &url_string);
if (Dart_IsError(result)) {
return result;
}
Dart_Handle library_url = Dart_LibraryUrl(library);
const char* library_url_string = NULL;
result = Dart_StringToCString(library_url, &library_url_string);
if (Dart_IsError(result)) {
return result;
}
if (tag == Dart_kImportTag) {
// Embedder handles all requests for external libraries.
return g_embedder_tag_handler(tag, library, url);
}
FXL_DCHECK((tag == Dart_kSourceTag) || (tag == Dart_kCanonicalizeUrl));
if (tag == Dart_kCanonicalizeUrl) {
// url is already canonicalized.
return url;
}
// Get source from builtin resources.
Dart_Handle source = GetSource(url_string);
if (Dart_IsError(source)) {
return source;
}
return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0);
}

} // namespace blink
9 changes: 0 additions & 9 deletions runtime/dart_service_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class DartServiceIsolate {
static bool Startup(std::string server_ip,
intptr_t server_port,
Dart_LibraryTagHandler embedder_tag_handler,
bool running_from_sources,
bool disable_origin_check,
char** error);

Expand All @@ -28,14 +27,6 @@ class DartServiceIsolate {
static void NotifyServerState(Dart_NativeArguments args);
static void Shutdown(Dart_NativeArguments args);

// Script loading.
static Dart_Handle GetSource(const char* name);
static Dart_Handle LoadScript(const char* name);
static Dart_Handle LoadSource(Dart_Handle library, const char* name);
static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag,
Dart_Handle library,
Dart_Handle url);

// Observatory resource loading.
static Dart_Handle LoadResources(Dart_Handle library);
static Dart_Handle LoadResource(Dart_Handle library, const char* name);
Expand Down
42 changes: 9 additions & 33 deletions runtime/dart_vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ static const char* kDartAssertArgs[] = {
// clang-format on
};

static const char* kDartCheckedModeArgs[] = {
// clang-format off
"--enable_type_checks",
"--error_on_bad_type",
"--error_on_bad_override",
// clang-format on
};

static const char* kDartStrongModeArgs[] = {
// clang-format off
"--strong",
Expand Down Expand Up @@ -324,18 +316,18 @@ DartVM::DartVM(const Settings& settings,
arraysize(kDartPrecompilationArgs));
}

// Enable checked mode if we are not running precompiled code. We run non-
// Enable asserts if we are not running precompiled code. We run non-
// precompiled code only in the debug product mode.
bool use_checked_mode = !settings.dart_non_checked_mode;
bool enable_asserts = true;

#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DYNAMIC_PROFILE || \
FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DYNAMIC_RELEASE
use_checked_mode = false;
enable_asserts = false;
#endif

#if !OS_FUCHSIA
if (IsRunningPrecompiledCode()) {
use_checked_mode = false;
enable_asserts = false;
}
#endif // !OS_FUCHSIA

Expand All @@ -346,29 +338,12 @@ DartVM::DartVM(const Settings& settings,
arraysize(kDartWriteProtectCodeArgs));
#endif

const bool isolate_snapshot_is_dart_2 =
Dart_IsDart2Snapshot(isolate_snapshot_->GetData()->GetSnapshotPointer());
// Require Dart 2.
FML_DCHECK(platform_kernel_mapping_->GetSize() > 0);

const bool is_preview_dart2 =
(platform_kernel_mapping_->GetSize() > 0) || isolate_snapshot_is_dart_2;

FXL_DLOG(INFO) << "Dart 2 " << (is_preview_dart2 ? "is" : "is NOT")
<< " enabled. Platform kernel: "
<< static_cast<bool>(platform_kernel_mapping_->GetSize() > 0)
<< " Isolate Snapshot is Dart 2: "
<< isolate_snapshot_is_dart_2;

if (is_preview_dart2) {
PushBackAll(&args, kDartStrongModeArgs, arraysize(kDartStrongModeArgs));
if (use_checked_mode) {
PushBackAll(&args, kDartAssertArgs, arraysize(kDartAssertArgs));
}
} else if (use_checked_mode) {
FXL_DLOG(INFO) << "Checked mode is ON";
PushBackAll(&args, kDartStrongModeArgs, arraysize(kDartStrongModeArgs));
if (enable_asserts) {
PushBackAll(&args, kDartAssertArgs, arraysize(kDartAssertArgs));
PushBackAll(&args, kDartCheckedModeArgs, arraysize(kDartCheckedModeArgs));
} else {
FXL_DLOG(INFO) << "Is not Dart 2 and Checked mode is OFF";
}

if (settings.start_paused) {
Expand All @@ -390,6 +365,7 @@ DartVM::DartVM(const Settings& settings,
PushBackAll(&args, kDartFuchsiaTraceArgs, arraysize(kDartFuchsiaTraceArgs));
#endif

// Add VM dart_flags last to allow user overrides.
for (size_t i = 0; i < settings.dart_flags.size(); i++)
args.push_back(settings.dart_flags[i].c_str());

Expand Down
11 changes: 0 additions & 11 deletions shell/common/isolate_configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,6 @@ std::unique_ptr<IsolateConfiguration> IsolateConfiguration::InferFromSettings(
}
}

// Running from script snapshot.
{
// TODO(engine): Add AssetManager::GetAsMapping or such to avoid the copy.
std::vector<uint8_t> script_snapshot;
if (asset_manager && asset_manager->GetAsBuffer(
settings.script_snapshot_path, &script_snapshot)) {
return CreateForSnapshot(
std::make_unique<fml::DataMapping>(std::move(script_snapshot)));
}
}

// Running from kernel divided into several pieces (for sharing).
{
// TODO(fuchsia): Add AssetManager::GetAsMapping or such to avoid the copy.
Expand Down
7 changes: 0 additions & 7 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ blink::Settings SettingsFromCommandLine(const fxl::CommandLine& command_line) {
}
}

// Checked mode overrides.
settings.dart_non_checked_mode =
command_line.HasOption(FlagForSwitch(Switch::DartNonCheckedMode));

settings.ipv6 = command_line.HasOption(FlagForSwitch(Switch::IPv6));

settings.start_paused =
Expand Down Expand Up @@ -161,9 +157,6 @@ blink::Settings SettingsFromCommandLine(const fxl::CommandLine& command_line) {
command_line.GetOptionValue(FlagForSwitch(Switch::FlutterAssetsDir),
&settings.assets_path);

command_line.GetOptionValue(FlagForSwitch(Switch::Snapshot),
&settings.script_snapshot_path);

command_line.GetOptionValue(FlagForSwitch(Switch::MainDartFile),
&settings.main_dart_file_path);

Expand Down
Loading

0 comments on commit 0ea93c3

Please sign in to comment.