Siva 11b6afe00c
Roll src/third_party/dart 67ab3be10d...b5aeaa6796 (#9675)
* Roll src/third_party/dart 67ab3be10d...b5aeaa6796

dart-lang/sdk@b5aeaa6796 Revert "Reland "[vm/ffi] SimDBC on Arm64 Android""
dart-lang/sdk@02fe07bbd3 [dart2js] new-rti: Set Array instance type
dart-lang/sdk@bae5bdefd5 [dart2js] Add '--golem-x' command-line flag
dart-lang/sdk@ac30ab12ab [dartdevc] Bump pedantic to v1.8.0 and apply new lints
dart-lang/sdk@4b0c5c166a fix field name
dart-lang/sdk@327f5eb826 Fix for issue 37429
dart-lang/sdk@43891316ca [ VM / Observatory ] Emit IsolateReload event after reload completes
dart-lang/sdk@2ea7e5513b Perform type promotion when NNBD, using flow analysis.
dart-lang/sdk@766e542e53 handle return in async function
dart-lang/sdk@51cf8f218a Add entension support to the summary idl
dart-lang/sdk@0e9957c7b1 [dartdevc] Adding support for analyzer dep pruning
dart-lang/sdk@c100308ba6 Repro for inferring arrays with out of range lengths
dart-lang/sdk@5d77657e7a Prepare to publish analyzer version 0.37.0.
dart-lang/sdk@86ce74caaa update NodeBuilder for default value type arguments
dart-lang/sdk@439692c9e2 Mark the name in an extension as being in a declaration context
dart-lang/sdk@372bcae536 [gardening] Fix 3xHEAD Flutter build after revert
dart-lang/sdk@052874e93e Avoid non-web integer literal in corelib_2/int_round_test
dart-lang/sdk@480337106e Implementation of extension override AST node
dart-lang/sdk@4f78ad90df An initial and partial implementation of an element model for extensions
dart-lang/sdk@744bb47361 [infra] Remove custom timeouts for dart2js compiler config
dart-lang/sdk@9b53686ffb update NodeBuilder for declared identifier implicit type
dart-lang/sdk@3d14b75f97 Revert "Reland "[vm/concurrency] Introduce concept of Isolate Groups""
dart-lang/sdk@527238e008 [vm] Cleanup C99 header includes
dart-lang/sdk@9f32f9b87e [cfe] Store the initializer tokens in constructor builders
dart-lang/sdk@bbbeb8b509 Pull in latest pub
dart-lang/sdk@851958ee54 update NodeBuilder to handle for loop
dart-lang/sdk@7a73682c6a update NodeBuilder to handle catch clause
dart-lang/sdk@fc6cb0ac21 [vm/ffi] Revamp struct representation in FFI.
dart-lang/sdk@5fd51b9fd2 Cleanup remnants of ignoring Dart v1.x subtype checks
dart-lang/sdk@45172f0690 Revert "Reland "[llvm] Add initial scaffolding""
dart-lang/sdk@b9a6630367 [ Observatory ] _getVMTimeline -> getVMTimeline in timeline.js
dart-lang/sdk@1f02c10b9a Update language_2/const_map4_test for type inference
dart-lang/sdk@99ed4871b3 Fix a hint in analysis server
dart-lang/sdk@c3c43689d5 [vm] Remove platform/math.h
dart-lang/sdk@524fdc13a9 Reland "[llvm] Add initial scaffolding"
dart-lang/sdk@45a9815aff [vm/debugger] break on asyncfunction entry
dart-lang/sdk@e0eeffaf9b update NodeBuilder parameter tracking when visiting executable declarations
dart-lang/sdk@182a59cebb Skip all tests that use spawnUri when running in simulator mode as it makes no sense to run the CFE on the simulator.
dart-lang/sdk@1427a218f3 update DecoratedType asserts
dart-lang/sdk@f4dc001729 Migration: begin adding support for LUB computations in conditional expressions.
dart-lang/sdk@585794ab75 Fix status file line.
dart-lang/sdk@4a69ef4a50 Skip all spawnURI tests for the simulator architectures as these tests involve invoking the front end for compilation which would mean the front end has to run in simulated mode.
dart-lang/sdk@26f369eb8e Fix doc comment for NullabilityNode.forLUB
dart-lang/sdk@9ed728ec7a Add: Example usage to fillRange method.
dart-lang/sdk@fc7049ae7d Migration: implement support for user-definable prefix expressions.
dart-lang/sdk@77aa5f0c02 Migration: Add support for function-typed formal parameters.
dart-lang/sdk@326e970b81 Migration: handle method invocations that resolve to a getter.
dart-lang/sdk@822de210b5 fix branch_canonicalization_test
dart-lang/sdk@a2e1434603 Breaking changes for analyzer version 0.37
dart-lang/sdk@6694aa821d [dart2js] new-rti: Temporary work-around for timeouts
dart-lang/sdk@18ff5ce893 [dart2js] new-rti: Implement general As/Check methods
dart-lang/sdk@90c88d984e Fix large integer literals in dart2js_extra/round_constant_folding_test
dart-lang/sdk@9349f71721 bump linter to 0.1.93
dart-lang/sdk@c384212f9e [vm] Remove vestigial verified_memory_test.cc file
dart-lang/sdk@f4824d332d [vm] Drop support for MSVC older than 2013
dart-lang/sdk@bbb027aa2a [vm] Fix offset that was breaking bare_instructions_trampolines_test
dart-lang/sdk@1db0b4436c [dart2js] new-rti: Implement type bounds check
dart-lang/sdk@686742585a Migration: add a more robust assertion to the DecoratedType constructor
dart-lang/sdk@2fd4ca570b set DecoratedType.returnType for FunctionType
dart-lang/sdk@ca4b6e533a [dart2js] new-rti: Implement basic is-test
dart-lang/sdk@39b71253ce Fix for curly_braces_in_flow_control_structures lint.
dart-lang/sdk@b6c3b2c98c Enable 'Surround with XYZ' only for Statement(s) in Block(s).
dart-lang/sdk@79e478e50e Fixed some links
dart-lang/sdk@279c1da42d Use absolute paths as canonical paths for inputs digest maps
dart-lang/sdk@cbf9cff19f Infer types of field formals before all fields.
dart-lang/sdk@0c6b3d1277 Migration: do better function type formatting in DecoratedType.toString.
dart-lang/sdk@a76c459239 Migration: Remove unnecessary duplicate type test
dart-lang/sdk@a515a0c256 Reland "[vm/ffi] SimDBC on Arm64 Android"
dart-lang/sdk@0baf81e7d6 Tests for Never and potential nullable / non-nullable.
dart-lang/sdk@26d308aad3 Use flow analysis for reporting use sites of not assigned locals during resolution.
dart-lang/sdk@79f276e07d Migration: handle field formal parameters.
dart-lang/sdk@c8c3572ca9 Migration: standardize method names in EdgeBuilderTest.
dart-lang/sdk@c0c15c1283 Migration: build nullability node for default type parameter bounds directly.
dart-lang/sdk@b57ff85906 Migration: clean up and test implicit dynamic return type of Function() syntax.
dart-lang/sdk@0f2eda8644 Migration: add support for function expression invocations.
dart-lang/sdk@a200980da0 Migration: add support for variable and field type inference.
dart-lang/sdk@ca25f56883 Migration: add support for type inference of function types.
dart-lang/sdk@a436c0621f Migration: fix DecoratedType.toString to support named function parameters.
dart-lang/sdk@9dee307bdb Migration: update nullability graph debug dump to support union edges.
dart-lang/sdk@b60dcdbf73 Migration: Remove the `create` parameter from Variables.decoratedElementType.
dart-lang/sdk@18c21ee9d1 Migration: add support for generic instance creation.
dart-lang/sdk@f7ddfdf6ca Migration: don't forget to visit variable initializers in NodeBuilder.
dart-lang/sdk@a39e4fabfb Add information about the deprecated ParameterElement.parameterKind
dart-lang/sdk@f6dfad02f4 [analyzer] add a space to the quick for for REPLACE_COLON_WITH_EQUALS

* Update license.
2019-07-03 19:10:07 -07:00

455 lines
15 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/runtime/dart_vm.h"
#include <sys/stat.h>
#include <mutex>
#include <vector>
#include "flutter/common/settings.h"
#include "flutter/fml/compiler_specific.h"
#include "flutter/fml/file.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/size.h"
#include "flutter/fml/synchronization/count_down_latch.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/time/time_delta.h"
#include "flutter/fml/trace_event.h"
#include "flutter/lib/io/dart_io.h"
#include "flutter/lib/ui/dart_runtime_hooks.h"
#include "flutter/lib/ui/dart_ui.h"
#include "flutter/runtime/dart_isolate.h"
#include "flutter/runtime/dart_service_isolate.h"
#include "flutter/runtime/start_up.h"
#include "third_party/dart/runtime/include/bin/dart_io_api.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/dart_class_library.h"
#include "third_party/tonic/dart_class_provider.h"
#include "third_party/tonic/file_loader/file_loader.h"
#include "third_party/tonic/logging/dart_error.h"
#include "third_party/tonic/scopes/dart_api_scope.h"
#include "third_party/tonic/typed_data/typed_list.h"
namespace dart {
namespace observatory {
#if !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_RELEASE)
// These two symbols are defined in |observatory_archive.cc| which is generated
// by the |//third_party/dart/runtime/observatory:archive_observatory| rule.
// Both of these symbols will be part of the data segment and therefore are read
// only.
extern unsigned int observatory_assets_archive_len;
extern const uint8_t* observatory_assets_archive;
#endif // !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE !=
// FLUTTER_RUNTIME_MODE_RELEASE)
} // namespace observatory
} // namespace dart
namespace flutter {
// Arguments passed to the Dart VM in all configurations.
static const char* kDartLanguageArgs[] = {
// clang-format off
"--enable_mirrors=false",
"--background_compilation",
"--causal_async_stacks",
// clang-format on
};
static const char* kDartPrecompilationArgs[] = {
"--precompilation",
};
FML_ALLOW_UNUSED_TYPE
static const char* kDartWriteProtectCodeArgs[] = {
"--no_write_protect_code",
};
static const char* kDartAssertArgs[] = {
// clang-format off
"--enable_asserts",
// clang-format on
};
static const char* kDartStartPausedArgs[]{
"--pause_isolates_on_start",
};
static const char* kDartDisableServiceAuthCodesArgs[]{
"--disable-service-auth-codes",
};
static const char* kDartTraceStartupArgs[]{
"--timeline_streams=Compiler,Dart,Debugger,Embedder,GC,Isolate,VM",
};
static const char* kDartEndlessTraceBufferArgs[]{
"--timeline_recorder=endless",
};
static const char* kDartSystraceTraceBufferArgs[]{
"--timeline_recorder=systrace",
};
static const char* kDartFuchsiaTraceArgs[] FML_ALLOW_UNUSED_TYPE = {
"--systrace_timeline",
};
static const char* kDartTraceStreamsArgs[] = {
"--timeline_streams=Compiler,Dart,Debugger,Embedder,GC,Isolate,VM",
};
constexpr char kFileUriPrefix[] = "file://";
constexpr size_t kFileUriPrefixLength = sizeof(kFileUriPrefix) - 1;
bool DartFileModifiedCallback(const char* source_url, int64_t since_ms) {
if (strncmp(source_url, kFileUriPrefix, kFileUriPrefixLength) != 0u) {
// Assume modified.
return true;
}
const char* path = source_url + kFileUriPrefixLength;
struct stat info;
if (stat(path, &info) < 0)
return true;
// If st_mtime is zero, it's more likely that the file system doesn't support
// mtime than that the file was actually modified in the 1970s.
if (!info.st_mtime)
return true;
// It's very unclear what time bases we're with here. The Dart API doesn't
// document the time base for since_ms. Reading the code, the value varies by
// platform, with a typical source being something like gettimeofday.
//
// We add one to st_mtime because st_mtime has less precision than since_ms
// and we want to treat the file as modified if the since time is between
// ticks of the mtime.
fml::TimeDelta mtime = fml::TimeDelta::FromSeconds(info.st_mtime + 1);
fml::TimeDelta since = fml::TimeDelta::FromMilliseconds(since_ms);
return mtime > since;
}
void ThreadExitCallback() {}
Dart_Handle GetVMServiceAssetsArchiveCallback() {
#if (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_RELEASE)
return nullptr;
#elif OS_FUCHSIA
fml::UniqueFD fd = fml::OpenFile("pkg/data/observatory.tar", false,
fml::FilePermission::kRead);
fml::FileMapping mapping(fd, {fml::FileMapping::Protection::kRead});
if (mapping.GetSize() == 0 || mapping.GetMapping() == nullptr) {
FML_LOG(ERROR) << "Fail to load Observatory archive";
return nullptr;
}
return tonic::DartConverter<tonic::Uint8List>::ToDart(mapping.GetMapping(),
mapping.GetSize());
#else
return tonic::DartConverter<tonic::Uint8List>::ToDart(
::dart::observatory::observatory_assets_archive,
::dart::observatory::observatory_assets_archive_len);
#endif
}
static const char kStdoutStreamId[] = "Stdout";
static const char kStderrStreamId[] = "Stderr";
static bool ServiceStreamListenCallback(const char* stream_id) {
if (strcmp(stream_id, kStdoutStreamId) == 0) {
dart::bin::SetCaptureStdout(true);
return true;
} else if (strcmp(stream_id, kStderrStreamId) == 0) {
dart::bin::SetCaptureStderr(true);
return true;
}
return false;
}
static void ServiceStreamCancelCallback(const char* stream_id) {
if (strcmp(stream_id, kStdoutStreamId) == 0) {
dart::bin::SetCaptureStdout(false);
} else if (strcmp(stream_id, kStderrStreamId) == 0) {
dart::bin::SetCaptureStderr(false);
}
}
bool DartVM::IsRunningPrecompiledCode() {
return Dart_IsPrecompiledRuntime();
}
static std::vector<const char*> ProfilingFlags(bool enable_profiling) {
// Disable Dart's built in profiler when building a debug build. This
// works around a race condition that would sometimes stop a crash's
// stack trace from being printed on Android.
#ifndef NDEBUG
enable_profiling = false;
#endif
// We want to disable profiling by default because it overwhelms LLDB. But
// the VM enables the same by default. In either case, we have some profiling
// flags.
if (enable_profiling) {
return {// This is the default. But just be explicit.
"--profiler",
// This instructs the profiler to walk C++ frames, and to include
// them in the profile.
"--profile-vm"};
} else {
return {"--no-profiler"};
}
}
void PushBackAll(std::vector<const char*>* args,
const char** argv,
size_t argc) {
for (size_t i = 0; i < argc; ++i) {
args->push_back(argv[i]);
}
}
static void EmbedderInformationCallback(Dart_EmbedderInformation* info) {
info->version = DART_EMBEDDER_INFORMATION_CURRENT_VERSION;
dart::bin::GetIOEmbedderInformation(info);
info->name = "Flutter";
}
std::shared_ptr<DartVM> DartVM::Create(
Settings settings,
fml::RefPtr<DartSnapshot> vm_snapshot,
fml::RefPtr<DartSnapshot> isolate_snapshot,
fml::RefPtr<DartSnapshot> shared_snapshot,
std::shared_ptr<IsolateNameServer> isolate_name_server) {
auto vm_data = DartVMData::Create(settings, //
std::move(vm_snapshot), //
std::move(isolate_snapshot), //
std::move(shared_snapshot) //
);
if (!vm_data) {
FML_LOG(ERROR) << "Could not setup VM data to bootstrap the VM from.";
return {};
}
// Note: std::make_shared unviable due to hidden constructor.
return std::shared_ptr<DartVM>(
new DartVM(std::move(vm_data), std::move(isolate_name_server)));
}
static std::atomic_size_t gVMLaunchCount;
size_t DartVM::GetVMLaunchCount() {
return gVMLaunchCount;
}
DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
std::shared_ptr<IsolateNameServer> isolate_name_server)
: settings_(vm_data->GetSettings()),
vm_data_(vm_data),
isolate_name_server_(std::move(isolate_name_server)),
service_protocol_(std::make_shared<ServiceProtocol>()) {
TRACE_EVENT0("flutter", "DartVMInitializer");
gVMLaunchCount++;
FML_DCHECK(vm_data_);
FML_DCHECK(isolate_name_server_);
FML_DCHECK(service_protocol_);
FML_DLOG(INFO) << "Attempting Dart VM launch for mode: "
<< (IsRunningPrecompiledCode() ? "AOT" : "Interpreter");
{
TRACE_EVENT0("flutter", "dart::bin::BootstrapDartIo");
dart::bin::BootstrapDartIo();
if (!settings_.temp_directory_path.empty()) {
dart::bin::SetSystemTempDirectory(settings_.temp_directory_path.c_str());
}
}
std::vector<const char*> args;
// Instruct the VM to ignore unrecognized flags.
// There is a lot of diversity in a lot of combinations when it
// comes to the arguments the VM supports. And, if the VM comes across a flag
// it does not recognize, it exits immediately.
args.push_back("--ignore-unrecognized-flags");
for (auto* const profiler_flag :
ProfilingFlags(settings_.enable_dart_profiling)) {
args.push_back(profiler_flag);
}
PushBackAll(&args, kDartLanguageArgs, fml::size(kDartLanguageArgs));
if (IsRunningPrecompiledCode()) {
PushBackAll(&args, kDartPrecompilationArgs,
fml::size(kDartPrecompilationArgs));
}
// Enable Dart assertions if we are not running precompiled code. We run non-
// precompiled code only in the debug product mode.
bool enable_asserts = !settings_.disable_dart_asserts;
#if !OS_FUCHSIA
if (IsRunningPrecompiledCode()) {
enable_asserts = false;
}
#endif // !OS_FUCHSIA
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
// Debug mode uses the JIT, disable code page write protection to avoid
// memory page protection changes before and after every compilation.
PushBackAll(&args, kDartWriteProtectCodeArgs,
fml::size(kDartWriteProtectCodeArgs));
#endif
if (enable_asserts) {
PushBackAll(&args, kDartAssertArgs, fml::size(kDartAssertArgs));
}
if (settings_.start_paused) {
PushBackAll(&args, kDartStartPausedArgs, fml::size(kDartStartPausedArgs));
}
if (settings_.disable_service_auth_codes) {
PushBackAll(&args, kDartDisableServiceAuthCodesArgs,
fml::size(kDartDisableServiceAuthCodesArgs));
}
if (settings_.endless_trace_buffer || settings_.trace_startup) {
// If we are tracing startup, make sure the trace buffer is endless so we
// don't lose early traces.
PushBackAll(&args, kDartEndlessTraceBufferArgs,
fml::size(kDartEndlessTraceBufferArgs));
}
if (settings_.trace_systrace) {
PushBackAll(&args, kDartSystraceTraceBufferArgs,
fml::size(kDartSystraceTraceBufferArgs));
PushBackAll(&args, kDartTraceStreamsArgs, fml::size(kDartTraceStreamsArgs));
}
if (settings_.trace_startup) {
PushBackAll(&args, kDartTraceStartupArgs, fml::size(kDartTraceStartupArgs));
}
#if defined(OS_FUCHSIA)
PushBackAll(&args, kDartFuchsiaTraceArgs, fml::size(kDartFuchsiaTraceArgs));
PushBackAll(&args, kDartTraceStreamsArgs, fml::size(kDartTraceStreamsArgs));
#endif
for (size_t i = 0; i < settings_.dart_flags.size(); i++)
args.push_back(settings_.dart_flags[i].c_str());
char* flags_error = Dart_SetVMFlags(args.size(), args.data());
if (flags_error) {
FML_LOG(FATAL) << "Error while setting Dart VM flags: " << flags_error;
::free(flags_error);
}
DartUI::InitForGlobal();
{
TRACE_EVENT0("flutter", "Dart_Initialize");
Dart_InitializeParams params = {};
params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
params.vm_snapshot_data = vm_data_->GetVMSnapshot().GetDataMapping();
params.vm_snapshot_instructions =
vm_data_->GetVMSnapshot().GetInstructionsMapping();
params.create = reinterpret_cast<decltype(params.create)>(
DartIsolate::DartIsolateCreateCallback);
params.shutdown = reinterpret_cast<decltype(params.shutdown)>(
DartIsolate::DartIsolateShutdownCallback);
params.cleanup = reinterpret_cast<decltype(params.cleanup)>(
DartIsolate::DartIsolateCleanupCallback);
params.thread_exit = ThreadExitCallback;
params.get_service_assets = GetVMServiceAssetsArchiveCallback;
params.entropy_source = dart::bin::GetEntropy;
char* init_error = Dart_Initialize(&params);
if (init_error) {
FML_LOG(FATAL) << "Error while initializing the Dart VM: " << init_error;
::free(init_error);
}
// Send the earliest available timestamp in the application lifecycle to
// timeline. The difference between this timestamp and the time we render
// the very first frame gives us a good idea about Flutter's startup time.
// Use a duration event so about:tracing will consider this event when
// deciding the earliest event to use as time 0.
if (engine_main_enter_ts != 0) {
Dart_TimelineEvent("FlutterEngineMainEnter", // label
engine_main_enter_ts, // timestamp0
engine_main_enter_ts, // timestamp1_or_async_id
Dart_Timeline_Event_Duration, // event type
0, // argument_count
nullptr, // argument_names
nullptr // argument_values
);
}
}
Dart_SetFileModifiedCallback(&DartFileModifiedCallback);
// Allow streaming of stdout and stderr by the Dart vm.
Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback,
&ServiceStreamCancelCallback);
Dart_SetEmbedderInformationCallback(&EmbedderInformationCallback);
if (settings_.dart_library_sources_kernel != nullptr) {
std::unique_ptr<fml::Mapping> dart_library_sources =
settings_.dart_library_sources_kernel();
// Set sources for dart:* libraries for debugging.
Dart_SetDartLibrarySourcesKernel(dart_library_sources->GetMapping(),
dart_library_sources->GetSize());
}
FML_DLOG(INFO) << "New Dart VM instance created. Instance count: "
<< gVMLaunchCount;
}
DartVM::~DartVM() {
if (Dart_CurrentIsolate() != nullptr) {
Dart_ExitIsolate();
}
char* result = Dart_Cleanup();
dart::bin::CleanupDartIo();
FML_CHECK(result == nullptr)
<< "Could not cleanly shut down the Dart VM. Error: \"" << result
<< "\".";
free(result);
FML_DLOG(INFO) << "Dart VM instance destroyed. Instance count: "
<< gVMLaunchCount;
}
std::shared_ptr<const DartVMData> DartVM::GetVMData() const {
return vm_data_;
}
const Settings& DartVM::GetSettings() const {
return settings_;
}
std::shared_ptr<ServiceProtocol> DartVM::GetServiceProtocol() const {
return service_protocol_;
}
std::shared_ptr<IsolateNameServer> DartVM::GetIsolateNameServer() const {
return isolate_name_server_;
}
} // namespace flutter