| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ | 5 #ifndef V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ |
| 6 #define V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ | 6 #define V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "include/v8.h" | 10 #include "include/v8.h" |
| 11 #include "src/base/macros.h" | 11 #include "src/base/macros.h" |
| 12 #include "src/globals.h" | 12 #include "src/globals.h" |
| 13 #include "src/handles.h" | 13 #include "src/handles.h" |
| 14 #include "testing/gtest/include/gtest/gtest_prod.h" | 14 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 15 | 15 |
| 16 namespace v8 { | 16 namespace v8 { |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 class AstValueFactory; | |
| 20 class CompilerDispatcherTracer; | 19 class CompilerDispatcherTracer; |
| 21 class CompilationInfo; | 20 class CompilationInfo; |
| 22 class CompilationJob; | 21 class CompilationJob; |
| 23 class FunctionLiteral; | |
| 24 class Isolate; | 22 class Isolate; |
| 25 class ParseInfo; | 23 class ParseInfo; |
| 26 class Parser; | 24 class Parser; |
| 27 class SharedFunctionInfo; | 25 class SharedFunctionInfo; |
| 28 class String; | 26 class String; |
| 29 class UnicodeCache; | 27 class UnicodeCache; |
| 30 class Utf16CharacterStream; | 28 class Utf16CharacterStream; |
| 31 class Zone; | 29 class Zone; |
| 32 | 30 |
| 33 enum class CompileJobStatus { | 31 enum class CompileJobStatus { |
| 34 kInitial, | 32 kInitial, |
| 35 kReadyToParse, | 33 kReadyToParse, |
| 36 kParsed, | 34 kParsed, |
| 37 kReadyToAnalyze, | 35 kReadyToAnalyse, |
| 38 kAnalyzed, | |
| 39 kReadyToCompile, | 36 kReadyToCompile, |
| 40 kCompiled, | 37 kCompiled, |
| 41 kFailed, | 38 kFailed, |
| 42 kDone, | 39 kDone, |
| 43 }; | 40 }; |
| 44 | 41 |
| 45 class V8_EXPORT_PRIVATE CompilerDispatcherJob { | 42 class V8_EXPORT_PRIVATE CompilerDispatcherJob { |
| 46 public: | 43 public: |
| 47 // Creates a CompilerDispatcherJob in the initial state. | |
| 48 CompilerDispatcherJob(Isolate* isolate, CompilerDispatcherTracer* tracer, | 44 CompilerDispatcherJob(Isolate* isolate, CompilerDispatcherTracer* tracer, |
| 49 Handle<SharedFunctionInfo> shared, | 45 Handle<SharedFunctionInfo> shared, |
| 50 size_t max_stack_size); | 46 size_t max_stack_size); |
| 51 // Creates a CompilerDispatcherJob in the analyzed state. | |
| 52 CompilerDispatcherJob(Isolate* isolate, CompilerDispatcherTracer* tracer, | |
| 53 Handle<SharedFunctionInfo> shared, | |
| 54 FunctionLiteral* literal, size_t max_stack_size); | |
| 55 ~CompilerDispatcherJob(); | 47 ~CompilerDispatcherJob(); |
| 56 | 48 |
| 57 CompileJobStatus status() const { return status_; } | 49 CompileJobStatus status() const { return status_; } |
| 58 | 50 |
| 59 // Returns true if this CompilerDispatcherJob was created for the given | 51 // Returns true if this CompilerDispatcherJob was created for the given |
| 60 // function. | 52 // function. |
| 61 bool IsAssociatedWith(Handle<SharedFunctionInfo> shared) const; | 53 bool IsAssociatedWith(Handle<SharedFunctionInfo> shared) const; |
| 62 | 54 |
| 63 // Transition from kInitial to kReadyToParse. | 55 // Transition from kInitial to kReadyToParse. |
| 64 void PrepareToParseOnMainThread(); | 56 void PrepareToParseOnMainThread(); |
| 65 | 57 |
| 66 // Transition from kReadyToParse to kParsed. | 58 // Transition from kReadyToParse to kParsed. |
| 67 void Parse(); | 59 void Parse(); |
| 68 | 60 |
| 69 // Transition from kParsed to kReadyToAnalyze (or kFailed). Returns false | 61 // Transition from kParsed to kReadyToAnalyse (or kFailed). Returns false |
| 70 // when transitioning to kFailed. In that case, an exception is pending. | 62 // when transitioning to kFailed. In that case, an exception is pending. |
| 71 bool FinalizeParsingOnMainThread(); | 63 bool FinalizeParsingOnMainThread(); |
| 72 | 64 |
| 73 // Transition from kReadyToAnalyze to kAnalyzed (or kFailed). Returns | 65 // Transition from kReadyToAnalyse to kReadyToCompile (or kFailed). Returns |
| 74 // false when transitioning to kFailed. In that case, an exception is pending. | |
| 75 bool AnalyzeOnMainThread(); | |
| 76 | |
| 77 // Transition from kAnalyzed to kReadyToCompile (or kFailed). Returns | |
| 78 // false when transitioning to kFailed. In that case, an exception is pending. | 66 // false when transitioning to kFailed. In that case, an exception is pending. |
| 79 bool PrepareToCompileOnMainThread(); | 67 bool PrepareToCompileOnMainThread(); |
| 80 | 68 |
| 81 // Transition from kReadyToCompile to kCompiled. | 69 // Transition from kReadyToCompile to kCompiled. |
| 82 void Compile(); | 70 void Compile(); |
| 83 | 71 |
| 84 // Transition from kCompiled to kDone (or kFailed). Returns false when | 72 // Transition from kCompiled to kDone (or kFailed). Returns false when |
| 85 // transitioning to kFailed. In that case, an exception is pending. | 73 // transitioning to kFailed. In that case, an exception is pending. |
| 86 bool FinalizeCompilingOnMainThread(); | 74 bool FinalizeCompilingOnMainThread(); |
| 87 | 75 |
| 88 // Transition from any state to kInitial and free all resources. | 76 // Transition from any state to kInitial and free all resources. |
| 89 void ResetOnMainThread(); | 77 void ResetOnMainThread(); |
| 90 | 78 |
| 91 // Estimate how long the next step will take using the tracer. | 79 // Estimate how long the next step will take using the tracer. |
| 92 double EstimateRuntimeOfNextStepInMs() const; | 80 double EstimateRuntimeOfNextStepInMs() const; |
| 93 | 81 |
| 94 // Even though the name does not imply this, ShortPrint() must only be invoked | 82 // Even though the name does not imply this, ShortPrint() must only be invoked |
| 95 // on the main thread. | 83 // on the main thread. |
| 96 void ShortPrint(); | 84 void ShortPrint(); |
| 97 | 85 |
| 98 private: | 86 private: |
| 99 FRIEND_TEST(CompilerDispatcherJobTest, ScopeChain); | 87 FRIEND_TEST(CompilerDispatcherJobTest, ScopeChain); |
| 100 | 88 |
| 101 CompileJobStatus status_; | 89 CompileJobStatus status_ = CompileJobStatus::kInitial; |
| 102 Isolate* isolate_; | 90 Isolate* isolate_; |
| 103 CompilerDispatcherTracer* tracer_; | 91 CompilerDispatcherTracer* tracer_; |
| 104 Handle<SharedFunctionInfo> shared_; // Global handle. | 92 Handle<SharedFunctionInfo> shared_; // Global handle. |
| 105 Handle<String> source_; // Global handle. | 93 Handle<String> source_; // Global handle. |
| 106 Handle<String> wrapper_; // Global handle. | 94 Handle<String> wrapper_; // Global handle. |
| 107 std::unique_ptr<v8::String::ExternalStringResourceBase> source_wrapper_; | 95 std::unique_ptr<v8::String::ExternalStringResourceBase> source_wrapper_; |
| 108 size_t max_stack_size_; | 96 size_t max_stack_size_; |
| 109 | 97 |
| 110 // Members required for parsing. | 98 // Members required for parsing. |
| 111 std::unique_ptr<UnicodeCache> unicode_cache_; | 99 std::unique_ptr<UnicodeCache> unicode_cache_; |
| 112 std::unique_ptr<Zone> zone_; | 100 std::unique_ptr<Zone> zone_; |
| 113 std::unique_ptr<Utf16CharacterStream> character_stream_; | 101 std::unique_ptr<Utf16CharacterStream> character_stream_; |
| 114 std::unique_ptr<ParseInfo> parse_info_; | 102 std::unique_ptr<ParseInfo> parse_info_; |
| 115 std::unique_ptr<Parser> parser_; | 103 std::unique_ptr<Parser> parser_; |
| 116 std::unique_ptr<DeferredHandles> handles_from_parsing_; | 104 std::unique_ptr<DeferredHandles> handles_from_parsing_; |
| 117 | 105 |
| 118 // Members required for compiling. | 106 // Members required for compiling. |
| 119 std::unique_ptr<CompilationInfo> compile_info_; | 107 std::unique_ptr<CompilationInfo> compile_info_; |
| 120 std::unique_ptr<CompilationJob> compile_job_; | 108 std::unique_ptr<CompilationJob> compile_job_; |
| 121 | 109 |
| 122 bool trace_compiler_dispatcher_jobs_; | 110 bool trace_compiler_dispatcher_jobs_; |
| 123 | 111 |
| 124 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob); | 112 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob); |
| 125 }; | 113 }; |
| 126 | 114 |
| 127 } // namespace internal | 115 } // namespace internal |
| 128 } // namespace v8 | 116 } // namespace v8 |
| 129 | 117 |
| 130 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ | 118 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ |
| OLD | NEW |