Flutter Engine
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 namespace flutter {
8 
9 std::shared_ptr<const DartVMData> DartVMData::Create(
10  Settings settings,
11  fml::RefPtr<DartSnapshot> vm_snapshot,
12  fml::RefPtr<DartSnapshot> isolate_snapshot) {
13  if (!vm_snapshot || !vm_snapshot->IsValid()) {
14  // Caller did not provide a valid VM snapshot. Attempt to infer one
15  // from the settings.
16  vm_snapshot = DartSnapshot::VMSnapshotFromSettings(settings);
17  if (!vm_snapshot) {
18  FML_LOG(ERROR)
19  << "VM snapshot invalid and could not be inferred from settings.";
20  return {};
21  }
22  }
23 
24  if (!isolate_snapshot || !isolate_snapshot->IsValid()) {
25  // Caller did not provide a valid isolate snapshot. Attempt to infer one
26  // from the settings.
27  isolate_snapshot = DartSnapshot::IsolateSnapshotFromSettings(settings);
28  if (!isolate_snapshot) {
29  FML_LOG(ERROR) << "Isolate snapshot invalid and could not be inferred "
30  "from settings.";
31  return {};
32  }
33  }
34 
35  return std::shared_ptr<const DartVMData>(new DartVMData(
36  std::move(settings), //
37  std::move(vm_snapshot), //
38  std::move(isolate_snapshot) //
39  ));
40 }
41 
42 DartVMData::DartVMData(Settings settings,
44  fml::RefPtr<const DartSnapshot> isolate_snapshot)
45  : settings_(settings),
46  vm_snapshot_(vm_snapshot),
47  isolate_snapshot_(isolate_snapshot) {}
48 
49 DartVMData::~DartVMData() = default;
50 
52  return settings_;
53 }
54 
56  return *vm_snapshot_;
57 }
58 
60  return isolate_snapshot_;
61 }
62 
63 } // namespace flutter
const Settings & GetSettings() const
The settings object from which the Dart snapshots were inferred.
Definition: dart_vm_data.cc:51
Provides thread-safe access to data that is necessary to bootstrap a new Dart VM instance. All snapshots referenced by this object are read-only.
Definition: dart_vm_data.h:18
static fml::RefPtr< DartSnapshot > IsolateSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the isolate snapshot. ...
#define FML_LOG(severity)
Definition: logging.h:65
~DartVMData()
Collect the DartVMData instance.
static std::shared_ptr< const DartVMData > Create(Settings settings, fml::RefPtr< DartSnapshot > vm_snapshot, fml::RefPtr< DartSnapshot > isolate_snapshot)
Creates a new instance of DartVMData. Both the VM and isolate snapshot members are optional and may b...
Definition: dart_vm_data.cc:9
A read-only Dart heap snapshot, or, read-executable mapping of AOT compiled Dart code.
Definition: dart_snapshot.h:42
const DartSnapshot & GetVMSnapshot() const
Gets the VM snapshot. This can be in the call to bootstrap the Dart VM via Dart_Initialize.
Definition: dart_vm_data.cc:55
static fml::RefPtr< DartSnapshot > VMSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the core snapshot.
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...
Definition: dart_vm_data.cc:59