• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/contexts.h"
9 #include "src/handles.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 class SharedFunctionInfo;
15 
16 class UnoptimizedCompileJob;
17 
18 class V8_EXPORT_PRIVATE CompilerDispatcherJob {
19  public:
20   enum class Type { kUnoptimizedCompile };
21 
22   enum class Status {
23     kInitial,
24     kPrepared,
25     kCompiled,
26     kHasErrorsToReport,
27     kDone,
28     kFailed,
29   };
30 
CompilerDispatcherJob(Type type)31   CompilerDispatcherJob(Type type) : type_(type), status_(Status::kInitial) {}
32 
~CompilerDispatcherJob()33   virtual ~CompilerDispatcherJob() {}
34 
type()35   Type type() const { return type_; }
36 
37   // Returns the current status of the compile
status()38   Status status() const { return status_; }
39 
40   // Returns true if this CompilerDispatcherJob has finished (either with a
41   // success or a failure).
IsFinished()42   bool IsFinished() const {
43     return status() == Status::kDone || status() == Status::kFailed;
44   }
45 
46   // Returns true if this CompilerDispatcherJob has failed.
IsFailed()47   bool IsFailed() const { return status() == Status::kFailed; }
48 
49   // Return true if the next step can be run on any thread.
NextStepCanRunOnAnyThread()50   bool NextStepCanRunOnAnyThread() const {
51     return status() == Status::kPrepared;
52   }
53 
54   // Casts to implementations.
55   const UnoptimizedCompileJob* AsUnoptimizedCompileJob() const;
56 
57   // Transition from kInitial to kPrepared. Must only be invoked on the
58   // main thread.
59   virtual void PrepareOnMainThread(Isolate* isolate) = 0;
60 
61   // Transition from kPrepared to kCompiled (or kReportErrors).
62   virtual void Compile(bool on_background_thread) = 0;
63 
64   // Transition from kCompiled to kDone (or kFailed). Must only be invoked on
65   // the main thread.
66   virtual void FinalizeOnMainThread(Isolate* isolate) = 0;
67 
68   // Transition from kReportErrors to kFailed. Must only be invoked on the main
69   // thread.
70   virtual void ReportErrorsOnMainThread(Isolate* isolate) = 0;
71 
72   // Free all resources. Must only be invoked on the main thread.
73   virtual void ResetOnMainThread(Isolate* isolate) = 0;
74 
75   // Estimate how long the next step will take using the tracer.
76   virtual double EstimateRuntimeOfNextStepInMs() const = 0;
77 
78   // Print short description of job. Must only be invoked on the main thread.
79   virtual void ShortPrintOnMainThread() = 0;
80 
81  protected:
set_status(Status status)82   void set_status(Status status) { status_ = status; }
83 
84  private:
85   Type type_;
86   Status status_;
87 };
88 
89 }  // namespace internal
90 }  // namespace v8
91 
92 #endif  // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_
93