11cb0ef41Sopenharmony_ci// Copyright 2012 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_CODEGEN_COMPILER_H_
61cb0ef41Sopenharmony_ci#define V8_CODEGEN_COMPILER_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <forward_list>
91cb0ef41Sopenharmony_ci#include <memory>
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci#include "src/ast/ast-value-factory.h"
121cb0ef41Sopenharmony_ci#include "src/base/platform/elapsed-timer.h"
131cb0ef41Sopenharmony_ci#include "src/base/small-vector.h"
141cb0ef41Sopenharmony_ci#include "src/codegen/bailout-reason.h"
151cb0ef41Sopenharmony_ci#include "src/common/globals.h"
161cb0ef41Sopenharmony_ci#include "src/execution/isolate.h"
171cb0ef41Sopenharmony_ci#include "src/execution/local-isolate.h"
181cb0ef41Sopenharmony_ci#include "src/handles/persistent-handles.h"
191cb0ef41Sopenharmony_ci#include "src/logging/code-events.h"
201cb0ef41Sopenharmony_ci#include "src/objects/contexts.h"
211cb0ef41Sopenharmony_ci#include "src/objects/debug-objects.h"
221cb0ef41Sopenharmony_ci#include "src/parsing/parse-info.h"
231cb0ef41Sopenharmony_ci#include "src/parsing/pending-compilation-error-handler.h"
241cb0ef41Sopenharmony_ci#include "src/snapshot/code-serializer.h"
251cb0ef41Sopenharmony_ci#include "src/utils/allocation.h"
261cb0ef41Sopenharmony_ci#include "src/zone/zone.h"
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_cinamespace v8 {
291cb0ef41Sopenharmony_cinamespace internal {
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci// Forward declarations.
321cb0ef41Sopenharmony_ciclass AlignedCachedData;
331cb0ef41Sopenharmony_ciclass BackgroundCompileTask;
341cb0ef41Sopenharmony_ciclass IsCompiledScope;
351cb0ef41Sopenharmony_ciclass OptimizedCompilationInfo;
361cb0ef41Sopenharmony_ciclass ParseInfo;
371cb0ef41Sopenharmony_ciclass RuntimeCallStats;
381cb0ef41Sopenharmony_ciclass TimedHistogram;
391cb0ef41Sopenharmony_ciclass TurbofanCompilationJob;
401cb0ef41Sopenharmony_ciclass UnoptimizedCompilationInfo;
411cb0ef41Sopenharmony_ciclass UnoptimizedCompilationJob;
421cb0ef41Sopenharmony_ciclass UnoptimizedFrame;
431cb0ef41Sopenharmony_ciclass WorkerThreadRuntimeCallStats;
441cb0ef41Sopenharmony_cistruct ScriptDetails;
451cb0ef41Sopenharmony_cistruct ScriptStreamingData;
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_cinamespace maglev {
481cb0ef41Sopenharmony_ciclass MaglevCompilationJob;
491cb0ef41Sopenharmony_ci}  // namespace maglev
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci// The V8 compiler API.
521cb0ef41Sopenharmony_ci//
531cb0ef41Sopenharmony_ci// This is the central hub for dispatching to the various compilers within V8.
541cb0ef41Sopenharmony_ci// Logic for which compiler to choose and how to wire compilation results into
551cb0ef41Sopenharmony_ci// the object heap should be kept inside this class.
561cb0ef41Sopenharmony_ci//
571cb0ef41Sopenharmony_ci// General strategy: Scripts are translated into anonymous functions w/o
581cb0ef41Sopenharmony_ci// parameters which then can be executed. If the source code contains other
591cb0ef41Sopenharmony_ci// functions, they might be compiled and allocated as part of the compilation
601cb0ef41Sopenharmony_ci// of the source code or deferred for lazy compilation at a later point.
611cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE Compiler : public AllStatic {
621cb0ef41Sopenharmony_ci public:
631cb0ef41Sopenharmony_ci  enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION };
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  // ===========================================================================
661cb0ef41Sopenharmony_ci  // The following family of methods ensures a given function is compiled. The
671cb0ef41Sopenharmony_ci  // general contract is that failures will be reported by returning {false},
681cb0ef41Sopenharmony_ci  // whereas successful compilation ensures the {is_compiled} predicate on the
691cb0ef41Sopenharmony_ci  // given function holds (except for live-edit, which compiles the world).
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci  static bool Compile(Isolate* isolate, Handle<SharedFunctionInfo> shared,
721cb0ef41Sopenharmony_ci                      ClearExceptionFlag flag,
731cb0ef41Sopenharmony_ci                      IsCompiledScope* is_compiled_scope,
741cb0ef41Sopenharmony_ci                      CreateSourcePositions create_source_positions_flag =
751cb0ef41Sopenharmony_ci                          CreateSourcePositions::kNo);
761cb0ef41Sopenharmony_ci  static bool Compile(Isolate* isolate, Handle<JSFunction> function,
771cb0ef41Sopenharmony_ci                      ClearExceptionFlag flag,
781cb0ef41Sopenharmony_ci                      IsCompiledScope* is_compiled_scope);
791cb0ef41Sopenharmony_ci  static MaybeHandle<SharedFunctionInfo> CompileToplevel(
801cb0ef41Sopenharmony_ci      ParseInfo* parse_info, Handle<Script> script, Isolate* isolate,
811cb0ef41Sopenharmony_ci      IsCompiledScope* is_compiled_scope);
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci  static bool CompileSharedWithBaseline(Isolate* isolate,
841cb0ef41Sopenharmony_ci                                        Handle<SharedFunctionInfo> shared,
851cb0ef41Sopenharmony_ci                                        ClearExceptionFlag flag,
861cb0ef41Sopenharmony_ci                                        IsCompiledScope* is_compiled_scope);
871cb0ef41Sopenharmony_ci  static bool CompileBaseline(Isolate* isolate, Handle<JSFunction> function,
881cb0ef41Sopenharmony_ci                              ClearExceptionFlag flag,
891cb0ef41Sopenharmony_ci                              IsCompiledScope* is_compiled_scope);
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  static bool CompileMaglev(Isolate* isolate, Handle<JSFunction> function,
921cb0ef41Sopenharmony_ci                            ConcurrencyMode mode,
931cb0ef41Sopenharmony_ci                            IsCompiledScope* is_compiled_scope);
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_ci  static void CompileOptimized(Isolate* isolate, Handle<JSFunction> function,
961cb0ef41Sopenharmony_ci                               ConcurrencyMode mode, CodeKind code_kind);
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci  // Generate and return optimized code for OSR. The empty handle is returned
991cb0ef41Sopenharmony_ci  // either on failure, or after spawning a concurrent OSR task (in which case
1001cb0ef41Sopenharmony_ci  // a future OSR request will pick up the resulting code object).
1011cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<CodeT> CompileOptimizedOSR(
1021cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSFunction> function, BytecodeOffset osr_offset,
1031cb0ef41Sopenharmony_ci      UnoptimizedFrame* frame, ConcurrencyMode mode);
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<SharedFunctionInfo>
1061cb0ef41Sopenharmony_ci  CompileForLiveEdit(ParseInfo* parse_info, Handle<Script> script,
1071cb0ef41Sopenharmony_ci                     Isolate* isolate);
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ci  // Collect source positions for a function that has already been compiled to
1101cb0ef41Sopenharmony_ci  // bytecode, but for which source positions were not collected (e.g. because
1111cb0ef41Sopenharmony_ci  // they were not immediately needed).
1121cb0ef41Sopenharmony_ci  static bool CollectSourcePositions(Isolate* isolate,
1131cb0ef41Sopenharmony_ci                                     Handle<SharedFunctionInfo> shared);
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci  // Finalize and install code from previously run background compile task.
1161cb0ef41Sopenharmony_ci  static bool FinalizeBackgroundCompileTask(BackgroundCompileTask* task,
1171cb0ef41Sopenharmony_ci                                            Isolate* isolate,
1181cb0ef41Sopenharmony_ci                                            ClearExceptionFlag flag);
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_ci  // Dispose a job without finalization.
1211cb0ef41Sopenharmony_ci  static void DisposeTurbofanCompilationJob(TurbofanCompilationJob* job,
1221cb0ef41Sopenharmony_ci                                            bool restore_function_code);
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci  // Finalize and install Turbofan code from a previously run job.
1251cb0ef41Sopenharmony_ci  static bool FinalizeTurbofanCompilationJob(TurbofanCompilationJob* job,
1261cb0ef41Sopenharmony_ci                                             Isolate* isolate);
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ci  // Finalize and install Maglev code from a previously run job.
1291cb0ef41Sopenharmony_ci  static bool FinalizeMaglevCompilationJob(maglev::MaglevCompilationJob* job,
1301cb0ef41Sopenharmony_ci                                           Isolate* isolate);
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_ci  // Give the compiler a chance to perform low-latency initialization tasks of
1331cb0ef41Sopenharmony_ci  // the given {function} on its instantiation. Note that only the runtime will
1341cb0ef41Sopenharmony_ci  // offer this chance, optimized closure instantiation will not call this.
1351cb0ef41Sopenharmony_ci  static void PostInstantiation(Handle<JSFunction> function);
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci  // ===========================================================================
1381cb0ef41Sopenharmony_ci  // The following family of methods instantiates new functions for scripts or
1391cb0ef41Sopenharmony_ci  // function literals. The decision whether those functions will be compiled,
1401cb0ef41Sopenharmony_ci  // is left to the discretion of the compiler.
1411cb0ef41Sopenharmony_ci  //
1421cb0ef41Sopenharmony_ci  // Please note this interface returns shared function infos.  This means you
1431cb0ef41Sopenharmony_ci  // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a
1441cb0ef41Sopenharmony_ci  // real function with a context.
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ci  // Create a (bound) function for a String source within a context for eval.
1471cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval(
1481cb0ef41Sopenharmony_ci      Handle<String> source, Handle<SharedFunctionInfo> outer_info,
1491cb0ef41Sopenharmony_ci      Handle<Context> context, LanguageMode language_mode,
1501cb0ef41Sopenharmony_ci      ParseRestriction restriction, int parameters_end_pos,
1511cb0ef41Sopenharmony_ci      int eval_scope_position, int eval_position,
1521cb0ef41Sopenharmony_ci      ParsingWhileDebugging parsing_while_debugging =
1531cb0ef41Sopenharmony_ci          ParsingWhileDebugging::kNo);
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci  // Create a function that results from wrapping |source| in a function,
1561cb0ef41Sopenharmony_ci  // with |arguments| being a list of parameters for that function.
1571cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetWrappedFunction(
1581cb0ef41Sopenharmony_ci      Handle<String> source, Handle<FixedArray> arguments,
1591cb0ef41Sopenharmony_ci      Handle<Context> context, const ScriptDetails& script_details,
1601cb0ef41Sopenharmony_ci      AlignedCachedData* cached_data,
1611cb0ef41Sopenharmony_ci      v8::ScriptCompiler::CompileOptions compile_options,
1621cb0ef41Sopenharmony_ci      v8::ScriptCompiler::NoCacheReason no_cache_reason);
1631cb0ef41Sopenharmony_ci
1641cb0ef41Sopenharmony_ci  // Create a (bound) function for a String source within a context for eval.
1651cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction> GetFunctionFromString(
1661cb0ef41Sopenharmony_ci      Handle<Context> context, Handle<i::Object> source,
1671cb0ef41Sopenharmony_ci      ParseRestriction restriction, int parameters_end_pos, bool is_code_like);
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci  // Decompose GetFunctionFromString into two functions, to allow callers to
1701cb0ef41Sopenharmony_ci  // deal seperately with a case of object not handled by the embedder.
1711cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static std::pair<MaybeHandle<String>, bool>
1721cb0ef41Sopenharmony_ci  ValidateDynamicCompilationSource(Isolate* isolate, Handle<Context> context,
1731cb0ef41Sopenharmony_ci                                   Handle<i::Object> source_object,
1741cb0ef41Sopenharmony_ci                                   bool is_code_like = false);
1751cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSFunction>
1761cb0ef41Sopenharmony_ci  GetFunctionFromValidatedString(Handle<Context> context,
1771cb0ef41Sopenharmony_ci                                 MaybeHandle<String> source,
1781cb0ef41Sopenharmony_ci                                 ParseRestriction restriction,
1791cb0ef41Sopenharmony_ci                                 int parameters_end_pos);
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ci  // Create a shared function info object for a String source.
1821cb0ef41Sopenharmony_ci  static MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScript(
1831cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<String> source,
1841cb0ef41Sopenharmony_ci      const ScriptDetails& script_details,
1851cb0ef41Sopenharmony_ci      ScriptCompiler::CompileOptions compile_options,
1861cb0ef41Sopenharmony_ci      ScriptCompiler::NoCacheReason no_cache_reason,
1871cb0ef41Sopenharmony_ci      NativesFlag is_natives_code);
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ci  // Create a shared function info object for a String source.
1901cb0ef41Sopenharmony_ci  static MaybeHandle<SharedFunctionInfo>
1911cb0ef41Sopenharmony_ci  GetSharedFunctionInfoForScriptWithExtension(
1921cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<String> source,
1931cb0ef41Sopenharmony_ci      const ScriptDetails& script_details, v8::Extension* extension,
1941cb0ef41Sopenharmony_ci      ScriptCompiler::CompileOptions compile_options,
1951cb0ef41Sopenharmony_ci      NativesFlag is_natives_code);
1961cb0ef41Sopenharmony_ci
1971cb0ef41Sopenharmony_ci  // Create a shared function info object for a String source and serialized
1981cb0ef41Sopenharmony_ci  // cached data. The cached data may be rejected, in which case this function
1991cb0ef41Sopenharmony_ci  // will set cached_data->rejected() to true.
2001cb0ef41Sopenharmony_ci  static MaybeHandle<SharedFunctionInfo>
2011cb0ef41Sopenharmony_ci  GetSharedFunctionInfoForScriptWithCachedData(
2021cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<String> source,
2031cb0ef41Sopenharmony_ci      const ScriptDetails& script_details, AlignedCachedData* cached_data,
2041cb0ef41Sopenharmony_ci      ScriptCompiler::CompileOptions compile_options,
2051cb0ef41Sopenharmony_ci      ScriptCompiler::NoCacheReason no_cache_reason,
2061cb0ef41Sopenharmony_ci      NativesFlag is_natives_code);
2071cb0ef41Sopenharmony_ci
2081cb0ef41Sopenharmony_ci  // Create a shared function info object for a String source and a task that
2091cb0ef41Sopenharmony_ci  // has deserialized cached data on a background thread. The cached data from
2101cb0ef41Sopenharmony_ci  // the task may be rejected, in which case this function will set
2111cb0ef41Sopenharmony_ci  // deserialize_task->rejected() to true.
2121cb0ef41Sopenharmony_ci  static MaybeHandle<SharedFunctionInfo>
2131cb0ef41Sopenharmony_ci  GetSharedFunctionInfoForScriptWithDeserializeTask(
2141cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<String> source,
2151cb0ef41Sopenharmony_ci      const ScriptDetails& script_details,
2161cb0ef41Sopenharmony_ci      BackgroundDeserializeTask* deserialize_task,
2171cb0ef41Sopenharmony_ci      ScriptCompiler::CompileOptions compile_options,
2181cb0ef41Sopenharmony_ci      ScriptCompiler::NoCacheReason no_cache_reason,
2191cb0ef41Sopenharmony_ci      NativesFlag is_natives_code);
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_ci  // Create a shared function info object for a Script source that has already
2221cb0ef41Sopenharmony_ci  // been parsed and possibly compiled on a background thread while being loaded
2231cb0ef41Sopenharmony_ci  // from a streamed source. On return, the data held by |streaming_data| will
2241cb0ef41Sopenharmony_ci  // have been released, however the object itself isn't freed and is still
2251cb0ef41Sopenharmony_ci  // owned by the caller.
2261cb0ef41Sopenharmony_ci  static MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForStreamedScript(
2271cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<String> source,
2281cb0ef41Sopenharmony_ci      const ScriptDetails& script_details, ScriptStreamingData* streaming_data);
2291cb0ef41Sopenharmony_ci
2301cb0ef41Sopenharmony_ci  static Handle<SharedFunctionInfo> GetSharedFunctionInfoForWebSnapshot(
2311cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<String> source, MaybeHandle<Object> script_name);
2321cb0ef41Sopenharmony_ci
2331cb0ef41Sopenharmony_ci  // Create a shared function info object for the given function literal
2341cb0ef41Sopenharmony_ci  // node (the code may be lazily compiled).
2351cb0ef41Sopenharmony_ci  template <typename IsolateT>
2361cb0ef41Sopenharmony_ci  static Handle<SharedFunctionInfo> GetSharedFunctionInfo(FunctionLiteral* node,
2371cb0ef41Sopenharmony_ci                                                          Handle<Script> script,
2381cb0ef41Sopenharmony_ci                                                          IsolateT* isolate);
2391cb0ef41Sopenharmony_ci};
2401cb0ef41Sopenharmony_ci
2411cb0ef41Sopenharmony_ci// A base class for compilation jobs intended to run concurrent to the main
2421cb0ef41Sopenharmony_ci// thread. The current state of the job can be checked using {state()}.
2431cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE CompilationJob {
2441cb0ef41Sopenharmony_ci public:
2451cb0ef41Sopenharmony_ci  enum Status { SUCCEEDED, FAILED, RETRY_ON_MAIN_THREAD };
2461cb0ef41Sopenharmony_ci  enum class State {
2471cb0ef41Sopenharmony_ci    kReadyToPrepare,
2481cb0ef41Sopenharmony_ci    kReadyToExecute,
2491cb0ef41Sopenharmony_ci    kReadyToFinalize,
2501cb0ef41Sopenharmony_ci    kSucceeded,
2511cb0ef41Sopenharmony_ci    kFailed,
2521cb0ef41Sopenharmony_ci  };
2531cb0ef41Sopenharmony_ci
2541cb0ef41Sopenharmony_ci  explicit CompilationJob(State initial_state) : state_(initial_state) {
2551cb0ef41Sopenharmony_ci    timer_.Start();
2561cb0ef41Sopenharmony_ci  }
2571cb0ef41Sopenharmony_ci  virtual ~CompilationJob() = default;
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci  State state() const { return state_; }
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_ci protected:
2621cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT base::TimeDelta ElapsedTime() const {
2631cb0ef41Sopenharmony_ci    return timer_.Elapsed();
2641cb0ef41Sopenharmony_ci  }
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Status UpdateState(Status status, State next_state) {
2671cb0ef41Sopenharmony_ci    switch (status) {
2681cb0ef41Sopenharmony_ci      case SUCCEEDED:
2691cb0ef41Sopenharmony_ci        state_ = next_state;
2701cb0ef41Sopenharmony_ci        break;
2711cb0ef41Sopenharmony_ci      case FAILED:
2721cb0ef41Sopenharmony_ci        state_ = State::kFailed;
2731cb0ef41Sopenharmony_ci        break;
2741cb0ef41Sopenharmony_ci      case RETRY_ON_MAIN_THREAD:
2751cb0ef41Sopenharmony_ci        // Don't change the state, we'll re-try on the main thread.
2761cb0ef41Sopenharmony_ci        break;
2771cb0ef41Sopenharmony_ci    }
2781cb0ef41Sopenharmony_ci    return status;
2791cb0ef41Sopenharmony_ci  }
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ci private:
2821cb0ef41Sopenharmony_ci  State state_;
2831cb0ef41Sopenharmony_ci  base::ElapsedTimer timer_;
2841cb0ef41Sopenharmony_ci};
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_ci// A base class for unoptimized compilation jobs.
2871cb0ef41Sopenharmony_ci//
2881cb0ef41Sopenharmony_ci// The job is split into two phases which are called in sequence on
2891cb0ef41Sopenharmony_ci// different threads and with different limitations:
2901cb0ef41Sopenharmony_ci//  1) ExecuteJob:   Runs concurrently. No heap allocation or handle derefs.
2911cb0ef41Sopenharmony_ci//  2) FinalizeJob:  Runs on main thread. No dependency changes.
2921cb0ef41Sopenharmony_ci//
2931cb0ef41Sopenharmony_ci// Either of phases can either fail or succeed.
2941cb0ef41Sopenharmony_ciclass UnoptimizedCompilationJob : public CompilationJob {
2951cb0ef41Sopenharmony_ci public:
2961cb0ef41Sopenharmony_ci  UnoptimizedCompilationJob(uintptr_t stack_limit, ParseInfo* parse_info,
2971cb0ef41Sopenharmony_ci                            UnoptimizedCompilationInfo* compilation_info)
2981cb0ef41Sopenharmony_ci      : CompilationJob(State::kReadyToExecute),
2991cb0ef41Sopenharmony_ci        stack_limit_(stack_limit),
3001cb0ef41Sopenharmony_ci        parse_info_(parse_info),
3011cb0ef41Sopenharmony_ci        compilation_info_(compilation_info) {}
3021cb0ef41Sopenharmony_ci
3031cb0ef41Sopenharmony_ci  // Executes the compile job. Can be called on a background thread.
3041cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Status ExecuteJob();
3051cb0ef41Sopenharmony_ci
3061cb0ef41Sopenharmony_ci  // Finalizes the compile job. Must be called on the main thread.
3071cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Status
3081cb0ef41Sopenharmony_ci  FinalizeJob(Handle<SharedFunctionInfo> shared_info, Isolate* isolate);
3091cb0ef41Sopenharmony_ci
3101cb0ef41Sopenharmony_ci  // Finalizes the compile job. Can be called on a background thread, and might
3111cb0ef41Sopenharmony_ci  // return RETRY_ON_MAIN_THREAD if the finalization can't be run on the
3121cb0ef41Sopenharmony_ci  // background thread, and should instead be retried on the foreground thread.
3131cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT Status
3141cb0ef41Sopenharmony_ci  FinalizeJob(Handle<SharedFunctionInfo> shared_info, LocalIsolate* isolate);
3151cb0ef41Sopenharmony_ci
3161cb0ef41Sopenharmony_ci  void RecordCompilationStats(Isolate* isolate) const;
3171cb0ef41Sopenharmony_ci  void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
3181cb0ef41Sopenharmony_ci                                 Handle<SharedFunctionInfo> shared,
3191cb0ef41Sopenharmony_ci                                 Isolate* isolate) const;
3201cb0ef41Sopenharmony_ci
3211cb0ef41Sopenharmony_ci  ParseInfo* parse_info() const {
3221cb0ef41Sopenharmony_ci    DCHECK_NOT_NULL(parse_info_);
3231cb0ef41Sopenharmony_ci    return parse_info_;
3241cb0ef41Sopenharmony_ci  }
3251cb0ef41Sopenharmony_ci  UnoptimizedCompilationInfo* compilation_info() const {
3261cb0ef41Sopenharmony_ci    return compilation_info_;
3271cb0ef41Sopenharmony_ci  }
3281cb0ef41Sopenharmony_ci
3291cb0ef41Sopenharmony_ci  uintptr_t stack_limit() const { return stack_limit_; }
3301cb0ef41Sopenharmony_ci
3311cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_execute() const {
3321cb0ef41Sopenharmony_ci    return time_taken_to_execute_;
3331cb0ef41Sopenharmony_ci  }
3341cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_finalize() const {
3351cb0ef41Sopenharmony_ci    return time_taken_to_finalize_;
3361cb0ef41Sopenharmony_ci  }
3371cb0ef41Sopenharmony_ci
3381cb0ef41Sopenharmony_ci  void ClearParseInfo() { parse_info_ = nullptr; }
3391cb0ef41Sopenharmony_ci
3401cb0ef41Sopenharmony_ci protected:
3411cb0ef41Sopenharmony_ci  // Overridden by the actual implementation.
3421cb0ef41Sopenharmony_ci  virtual Status ExecuteJobImpl() = 0;
3431cb0ef41Sopenharmony_ci  virtual Status FinalizeJobImpl(Handle<SharedFunctionInfo> shared_info,
3441cb0ef41Sopenharmony_ci                                 Isolate* isolate) = 0;
3451cb0ef41Sopenharmony_ci  virtual Status FinalizeJobImpl(Handle<SharedFunctionInfo> shared_info,
3461cb0ef41Sopenharmony_ci                                 LocalIsolate* isolate) = 0;
3471cb0ef41Sopenharmony_ci
3481cb0ef41Sopenharmony_ci private:
3491cb0ef41Sopenharmony_ci  uintptr_t stack_limit_;
3501cb0ef41Sopenharmony_ci  ParseInfo* parse_info_;
3511cb0ef41Sopenharmony_ci  UnoptimizedCompilationInfo* compilation_info_;
3521cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_execute_;
3531cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_finalize_;
3541cb0ef41Sopenharmony_ci};
3551cb0ef41Sopenharmony_ci
3561cb0ef41Sopenharmony_ci// A base class for optimized compilation jobs.
3571cb0ef41Sopenharmony_ci//
3581cb0ef41Sopenharmony_ci// The job is split into three phases which are called in sequence on
3591cb0ef41Sopenharmony_ci// different threads and with different limitations:
3601cb0ef41Sopenharmony_ci//  1) PrepareJob:   Runs on main thread. No major limitations.
3611cb0ef41Sopenharmony_ci//  2) ExecuteJob:   Runs concurrently. No heap allocation or handle derefs.
3621cb0ef41Sopenharmony_ci//  3) FinalizeJob:  Runs on main thread. No dependency changes.
3631cb0ef41Sopenharmony_ci//
3641cb0ef41Sopenharmony_ci// Each of the three phases can either fail or succeed.
3651cb0ef41Sopenharmony_ciclass OptimizedCompilationJob : public CompilationJob {
3661cb0ef41Sopenharmony_ci public:
3671cb0ef41Sopenharmony_ci  OptimizedCompilationJob(const char* compiler_name, State initial_state)
3681cb0ef41Sopenharmony_ci      : CompilationJob(initial_state), compiler_name_(compiler_name) {}
3691cb0ef41Sopenharmony_ci
3701cb0ef41Sopenharmony_ci  // Prepare the compile job. Must be called on the main thread.
3711cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status PrepareJob(Isolate* isolate);
3721cb0ef41Sopenharmony_ci
3731cb0ef41Sopenharmony_ci  // Executes the compile job. Can be called on a background thread.
3741cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status
3751cb0ef41Sopenharmony_ci  ExecuteJob(RuntimeCallStats* stats, LocalIsolate* local_isolate = nullptr);
3761cb0ef41Sopenharmony_ci
3771cb0ef41Sopenharmony_ci  // Finalizes the compile job. Must be called on the main thread.
3781cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status FinalizeJob(Isolate* isolate);
3791cb0ef41Sopenharmony_ci
3801cb0ef41Sopenharmony_ci  const char* compiler_name() const { return compiler_name_; }
3811cb0ef41Sopenharmony_ci
3821cb0ef41Sopenharmony_ci protected:
3831cb0ef41Sopenharmony_ci  // Overridden by the actual implementation.
3841cb0ef41Sopenharmony_ci  virtual Status PrepareJobImpl(Isolate* isolate) = 0;
3851cb0ef41Sopenharmony_ci  virtual Status ExecuteJobImpl(RuntimeCallStats* stats,
3861cb0ef41Sopenharmony_ci                                LocalIsolate* local_heap) = 0;
3871cb0ef41Sopenharmony_ci  virtual Status FinalizeJobImpl(Isolate* isolate) = 0;
3881cb0ef41Sopenharmony_ci
3891cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_prepare_;
3901cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_execute_;
3911cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_finalize_;
3921cb0ef41Sopenharmony_ci
3931cb0ef41Sopenharmony_ci private:
3941cb0ef41Sopenharmony_ci  const char* const compiler_name_;
3951cb0ef41Sopenharmony_ci};
3961cb0ef41Sopenharmony_ci
3971cb0ef41Sopenharmony_ci// Thin wrapper to split off Turbofan-specific parts.
3981cb0ef41Sopenharmony_ciclass TurbofanCompilationJob : public OptimizedCompilationJob {
3991cb0ef41Sopenharmony_ci public:
4001cb0ef41Sopenharmony_ci  TurbofanCompilationJob(OptimizedCompilationInfo* compilation_info,
4011cb0ef41Sopenharmony_ci                         State initial_state)
4021cb0ef41Sopenharmony_ci      : OptimizedCompilationJob("Turbofan", initial_state),
4031cb0ef41Sopenharmony_ci        compilation_info_(compilation_info) {}
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci  OptimizedCompilationInfo* compilation_info() const {
4061cb0ef41Sopenharmony_ci    return compilation_info_;
4071cb0ef41Sopenharmony_ci  }
4081cb0ef41Sopenharmony_ci
4091cb0ef41Sopenharmony_ci  // Report a transient failure, try again next time. Should only be called on
4101cb0ef41Sopenharmony_ci  // optimization compilation jobs.
4111cb0ef41Sopenharmony_ci  Status RetryOptimization(BailoutReason reason);
4121cb0ef41Sopenharmony_ci
4131cb0ef41Sopenharmony_ci  // Report a persistent failure, disable future optimization on the function.
4141cb0ef41Sopenharmony_ci  // Should only be called on optimization compilation jobs.
4151cb0ef41Sopenharmony_ci  Status AbortOptimization(BailoutReason reason);
4161cb0ef41Sopenharmony_ci
4171cb0ef41Sopenharmony_ci  void RecordCompilationStats(ConcurrencyMode mode, Isolate* isolate) const;
4181cb0ef41Sopenharmony_ci  void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
4191cb0ef41Sopenharmony_ci                                 Isolate* isolate) const;
4201cb0ef41Sopenharmony_ci
4211cb0ef41Sopenharmony_ci private:
4221cb0ef41Sopenharmony_ci  OptimizedCompilationInfo* const compilation_info_;
4231cb0ef41Sopenharmony_ci};
4241cb0ef41Sopenharmony_ci
4251cb0ef41Sopenharmony_ciclass FinalizeUnoptimizedCompilationData {
4261cb0ef41Sopenharmony_ci public:
4271cb0ef41Sopenharmony_ci  FinalizeUnoptimizedCompilationData(Isolate* isolate,
4281cb0ef41Sopenharmony_ci                                     Handle<SharedFunctionInfo> function_handle,
4291cb0ef41Sopenharmony_ci                                     MaybeHandle<CoverageInfo> coverage_info,
4301cb0ef41Sopenharmony_ci                                     base::TimeDelta time_taken_to_execute,
4311cb0ef41Sopenharmony_ci                                     base::TimeDelta time_taken_to_finalize)
4321cb0ef41Sopenharmony_ci      : time_taken_to_execute_(time_taken_to_execute),
4331cb0ef41Sopenharmony_ci        time_taken_to_finalize_(time_taken_to_finalize),
4341cb0ef41Sopenharmony_ci        function_handle_(function_handle),
4351cb0ef41Sopenharmony_ci        coverage_info_(coverage_info) {}
4361cb0ef41Sopenharmony_ci
4371cb0ef41Sopenharmony_ci  FinalizeUnoptimizedCompilationData(LocalIsolate* isolate,
4381cb0ef41Sopenharmony_ci                                     Handle<SharedFunctionInfo> function_handle,
4391cb0ef41Sopenharmony_ci                                     MaybeHandle<CoverageInfo> coverage_info,
4401cb0ef41Sopenharmony_ci                                     base::TimeDelta time_taken_to_execute,
4411cb0ef41Sopenharmony_ci                                     base::TimeDelta time_taken_to_finalize);
4421cb0ef41Sopenharmony_ci
4431cb0ef41Sopenharmony_ci  Handle<SharedFunctionInfo> function_handle() const {
4441cb0ef41Sopenharmony_ci    return function_handle_;
4451cb0ef41Sopenharmony_ci  }
4461cb0ef41Sopenharmony_ci
4471cb0ef41Sopenharmony_ci  MaybeHandle<CoverageInfo> coverage_info() const { return coverage_info_; }
4481cb0ef41Sopenharmony_ci
4491cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_execute() const {
4501cb0ef41Sopenharmony_ci    return time_taken_to_execute_;
4511cb0ef41Sopenharmony_ci  }
4521cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_finalize() const {
4531cb0ef41Sopenharmony_ci    return time_taken_to_finalize_;
4541cb0ef41Sopenharmony_ci  }
4551cb0ef41Sopenharmony_ci
4561cb0ef41Sopenharmony_ci private:
4571cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_execute_;
4581cb0ef41Sopenharmony_ci  base::TimeDelta time_taken_to_finalize_;
4591cb0ef41Sopenharmony_ci  Handle<SharedFunctionInfo> function_handle_;
4601cb0ef41Sopenharmony_ci  MaybeHandle<CoverageInfo> coverage_info_;
4611cb0ef41Sopenharmony_ci};
4621cb0ef41Sopenharmony_ci
4631cb0ef41Sopenharmony_ciusing FinalizeUnoptimizedCompilationDataList =
4641cb0ef41Sopenharmony_ci    std::vector<FinalizeUnoptimizedCompilationData>;
4651cb0ef41Sopenharmony_ci
4661cb0ef41Sopenharmony_ciclass DeferredFinalizationJobData {
4671cb0ef41Sopenharmony_ci public:
4681cb0ef41Sopenharmony_ci  DeferredFinalizationJobData(Isolate* isolate,
4691cb0ef41Sopenharmony_ci                              Handle<SharedFunctionInfo> function_handle,
4701cb0ef41Sopenharmony_ci                              std::unique_ptr<UnoptimizedCompilationJob> job) {
4711cb0ef41Sopenharmony_ci    UNREACHABLE();
4721cb0ef41Sopenharmony_ci  }
4731cb0ef41Sopenharmony_ci  DeferredFinalizationJobData(LocalIsolate* isolate,
4741cb0ef41Sopenharmony_ci                              Handle<SharedFunctionInfo> function_handle,
4751cb0ef41Sopenharmony_ci                              std::unique_ptr<UnoptimizedCompilationJob> job);
4761cb0ef41Sopenharmony_ci
4771cb0ef41Sopenharmony_ci  Handle<SharedFunctionInfo> function_handle() const {
4781cb0ef41Sopenharmony_ci    return function_handle_;
4791cb0ef41Sopenharmony_ci  }
4801cb0ef41Sopenharmony_ci
4811cb0ef41Sopenharmony_ci  UnoptimizedCompilationJob* job() const { return job_.get(); }
4821cb0ef41Sopenharmony_ci
4831cb0ef41Sopenharmony_ci private:
4841cb0ef41Sopenharmony_ci  Handle<SharedFunctionInfo> function_handle_;
4851cb0ef41Sopenharmony_ci  std::unique_ptr<UnoptimizedCompilationJob> job_;
4861cb0ef41Sopenharmony_ci};
4871cb0ef41Sopenharmony_ci
4881cb0ef41Sopenharmony_ci// A wrapper around a OptimizedCompilationInfo that detaches the Handles from
4891cb0ef41Sopenharmony_ci// the underlying PersistentHandlesScope and stores them in info_ on
4901cb0ef41Sopenharmony_ci// destruction.
4911cb0ef41Sopenharmony_ciclass V8_NODISCARD CompilationHandleScope final {
4921cb0ef41Sopenharmony_ci public:
4931cb0ef41Sopenharmony_ci  explicit CompilationHandleScope(Isolate* isolate,
4941cb0ef41Sopenharmony_ci                                  OptimizedCompilationInfo* info)
4951cb0ef41Sopenharmony_ci      : persistent_(isolate), info_(info) {}
4961cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE ~CompilationHandleScope();
4971cb0ef41Sopenharmony_ci
4981cb0ef41Sopenharmony_ci private:
4991cb0ef41Sopenharmony_ci  PersistentHandlesScope persistent_;
5001cb0ef41Sopenharmony_ci  OptimizedCompilationInfo* info_;
5011cb0ef41Sopenharmony_ci};
5021cb0ef41Sopenharmony_ci
5031cb0ef41Sopenharmony_ciusing DeferredFinalizationJobDataList =
5041cb0ef41Sopenharmony_ci    std::vector<DeferredFinalizationJobData>;
5051cb0ef41Sopenharmony_ci
5061cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE BackgroundCompileTask {
5071cb0ef41Sopenharmony_ci public:
5081cb0ef41Sopenharmony_ci  // Creates a new task that when run will parse and compile the streamed
5091cb0ef41Sopenharmony_ci  // script associated with |data| and can be finalized with FinalizeScript.
5101cb0ef41Sopenharmony_ci  // Note: does not take ownership of |data|.
5111cb0ef41Sopenharmony_ci  BackgroundCompileTask(ScriptStreamingData* data, Isolate* isolate,
5121cb0ef41Sopenharmony_ci                        v8::ScriptType type);
5131cb0ef41Sopenharmony_ci  BackgroundCompileTask(const BackgroundCompileTask&) = delete;
5141cb0ef41Sopenharmony_ci  BackgroundCompileTask& operator=(const BackgroundCompileTask&) = delete;
5151cb0ef41Sopenharmony_ci  ~BackgroundCompileTask();
5161cb0ef41Sopenharmony_ci
5171cb0ef41Sopenharmony_ci  // Creates a new task that when run will parse and compile the top-level
5181cb0ef41Sopenharmony_ci  // |shared_info| and can be finalized with FinalizeFunction in
5191cb0ef41Sopenharmony_ci  // Compiler::FinalizeBackgroundCompileTask.
5201cb0ef41Sopenharmony_ci  BackgroundCompileTask(
5211cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
5221cb0ef41Sopenharmony_ci      std::unique_ptr<Utf16CharacterStream> character_stream,
5231cb0ef41Sopenharmony_ci      WorkerThreadRuntimeCallStats* worker_thread_runtime_stats,
5241cb0ef41Sopenharmony_ci      TimedHistogram* timer, int max_stack_size);
5251cb0ef41Sopenharmony_ci
5261cb0ef41Sopenharmony_ci  void Run();
5271cb0ef41Sopenharmony_ci  void RunOnMainThread(Isolate* isolate);
5281cb0ef41Sopenharmony_ci  void Run(LocalIsolate* isolate,
5291cb0ef41Sopenharmony_ci           ReusableUnoptimizedCompileState* reusable_state);
5301cb0ef41Sopenharmony_ci
5311cb0ef41Sopenharmony_ci  MaybeHandle<SharedFunctionInfo> FinalizeScript(
5321cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<String> source,
5331cb0ef41Sopenharmony_ci      const ScriptDetails& script_details);
5341cb0ef41Sopenharmony_ci
5351cb0ef41Sopenharmony_ci  bool FinalizeFunction(Isolate* isolate, Compiler::ClearExceptionFlag flag);
5361cb0ef41Sopenharmony_ci
5371cb0ef41Sopenharmony_ci  void AbortFunction();
5381cb0ef41Sopenharmony_ci
5391cb0ef41Sopenharmony_ci  UnoptimizedCompileFlags flags() const { return flags_; }
5401cb0ef41Sopenharmony_ci
5411cb0ef41Sopenharmony_ci private:
5421cb0ef41Sopenharmony_ci  void ReportStatistics(Isolate* isolate);
5431cb0ef41Sopenharmony_ci
5441cb0ef41Sopenharmony_ci  void ClearFunctionJobPointer();
5451cb0ef41Sopenharmony_ci
5461cb0ef41Sopenharmony_ci  // Data needed for parsing and compilation. These need to be initialized
5471cb0ef41Sopenharmony_ci  // before the compilation starts.
5481cb0ef41Sopenharmony_ci  Isolate* isolate_for_local_isolate_;
5491cb0ef41Sopenharmony_ci  UnoptimizedCompileFlags flags_;
5501cb0ef41Sopenharmony_ci  UnoptimizedCompileState compile_state_;
5511cb0ef41Sopenharmony_ci  std::unique_ptr<Utf16CharacterStream> character_stream_;
5521cb0ef41Sopenharmony_ci  int stack_size_;
5531cb0ef41Sopenharmony_ci  WorkerThreadRuntimeCallStats* worker_thread_runtime_call_stats_;
5541cb0ef41Sopenharmony_ci  TimedHistogram* timer_;
5551cb0ef41Sopenharmony_ci
5561cb0ef41Sopenharmony_ci  // Data needed for merging onto the main thread after background finalization.
5571cb0ef41Sopenharmony_ci  std::unique_ptr<PersistentHandles> persistent_handles_;
5581cb0ef41Sopenharmony_ci  MaybeHandle<SharedFunctionInfo> outer_function_sfi_;
5591cb0ef41Sopenharmony_ci  Handle<Script> script_;
5601cb0ef41Sopenharmony_ci  IsCompiledScope is_compiled_scope_;
5611cb0ef41Sopenharmony_ci  FinalizeUnoptimizedCompilationDataList finalize_unoptimized_compilation_data_;
5621cb0ef41Sopenharmony_ci  DeferredFinalizationJobDataList jobs_to_retry_finalization_on_main_thread_;
5631cb0ef41Sopenharmony_ci  base::SmallVector<v8::Isolate::UseCounterFeature, 8> use_counts_;
5641cb0ef41Sopenharmony_ci  int total_preparse_skipped_ = 0;
5651cb0ef41Sopenharmony_ci
5661cb0ef41Sopenharmony_ci  // Single function data for top-level function compilation.
5671cb0ef41Sopenharmony_ci  MaybeHandle<SharedFunctionInfo> input_shared_info_;
5681cb0ef41Sopenharmony_ci  int start_position_;
5691cb0ef41Sopenharmony_ci  int end_position_;
5701cb0ef41Sopenharmony_ci  int function_literal_id_;
5711cb0ef41Sopenharmony_ci};
5721cb0ef41Sopenharmony_ci
5731cb0ef41Sopenharmony_ci// Contains all data which needs to be transmitted between threads for
5741cb0ef41Sopenharmony_ci// background parsing and compiling and finalizing it on the main thread.
5751cb0ef41Sopenharmony_cistruct ScriptStreamingData {
5761cb0ef41Sopenharmony_ci  ScriptStreamingData(
5771cb0ef41Sopenharmony_ci      std::unique_ptr<ScriptCompiler::ExternalSourceStream> source_stream,
5781cb0ef41Sopenharmony_ci      ScriptCompiler::StreamedSource::Encoding encoding);
5791cb0ef41Sopenharmony_ci  ScriptStreamingData(const ScriptStreamingData&) = delete;
5801cb0ef41Sopenharmony_ci  ScriptStreamingData& operator=(const ScriptStreamingData&) = delete;
5811cb0ef41Sopenharmony_ci  ~ScriptStreamingData();
5821cb0ef41Sopenharmony_ci
5831cb0ef41Sopenharmony_ci  void Release();
5841cb0ef41Sopenharmony_ci
5851cb0ef41Sopenharmony_ci  // Internal implementation of v8::ScriptCompiler::StreamedSource.
5861cb0ef41Sopenharmony_ci  std::unique_ptr<ScriptCompiler::ExternalSourceStream> source_stream;
5871cb0ef41Sopenharmony_ci  ScriptCompiler::StreamedSource::Encoding encoding;
5881cb0ef41Sopenharmony_ci
5891cb0ef41Sopenharmony_ci  // Task that performs background parsing and compilation.
5901cb0ef41Sopenharmony_ci  std::unique_ptr<BackgroundCompileTask> task;
5911cb0ef41Sopenharmony_ci};
5921cb0ef41Sopenharmony_ci
5931cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE BackgroundDeserializeTask {
5941cb0ef41Sopenharmony_ci public:
5951cb0ef41Sopenharmony_ci  BackgroundDeserializeTask(Isolate* isolate,
5961cb0ef41Sopenharmony_ci                            std::unique_ptr<ScriptCompiler::CachedData> data);
5971cb0ef41Sopenharmony_ci
5981cb0ef41Sopenharmony_ci  void Run();
5991cb0ef41Sopenharmony_ci
6001cb0ef41Sopenharmony_ci  MaybeHandle<SharedFunctionInfo> Finish(Isolate* isolate,
6011cb0ef41Sopenharmony_ci                                         Handle<String> source,
6021cb0ef41Sopenharmony_ci                                         ScriptOriginOptions origin_options);
6031cb0ef41Sopenharmony_ci
6041cb0ef41Sopenharmony_ci  bool rejected() const { return cached_data_.rejected(); }
6051cb0ef41Sopenharmony_ci
6061cb0ef41Sopenharmony_ci private:
6071cb0ef41Sopenharmony_ci  Isolate* isolate_for_local_isolate_;
6081cb0ef41Sopenharmony_ci  AlignedCachedData cached_data_;
6091cb0ef41Sopenharmony_ci  CodeSerializer::OffThreadDeserializeData off_thread_data_;
6101cb0ef41Sopenharmony_ci};
6111cb0ef41Sopenharmony_ci
6121cb0ef41Sopenharmony_ci}  // namespace internal
6131cb0ef41Sopenharmony_ci}  // namespace v8
6141cb0ef41Sopenharmony_ci
6151cb0ef41Sopenharmony_ci#endif  // V8_CODEGEN_COMPILER_H_
616