Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
dart::Compiler Class Reference

#include <compiler.h>

Inheritance diagram for dart::Compiler:
dart::AllStatic

Static Public Member Functions

static bool IsBackgroundCompilation ()
 
static bool CanOptimizeFunction (Thread *thread, const Function &function)
 
static ObjectPtr CompileFunction (Thread *thread, const Function &function)
 
static ErrorPtr EnsureUnoptimizedCode (Thread *thread, const Function &function)
 
static ObjectPtr CompileOptimizedFunction (Thread *thread, const Function &function, intptr_t osr_id=kNoOSRDeoptId)
 
static void ComputeLocalVarDescriptors (const Code &code)
 
static ErrorPtr CompileAllFunctions (const Class &cls)
 
static void AbortBackgroundCompilation (intptr_t deopt_id, const char *msg)
 

Static Public Attributes

static constexpr intptr_t kNoOSRDeoptId = DeoptId::kNone
 

Detailed Description

Definition at line 71 of file compiler.h.

Member Function Documentation

◆ AbortBackgroundCompilation()

void dart::Compiler::AbortBackgroundCompilation ( intptr_t  deopt_id,
const char *  msg 
)
static

Definition at line 972 of file compiler.cc.

972 {
973 if (FLAG_trace_compiler) {
974 THR_Print("ABORT background compilation: %s\n", msg);
975 }
976#if !defined(PRODUCT)
977 TimelineStream* stream = Timeline::GetCompilerStream();
978 ASSERT(stream != nullptr);
979 TimelineEvent* event = stream->StartEvent();
980 if (event != nullptr) {
981 event->Instant("AbortBackgroundCompilation");
982 event->SetNumArguments(1);
983 event->CopyArgument(0, "reason", msg);
984 event->Complete();
985 }
986#endif // !defined(PRODUCT)
989 deopt_id, Object::background_compilation_error());
990}
static bool IsBackgroundCompilation()
Definition compiler.cc:299
DART_NORETURN void Jump(int value, const Error &error)
Definition longjump.cc:22
LongJumpScope * long_jump_base() const
static Thread * Current()
Definition thread.h:361
#define THR_Print(format,...)
Definition log.h:20
#define ASSERT(E)
FlKeyEvent * event

◆ CanOptimizeFunction()

bool dart::Compiler::CanOptimizeFunction ( Thread thread,
const Function function 
)
static

Definition at line 230 of file compiler.cc.

230 {
231#if !defined(PRODUCT)
232 if (thread->isolate_group()->debugger()->IsDebugging(thread, function)) {
233 // We cannot set breakpoints and single step in optimized code,
234 // so do not optimize the function. Bump usage counter down to avoid
235 // repeatedly entering the runtime for an optimization attempt.
236 function.SetUsageCounter(0);
237
238 // If the optimization counter = 1, the unoptimized code will come back here
239 // immediately, causing an infinite compilation loop. The compiler raises
240 // the threshold for functions with breakpoints, so we drop the unoptimized
241 // to force it to be recompiled.
242 if (thread->isolate_group()->optimization_counter_threshold() < 2) {
243 function.ClearCode();
244 }
245 return false;
246 }
247#endif
248 if (function.deoptimization_counter() >=
249 FLAG_max_deoptimization_counter_threshold) {
250 if (FLAG_trace_failed_optimization_attempts ||
251 FLAG_stop_on_excessive_deoptimization) {
252 THR_Print("Too many deoptimizations: %s\n",
253 function.ToFullyQualifiedCString());
254 if (FLAG_stop_on_excessive_deoptimization) {
255 FATAL("Stop on excessive deoptimization");
256 }
257 }
258 // The function will not be optimized any longer. This situation can occur
259 // mostly with small optimization counter thresholds.
260 function.SetIsOptimizable(false);
261 function.SetUsageCounter(INT32_MIN);
262 return false;
263 }
264 if (FLAG_optimization_filter != nullptr) {
265 // FLAG_optimization_filter is a comma-separated list of strings that are
266 // matched against the fully-qualified function name.
267 char* save_ptr; // Needed for strtok_r.
268 const char* function_name = function.ToFullyQualifiedCString();
269 intptr_t len = strlen(FLAG_optimization_filter) + 1; // Length with \0.
270 char* filter = new char[len];
271 strncpy(filter, FLAG_optimization_filter, len); // strtok modifies arg 1.
272 char* token = strtok_r(filter, ",", &save_ptr);
273 bool found = false;
274 while (token != nullptr) {
275 if (strstr(function_name, token) != nullptr) {
276 found = true;
277 break;
278 }
279 token = strtok_r(nullptr, ",", &save_ptr);
280 }
281 delete[] filter;
282 if (!found) {
283 function.SetUsageCounter(INT32_MIN);
284 return false;
285 }
286 }
287 if (!function.IsOptimizable()) {
288 // Huge methods (code size above --huge_method_cutoff_in_code_size) become
289 // non-optimizable only after the code has been generated.
290 if (FLAG_trace_failed_optimization_attempts) {
291 THR_Print("Not optimizable: %s\n", function.ToFullyQualifiedCString());
292 }
293 function.SetUsageCounter(INT32_MIN);
294 return false;
295 }
296 return true;
297}
#define FATAL(error)
Dart_NativeFunction function
Definition fuchsia.cc:51
const char *const function_name

