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";
259std::shared_ptr<DartVM> DartVM::Create(
260 const Settings& settings,
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)));
285DartVM::DartVM(
const std::shared_ptr<const DartVMData>& vm_data,
286 std::shared_ptr<IsolateNameServer> isolate_name_server)
288 concurrent_message_loop_(
fml::ConcurrentMessageLoop::
Create(
289 fml::EfficiencyCoreCount().value_or(
290 std::thread::hardware_concurrency()))),
291 skia_concurrent_executor_(
292 [runner = concurrent_message_loop_->GetTaskRunner()](
293 const
fml::closure& work) { runner->PostTask(work); }),
295 isolate_name_server_(std::move(isolate_name_server)),
296 service_protocol_(std::make_shared<ServiceProtocol>()) {
318 std::vector<const char*>
args;
324 args.push_back(
"--ignore-unrecognized-flags");
326 for (
auto*
const profiler_flag :
328 args.push_back(profiler_flag);
333 if (IsRunningPrecompiledCode()) {
343 if (IsRunningPrecompiledCode()) {
344 enable_asserts =
false;
348#if (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
349#if !FML_OS_IOS && !FML_OS_MACOSX
360 <<
"Tracing not enabled before attempting to run JIT mode VM.";
372 if (enable_asserts) {
401 std::string file_recorder_args;
404 args.push_back(file_recorder_args.c_str());
414#if defined(OS_FUCHSIA)
426 std::string old_gen_heap_size_args;
428 old_gen_heap_size_args =
430 args.push_back(old_gen_heap_size_args.c_str());
439 FML_LOG(
FATAL) <<
"Error while setting Dart VM flags: " << flags_error;
449 params.vm_snapshot_data = vm_data_->GetVMSnapshot().GetDataMapping();
450 params.vm_snapshot_instructions =
451 vm_data_->GetVMSnapshot().GetInstructionsMapping();
452 params.create_group =
reinterpret_cast<decltype(
params.create_group)
>(
453 DartIsolate::DartIsolateGroupCreateCallback);
454 params.initialize_isolate =
455 reinterpret_cast<decltype(
params.initialize_isolate)
>(
456 DartIsolate::DartIsolateInitializeCallback);
458 reinterpret_cast<decltype(
params.shutdown_isolate)
>(
459 DartIsolate::DartIsolateShutdownCallback);
460 params.cleanup_isolate =
reinterpret_cast<decltype(
params.cleanup_isolate)
>(
461 DartIsolate::DartIsolateCleanupCallback);
462 params.cleanup_group =
reinterpret_cast<decltype(
params.cleanup_group)
>(
463 DartIsolate::DartIsolateGroupCleanupCallback);
503 std::unique_ptr<fml::Mapping> dart_library_sources =
507 dart_library_sources->GetSize());
511 concurrent_message_loop_->PostTaskToAllWorkers(
538 return service_protocol_;
542 return isolate_name_server_;
545std::shared_ptr<fml::ConcurrentTaskRunner>
547 return concurrent_message_loop_->GetTaskRunner();
551 return concurrent_message_loop_;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static sk_sp< Effect > Create()
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...
const Settings & GetSettings() const
The settings used to launch the running VM instance.
std::shared_ptr< const DartVMData > GetVMData() const
The VM and isolate snapshots used by this running Dart VM instance.
std::shared_ptr< IsolateNameServer > GetIsolateNameServer() const
The isolate name server for this running VM instance. The isolate name server maps names (strings) to...
std::shared_ptr< fml::ConcurrentTaskRunner > GetConcurrentWorkerTaskRunner() const
The task runner whose tasks may be executed concurrently on a pool of worker threads....
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
std::shared_ptr< fml::ConcurrentMessageLoop > GetConcurrentMessageLoop()
The concurrent message loop hosts threads that are used by the engine to perform tasks long running b...
std::shared_ptr< ServiceProtocol > GetServiceProtocol() const
The service protocol instance associated with this running Dart VM instance. This object manages nati...
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[]
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[]
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])
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
bool endless_trace_buffer
std::string temp_directory_path
std::vector< std::string > dart_flags
bool enable_timeline_event_handler
std::string executable_name
std::string trace_to_file
bool disable_dart_asserts
MappingCallback dart_library_sources_kernel
int64_t old_gen_heap_size
#define TRACE_EVENT0(category_group, name)