Flutter Engine
The Flutter Engine
kernel.h
Go to the documentation of this file.
1// Copyright (c) 2016, 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_VM_KERNEL_H_
6#define RUNTIME_VM_KERNEL_H_
7
8#include <memory>
9
10#include "platform/assert.h"
11#include "vm/allocation.h"
12#include "vm/globals.h"
13#include "vm/growable_array.h"
14#include "vm/object.h"
15#include "vm/token_position.h"
16
17namespace dart {
18namespace kernel {
19class NameIndex {
20 public:
21 static constexpr int kInvalidName = -1;
22
23 NameIndex() : value_(kInvalidName) {}
24 explicit NameIndex(int value) : value_(value) {}
25
26 operator int() const { return value_; }
27
28 private:
29 int value_;
30};
31} // namespace kernel
32} // namespace dart
33
34#if !defined(DART_PRECOMPILED_RUNTIME)
35namespace dart {
36
37class BitVector;
38class Field;
39class ParsedFunction;
40class Zone;
41
42namespace kernel {
43
44class Reader;
45struct ProcedureAttributesMetadata;
46class TableSelectorMetadata;
47class UnboxingInfoMetadata;
48
50 public:
51 StringIndex() : value_(-1) {}
52 explicit StringIndex(int value) : value_(value) {}
53
54 operator int() const { return value_; }
55
56 private:
57 int value_;
58};
59
61
62class Program {
63 public:
64 // Read a kernel Program from the given Reader. Note the returned Program
65 // can potentially contain several "sub programs", though the library count
66 // etc will reference the last "sub program" only.
67 static std::unique_ptr<Program> ReadFrom(Reader* reader,
68 const char** error = nullptr);
69
70 static std::unique_ptr<Program> ReadFromFile(const char* script_uri,
71 const char** error = nullptr);
72 static std::unique_ptr<Program> ReadFromBuffer(const uint8_t* buffer,
73 intptr_t buffer_length,
74 const char** error = nullptr);
75 static std::unique_ptr<Program> ReadFromTypedData(
76 const ExternalTypedData& typed_data,
77 const char** error = nullptr);
78
79 bool is_single_program() { return single_program_; }
80 NameIndex main_method() { return main_method_reference_; }
81 intptr_t source_table_offset() const { return source_table_offset_; }
82 intptr_t string_table_offset() const { return string_table_offset_; }
83 intptr_t name_table_offset() const { return name_table_offset_; }
84 intptr_t metadata_payloads_offset() const {
85 return metadata_payloads_offset_;
86 }
87 intptr_t metadata_mappings_offset() const {
88 return metadata_mappings_offset_;
89 }
90 intptr_t constant_table_offset() { return constant_table_offset_; }
91 intptr_t component_index_offset() { return component_index_offset_; }
92 intptr_t library_count() { return library_count_; }
93
94 // The data of the kernel file (single or multiple encoded components).
95 const TypedDataBase& binary() { return *binary_; }
96
97 private:
98 explicit Program(const TypedDataBase* binary) : binary_(binary) {}
99
100 bool single_program_;
101 NameIndex main_method_reference_; // Procedure.
102 intptr_t library_count_;
103
104 // The offset from the start of the binary to the start of the source table.
105 intptr_t source_table_offset_;
106
107 // The offset from the start of the binary to the start of the constant table.
108 intptr_t constant_table_offset_;
109
110 // The offset from the start of the binary to the start of the ending-index.
111 intptr_t component_index_offset_;
112
113 // The offset from the start of the binary to the canonical name table.
114 intptr_t name_table_offset_;
115
116 // The offset from the start of the binary to the metadata payloads.
117 intptr_t metadata_payloads_offset_;
118
119 // The offset from the start of the binary to the metadata mappings.
120 intptr_t metadata_mappings_offset_;
121
122 // The offset from the start of the binary to the start of the string table.
123 intptr_t string_table_offset_;
124
125 const TypedDataBase* binary_ = nullptr;
126
127 DISALLOW_COPY_AND_ASSIGN(Program);
128};
129
131 public:
132 KernelLineStartsReader(const dart::TypedData& line_starts_data,
133 dart::Zone* zone);
134
135 ~KernelLineStartsReader() { delete helper_; }
136
137 uint32_t At(intptr_t index) const {
138 return helper_->At(line_starts_data_, index);
139 }
140
141 uint32_t MaxPosition() const;
142
143 // Returns whether the given offset corresponds to a valid source offset
144 // If it does, then *line and *column (if column is not nullptr) are set
145 // to the line and column the token starts at.
147 intptr_t position,
148 intptr_t* line,
149 intptr_t* col = nullptr) const;
150
151 // Returns whether any tokens were found for the given line. When found,
152 // *first_token_index and *last_token_index are set to the first and
153 // last token on the line, respectively.
155 intptr_t line_number,
156 dart::TokenPosition* first_token_index,
157 dart::TokenPosition* last_token_index) const;
158
159 private:
160 class KernelLineStartsHelper {
161 public:
162 KernelLineStartsHelper() {}
163 virtual ~KernelLineStartsHelper() {}
164 virtual uint32_t At(const dart::TypedData& data, intptr_t index) const = 0;
165
166 private:
167 DISALLOW_COPY_AND_ASSIGN(KernelLineStartsHelper);
168 };
169
170 class KernelUint16LineStartsHelper : public KernelLineStartsHelper {
171 public:
172 KernelUint16LineStartsHelper() {}
173 virtual uint32_t At(const dart::TypedData& data, intptr_t index) const;
174
175 private:
176 DISALLOW_COPY_AND_ASSIGN(KernelUint16LineStartsHelper);
177 };
178
179 class KernelUint32LineStartsHelper : public KernelLineStartsHelper {
180 public:
181 KernelUint32LineStartsHelper() {}
182 virtual uint32_t At(const dart::TypedData& data, intptr_t index) const;
183
184 private:
185 DISALLOW_COPY_AND_ASSIGN(KernelUint32LineStartsHelper);
186 };
187
188 const dart::TypedData& line_starts_data_;
189 KernelLineStartsHelper* helper_;
190
191 DISALLOW_COPY_AND_ASSIGN(KernelLineStartsReader);
192};
193
194ObjectPtr EvaluateStaticConstFieldInitializer(const Field& field);
195ObjectPtr EvaluateMetadata(const Library& library,
196 intptr_t kernel_offset,
197 bool is_annotations_offset);
198ObjectPtr BuildParameterDescriptor(const Function& function);
199
200// Fills in [is_covariant] and [is_generic_covariant_impl] vectors
201// according to covariance attributes of [function] parameters.
202//
203// [is_covariant] and [is_generic_covariant_impl] should contain bitvectors
204// of function.NumParameters() length.
205void ReadParameterCovariance(const Function& function,
206 BitVector* is_covariant,
207 BitVector* is_generic_covariant_impl);
208
209// Returns true if the given function needs dynamic invocation forwarder:
210// that is if any of the arguments require checking on the dynamic
211// call-site: if function has no parameters or has only covariant parameters
212// as such function already checks all of its parameters.
213bool NeedsDynamicInvocationForwarder(const Function& function);
214
215ProcedureAttributesMetadata ProcedureAttributesOf(const Function& function,
216 Zone* zone);
217
218ProcedureAttributesMetadata ProcedureAttributesOf(const Field& field,
219 Zone* zone);
220
221UnboxingInfoMetadata* UnboxingInfoMetadataOf(const Function& function,
222 Zone* zone);
223
224TableSelectorMetadata* TableSelectorMetadataForProgram(
225 const KernelProgramInfo& info,
226 Zone* zone);
227
228} // namespace kernel
229} // namespace dart
230
231#endif // !defined(DART_PRECOMPILED_RUNTIME)
232#endif // RUNTIME_VM_KERNEL_H_
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
DART_WARN_UNUSED_RESULT bool LocationForPosition(intptr_t position, intptr_t *line, intptr_t *col=nullptr) const
Definition: kernel.cc:43
KernelLineStartsReader(const dart::TypedData &line_starts_data, dart::Zone *zone)
Definition: kernel.cc:21
DART_WARN_UNUSED_RESULT bool TokenRangeAtLine(intptr_t line_number, dart::TokenPosition *first_token_index, dart::TokenPosition *last_token_index) const
Definition: kernel.cc:71
uint32_t At(intptr_t index) const
Definition: kernel.h:137
NameIndex(int value)
Definition: kernel.h:24
static constexpr int kInvalidName
Definition: kernel.h:21
intptr_t metadata_mappings_offset() const
Definition: kernel.h:87
intptr_t constant_table_offset()
Definition: kernel.h:90
intptr_t component_index_offset()
Definition: kernel.h:91
intptr_t library_count()
Definition: kernel.h:92
intptr_t string_table_offset() const
Definition: kernel.h:82
static std::unique_ptr< Program > ReadFromBuffer(const uint8_t *buffer, intptr_t buffer_length, const char **error=nullptr)
intptr_t name_table_offset() const
Definition: kernel.h:83
bool is_single_program()
Definition: kernel.h:79
const TypedDataBase & binary()
Definition: kernel.h:95
static std::unique_ptr< Program > ReadFrom(Reader *reader, const char **error=nullptr)
static std::unique_ptr< Program > ReadFromTypedData(const ExternalTypedData &typed_data, const char **error=nullptr)
static std::unique_ptr< Program > ReadFromFile(const char *script_uri, const char **error=nullptr)
intptr_t source_table_offset() const
Definition: kernel.h:81
intptr_t metadata_payloads_offset() const
Definition: kernel.h:84
NameIndex main_method()
Definition: kernel.h:80
StringIndex(int value)
Definition: kernel.h:52
#define DART_WARN_UNUSED_RESULT
Definition: dart_api.h:66
const uint8_t uint32_t uint32_t GError ** error
uint8_t value
Dart_NativeFunction function
Definition: fuchsia.cc:51
ObjectPtr BuildParameterDescriptor(const Function &function)
Definition: kernel.cc:573
bool NeedsDynamicInvocationForwarder(const Function &function)
Definition: kernel.cc:657
void ReadParameterCovariance(const Function &function, BitVector *is_covariant, BitVector *is_generic_covariant_impl)
Definition: kernel.cc:599
static ProcedureAttributesMetadata ProcedureAttributesOf(Zone *zone, const KernelProgramInfo &kernel_program_info, const TypedDataView &kernel_data, intptr_t kernel_data_program_offset, intptr_t kernel_offset)
Definition: kernel.cc:740
LogicalOperator
Definition: kernel.h:60
TableSelectorMetadata * TableSelectorMetadataForProgram(const KernelProgramInfo &info, Zone *zone)
Definition: kernel.cc:802
ObjectPtr EvaluateMetadata(const Library &library, intptr_t kernel_offset, bool is_annotations_offset)
Definition: kernel.cc:467
static UnboxingInfoMetadata * UnboxingInfoMetadataOf(Zone *zone, const KernelProgramInfo &kernel_program_info, const TypedDataView &kernel_data, intptr_t kernel_data_program_offset, intptr_t kernel_offset)
Definition: kernel.cc:778
ObjectPtr EvaluateStaticConstFieldInitializer(const Field &field)
Definition: kernel.cc:381
Definition: dart_vm.cc:33
static int8_t data[kExtLength]
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
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:581