◆ CompileAllFunctions()

ErrorPtr dart::Compiler::CompileAllFunctions ( const Class cls)
static

Definition at line 949 of file compiler.cc.

949 {
950 Thread* thread = Thread::Current();
951 Zone* zone = thread->zone();
952 Object& result = Object::Handle(zone);
953 // We don't expect functions() to change as the class was finalized.
954 ASSERT(cls.is_finalized());
955 Array& functions = Array::Handle(zone, cls.current_functions());
956 Function& func = Function::Handle(zone);
957 // Compile all the regular functions.
958 for (int i = 0; i < functions.Length(); i++) {
959 func ^= functions.At(i);
960 ASSERT(!func.IsNull());
961 if (!func.HasCode() && !func.is_abstract()) {
962 result = CompileFunction(thread, func);
963 if (result.IsError()) {
964 return Error::Cast(result).ptr();
965 }
966 ASSERT(!result.IsNull());
967 }
968 }
969 return Error::null();
970}
static ObjectPtr CompileFunction(Thread *thread, const Function &function)
Definition compiler.cc:825
static ObjectPtr null()
Definition object.h:433
static Object & Handle()
Definition object.h:407
GAsyncResult * result

◆ CompileFunction()

ObjectPtr dart::Compiler::CompileFunction ( Thread thread,
const Function function 
)
static

Definition at line 825 of file compiler.cc.

825 {
826#if defined(DART_PRECOMPILER) && !defined(TARGET_ARCH_IA32)
827 RELEASE_ASSERT(!FLAG_precompiled_mode);
828#endif
829
830#if defined(DART_PRECOMPILED_RUNTIME)
831 FATAL("Precompilation missed function %s (%s, %s)\n",
832 function.ToLibNamePrefixedQualifiedCString(),
833 function.token_pos().ToCString(),
835#endif // defined(DART_PRECOMPILED_RUNTIME)
836
837 VMTagScope tagScope(thread, VMTag::kCompileUnoptimizedTagId);
838#if defined(SUPPORT_TIMELINE)
839 const char* event_name;
841 event_name = "CompileFunctionUnoptimizedBackground";
842 } else {
843 event_name = "CompileFunction";
844 }
846#endif // defined(SUPPORT_TIMELINE)
847
848 CompilationPipeline* pipeline =
849 CompilationPipeline::New(thread->zone(), function);
850
851 const bool optimized = function.ForceOptimize();
852 return CompileFunctionHelper(pipeline, function, optimized, kNoOSRDeoptId);
853}
#define RELEASE_ASSERT(cond)
Definition assert.h:327
static CompilationPipeline * New(Zone *zone, const Function &function)
Definition compiler.cc:202
static constexpr intptr_t kNoOSRDeoptId
Definition compiler.h:73
static const char * KindToCString(UntaggedFunction::Kind kind)
Definition object.cc:8477
static ObjectPtr CompileFunctionHelper(CompilationPipeline *pipeline, const Function &function, volatile bool optimized, intptr_t osr_id)
Definition compiler.cc:683
#define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, name, function)
Definition timeline.h:40

◆ CompileOptimizedFunction()

ObjectPtr dart::Compiler::CompileOptimizedFunction ( Thread thread,
const Function function,
intptr_t  osr_id = kNoOSRDeoptId 
)
static

Definition at line 887 of file compiler.cc.

