Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
dart::kernel::Program Class Reference

#include <kernel.h>

Public Member Functions

bool is_single_program ()
 
NameIndex main_method ()
 
intptr_t source_table_offset () const
 
intptr_t string_table_offset () const
 
intptr_t name_table_offset () const
 
intptr_t metadata_payloads_offset () const
 
intptr_t metadata_mappings_offset () const
 
intptr_t constant_table_offset ()
 
intptr_t component_index_offset ()
 
intptr_t library_count ()
 
const TypedDataBasebinary ()
 

Static Public Member Functions

static std::unique_ptr< ProgramReadFrom (Reader *reader, const char **error=nullptr)
 
static std::unique_ptr< ProgramReadFromFile (const char *script_uri, const char **error=nullptr)
 
static std::unique_ptr< ProgramReadFromBuffer (const uint8_t *buffer, intptr_t buffer_length, const char **error=nullptr)
 
static std::unique_ptr< ProgramReadFromTypedData (const ExternalTypedData &typed_data, const char **error=nullptr)
 

Detailed Description

Definition at line 62 of file kernel.h.

Member Function Documentation

◆ binary()

const TypedDataBase & dart::kernel::Program::binary ( )
inline

Definition at line 95 of file kernel.h.

95{ return *binary_; }

◆ component_index_offset()

intptr_t dart::kernel::Program::component_index_offset ( )
inline

Definition at line 91 of file kernel.h.

91{ return component_index_offset_; }

◆ constant_table_offset()

intptr_t dart::kernel::Program::constant_table_offset ( )
inline

Definition at line 90 of file kernel.h.

90{ return constant_table_offset_; }

◆ is_single_program()

bool dart::kernel::Program::is_single_program ( )
inline

Definition at line 79 of file kernel.h.

79{ return single_program_; }

◆ library_count()

intptr_t dart::kernel::Program::library_count ( )
inline

Definition at line 92 of file kernel.h.

92{ return library_count_; }

◆ main_method()

NameIndex dart::kernel::Program::main_method ( )
inline

Definition at line 80 of file kernel.h.

80{ return main_method_reference_; }

◆ metadata_mappings_offset()

intptr_t dart::kernel::Program::metadata_mappings_offset ( ) const
inline

Definition at line 87 of file kernel.h.

87 {
88 return metadata_mappings_offset_;
89 }

◆ metadata_payloads_offset()

intptr_t dart::kernel::Program::metadata_payloads_offset ( ) const
inline

Definition at line 84 of file kernel.h.

84 {
85 return metadata_payloads_offset_;
86 }

◆ name_table_offset()

intptr_t dart::kernel::Program::name_table_offset ( ) const
inline

Definition at line 83 of file kernel.h.

83{ return name_table_offset_; }

◆ ReadFrom()

std::unique_ptr< Program > dart::kernel::Program::ReadFrom ( Reader reader,
const char **  error = nullptr 
)
static

Definition at line 88 of file kernel_binary.cc.

88 {
89 if (reader->size() < 70) {
90 // A kernel file (v43) currently contains at least the following:
91 // * Magic number (32)
92 // * Kernel version (32)
93 // * SDK Hash (10 * 8)
94 // * List of problems (8)
95 // * Length of source map (32)
96 // * Length of canonical name table (8)
97 // * Metadata length (32)
98 // * Length of string table (8)
99 // * Length of constant table (8)
100 // * Component index (11 * 32)
101 //
102 // so is at least 74 bytes.
103 // (Technically it will also contain an empty entry in both source map and
104 // string table, taking up another 8 bytes.)
105 if (error != nullptr) {
107 }
108 return nullptr;
109 }
110
111 uint32_t magic = reader->ReadUInt32();
112 if (magic != kMagicProgramFile) {
113 if (error != nullptr) {
115 }
116 return nullptr;
117 }
118
119 const uint32_t format_version = reader->ReadUInt32();
120 if (format_version != kSupportedKernelFormatVersion) {
121 if (error != nullptr) {
123 }
124 return nullptr;
125 }
126
127 if (!IsValidSdkHash(reader->BufferAt(reader->offset()))) {
128 if (error != nullptr) {
130 }
131 return nullptr;
132 }
133 reader->set_offset(reader->offset() + kSdkHashSizeInBytes);
134
135 std::unique_ptr<Program> program(new Program(reader->typed_data()));
136
137 // Dill files can be concatenated (e.g. cat a.dill b.dill > c.dill). Find out
138 // if this dill contains more than one program.
139 int subprogram_count = 0;
140 reader->set_offset(reader->size() - 4);
141 while (reader->offset() > 0) {
142 intptr_t size = reader->ReadUInt32();
143 intptr_t start = reader->offset() - size;
144 if (start < 0 || size <= 0) {
145 if (error != nullptr) {
147 }
148 return nullptr;
149 }
150 ++subprogram_count;
151 if (subprogram_count > 1) break;
152 reader->set_offset(start - 4);
153 }
154 program->single_program_ = subprogram_count == 1;
155
156 // Read backwards at the end.
157 program->library_count_ = reader->ReadFromIndexNoReset(
158 reader->size_, LibraryCountFieldCountFromEnd, 1, 0);
159 intptr_t count_from_first_library_offset =
161 program->source_table_offset_ = reader->ReadFromIndexNoReset(
162 reader->size_,
163 LibraryCountFieldCountFromEnd + 1 + program->library_count_ + 1 +
164 count_from_first_library_offset,
165 1, 0);
166 program->constant_table_offset_ = reader->ReadUInt32();
167 reader->ReadUInt32(); // offset for constant table index.
168 program->name_table_offset_ = reader->ReadUInt32();
169 program->metadata_payloads_offset_ = reader->ReadUInt32();
170 program->metadata_mappings_offset_ = reader->ReadUInt32();
171 program->string_table_offset_ = reader->ReadUInt32();
172 // The below includes any 8-bit alignment; denotes the end of the previous
173 // block.
174 program->component_index_offset_ = reader->ReadUInt32();
175
176 program->main_method_reference_ = NameIndex(reader->ReadUInt32() - 1);
177 reader->ReadUInt32(); // Read and ignore NNBD compilation mode.
178
179 return program;
180}
const uint8_t uint32_t uint32_t GError ** error
bool IsValidSdkHash(const uint8_t *sdk_hash)
const char * kKernelInvalidMagicIdentifier
const char * kKernelInvalidSdkHash
const int kSdkHashSizeInBytes
const char * kKernelInvalidSizeIndicated
const char * kKernelInvalidBinaryFormatVersion
const char * kKernelInvalidFilesize
static const uint32_t kMagicProgramFile
Definition: kernel_binary.h:20
static constexpr int SourceTableFieldCountFromFirstLibraryOffset
static constexpr int LibraryCountFieldCountFromEnd
static const uint32_t kSupportedKernelFormatVersion
Definition: kernel_binary.h:21
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

