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 "src/base/macros.h" | 10 #include "src/base/macros.h" |
11 #include "src/handles.h" | 11 #include "src/handles.h" |
12 #include "testing/gtest/include/gtest/gtest_prod.h" | 12 #include "testing/gtest/include/gtest/gtest_prod.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 class CompilationInfo; | 17 class CompilationInfo; |
| 18 class CompilationJob; |
18 class Isolate; | 19 class Isolate; |
19 class JSFunction; | 20 class JSFunction; |
20 class ParseInfo; | 21 class ParseInfo; |
21 class Parser; | 22 class Parser; |
22 class String; | 23 class String; |
23 class UnicodeCache; | 24 class UnicodeCache; |
24 class Utf16CharacterStream; | 25 class Utf16CharacterStream; |
25 class Zone; | 26 class Zone; |
26 | 27 |
27 enum class CompileJobStatus { | 28 enum class CompileJobStatus { |
28 kInitial, | 29 kInitial, |
29 kReadyToParse, | 30 kReadyToParse, |
30 kParsed, | 31 kParsed, |
| 32 kReadyToAnalyse, |
31 kReadyToCompile, | 33 kReadyToCompile, |
| 34 kCompiled, |
32 kFailed, | 35 kFailed, |
33 kDone, | 36 kDone, |
34 }; | 37 }; |
35 | 38 |
36 class CompilerDispatcherJob { | 39 class CompilerDispatcherJob { |
37 public: | 40 public: |
38 CompilerDispatcherJob(Isolate* isolate, Handle<JSFunction> function, | 41 CompilerDispatcherJob(Isolate* isolate, Handle<JSFunction> function, |
39 size_t max_stack_size); | 42 size_t max_stack_size); |
40 ~CompilerDispatcherJob(); | 43 ~CompilerDispatcherJob(); |
41 | 44 |
42 CompileJobStatus status() const { return status_; } | 45 CompileJobStatus status() const { return status_; } |
43 bool can_parse_on_background_thread() const { | 46 bool can_parse_on_background_thread() const { |
44 return can_parse_on_background_thread_; | 47 return can_parse_on_background_thread_; |
45 } | 48 } |
| 49 // Should only be called after kReadyToCompile. |
| 50 bool can_compile_on_background_thread() const { |
| 51 DCHECK(compile_job_.get()); |
| 52 return can_compile_on_background_thread_; |
| 53 } |
46 | 54 |
47 // Transition from kInitial to kReadyToParse. | 55 // Transition from kInitial to kReadyToParse. |
48 void PrepareToParseOnMainThread(); | 56 void PrepareToParseOnMainThread(); |
49 | 57 |
50 // Transition from kReadyToParse to kParsed. | 58 // Transition from kReadyToParse to kParsed. |
51 void Parse(); | 59 void Parse(); |
52 | 60 |
53 // Transition from kParsed to kReadyToCompile (or kFailed). Returns false | 61 // Transition from kParsed to kReadyToAnalyse (or kFailed). Returns false |
54 // when transitioning to kFailed. In that case, an exception is pending. | 62 // when transitioning to kFailed. In that case, an exception is pending. |
55 bool FinalizeParsingOnMainThread(); | 63 bool FinalizeParsingOnMainThread(); |
56 | 64 |
| 65 // Transition from kReadyToAnalyse to kReadyToCompile (or kFailed). Returns |
| 66 // false when transitioning to kFailed. In that case, an exception is pending. |
| 67 bool PrepareToCompileOnMainThread(); |
| 68 |
| 69 // Transition from kReadyToCompile to kCompiled. |
| 70 void Compile(); |
| 71 |
| 72 // Transition from kCompiled to kDone (or kFailed). Returns false when |
| 73 // transitioning to kFailed. In that case, an exception is pending. |
| 74 bool FinalizeCompilingOnMainThread(); |
| 75 |
57 // Transition from any state to kInitial and free all resources. | 76 // Transition from any state to kInitial and free all resources. |
58 void ResetOnMainThread(); | 77 void ResetOnMainThread(); |
59 | 78 |
60 private: | 79 private: |
61 FRIEND_TEST(CompilerDispatcherJobTest, ScopeChain); | 80 FRIEND_TEST(CompilerDispatcherJobTest, ScopeChain); |
62 | 81 |
63 CompileJobStatus status_ = CompileJobStatus::kInitial; | 82 CompileJobStatus status_ = CompileJobStatus::kInitial; |
64 Isolate* isolate_; | 83 Isolate* isolate_; |
65 Handle<JSFunction> function_; // Global handle. | 84 Handle<JSFunction> function_; // Global handle. |
66 Handle<String> source_; // Global handle. | 85 Handle<String> source_; // Global handle. |
67 size_t max_stack_size_; | 86 size_t max_stack_size_; |
68 | 87 |
69 // Members required for parsing. | 88 // Members required for parsing. |
70 std::unique_ptr<UnicodeCache> unicode_cache_; | 89 std::unique_ptr<UnicodeCache> unicode_cache_; |
71 std::unique_ptr<Zone> zone_; | 90 std::unique_ptr<Zone> zone_; |
72 std::unique_ptr<Utf16CharacterStream> character_stream_; | 91 std::unique_ptr<Utf16CharacterStream> character_stream_; |
73 std::unique_ptr<ParseInfo> parse_info_; | 92 std::unique_ptr<ParseInfo> parse_info_; |
74 std::unique_ptr<Parser> parser_; | 93 std::unique_ptr<Parser> parser_; |
75 std::unique_ptr<DeferredHandles> handles_from_parsing_; | 94 std::unique_ptr<DeferredHandles> handles_from_parsing_; |
76 | 95 |
| 96 // Members required for compiling. |
| 97 std::unique_ptr<CompilationInfo> compile_info_; |
| 98 std::unique_ptr<CompilationJob> compile_job_; |
| 99 |
77 bool can_parse_on_background_thread_; | 100 bool can_parse_on_background_thread_; |
| 101 bool can_compile_on_background_thread_; |
78 | 102 |
79 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob); | 103 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob); |
80 }; | 104 }; |
81 | 105 |
82 } // namespace internal | 106 } // namespace internal |
83 } // namespace v8 | 107 } // namespace v8 |
84 | 108 |
85 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ | 109 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ |
OLD | NEW |