889 {
890 VMTagScope tag_scope(thread, VMTag::kCompileOptimizedTagId);
891
892#if defined(SUPPORT_TIMELINE)
893 const char* event_name;
894 if (osr_id != kNoOSRDeoptId) {
895 event_name = "CompileFunctionOptimizedOSR";
896 } else if (IsBackgroundCompilation()) {
897 event_name = "CompileFunctionOptimizedBackground";
898 } else {
899 event_name = "CompileFunctionOptimized";
900 }
902#endif // defined(SUPPORT_TIMELINE)
903
904 CompilationPipeline* pipeline =
905 CompilationPipeline::New(thread->zone(), function);
906 return CompileFunctionHelper(pipeline, function, /* optimized = */ true,
907 osr_id);
908}

◆ ComputeLocalVarDescriptors()

void dart::Compiler::ComputeLocalVarDescriptors ( const Code code)
static

Definition at line 910 of file compiler.cc.

910 {
911 ASSERT(!code.is_optimized());
912 ASSERT(!FLAG_precompiled_mode);
913 const Function& function = Function::Handle(code.function());
914 ASSERT(code.var_descriptors() == Object::null());
915 // IsIrregexpFunction have eager var descriptors generation.
916 ASSERT(!function.IsIrregexpFunction());
917 // In background compilation, parser can produce 'errors": bailouts
918 // if state changed while compiling in background.
919 Thread* thread = Thread::Current();
920 Zone* zone = thread->zone();
921 CompilerState state(thread, /*is_aot=*/false, /*is_optimizing=*/false);
922 LongJumpScope jump;
923 if (setjmp(*jump.Set()) == 0) {
924 ParsedFunction* parsed_function =
925 new ParsedFunction(thread, Function::ZoneHandle(zone, function.ptr()));
926 ZoneGrowableArray<const ICData*>* ic_data_array =
927 new ZoneGrowableArray<const ICData*>();
928 ZoneGrowableArray<intptr_t>* context_level_array =
929 new ZoneGrowableArray<intptr_t>();
930
931 kernel::FlowGraphBuilder builder(
932 parsed_function, ic_data_array, context_level_array,
933 /* not inlining */ nullptr, false, Compiler::kNoOSRDeoptId);
934 builder.BuildGraph();
935
936 auto& var_descs = LocalVarDescriptors::Handle(zone);
937
938 var_descs = parsed_function->scope()->GetVarDescriptors(
939 function, context_level_array);
940
941 ASSERT(!var_descs.IsNull());
942 code.set_var_descriptors(var_descs);
943 } else {
944 // Only possible with background compilation.
946 }
947}
static Object & ZoneHandle()
Definition object.h:419
AtkStateType state

◆ EnsureUnoptimizedCode()

ErrorPtr dart::Compiler::EnsureUnoptimizedCode ( Thread thread,
const Function function 
)
static

Definition at line 855 of file compiler.cc.

856 {
857 ASSERT(!function.ForceOptimize());
858 if (function.unoptimized_code() != Object::null()) {
859 return Error::null();
860 }
861 Code& original_code = Code::ZoneHandle(thread->zone());
862 if (function.HasCode()) {
863 original_code = function.CurrentCode();
864 }
865 CompilationPipeline* pipeline =
866 CompilationPipeline::New(thread->zone(), function);
867 const Object& result = Object::Handle(
868 CompileFunctionHelper(pipeline, function, false, /* not optimized */
870 if (result.IsError()) {
871 return Error::Cast(result).ptr();
872 }
873 // Since CompileFunctionHelper replaces the current code, re-attach the
874 // the original code if the function was already compiled.
875 if (!original_code.IsNull() && result.ptr() == function.CurrentCode() &&
876 !original_code.IsDisabled()) {
877 function.AttachCode(original_code);
878 }
879 ASSERT(function.unoptimized_code() != Object::null());
880 ASSERT(function.unoptimized_code() == result.ptr());
881 if (FLAG_trace_compiler) {
882 THR_Print("Ensure unoptimized code for %s\n", function.ToCString());
883 }
884 return Error::null();
885}

◆ IsBackgroundCompilation()

bool dart::Compiler::IsBackgroundCompilation ( )
static

Definition at line 299 of file compiler.cc.

299 {
300 // For now: compilation in non mutator thread is the background compilation.
302}
bool IsDartMutatorThread() const
Definition thread.h:546

Member Data Documentation

◆ kNoOSRDeoptId

constexpr intptr_t dart::Compiler::kNoOSRDeoptId = DeoptId::kNone
staticconstexpr

Definition at line 73 of file compiler.h.


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