compiler-dispatcher-job.h 2.6 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 "src/contexts.h"
9 10 11 12 13
#include "src/handles.h"

namespace v8 {
namespace internal {

14
class SharedFunctionInfo;
15

16
class UnoptimizedCompileJob;
17

18 19
class V8_EXPORT_PRIVATE CompilerDispatcherJob {
 public:
20 21 22 23 24 25 26 27 28 29 30 31
  enum class Type { kUnoptimizedCompile };

  enum class Status {
    kInitial,
    kPrepared,
    kCompiled,
    kHasErrorsToReport,
    kDone,
    kFailed,
  };

  CompilerDispatcherJob(Type type) : type_(type), status_(Status::kInitial) {}
32 33 34

  virtual ~CompilerDispatcherJob() {}

35 36 37 38
  Type type() const { return type_; }

  // Returns the current status of the compile
  Status status() const { return status_; }
39 40 41

  // Returns true if this CompilerDispatcherJob has finished (either with a
  // success or a failure).
42 43 44
  bool IsFinished() const {
    return status() == Status::kDone || status() == Status::kFailed;
  }
45 46

  // Returns true if this CompilerDispatcherJob has failed.
47
  bool IsFailed() const { return status() == Status::kFailed; }
48

49 50 51 52 53 54 55
  // Return true if the next step can be run on any thread.
  bool NextStepCanRunOnAnyThread() const {
    return status() == Status::kPrepared;
  }

  // Casts to implementations.
  const UnoptimizedCompileJob* AsUnoptimizedCompileJob() const;
56

57 58 59
  // Transition from kInitial to kPrepared. Must only be invoked on the
  // main thread.
  virtual void PrepareOnMainThread(Isolate* isolate) = 0;
60

61 62
  // Transition from kPrepared to kCompiled (or kReportErrors).
  virtual void Compile(bool on_background_thread) = 0;
63

64 65 66 67 68 69 70 71 72
  // Transition from kCompiled to kDone (or kFailed). Must only be invoked on
  // the main thread.
  virtual void FinalizeOnMainThread(Isolate* isolate) = 0;

  // Transition from kReportErrors to kFailed. Must only be invoked on the main
  // thread.
  virtual void ReportErrorsOnMainThread(Isolate* isolate) = 0;

  // Free all resources. Must only be invoked on the main thread.
73
  virtual void ResetOnMainThread(Isolate* isolate) = 0;
jochen's avatar
jochen committed
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 82 83 84 85 86
 protected:
  void set_status(Status status) { status_ = status; }

 private:
  Type type_;
  Status status_;
87 88 89 90 91 92
};

}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_