Flutter Engine
The Flutter Engine
compiler_state.cc
Go to the documentation of this file.
1// Copyright (c) 2018, 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
6
7#include <functional>
8
13#include "vm/growable_array.h"
14#include "vm/scopes.h"
15
16namespace dart {
17
18template <typename T>
20 ZoneGrowableArray<T*>** array_slot,
21 intptr_t index,
23 auto array = *array_slot;
24
25 if (array == nullptr) {
26 Zone* const Z = thread->zone();
27 *array_slot = array = new (Z) ZoneGrowableArray<T*>(Z, index + 1);
28 }
29
30 while (array->length() <= index) {
31 array->Add(nullptr);
32 }
33
34 if (array->At(index) == nullptr) {
35 (*array)[index] = create();
36 }
37 return array->At(index);
38}
39
43}
44
46 if (comparable_class_ == nullptr) {
48 Zone* zone = thread->zone();
49
50 // When obfuscation is enabled we need to obfuscate the name of the
51 // class before looking it up.
52 String& name = String::Handle(zone, Symbols::New(thread, "Comparable"));
53 if (thread->isolate_group()->obfuscate()) {
54 Obfuscator obfuscator(thread, Object::null_string());
55 name = obfuscator.Rename(name);
56 }
57
58 const Library& lib = Library::Handle(zone, Library::CoreLibrary());
59 const Class& cls = Class::ZoneHandle(zone, lib.LookupClass(name));
60 ASSERT(!cls.IsNull());
61 comparable_class_ = &cls;
62 }
63 return *comparable_class_;
64}
65
67 if (interpolate_single_ == nullptr) {
69 Zone* zone = thread->zone();
70
71 const Class& cls =
72 Class::Handle(Library::LookupCoreClass(Symbols::StringBase()));
73 ASSERT(!cls.IsNull());
74 interpolate_single_ = &Function::ZoneHandle(
75 zone, cls.LookupFunctionAllowPrivate(Symbols::InterpolateSingle()));
76 ASSERT(!interpolate_single_->IsNull());
77 }
78 return *interpolate_single_;
79}
80
82 if (interpolate_ == nullptr) {
84 Zone* zone = thread->zone();
85
86 const Class& cls =
87 Class::Handle(Library::LookupCoreClass(Symbols::StringBase()));
88 ASSERT(!cls.IsNull());
89 interpolate_ = &Function::ZoneHandle(
90 zone, cls.LookupFunctionAllowPrivate(Symbols::Interpolate()));
91 ASSERT(!interpolate_->IsNull());
92 }
93 return *interpolate_;
94}
95#define DEFINE_TYPED_LIST_NATIVE_FUNCTION_GETTER(Upper, Lower) \
96 const Function& CompilerState::TypedListGet##Upper() { \
97 if (typed_list_get_##Lower##_ == nullptr) { \
98 Thread* thread = Thread::Current(); \
99 Zone* zone = thread->zone(); \
100 const auto& cls = CompilerState::TypedListClass(); \
101 typed_list_get_##Lower##_ = &Function::ZoneHandle( \
102 zone, cls.LookupFunctionAllowPrivate(Symbols::_nativeGet##Upper())); \
103 ASSERT(!typed_list_get_##Lower##_->IsNull()); \
104 } \
105 return *typed_list_get_##Lower##_; \
106 } \
107 const Function& CompilerState::TypedListSet##Upper() { \
108 if (typed_list_set_##Lower##_ == nullptr) { \
109 Thread* thread = Thread::Current(); \
110 Zone* zone = thread->zone(); \
111 const auto& cls = CompilerState::TypedListClass(); \
112 typed_list_set_##Lower##_ = &Function::ZoneHandle( \
113 zone, cls.LookupFunctionAllowPrivate(Symbols::_nativeSet##Upper())); \
114 ASSERT(!typed_list_set_##Lower##_->IsNull()); \
115 } \
116 return *typed_list_set_##Lower##_; \
117 }
118
124
125#undef DEFINE_TYPED_LIST_NATIVE_FUNCTION_GETTER
126
127#define DEFINE_CLASS_GETTER(Lib, Upper, Lower, Symbol) \
128 const Class& CompilerState::Upper##Class() { \
129 if (Lower##_class_ == nullptr) { \
130 Thread* thread = Thread::Current(); \
131 Zone* zone = thread->zone(); \
132 const auto& lib = Library::Handle(zone, Library::Lib##Library()); \
133 const auto& cls = \
134 Class::Handle(zone, lib.LookupClassAllowPrivate(Symbols::Symbol())); \
135 ASSERT(!cls.IsNull()); \
136 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); \
137 ASSERT(error.IsNull()); \
138 Lower##_class_ = &cls; \
139 } \
140 return *Lower##_class_; \
141 }
142
143DEFINE_CLASS_GETTER(Ffi, Array, array, Array)
144DEFINE_CLASS_GETTER(Ffi, Compound, compound, Compound)
145DEFINE_CLASS_GETTER(Ffi, Struct, struct, Struct)
146DEFINE_CLASS_GETTER(Ffi, Union, union, Union)
147DEFINE_CLASS_GETTER(TypedData, TypedData, typed_data, TypedData)
148DEFINE_CLASS_GETTER(TypedData, TypedList, typed_list, _TypedList)
149
150#undef DEFINE_CLASS_GETTER
151
153 if (compound_offset_in_bytes_field_ == nullptr) {
155 Zone* zone = thread->zone();
156 const auto& field =
157 Field::ZoneHandle(zone, CompoundClass().LookupInstanceFieldAllowPrivate(
158 Symbols::_offsetInBytes()));
159 ASSERT(!field.IsNull());
160 compound_offset_in_bytes_field_ = &field;
161 }
162 return *compound_offset_in_bytes_field_;
163}
164
166 if (compound_typed_data_base_field_ == nullptr) {
168 Zone* zone = thread->zone();
169 const auto& field =
170 Field::ZoneHandle(zone, CompoundClass().LookupInstanceFieldAllowPrivate(
171 Symbols::_typedDataBase()));
172 ASSERT(!field.IsNull());
173 compound_typed_data_base_field_ = &field;
174 }
175 return *compound_typed_data_base_field_;
176}
177
179 OS::PrintErr("=== Crash occurred when compiling %s in %s mode in %s pass\n",
180 function() != nullptr ? function()->ToFullyQualifiedCString()
181 : "unknown function",
182 is_aot() ? "AOT"
183 : is_optimizing() ? "optimizing JIT"
184 : "unoptimized JIT",
185 pass() != nullptr ? pass()->name() : "unknown");
186 if (pass_state() != nullptr && pass()->id() == CompilerPass::kGenerateCode) {
187 if (pass_state()->graph_compiler->current_block() != nullptr) {
188 OS::PrintErr("=== When compiling block %s\n",
189 pass_state()->graph_compiler->current_block()->ToCString());
190 }
191 if (pass_state()->graph_compiler->current_instruction() != nullptr) {
193 "=== When compiling instruction %s\n",
194 pass_state()->graph_compiler->current_instruction()->ToCString());
195 }
196 }
197 if (pass_state() != nullptr && pass_state()->flow_graph() != nullptr) {
198 pass_state()->flow_graph()->Print(pass()->name());
199 } else {
200 OS::PrintErr("=== Flow Graph not available\n");
201 }
202}
203
204} // namespace dart
#define Z
void Add(const T &value)
FunctionPtr LookupFunctionAllowPrivate(const String &name) const
Definition: object.cc:6167
const Class & CompoundClass()
const Class & ComparableClass()
bool is_optimizing() const
const Function & StringBaseInterpolateSingle()
const CompilerPass * pass() const
bool is_aot() const
static bool ShouldTrace()
const Field & CompoundTypedDataBaseField()
const Function & StringBaseInterpolate()
const Field & CompoundOffsetInBytesField()
const CompilerPassState * pass_state() const
const Function * function() const
static bool ShouldPrint(const Function &function, uint8_t **compiler_pass_filter=nullptr)
Definition: il_printer.cc:1715
void Print(const char *phase="unknown")
Definition: flow_graph.cc:3012
static LibraryPtr CoreLibrary()
Definition: object.cc:14787
static ClassPtr LookupCoreClass(const String &class_name)
Definition: object.cc:14689
ClassPtr LookupClass(const String &name) const
Definition: object.cc:14105
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
StringPtr Rename(const String &name, bool atomic=false)
Definition: precompiler.h:624
bool IsNull() const
Definition: object.h:363
static Object & Handle()
Definition: object.h:407
static Object & ZoneHandle()
Definition: object.h:419
static StringPtr New(Thread *thread, const char *cstr)
Definition: symbols.h:723
Zone * zone() const
Definition: thread_state.h:37
static Thread * Current()
Definition: thread.h:362
IsolateGroup * isolate_group() const
Definition: thread.h:541
#define DEFINE_TYPED_LIST_NATIVE_FUNCTION_GETTER(Upper, Lower)
#define DEFINE_CLASS_GETTER(Lib, Upper, Lower, Symbol)
#define ASSERT(E)
Dart_NativeFunction function
Definition: fuchsia.cc:51
Definition: create.py:1
Definition: dart_vm.cc:33
const char *const name
CompilerTracing
static void Union(GrowableArray< Chain * > *chains, Chain *source_chain, Chain *target_chain)
T * PutIfAbsent(Thread *thread, ZoneGrowableArray< T * > **array_slot, intptr_t index, std::function< T *()> create)
#define T
Definition: precompiler.cc:65
FlowGraph * flow_graph() const
Definition: compiler_pass.h:77
int_closure create