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