Flutter Engine
The Flutter Engine
compiler_state.h
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
5#ifndef RUNTIME_VM_COMPILER_COMPILER_STATE_H_
6#define RUNTIME_VM_COMPILER_COMPILER_STATE_H_
7
8#if defined(DART_PRECOMPILED_RUNTIME)
9#error "AOT runtime should not use compiler sources (including header files)"
10#endif // defined(DART_PRECOMPILED_RUNTIME)
11
13#include "vm/compiler/cha.h"
14#include "vm/heap/safepoint.h"
15#include "vm/thread.h"
16#include "vm/timer.h"
17
18namespace dart {
19
20class CompilerPass;
21struct CompilerPassState;
22class Function;
23class LocalScope;
24class LocalVariable;
25class SlotCache;
26class Slot;
27
28enum class CompilerTracing {
29 kOn,
30 kOff,
31};
32
33// Global compiler state attached to the thread.
35 public:
37 bool is_aot,
38 bool is_optimizing,
41 cha_(thread),
42 is_aot_(is_aot),
43 is_optimizing_(is_optimizing),
44 tracing_(tracing) {
45 previous_ = thread->SetCompilerState(this);
46 }
47
49 ASSERT(&thread()->compiler_state() == this);
50 thread()->SetCompilerState(previous_);
51 }
52
53 CHA& cha() { return cha_; }
54
55 intptr_t deopt_id() const { return deopt_id_; }
56 void set_deopt_id(int value) {
57 ASSERT(value >= 0);
58 deopt_id_ = value;
59 }
60
61 intptr_t GetNextDeoptId() {
62 ASSERT(deopt_id_ != DeoptId::kNone);
63 const intptr_t id = deopt_id_;
64 deopt_id_ = DeoptId::Next(deopt_id_);
65 return id;
66 }
67
70 }
71
72 SlotCache* slot_cache() const { return slot_cache_; }
73 void set_slot_cache(SlotCache* cache) { slot_cache_ = cache; }
74
75 bool is_aot() const { return is_aot_; }
76
77 bool is_optimizing() const { return is_optimizing_; }
79 return !is_aot() && (is_optimizing() || FLAG_force_clone_compiler_objects);
80 }
81
82 bool should_trace() const { return tracing_ == CompilerTracing::kOn; }
83
84 static bool ShouldTrace() { return Current().should_trace(); }
85
86 static CompilerTracing ShouldTrace(const Function& func);
87
88 // Returns class Comparable<T> from dart:core.
89 const Class& ComparableClass();
90
91 // Returns _StringBase._interpolate
93
94 // Returns _StringBase._interpolateSingle
96
107
113
116
117 const Function* function() const { return function_; }
118
119 void set_function(const Function& function) { function_ = &function; }
122 pass_ = pass;
123 pass_state_ = pass_state;
124 }
125
126 const CompilerPass* pass() const { return pass_; }
127 const CompilerPassState* pass_state() const { return pass_state_; }
128
129 void ReportCrash();
130
131 private:
132 const Class& TypedListClass();
133
134 CHA cha_;
135 intptr_t deopt_id_ = 0;
136
137 // Cache for Slot objects created during compilation (see slot.h).
138 SlotCache* slot_cache_ = nullptr;
139
140 // Caches for dummy LocalVariables and context Slots.
141 ZoneGrowableArray<ZoneGrowableArray<const Slot*>*>* dummy_slots_ = nullptr;
142 ZoneGrowableArray<LocalVariable*>* dummy_captured_vars_ = nullptr;
143
144 const bool is_aot_;
145 const bool is_optimizing_;
146
147 const CompilerTracing tracing_;
148
149 // Lookup cache for various classes (to avoid polluting object store with
150 // compiler specific classes).
151 const Class* comparable_class_ = nullptr;
152 const Function* interpolate_ = nullptr;
153 const Function* interpolate_single_ = nullptr;
154 const Class* typed_list_class_ = nullptr;
155 const Class* array_class_ = nullptr;
156 const Class* compound_class_ = nullptr;
157 const Class* struct_class_ = nullptr;
158 const Class* typed_data_class_ = nullptr;
159 const Class* union_class_ = nullptr;
160 const Field* compound_offset_in_bytes_field_ = nullptr;
161 const Field* compound_typed_data_base_field_ = nullptr;
162 const Function* typed_list_get_float32_ = nullptr;
163 const Function* typed_list_set_float32_ = nullptr;
164 const Function* typed_list_get_float64_ = nullptr;
165 const Function* typed_list_set_float64_ = nullptr;
166 const Function* typed_list_get_float32x4_ = nullptr;
167 const Function* typed_list_set_float32x4_ = nullptr;
168 const Function* typed_list_get_int32x4_ = nullptr;
169 const Function* typed_list_set_int32x4_ = nullptr;
170 const Function* typed_list_get_float64x2_ = nullptr;
171 const Function* typed_list_set_float64x2_ = nullptr;
172
173 const Function* function_ = nullptr;
174 const CompilerPass* pass_ = nullptr;
175 const CompilerPassState* pass_state_ = nullptr;
176
177 CompilerState* previous_;
178};
179
181 public:
182 DeoptIdScope(Thread* thread, intptr_t deopt_id)
184 prev_deopt_id_(thread->compiler_state().deopt_id()) {
186 }
187
189
190 private:
191 const intptr_t prev_deopt_id_;
192
193 DISALLOW_COPY_AND_ASSIGN(DeoptIdScope);
194};
195
196/// Ensures that there were no deopt id allocations during the lifetime of this
197/// object.
199 public:
202 prev_deopt_id_(thread->compiler_state().deopt_id()) {}
203
205 ASSERT(thread()->compiler_state().deopt_id() == prev_deopt_id_);
206 }
207
208 private:
209 const intptr_t prev_deopt_id_;
210
211 DISALLOW_COPY_AND_ASSIGN(AssertNoDeoptIdsAllocatedScope);
212};
213
214} // namespace dart
215
216#endif // RUNTIME_VM_COMPILER_COMPILER_STATE_H_
Definition: cha.h:25
const Class & CompoundClass()
void set_slot_cache(SlotCache *cache)
const Class & ComparableClass()
intptr_t deopt_id() const
const Function & TypedListSetFloat64()
const Class & ArrayClass()
intptr_t GetNextDeoptId()
bool is_optimizing() const
void set_current_pass(const CompilerPass *pass, const CompilerPassState *pass_state)
const Function & TypedListGetFloat32()
const Function & TypedListGetInt32x4()
const Function & TypedListGetFloat32x4()
const Function & TypedListSetFloat32x4()
const Function & StringBaseInterpolateSingle()
CompilerState(Thread *thread, bool is_aot, bool is_optimizing, CompilerTracing tracing=CompilerTracing::kOn)
void set_deopt_id(int value)
const Function & TypedListSetInt32x4()
const CompilerPass * pass() const
bool is_aot() const
void set_function(const Function &function)
const Class & UnionClass()
bool should_trace() const
static bool ShouldTrace()
const Class & StructClass()
const Function & TypedListGetFloat64x2()
const Function & TypedListSetFloat64x2()
static CompilerState & Current()
const Class & TypedDataClass()
const Field & CompoundTypedDataBaseField()
const Function & TypedListGetFloat64()
const Function & StringBaseInterpolate()
const Field & CompoundOffsetInBytesField()
const CompilerPassState * pass_state() const
const Function & TypedListSetFloat32()
SlotCache * slot_cache() const
const Function * function() const
DeoptIdScope(Thread *thread, intptr_t deopt_id)
static constexpr intptr_t kNone
Definition: deopt_id.h:27
static intptr_t Next(intptr_t deopt_id)
Definition: deopt_id.h:29
static Thread * Current()
Definition: thread.h:362
CompilerState & compiler_state()
Definition: thread.h:588
#define ASSERT(E)
uint8_t value
Definition: dart_vm.cc:33
CompilerTracing
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 The size limit in megabytes for the Dart VM old gen heap space enable Enable the Impeller renderer on supported platforms Ignored if Impeller is not supported on the platform enable vulkan Enable loading Vulkan validation layers The layers must be available to the application and loadable On non Vulkan this flag does nothing enable vulkan gpu tracing
Definition: switches.h:283
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 Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191
const uintptr_t id