◆ ReadFromBuffer()

std::unique_ptr< Program > dart::kernel::Program::ReadFromBuffer ( const uint8_t *  buffer,
intptr_t  buffer_length,
const char **  error = nullptr 
)
static

Definition at line 213 of file kernel_binary.cc.

215 {
216 // Whoever called this method (e.g. embedder) has to ensure the buffer stays
217 // alive until the VM is done with the last usage (e.g. isolate shutdown).
219 kExternalTypedDataUint8ArrayCid, const_cast<uint8_t*>(buffer),
220 buffer_length, Heap::kNew));
221 kernel::Reader reader(binary);
222 return kernel::Program::ReadFrom(&reader, error);
223}
static ExternalTypedDataPtr New(intptr_t class_id, uint8_t *data, intptr_t len, Heap::Space space=Heap::kNew, bool perform_eager_msan_initialization_check=true)
Definition: object.cc:25626
@ kNew
Definition: heap.h:38
static Object & Handle()
Definition: object.h:407
const TypedDataBase & binary()
Definition: kernel.h:95
static std::unique_ptr< Program > ReadFrom(Reader *reader, const char **error=nullptr)
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

◆ ReadFromFile()

std::unique_ptr< Program > dart::kernel::Program::ReadFromFile ( const char *  script_uri,
const char **  error = nullptr 
)
static

Definition at line 182 of file kernel_binary.cc.

184 {
185 Thread* thread = Thread::Current();
186 auto isolate_group = thread->isolate_group();
187 if (script_uri == nullptr) {
188 return nullptr;
189 }
190 if (!isolate_group->HasTagHandler()) {
191 return nullptr;
192 }
193 std::unique_ptr<kernel::Program> kernel_program;
194
195 const String& uri = String::Handle(String::New(script_uri));
196 const Object& ret = Object::Handle(isolate_group->CallTagHandler(
197 Dart_kKernelTag, Object::null_object(), uri));
198 if (ret.IsExternalTypedData()) {
199 const auto& typed_data = ExternalTypedData::Cast(ret);
200 kernel_program = kernel::Program::ReadFromTypedData(typed_data);
201 return kernel_program;
202 } else if (error != nullptr) {
203 Api::Scope api_scope(thread);
204 Dart_Handle retval = Api::NewHandle(thread, ret.ptr());
205 {
206 TransitionVMToNative transition(thread);
207 *error = Dart_GetError(retval);
208 }
209 }
210 return kernel_program;
211}
static Dart_Handle NewHandle(Thread *thread, ObjectPtr raw)
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
static Thread * Current()
Definition: thread.h:362
static std::unique_ptr< Program > ReadFromTypedData(const ExternalTypedData &typed_data, const char **error=nullptr)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
@ Dart_kKernelTag
Definition: dart_api.h:3422
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)

◆ ReadFromTypedData()

std::unique_ptr< Program > dart::kernel::Program::ReadFromTypedData ( const ExternalTypedData typed_data,
const char **  error = nullptr 
)
static

Definition at line 225 of file kernel_binary.cc.

227 {
228 kernel::Reader reader(typed_data);
229 return kernel::Program::ReadFrom(&reader, error);
230}

◆ source_table_offset()

intptr_t dart::kernel::Program::source_table_offset ( ) const
inline

Definition at line 81 of file kernel.h.

81{ return source_table_offset_; }

◆ string_table_offset()

intptr_t dart::kernel::Program::string_table_offset ( ) const
inline

Definition at line 82 of file kernel.h.

82{ return string_table_offset_; }

The documentation for this class was generated from the following files: