5#include "flutter/runtime/dart_vm.h"
12#include "flutter/common/settings.h"
13#include "flutter/fml/compiler_specific.h"
14#include "flutter/fml/cpu_affinity.h"
15#include "flutter/fml/logging.h"
16#include "flutter/fml/mapping.h"
17#include "flutter/fml/size.h"
18#include "flutter/fml/time/time_delta.h"
19#include "flutter/fml/trace_event.h"
20#include "flutter/lib/ui/dart_ui.h"
21#include "flutter/runtime/dart_isolate.h"
22#include "flutter/runtime/dart_vm_initializer.h"
23#include "flutter/runtime/ptrace_check.h"
24#include "third_party/dart/runtime/include/bin/dart_io_api.h"
34namespace observatory {
36#if !OS_FUCHSIA && !FLUTTER_RELEASE
55 "--enable_mirrors=false",
56 "--background_compilation",
66 "--concurrent_mark=false",
67 "--concurrent_sweep=false",
68 "--compactor_tasks=1",
69 "--scavenger_tasks=0",
76 "--no_write_protect_code",
81 "--no_use_integer_division",
91 "--pause_isolates_on_start",
95 "--timeline_recorder=endless",
99 "--timeline_recorder=systrace",
103 std::ostringstream oss;
104 oss <<
"--timeline_recorder=perfettofile:" <<
path;
110 "--timeline_streams=Dart,Embedder,GC",
114 "--timeline_streams=Compiler,Dart,Debugger,Embedder,GC,Isolate,VM,API",
118 "--timeline_streams=Compiler,Dart,Debugger,Embedder,GC,Isolate,VM,API",
122 std::ostringstream oss;
123 oss <<
"--old_gen_heap_size=" << heap_size;
144 if (!
info.st_mtime) {
158 return mtime > since;
170 if (mapping.GetSize() == 0 || mapping.GetMapping() ==
nullptr) {
214 enable_profiling =
false;
220 if (enable_profiling) {
227#if FML_OS_IOS && FML_ARCH_CPU_ARM_FAMILY && FML_ARCH_CPU_ARMEL
235 "--profile_period=2000",
237 "--profile_period=1000",
241 return {
"--no-profiler"};
248 for (
size_t i = 0;
i < argc; ++
i) {
256 info->name =
"Flutter";
263 std::shared_ptr<IsolateNameServer> isolate_name_server) {
265 std::move(vm_snapshot),
266 std::move(isolate_snapshot)
270 FML_LOG(
ERROR) <<
"Could not set up VM data to bootstrap the VM from.";
275 return std::shared_ptr<DartVM>(
276 new DartVM(vm_data, std::move(isolate_name_server)));
289DartVM::DartVM(
const std::shared_ptr<const DartVMData>& vm_data,
290 std::shared_ptr<IsolateNameServer> isolate_name_server)
292 concurrent_message_loop_(
fml::ConcurrentMessageLoop::
Create(
294 std::thread::hardware_concurrency()) /
298 skia_concurrent_executor_(
299 [runner = concurrent_message_loop_->GetTaskRunner()](
300 const
fml::
closure& work) { runner->PostTask(work); }),
302 isolate_name_server_(std::move(isolate_name_server)),
303 service_protocol_(std::make_shared<ServiceProtocol>()) {
320 if (!
settings_.temp_directory_path.empty()) {
325 std::vector<const char*>
args;
331 args.push_back(
"--ignore-unrecognized-flags");
333 for (
auto*
const profiler_flag :
335 args.push_back(profiler_flag);
340 if (IsRunningPrecompiledCode()) {
347 bool enable_asserts = !
settings_.disable_dart_asserts;
350 if (IsRunningPrecompiledCode()) {
351 enable_asserts =
false;
355#if (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
356#if !FML_OS_IOS && !FML_OS_MACOSX
367 <<
"Tracing not enabled before attempting to run JIT mode VM.";
379 if (enable_asserts) {
408 std::string file_recorder_args;
411 args.push_back(file_recorder_args.c_str());
421#if defined(OS_FUCHSIA)
433 std::string old_gen_heap_size_args;
435 old_gen_heap_size_args =
437 args.push_back(old_gen_heap_size_args.c_str());
440 for (
size_t i = 0;
i <
settings_.dart_flags.size();
i++) {
446 FML_LOG(
FATAL) <<
"Error while setting Dart VM flags: " << flags_error;
456 params.vm_snapshot_data = vm_data_->GetVMSnapshot().GetDataMapping();
457 params.vm_snapshot_instructions =
458 vm_data_->GetVMSnapshot().GetInstructionsMapping();
459 params.create_group =
reinterpret_cast<decltype(
params.create_group)
>(
460 DartIsolate::DartIsolateGroupCreateCallback);
461 params.initialize_isolate =
462 reinterpret_cast<decltype(
params.initialize_isolate)
>(
463 DartIsolate::DartIsolateInitializeCallback);
465 reinterpret_cast<decltype(
params.shutdown_isolate)
>(
466 DartIsolate::DartIsolateShutdownCallback);
467 params.cleanup_isolate =
reinterpret_cast<decltype(
params.cleanup_isolate)
>(
468 DartIsolate::DartIsolateCleanupCallback);
469 params.cleanup_group =
reinterpret_cast<decltype(
params.cleanup_group)
>(
470 DartIsolate::DartIsolateGroupCleanupCallback);
509 if (
settings_.dart_library_sources_kernel !=
nullptr) {
510 std::unique_ptr<fml::Mapping> dart_library_sources =
514 dart_library_sources->GetSize());
518 concurrent_message_loop_->PostTaskToAllWorkers(
536std::shared_ptr<const DartVMData> DartVM::GetVMData()
const {
544std::shared_ptr<ServiceProtocol> DartVM::GetServiceProtocol()
const {
545 return service_protocol_;
548std::shared_ptr<IsolateNameServer> DartVM::GetIsolateNameServer()
const {
549 return isolate_name_server_;
552std::shared_ptr<fml::ConcurrentTaskRunner>
553DartVM::GetConcurrentWorkerTaskRunner()
const {
554 return concurrent_message_loop_->GetTaskRunner();
557std::shared_ptr<fml::ConcurrentMessageLoop> DartVM::GetConcurrentMessageLoop() {
558 return concurrent_message_loop_;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static sk_sp< Effect > Create()
static unsigned clamp(SkFixed fx, int max)
static void Initialize(Dart_InitializeParams *params, bool enable_timeline_event_handler, bool trace_systrace)
static void SetDefault(SkExecutor *)
static std::shared_ptr< const DartVMData > Create(const Settings &settings, fml::RefPtr< const DartSnapshot > vm_snapshot, fml::RefPtr< const DartSnapshot > isolate_snapshot)
Creates a new instance of DartVMData. Both the VM and isolate snapshot members are optional and may b...
static size_t GetVMLaunchCount()
The number of times the VM has been launched in the process. This call is inherently racy because the...
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
static constexpr TimeDelta FromSeconds(int64_t seconds)
static constexpr TimeDelta FromMilliseconds(int64_t millis)
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION
struct _Dart_Handle * Dart_Handle
DART_EXPORT bool Dart_IsPrecompiledRuntime(void)
DART_EXPORT Dart_Isolate Dart_CurrentIsolate(void)
DART_EXPORT void Dart_SetDartLibrarySourcesKernel(const uint8_t *platform_kernel, const intptr_t platform_kernel_size)
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_SetVMFlags(int argc, const char **argv)
DART_EXPORT void Dart_ExitIsolate(void)
const EmbeddedViewParams * params
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define FML_ALLOW_UNUSED_TYPE
#define FML_LOG(severity)
#define FML_CHECK(condition)
#define FML_DCHECK(condition)
void SetExecutableName(const char *executable_name)
void WriteFile(const void *buffer, intptr_t num_bytes, void *stream)
void ReadFile(uint8_t **data, intptr_t *file_len, void *stream)
void GetIOEmbedderInformation(Dart_EmbedderInformation *info)
void SetCaptureStdout(bool value)
void CloseFile(void *stream)
void SetCaptureStderr(bool value)
bool GetEntropy(uint8_t *buffer, intptr_t length)
void * OpenFile(const char *name, bool write)
void SetSystemTempDirectory(const char *system_temp)
const uint8_t * observatory_assets_archive
unsigned int observatory_assets_archive_len
void ThreadExitCallback()
static const char kStderrStreamId[]
static constexpr size_t kMaxCount
Dart_Handle GetVMServiceAssetsArchiveCallback()
static const char * kDartPrecompilationArgs[]
static const char * kSerialGCArgs[]
static std::string DartFileRecorderArgs(const std::string &path)
constexpr size_t kFileUriPrefixLength
void PushBackAll(std::vector< const char * > *args, const char **argv, size_t argc)
static std::string DartOldGenHeapSizeArgs(uint64_t heap_size)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
static const char * kDartAllConfigsArgs[]
static const char * kDartStartPausedArgs[]
static void EmbedderInformationCallback(Dart_EmbedderInformation *info)
static const char * kDartStartupTraceStreamsArgs[]
static void ServiceStreamCancelCallback(const char *stream_id)
static FML_ALLOW_UNUSED_TYPE const char * kDartWriteProtectCodeArgs[]
static constexpr size_t kMinCount
constexpr char kFileUriPrefix[]
static const char * kDartEndlessTraceBufferArgs[]
static const char * kDartAssertArgs[]
bool EnableTracingIfNecessary(const Settings &vm_settings)
Enables tracing in the process so that JIT mode VMs may be launched. Explicitly enabling tracing is n...
static const char * kDartSystraceTraceBufferArgs[]
static std::atomic_size_t gVMLaunchCount
static const char kStdoutStreamId[]
static FML_ALLOW_UNUSED_TYPE const char * kDartDefaultTraceStreamsArgs[]
static const char * kDartSystraceTraceStreamsArgs[]
bool DartFileModifiedCallback(const char *source_url, int64_t since_ms)
static bool ServiceStreamListenCallback(const char *stream_id)
static std::vector< const char * > ProfilingFlags(bool enable_profiling)
static FML_ALLOW_UNUSED_TYPE const char * kDartDisableIntegerDivisionArgs[]
constexpr std::size_t size(T(&array)[N])
std::optional< size_t > EfficiencyCoreCount()
Request count of efficiency cores.
std::function< void()> closure
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Dart_Handle ToDart(const T &object)
#define TRACE_EVENT0(category_group, name)