// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_CODEGEN_COMPILER_H_ #define V8_CODEGEN_COMPILER_H_ #include #include #include "src/base/platform/elapsed-timer.h" #include "src/codegen/bailout-reason.h" #include "src/common/globals.h" #include "src/execution/isolate.h" #include "src/execution/local-isolate.h" #include "src/handles/persistent-handles.h" #include "src/logging/code-events.h" #include "src/objects/contexts.h" #include "src/objects/debug-objects.h" #include "src/parsing/parse-info.h" #include "src/parsing/pending-compilation-error-handler.h" #include "src/snapshot/code-serializer.h" #include "src/utils/allocation.h" #include "src/zone/zone.h" namespace v8 { namespace internal { // Forward declarations. class AlignedCachedData; class AstRawString; class BackgroundCompileTask; class IsCompiledScope; class JavaScriptFrame; class OptimizedCompilationInfo; class OptimizedCompilationJob; class ParseInfo; class Parser; class RuntimeCallStats; class TimedHistogram; class UnoptimizedCompilationInfo; class UnoptimizedCompilationJob; class WorkerThreadRuntimeCallStats; struct ScriptDetails; struct ScriptStreamingData; using UnoptimizedCompilationJobList = std::forward_list>; // The V8 compiler API. // // This is the central hub for dispatching to the various compilers within V8. // Logic for which compiler to choose and how to wire compilation results into // the object heap should be kept inside this class. // // General strategy: Scripts are translated into anonymous functions w/o // parameters which then can be executed. If the source code contains other // functions, they might be compiled and allocated as part of the compilation // of the source code or deferred for lazy compilation at a later point. class V8_EXPORT_PRIVATE Compiler : public AllStatic { public: enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION }; // =========================================================================== // The following family of methods ensures a given function is compiled. The // general contract is that failures will be reported by returning {false}, // whereas successful compilation ensures the {is_compiled} predicate on the // given function holds (except for live-edit, which compiles the world). static bool Compile(Isolate* isolate, Handle shared, ClearExceptionFlag flag, IsCompiledScope* is_compiled_scope); static bool Compile(Isolate* isolate, Handle function, ClearExceptionFlag flag, IsCompiledScope* is_compiled_scope); static bool CompileSharedWithBaseline(Isolate* isolate, Handle shared, ClearExceptionFlag flag, IsCompiledScope* is_compiled_scope); static bool CompileBaseline(Isolate* isolate, Handle function, ClearExceptionFlag flag, IsCompiledScope* is_compiled_scope); static bool CompileOptimized(Isolate* isolate, Handle function, ConcurrencyMode mode, CodeKind code_kind); static MaybeHandle CompileToplevel( ParseInfo* parse_info, Handle