// 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/off-thread-isolate.h" #include "src/logging/code-events.h" #include "src/objects/contexts.h" #include "src/parsing/parse-info.h" #include "src/parsing/pending-compilation-error-handler.h" #include "src/utils/allocation.h" #include "src/zone/zone.h" namespace v8 { namespace internal { // Forward declarations. class AstRawString; class BackgroundCompileTask; class IsCompiledScope; class JavaScriptFrame; class OptimizedCompilationInfo; class OptimizedCompilationJob; class ParseInfo; class Parser; class RuntimeCallStats; class ScriptData; struct ScriptStreamingData; class TimedHistogram; class UnoptimizedCompilationInfo; class UnoptimizedCompilationJob; class WorkerThreadRuntimeCallStats; 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(Handle shared, ClearExceptionFlag flag, IsCompiledScope* is_compiled_scope); static bool Compile(Handle function, ClearExceptionFlag flag, IsCompiledScope* is_compiled_scope); static bool CompileOptimized(Handle function, ConcurrencyMode); // Collect source positions for a function that has already been compiled to // bytecode, but for which source positions were not collected (e.g. because // they were not immediately needed). static bool CollectSourcePositions(Isolate* isolate, Handle shared); V8_WARN_UNUSED_RESULT static MaybeHandle CompileForLiveEdit(ParseInfo* parse_info, Handle