LCOV - code coverage report
Current view: top level - src/compiler-dispatcher - compiler-dispatcher-job.h (source / functions) Hit Total Coverage
Test: app.info Lines: 0 1 0.0 %
Date: 2017-04-26 Functions: 0 2 0.0 %

          Line data    Source code
       1             : // Copyright 2016 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_
       6             : #define V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_
       7             : 
       8             : #include <memory>
       9             : 
      10             : #include "include/v8.h"
      11             : #include "src/base/macros.h"
      12             : #include "src/globals.h"
      13             : #include "src/handles.h"
      14             : #include "testing/gtest/include/gtest/gtest_prod.h"  // nogncheck
      15             : 
      16             : namespace v8 {
      17             : namespace internal {
      18             : 
      19             : class AstValueFactory;
      20             : class AstStringConstants;
      21             : class CompilerDispatcherTracer;
      22             : class CompilationInfo;
      23             : class CompilationJob;
      24             : class DeferredHandles;
      25             : class FunctionLiteral;
      26             : class Isolate;
      27             : class ParseInfo;
      28             : class Parser;
      29             : class SharedFunctionInfo;
      30             : class String;
      31             : class UnicodeCache;
      32             : class Utf16CharacterStream;
      33             : 
      34             : enum class CompileJobStatus {
      35             :   kInitial,
      36             :   kReadyToParse,
      37             :   kParsed,
      38             :   kReadyToAnalyze,
      39             :   kAnalyzed,
      40             :   kReadyToCompile,
      41             :   kCompiled,
      42             :   kFailed,
      43             :   kDone,
      44             : };
      45             : 
      46             : class CompileJobFinishCallback {
      47             :  public:
      48           0 :   virtual ~CompileJobFinishCallback() {}
      49             :   virtual void ParseFinished(std::unique_ptr<ParseInfo> parse_info) = 0;
      50             : };
      51             : 
      52             : class V8_EXPORT_PRIVATE CompilerDispatcherJob {
      53             :  public:
      54             :   // Creates a CompilerDispatcherJob in the initial state.
      55             :   CompilerDispatcherJob(Isolate* isolate, CompilerDispatcherTracer* tracer,
      56             :                         Handle<SharedFunctionInfo> shared,
      57             :                         size_t max_stack_size);
      58             :   // TODO(wiktorg) document it better once I know how it relates to whole stuff
      59             :   // Creates a CompilerDispatcherJob in ready to parse top-level function state.
      60             :   CompilerDispatcherJob(CompilerDispatcherTracer* tracer, size_t max_stack_size,
      61             :                         Handle<String> source, int start_position,
      62             :                         int end_position, LanguageMode language_mode,
      63             :                         int function_literal_id, bool native, bool module,
      64             :                         bool is_named_expression, uint32_t hash_seed,
      65             :                         AccountingAllocator* zone_allocator, int compiler_hints,
      66             :                         const AstStringConstants* ast_string_constants,
      67             :                         CompileJobFinishCallback* finish_callback);
      68             :   // Creates a CompilerDispatcherJob in the analyzed state.
      69             :   CompilerDispatcherJob(Isolate* isolate, CompilerDispatcherTracer* tracer,
      70             :                         Handle<Script> script,
      71             :                         Handle<SharedFunctionInfo> shared,
      72             :                         FunctionLiteral* literal,
      73             :                         std::shared_ptr<Zone> parse_zone,
      74             :                         std::shared_ptr<DeferredHandles> parse_handles,
      75             :                         std::shared_ptr<DeferredHandles> compile_handles,
      76             :                         size_t max_stack_size);
      77             :   ~CompilerDispatcherJob();
      78             : 
      79             :   CompileJobStatus status() const { return status_; }
      80             : 
      81             :   bool has_context() const { return !context_.is_null(); }
      82             :   Context* context() { return *context_; }
      83             : 
      84             :   Handle<SharedFunctionInfo> shared() const { return shared_; }
      85             : 
      86             :   // Returns true if this CompilerDispatcherJob was created for the given
      87             :   // function.
      88             :   bool IsAssociatedWith(Handle<SharedFunctionInfo> shared) const;
      89             : 
      90             :   // Transition from kInitial to kReadyToParse.
      91             :   void PrepareToParseOnMainThread();
      92             : 
      93             :   // Transition from kReadyToParse to kParsed (or kDone if there is
      94             :   // finish_callback).
      95             :   void Parse();
      96             : 
      97             :   // Transition from kParsed to kReadyToAnalyze (or kFailed). Returns false
      98             :   // when transitioning to kFailed. In that case, an exception is pending.
      99             :   bool FinalizeParsingOnMainThread();
     100             : 
     101             :   // Transition from kReadyToAnalyze to kAnalyzed (or kFailed). Returns
     102             :   // false when transitioning to kFailed. In that case, an exception is pending.
     103             :   bool AnalyzeOnMainThread();
     104             : 
     105             :   // Transition from kAnalyzed to kReadyToCompile (or kFailed). Returns
     106             :   // false when transitioning to kFailed. In that case, an exception is pending.
     107             :   bool PrepareToCompileOnMainThread();
     108             : 
     109             :   // Transition from kReadyToCompile to kCompiled.
     110             :   void Compile();
     111             : 
     112             :   // Transition from kCompiled to kDone (or kFailed). Returns false when
     113             :   // transitioning to kFailed. In that case, an exception is pending.
     114             :   bool FinalizeCompilingOnMainThread();
     115             : 
     116             :   // Transition from any state to kInitial and free all resources.
     117             :   void ResetOnMainThread();
     118             : 
     119             :   // Estimate how long the next step will take using the tracer.
     120             :   double EstimateRuntimeOfNextStepInMs() const;
     121             : 
     122             :   // Even though the name does not imply this, ShortPrint() must only be invoked
     123             :   // on the main thread.
     124             :   void ShortPrint();
     125             : 
     126             :  private:
     127             :   FRIEND_TEST(CompilerDispatcherJobTest, ScopeChain);
     128             : 
     129             :   CompileJobStatus status_;
     130             :   Isolate* isolate_;
     131             :   CompilerDispatcherTracer* tracer_;
     132             :   Handle<Context> context_;            // Global handle.
     133             :   Handle<SharedFunctionInfo> shared_;  // Global handle.
     134             :   Handle<String> source_;        // Global handle.
     135             :   Handle<String> wrapper_;       // Global handle.
     136             :   std::unique_ptr<v8::String::ExternalStringResourceBase> source_wrapper_;
     137             :   size_t max_stack_size_;
     138             :   CompileJobFinishCallback* finish_callback_ = nullptr;
     139             : 
     140             :   // Members required for parsing.
     141             :   std::unique_ptr<UnicodeCache> unicode_cache_;
     142             :   std::unique_ptr<Utf16CharacterStream> character_stream_;
     143             :   std::unique_ptr<ParseInfo> parse_info_;
     144             :   std::unique_ptr<Parser> parser_;
     145             : 
     146             :   // Members required for compiling a parsed function.
     147             :   std::shared_ptr<Zone> parse_zone_;
     148             : 
     149             :   // Members required for compiling.
     150             :   std::unique_ptr<CompilationInfo> compile_info_;
     151             :   std::unique_ptr<CompilationJob> compile_job_;
     152             : 
     153             :   bool trace_compiler_dispatcher_jobs_;
     154             : 
     155             :   DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob);
     156             : };
     157             : 
     158             : }  // namespace internal
     159             : }  // namespace v8
     160             : 
     161             : #endif  // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_

Generated by: LCOV version 1.10