compiler-dispatcher-job.h 3.2 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 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_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_
#define V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_

8
#include <memory>
9

10
#include "src/base/macros.h"
11
#include "src/globals.h"
12
#include "src/handles.h"
13
#include "testing/gtest/include/gtest/gtest_prod.h"
14 15 16 17

namespace v8 {
namespace internal {

18
class CompilerDispatcherTracer;
19
class CompilationInfo;
20
class CompilationJob;
21
class Isolate;
22
class ParseInfo;
23
class Parser;
24
class SharedFunctionInfo;
jochen's avatar
jochen committed
25
class String;
26
class UnicodeCache;
27
class Utf16CharacterStream;
28
class Zone;
29 30 31

enum class CompileJobStatus {
  kInitial,
32
  kReadyToParse,
33
  kParsed,
34
  kReadyToAnalyse,
jochen's avatar
jochen committed
35
  kReadyToCompile,
36
  kCompiled,
jochen's avatar
jochen committed
37 38
  kFailed,
  kDone,
39 40
};

41
class V8_EXPORT_PRIVATE CompilerDispatcherJob {
42
 public:
43
  CompilerDispatcherJob(Isolate* isolate, Handle<SharedFunctionInfo> shared,
44
                        size_t max_stack_size);
45 46
  ~CompilerDispatcherJob();

47
  CompileJobStatus status() const { return status_; }
48 49 50
  bool can_parse_on_background_thread() const {
    return can_parse_on_background_thread_;
  }
51 52 53 54 55
  // Should only be called after kReadyToCompile.
  bool can_compile_on_background_thread() const {
    DCHECK(compile_job_.get());
    return can_compile_on_background_thread_;
  }
56

57 58 59
  // Transition from kInitial to kReadyToParse.
  void PrepareToParseOnMainThread();

60 61 62
  // Transition from kReadyToParse to kParsed.
  void Parse();

63
  // Transition from kParsed to kReadyToAnalyse (or kFailed). Returns false
64 65
  // when transitioning to kFailed. In that case, an exception is pending.
  bool FinalizeParsingOnMainThread();
jochen's avatar
jochen committed
66

67 68 69 70 71 72 73 74 75 76 77
  // Transition from kReadyToAnalyse to kReadyToCompile (or kFailed). Returns
  // false when transitioning to kFailed. In that case, an exception is pending.
  bool PrepareToCompileOnMainThread();

  // Transition from kReadyToCompile to kCompiled.
  void Compile();

  // Transition from kCompiled to kDone (or kFailed). Returns false when
  // transitioning to kFailed. In that case, an exception is pending.
  bool FinalizeCompilingOnMainThread();

jochen's avatar
jochen committed
78 79 80
  // Transition from any state to kInitial and free all resources.
  void ResetOnMainThread();

81
 private:
82 83
  FRIEND_TEST(CompilerDispatcherJobTest, ScopeChain);

84
  CompileJobStatus status_ = CompileJobStatus::kInitial;
85
  Isolate* isolate_;
86
  CompilerDispatcherTracer* tracer_;
87
  Handle<SharedFunctionInfo> shared_;  // Global handle.
jochen's avatar
jochen committed
88
  Handle<String> source_;        // Global handle.
89
  size_t max_stack_size_;
90

91 92 93
  // Members required for parsing.
  std::unique_ptr<UnicodeCache> unicode_cache_;
  std::unique_ptr<Zone> zone_;
94
  std::unique_ptr<Utf16CharacterStream> character_stream_;
95
  std::unique_ptr<ParseInfo> parse_info_;
96
  std::unique_ptr<Parser> parser_;
97
  std::unique_ptr<DeferredHandles> handles_from_parsing_;
98

99 100 101 102
  // Members required for compiling.
  std::unique_ptr<CompilationInfo> compile_info_;
  std::unique_ptr<CompilationJob> compile_job_;

103
  bool can_parse_on_background_thread_;
104
  bool can_compile_on_background_thread_;
105

106 107 108 109 110 111 112
  DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob);
};

}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_