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 |
26 enum class LazyCompilationMode { kAlways, kIfRequested }; | |
27 | |
28 // The V8 compiler API. | 26 // The V8 compiler API. |
29 // | 27 // |
30 // This is the central hub for dispatching to the various compilers within V8. | 28 // 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 | 29 // Logic for which compiler to choose and how to wire compilation results into |
32 // the object heap should be kept inside this class. | 30 // the object heap should be kept inside this class. |
33 // | 31 // |
34 // General strategy: Scripts are translated into anonymous functions w/o | 32 // General strategy: Scripts are translated into anonymous functions w/o |
35 // parameters which then can be executed. If the source code contains other | 33 // 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 | 34 // 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. | 35 // of the source code or deferred for lazy compilation at a later point. |
38 class Compiler : public AllStatic { | 36 class Compiler : public AllStatic { |
39 public: | 37 public: |
40 enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION }; | 38 enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION }; |
41 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; | 39 enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; |
42 enum CompilationTier { INTERPRETED, BASELINE, OPTIMIZED }; | 40 enum CompilationTier { INTERPRETED, BASELINE, OPTIMIZED }; |
43 | 41 |
44 // =========================================================================== | 42 // =========================================================================== |
45 // The following family of methods ensures a given function is compiled. The | 43 // The following family of methods ensures a given function is compiled. The |
46 // general contract is that failures will be reported by returning {false}, | 44 // general contract is that failures will be reported by returning {false}, |
47 // whereas successful compilation ensures the {is_compiled} predicate on the | 45 // whereas successful compilation ensures the {is_compiled} predicate on the |
48 // given function holds (except for live-edit, which compiles the world). | 46 // given function holds (except for live-edit, which compiles the world). |
49 | 47 |
50 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); | 48 static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); |
51 static bool CompileBaseline(Handle<JSFunction> function); | 49 static bool CompileBaseline(Handle<JSFunction> function); |
52 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); | 50 static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); |
53 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); | 51 static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); |
54 static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script); | 52 static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script); |
55 | 53 |
56 // Prepare a compilation job for unoptimized code. If |mode| is | 54 // 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( | 55 static CompilationJob* PrepareUnoptimizedCompilationJob( |
60 CompilationInfo* info, LazyCompilationMode mode); | 56 CompilationInfo* info); |
61 | 57 |
62 // Generate and install code from previously queued compilation job. | 58 // Generate and install code from previously queued compilation job. |
63 static bool FinalizeCompilationJob(CompilationJob* job); | 59 static bool FinalizeCompilationJob(CompilationJob* job); |
64 | 60 |
65 // Give the compiler a chance to perform low-latency initialization tasks of | 61 // 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 | 62 // the given {function} on its instantiation. Note that only the runtime will |
67 // offer this chance, optimized closure instantiation will not call this. | 63 // offer this chance, optimized closure instantiation will not call this. |
68 static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); | 64 static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); |
69 | 65 |
70 // Parser::Parse, then Compiler::Analyze. | 66 // Parser::Parse, then Compiler::Analyze. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ScriptCompiler::CompileOptions compile_options, | 108 ScriptCompiler::CompileOptions compile_options, |
113 NativesFlag is_natives_code, bool is_module); | 109 NativesFlag is_natives_code, bool is_module); |
114 | 110 |
115 // Create a shared function info object for a Script that has already been | 111 // 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. | 112 // parsed while the script was being loaded from a streamed source. |
117 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForStreamedScript( | 113 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForStreamedScript( |
118 Handle<Script> script, ParseInfo* info, int source_length); | 114 Handle<Script> script, ParseInfo* info, int source_length); |
119 | 115 |
120 // Create a shared function info object (the code may be lazily compiled). | 116 // Create a shared function info object (the code may be lazily compiled). |
121 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( | 117 static Handle<SharedFunctionInfo> GetSharedFunctionInfo( |
122 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer, | 118 FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); |
123 LazyCompilationMode mode = LazyCompilationMode::kIfRequested); | |
124 | 119 |
125 // Create a shared function info object for a native function literal. | 120 // Create a shared function info object for a native function literal. |
126 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( | 121 static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( |
127 v8::Extension* extension, Handle<String> name); | 122 v8::Extension* extension, Handle<String> name); |
128 | 123 |
129 // =========================================================================== | 124 // =========================================================================== |
130 // The following family of methods provides support for OSR. Code generated | 125 // 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 | 126 // for entry via OSR might not be suitable for normal entry, hence will be |
132 // returned directly to the caller. | 127 // returned directly to the caller. |
133 // | 128 // |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 state_ = State::kFailed; | 224 state_ = State::kFailed; |
230 } | 225 } |
231 return status; | 226 return status; |
232 } | 227 } |
233 }; | 228 }; |
234 | 229 |
235 } // namespace internal | 230 } // namespace internal |
236 } // namespace v8 | 231 } // namespace v8 |
237 | 232 |
238 #endif // V8_COMPILER_H_ | 233 #endif // V8_COMPILER_H_ |
OLD | NEW |