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 } |
46 | 49 |
47 // Transition from kInitial to kReadyToParse. | 50 // Transition from kInitial to kReadyToParse. |
48 void PrepareToParseOnMainThread(); | 51 void PrepareToParseOnMainThread(); |
49 | 52 |
50 // Transition from kReadyToParse to kParsed. | 53 // Transition from kReadyToParse to kParsed. |
51 void Parse(); | 54 void Parse(); |
52 | 55 |
53 // Transition from kParsed to kReadyToCompile (or kFailed). Returns false | 56 // Transition from kParsed to kReadyToAnalyse (or kFailed). Returns false |
54 // when transitioning to kFailed. In that case, an exception is pending. | 57 // when transitioning to kFailed. In that case, an exception is pending. |
55 bool FinalizeParsingOnMainThread(); | 58 bool FinalizeParsingOnMainThread(); |
56 | 59 |
| 60 // Transition from kReadyToAnalyse to kReadyToCompile (or kFailed). Returns |
| 61 // false when transitioning to kFailed. In that case, an exception is pending. |
| 62 bool PrepareToCompileOnMainThread(); |
| 63 |
| 64 // Transition from kReadyToCompile to kCompiled. |
| 65 void Compile(); |
| 66 |
| 67 // Transition from kCompiled to kDone (or kFailed). Returns false when |
| 68 // transitioning to kFailed. In that case, an exception is pending. |
| 69 bool FinalizeCompilingOnMainThread(); |
| 70 |
57 // Transition from any state to kInitial and free all resources. | 71 // Transition from any state to kInitial and free all resources. |
58 void ResetOnMainThread(); | 72 void ResetOnMainThread(); |
59 | 73 |
60 private: | 74 private: |
61 FRIEND_TEST(CompilerDispatcherJobTest, ScopeChain); | 75 FRIEND_TEST(CompilerDispatcherJobTest, ScopeChain); |
62 | 76 |
63 CompileJobStatus status_ = CompileJobStatus::kInitial; | 77 CompileJobStatus status_ = CompileJobStatus::kInitial; |
64 Isolate* isolate_; | 78 Isolate* isolate_; |
65 Handle<JSFunction> function_; // Global handle. | 79 Handle<JSFunction> function_; // Global handle. |
66 Handle<String> source_; // Global handle. | 80 Handle<String> source_; // Global handle. |
67 size_t max_stack_size_; | 81 size_t max_stack_size_; |
68 | 82 |
69 // Members required for parsing. | 83 // Members required for parsing. |
70 std::unique_ptr<UnicodeCache> unicode_cache_; | 84 std::unique_ptr<UnicodeCache> unicode_cache_; |
71 std::unique_ptr<Zone> zone_; | 85 std::unique_ptr<Zone> zone_; |
72 std::unique_ptr<Utf16CharacterStream> character_stream_; | 86 std::unique_ptr<Utf16CharacterStream> character_stream_; |
73 std::unique_ptr<ParseInfo> parse_info_; | 87 std::unique_ptr<ParseInfo> parse_info_; |
74 std::unique_ptr<Parser> parser_; | 88 std::unique_ptr<Parser> parser_; |
75 std::unique_ptr<DeferredHandles> handles_from_parsing_; | 89 std::unique_ptr<DeferredHandles> handles_from_parsing_; |
76 | 90 |
| 91 // Members required for compiling. |
| 92 std::unique_ptr<CompilationInfo> compile_info_; |
| 93 std::unique_ptr<CompilationJob> compile_job_; |
| 94 std::unique_ptr<DeferredHandles> handles_from_analysing_; |
| 95 |
77 bool can_parse_on_background_thread_; | 96 bool can_parse_on_background_thread_; |
78 | 97 |
79 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob); | 98 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherJob); |
80 }; | 99 }; |
81 | 100 |
82 } // namespace internal | 101 } // namespace internal |
83 } // namespace v8 | 102 } // namespace v8 |
84 | 103 |
85 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ | 104 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_JOB_H_ |
OLD | NEW |