Flutter Engine
The Flutter Engine
isolate_data.h
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_ISOLATE_DATA_H_
6#define RUNTIME_BIN_ISOLATE_DATA_H_
7
8#include <memory>
9#include <utility>
10
11#include "include/dart_api.h"
12#include "platform/assert.h"
13#include "platform/globals.h"
15#include "platform/utils.h"
16
17namespace dart {
18
19// Forward declaration.
20template <typename T>
21class MallocGrowableArray;
22
23} // namespace dart
24
25namespace dart {
26namespace bin {
27
28// Forward declaration.
29class AppSnapshot;
30class EventHandler;
31class Loader;
32
33// Data associated with every isolate group in the standalone VM
34// embedding. This is used to free external resources for each isolate
35// group when the isolate group shuts down.
37 public:
38 IsolateGroupData(const char* url,
39 const char* packages_file,
40 AppSnapshot* app_snapshot,
41 bool isolate_run_app_snapshot);
43
45
46 const std::shared_ptr<uint8_t>& kernel_buffer() const {
47 return kernel_buffer_;
48 }
49
50 intptr_t kernel_buffer_size() const { return kernel_buffer_size_; }
51
52 // Associate the given kernel buffer with this IsolateGroupData without
53 // giving it ownership of the buffer.
54 void SetKernelBufferUnowned(uint8_t* buffer, intptr_t size) {
55 ASSERT(kernel_buffer_.get() == nullptr);
56 kernel_buffer_ = std::shared_ptr<uint8_t>(buffer, FreeUnownedKernelBuffer);
57 kernel_buffer_size_ = size;
58 }
59
60 // Associate the given kernel buffer with this IsolateGroupData and give it
61 // ownership of the buffer. This IsolateGroupData is the first one to own the
62 // buffer.
63 void SetKernelBufferNewlyOwned(uint8_t* buffer, intptr_t size) {
64 ASSERT(kernel_buffer_.get() == nullptr);
65 kernel_buffer_ = std::shared_ptr<uint8_t>(buffer, free);
66 kernel_buffer_size_ = size;
67 }
68
69 // Associate the given kernel buffer with this IsolateGroupData and give it
70 // ownership of the buffer. The buffer is already owned by another
71 // IsolateGroupData.
72 void SetKernelBufferAlreadyOwned(std::shared_ptr<uint8_t> buffer,
73 intptr_t size) {
74 ASSERT(kernel_buffer_.get() == nullptr);
75 kernel_buffer_ = std::move(buffer);
76 kernel_buffer_size_ = size;
77 }
78
79 const char* resolved_packages_config() const {
80 return resolved_packages_config_;
81 }
82
83 void set_resolved_packages_config(const char* packages_config) {
84 if (resolved_packages_config_ != nullptr) {
85 free(resolved_packages_config_);
86 resolved_packages_config_ = nullptr;
87 }
88 resolved_packages_config_ = Utils::StrDup(packages_config);
89 }
90
91 bool RunFromAppSnapshot() const {
92 // If the main isolate is using an app snapshot the [app_snapshot_] pointer
93 // will be still nullptr (see main.cc:CreateIsolateGroupAndSetupHelper)
94 //
95 // Because of thus we have an additional boolean signaling whether the
96 // isolate was started from an app snapshot.
97 return app_snapshot_ != nullptr || isolate_run_app_snapshot_;
98 }
99
100 void AddLoadingUnit(AppSnapshot* loading_unit) {
101 loading_units_.Add(loading_unit);
102 }
103
104 private:
105 friend class IsolateData; // For packages_file_
106
107 std::unique_ptr<AppSnapshot> app_snapshot_;
109 char* resolved_packages_config_;
110 std::shared_ptr<uint8_t> kernel_buffer_;
111 intptr_t kernel_buffer_size_;
112 char* packages_file_ = nullptr;
113 bool isolate_run_app_snapshot_;
114
115 static void FreeUnownedKernelBuffer(uint8_t*) {}
116
118};
119
120// Data associated with every isolate in the standalone VM
121// embedding. This is used to free external resources for each isolate
122// when the isolate shuts down.
124 public:
126 ~IsolateData();
127
128 IsolateGroupData* isolate_group_data() const { return isolate_group_data_; }
129
131 if (packages_file != nullptr) {
132 free(packages_file_);
133 packages_file_ = nullptr;
134 }
135 packages_file_ = Utils::StrDup(packages_file);
136 }
137
138 // While loading a loader is associated with the isolate.
139 bool HasLoader() const { return loader_ != nullptr; }
140 Loader* loader() const {
141 ASSERT(loader_ != nullptr);
142 return loader_;
143 }
145 ASSERT((loader_ == nullptr) || (loader == nullptr));
146 loader_ = loader;
147 }
148
149 const char* packages_file() const { return packages_file_; }
150
151 private:
152 IsolateGroupData* isolate_group_data_;
153 Loader* loader_;
154 char* packages_file_;
155
156 DISALLOW_COPY_AND_ASSIGN(IsolateData);
157};
158
159} // namespace bin
160} // namespace dart
161
162#endif // RUNTIME_BIN_ISOLATE_DATA_H_
static char * StrDup(const char *s)
void UpdatePackagesFile(const char *packages_file)
Definition: isolate_data.h:130
void set_loader(Loader *loader)
Definition: isolate_data.h:144
const char * packages_file() const
Definition: isolate_data.h:149
IsolateData(IsolateGroupData *isolate_group_data)
Definition: isolate_data.cc:41
IsolateGroupData * isolate_group_data() const
Definition: isolate_data.h:128
Loader * loader() const
Definition: isolate_data.h:140
bool HasLoader() const
Definition: isolate_data.h:139
void SetKernelBufferAlreadyOwned(std::shared_ptr< uint8_t > buffer, intptr_t size)
Definition: isolate_data.h:72
IsolateGroupData(const char *url, const char *packages_file, AppSnapshot *app_snapshot, bool isolate_run_app_snapshot)
Definition: isolate_data.cc:12
intptr_t kernel_buffer_size() const
Definition: isolate_data.h:50
void SetKernelBufferNewlyOwned(uint8_t *buffer, intptr_t size)
Definition: isolate_data.h:63
void set_resolved_packages_config(const char *packages_config)
Definition: isolate_data.h:83
void AddLoadingUnit(AppSnapshot *loading_unit)
Definition: isolate_data.h:100
const std::shared_ptr< uint8_t > & kernel_buffer() const
Definition: isolate_data.h:46
bool RunFromAppSnapshot() const
Definition: isolate_data.h:91
void SetKernelBufferUnowned(uint8_t *buffer, intptr_t size)
Definition: isolate_data.h:54
const char * resolved_packages_config() const
Definition: isolate_data.h:79
#define ASSERT(E)
Definition: dart_vm.cc:33
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:581