OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_H_ | 5 #ifndef V8_COMPILER_H_ |
6 #define V8_COMPILER_H_ | 6 #define V8_COMPILER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
11 #include "src/bailout-reason.h" | 11 #include "src/bailout-reason.h" |
12 #include "src/contexts.h" | 12 #include "src/contexts.h" |
13 #include "src/isolate.h" | 13 #include "src/isolate.h" |
14 #include "src/zone/zone.h" | 14 #include "src/zone/zone.h" |
15 | 15 |
16 namespace v8 { | 16 namespace v8 { |
17 namespace internal { | 17 namespace internal { |
18 | 18 |
19 // Forward declarations. | 19 // Forward declarations. |
20 class CompilationInfo; | 20 class CompilationInfo; |
21 class CompilationJob; | 21 class CompilationJob; |
22 class JavaScriptFrame; | 22 class JavaScriptFrame; |
23 class ParseInfo; | 23 class ParseInfo; |
24 class ScriptData; | 24 class ScriptData; |
25 | 25 template <typename T> |
26 enum class LazyCompilationMode { kAlways, kIfRequested }; | 26 class ThreadedList; |
| 27 template <typename T> |
| 28 class ThreadedListZoneEntry; |
27 | 29 |
28 // The V8 compiler API. | 30 // The V8 compiler API. |
29 // | 31 // |
30 // This is the central hub for dispatching to the various compilers within V8. | 32 // This is the central hub for dispatching to the various compilers within V8. |
31 // Logic for which compiler to choose and how to wire compilation results into | 33 // Logic for which compiler to choose and how to wire compilation results into |
32 // the object heap should be kept inside this class. | 34 // the object heap should be kept inside this class. |
33 // | 35 // |
34 // General strategy: Scripts are translated into anonymous functions w/o | 36 // General strategy: Scripts are translated into anonymous functions w/o |
35 // parameters which then can be executed. If the source code contains other | 37 // parameters which then can be executed. If the source code contains other |
36 // functions, they might be compiled and allocated as part of the compilation | 38 // functions, they might be compiled and allocated as part of the compilation |
37 // of the source code or deferred for lazy compilation at a later point. | 39 // of the source code or deferred for lazy compilation at a later point. |
38 class Compiler : public AllStatic { | 40 class Compiler : public AllStatic { |
39 public: | 41 public: |
40 enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION }; | 42 enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION }; |
41 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; | 43 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; |
42 enum CompilationTier { INTERPRETED, BASELINE, OPTIMIZED }; | 44 enum CompilationTier { INTERPRETED, BASELINE, OPTIMIZED }; |
43 | 45 |
44 // =========================================================================== | 46 // =========================================================================== |
45 // The following family of methods ensures a given function is compiled. The | 47 // The following family of methods ensures a given function is compiled. The |
46 // general contract is that failures will be reported by returning {false}, | 48 // general contract is that failures will be reported by returning {false}, |
47 // whereas successful compilation ensures the {is_compiled} predicate on the | 49 // whereas successful compilation ensures the {is_compiled} predicate on the |
48 // given function holds (except for live-edit, which compiles the world). | 50 // given function holds (except for live-edit, which compiles the world). |
49 | 51 |
50 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); | 52 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); |
51 static bool CompileBaseline(Handle<JSFunction> function); | 53 static bool CompileBaseline(Handle<JSFunction> function); |
52 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); | 54 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); |
53 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); | 55 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); |
54 static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script); | 56 static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script); |
55 | 57 |
56 // Prepare a compilation job for unoptimized code. If |mode| is | 58 // Prepare a compilation job for unoptimized code. Requires ParseAndAnalyse. |
57 // LazyCompilationMode::kAlways, the returned job will not compile any inner | |
58 // functions. Requires ParseAndAnalyse. | |
59 static CompilationJob* PrepareUnoptimizedCompilationJob( | 59 static CompilationJob* PrepareUnoptimizedCompilationJob( |
60 CompilationInfo* info, LazyCompilationMode mode); | 60 CompilationInfo* info); |
61 | 61 |
62 // Generate and install code from previously queued compilation job. | 62 // Generate and install code from previously queued compilation job. |
63 static bool FinalizeCompilationJob(CompilationJob* job); | 63 static bool FinalizeCompilationJob(CompilationJob* job); |
64 | 64 |
65 // Give the compiler a chance to perform low-latency initialization tasks of | 65 // Give the compiler a chance to perform low-latency initialization tasks of |
66 // the given {function} on its instantiation. Note that only the runtime will | 66 // the given {function} on its instantiation. Note that only the runtime will |
67 // offer this chance, optimized closure instantiation will not call this. | 67 // offer this chance, optimized closure instantiation will not call this. |
68 static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); | 68 static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); |
69 | 69 |
| 70 typedef ThreadedList<ThreadedListZoneEntry<FunctionLiteral*>> |
| 71 EagerInnerFunctionLiterals; |
| 72 |
70 // Parser::Parse, then Compiler::Analyze. | 73 // Parser::Parse, then Compiler::Analyze. |
71 static bool ParseAndAnalyze(ParseInfo* info); | 74 static bool ParseAndAnalyze(ParseInfo* info); |
72 // Rewrite, analyze scopes, and renumber. | 75 // Rewrite, analyze scopes, and renumber. If |eager_literals| is non-null, it |
73 static bool Analyze(ParseInfo* info); | 76 // is appended with inner function literals which should be eagerly compiled. |
| 77 static bool Analyze(ParseInfo* info, |
| 78 EagerInnerFunctionLiterals* eager_literals = nullptr); |
74 // Adds deoptimization support, requires ParseAndAnalyze. | 79 // Adds deoptimization support, requires ParseAndAnalyze. |
75 static bool EnsureDeoptimizationSupport(CompilationInfo* info); | 80 static bool EnsureDeoptimizationSupport(CompilationInfo* info); |
76 // Ensures that bytecode is generated, calls ParseAndAnalyze internally. | 81 // Ensures that bytecode is generated, calls ParseAndAnalyze internally. |
77 static bool EnsureBytecode(CompilationInfo* info); | 82 static bool EnsureBytecode(CompilationInfo* info); |
78 | 83 |
79 // The next compilation tier which the function should be compiled to for | 84 // The next compilation tier which the function should be compiled to for |
80 // optimization. This is used as a hint by the runtime profiler. | 85 // optimization. This is used as a hint by the runtime profiler. |
81 static CompilationTier NextCompilationTier(JSFunction* function); | 86 static CompilationTier NextCompilationTier(JSFunction* function); |
82 | 87 |
83 // =========================================================================== | 88 // =========================================================================== |
(...skipping 28 matching lines...) Expand all Loading... |
112 ScriptCompiler::CompileOptions compile_options, | 117 ScriptCompiler::CompileOptions compile_options, |
113 NativesFlag is_natives_code, bool is_module); | 118 NativesFlag is_natives_code, bool is_module); |
114 | 119 |
115 // Create a shared function info object for a Script that has already been | 120 // Create a shared function info object for a Script that has already been |
116 // parsed while the script was being loaded from a streamed source. | 121 // parsed while the script was being loaded from a streamed source. |
117 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForStreamedScript( | 122 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForStreamedScript( |
118 Handle<Script> script, ParseInfo* info, int source_length); | 123 Handle<Script> script, ParseInfo* info, int source_length); |
119 | 124 |
120 // Create a shared function info object (the code may be lazily compiled). | 125 // Create a shared function info object (the code may be lazily compiled). |
121 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( | 126 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( |
122 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer, | 127 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); |
123 LazyCompilationMode mode = LazyCompilationMode::kIfRequested); | |
124 | 128 |
125 // Create a shared function info object for a native function literal. | 129 // Create a shared function info object for a native function literal. |
126 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( | 130 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( |
127 v8::Extension* extension, Handle<String> name); | 131 v8::Extension* extension, Handle<String> name); |
128 | 132 |
129 // =========================================================================== | 133 // =========================================================================== |
130 // The following family of methods provides support for OSR. Code generated | 134 // The following family of methods provides support for OSR. Code generated |
131 // for entry via OSR might not be suitable for normal entry, hence will be | 135 // for entry via OSR might not be suitable for normal entry, hence will be |
132 // returned directly to the caller. | 136 // returned directly to the caller. |
133 // | 137 // |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 state_ = State::kFailed; | 233 state_ = State::kFailed; |
230 } | 234 } |
231 return status; | 235 return status; |
232 } | 236 } |
233 }; | 237 }; |
234 | 238 |
235 } // namespace internal | 239 } // namespace internal |
236 } // namespace v8 | 240 } // namespace v8 |
237 | 241 |
238 #endif // V8_COMPILER_H_ | 242 #endif // V8_COMPILER_H_ |
OLD | NEW |