Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dart_vm_data.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/runtime/dart_vm_data.h"
6
7#include <utility>
8
9namespace flutter {
10
11std::shared_ptr<const DartVMData> DartVMData::Create(
12 const Settings& settings,
14 fml::RefPtr<const DartSnapshot> isolate_snapshot) {
15 if (!vm_snapshot || !vm_snapshot->IsValid()) {
16 // Caller did not provide a valid VM snapshot. Attempt to infer one
17 // from the settings.
18 vm_snapshot = DartSnapshot::VMSnapshotFromSettings(settings);
19 if (!vm_snapshot) {
21 << "VM snapshot invalid and could not be inferred from settings.";
22 return {};
23 }
24 }
25
26 if (!isolate_snapshot || !isolate_snapshot->IsValid()) {
27 // Caller did not provide a valid isolate snapshot. Attempt to infer one
28 // from the settings.
29 isolate_snapshot = DartSnapshot::IsolateSnapshotFromSettings(settings);
30 if (!isolate_snapshot) {
31 FML_LOG(ERROR) << "Isolate snapshot invalid and could not be inferred "
32 "from settings.";
33 return {};
34 }
35 }
36
37 fml::RefPtr<const DartSnapshot> service_isolate_snapshot =
39
40 return std::shared_ptr<const DartVMData>(new DartVMData(
41 settings, //
42 std::move(vm_snapshot), //
43 std::move(isolate_snapshot), //
44 std::move(service_isolate_snapshot) //
45 ));
46}
47
48DartVMData::DartVMData(const Settings& settings,
50 fml::RefPtr<const DartSnapshot> isolate_snapshot,
51 fml::RefPtr<const DartSnapshot> service_isolate_snapshot)
52 : settings_(settings),
53 vm_snapshot_(std::move(vm_snapshot)),
54 isolate_snapshot_(std::move(isolate_snapshot)),
55 service_isolate_snapshot_(std::move(service_isolate_snapshot)) {}
56
57DartVMData::~DartVMData() = default;
58
60 return settings_;
61}
62
64 return *vm_snapshot_;
65}
66
68 return isolate_snapshot_;
69}
70
72 // Use the specialized snapshot for the service isolate if the embedder
73 // provides one. Otherwise, use the application snapshot.
74 return service_isolate_snapshot_ ? service_isolate_snapshot_
75 : isolate_snapshot_;
76}
77
79 if (service_isolate_snapshot_) {
80 // The specialized snapshot for the service isolate is always built
81 // using null safety. However, calling Dart_DetectNullSafety on
82 // the service isolate snapshot will not work as expected - it will
83 // instead return a cached value representing the app snapshot.
84 return true;
85 } else {
86 return isolate_snapshot_->IsNullSafetyEnabled(nullptr);
87 }
88}
89
90} // namespace flutter
A read-only Dart heap snapshot, or, read-executable mapping of AOT compiled Dart code.
static fml::RefPtr< DartSnapshot > VMServiceIsolateSnapshotFromSettings(const Settings &settings)
Create an isolate snapshot specialized for launching the service isolate. Returns nullptr if no such ...
static fml::RefPtr< const DartSnapshot > VMSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the core snapshot.
static fml::RefPtr< const DartSnapshot > IsolateSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the isolate snapshot.
Provides thread-safe access to data that is necessary to bootstrap a new Dart VM instance....
fml::RefPtr< const DartSnapshot > GetIsolateSnapshot() const
Get the isolate snapshot necessary to launch isolates in the Dart VM. The Dart VM instance in which t...
const DartSnapshot & GetVMSnapshot() const
Gets the VM snapshot. This can be in the call to bootstrap the Dart VM via Dart_Initialize.
~DartVMData()
Collect the DartVMData instance.
bool GetServiceIsolateSnapshotNullSafety() const
Returns whether the service isolate snapshot requires null safety in the Dart_IsolateFlags used to cr...
const Settings & GetSettings() const
The settings object from which the Dart snapshots were inferred.
fml::RefPtr< const DartSnapshot > GetServiceIsolateSnapshot() const
Get the isolate snapshot used to launch the service isolate in the Dart VM.
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...
Settings settings_
#define FML_LOG(severity)
Definition logging.h:82
Definition ref_ptr.h:256
#define ERROR(message)