diff options
author | Michaël Zasso <targos@protonmail.com> | 2016-05-27 16:37:42 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2016-06-29 09:04:28 +0200 |
commit | 2cc29517966de7257a2f1b34c58c77225a21e05d (patch) | |
tree | 210bd177df2f06eec16e1e22edafdbcbffe66f8a /deps/v8/src/compiler.h | |
parent | bbf3838c70aaec1dd296fa75ae334fd1c7866df3 (diff) | |
download | node-new-2cc29517966de7257a2f1b34c58c77225a21e05d.tar.gz |
deps: update V8 to 5.1.281.69
Pick up the latest branch-head for V8 5.1. This branch brings in
improved language support and performance improvements. For full
details: http://v8project.blogspot.com/2016/04/v8-release-51.html
* Picks up the latest branch head for 5.1 [1]
* Edit v8 gitignore to allow trace_event copy
* Update V8 DEP trace_event as per deps/v8/DEPS [2]
[1] https://chromium.googlesource.com/v8/v8.git/+/dc81244
[2] https://chromium.googlesource.com/chromium/src/base/trace_event/common/+/c8c8665
PR-URL: https://github.com/nodejs/node/pull/7016
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/src/compiler.h')
-rw-r--r-- | deps/v8/src/compiler.h | 274 |
1 files changed, 122 insertions, 152 deletions
diff --git a/deps/v8/src/compiler.h b/deps/v8/src/compiler.h index a56fa13c48..fa043995b4 100644 --- a/deps/v8/src/compiler.h +++ b/deps/v8/src/compiler.h @@ -9,7 +9,6 @@ #include "src/ast/ast.h" #include "src/bailout-reason.h" #include "src/compilation-dependencies.h" -#include "src/signature.h" #include "src/source-position.h" #include "src/zone.h" @@ -17,10 +16,107 @@ namespace v8 { namespace internal { // Forward declarations. +class CompilationInfo; class JavaScriptFrame; +class OptimizedCompileJob; class ParseInfo; class ScriptData; +// The V8 compiler API. +// +// This is the central hub for dispatching to the various compilers within V8. +// Logic for which compiler to choose and how to wire compilation results into +// the object heap should be kept inside this class. +// +// General strategy: Scripts are translated into anonymous functions w/o +// parameters which then can be executed. If the source code contains other +// functions, they might be compiled and allocated as part of the compilation +// of the source code or deferred for lazy compilation at a later point. +class Compiler : public AllStatic { + public: + enum ClearExceptionFlag { KEEP_EXCEPTION, CLEAR_EXCEPTION }; + enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; + + // =========================================================================== + // The following family of methods ensures a given function is compiled. The + // general contract is that failures will be reported by returning {false}, + // whereas successful compilation ensures the {is_compiled} predicate on the + // given function holds (except for live-edit, which compiles the world). + + static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); + static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode); + static bool CompileDebugCode(Handle<JSFunction> function); + static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); + static void CompileForLiveEdit(Handle<Script> script); + + // Generate and install code from previously queued optimization job. + static void FinalizeOptimizedCompileJob(OptimizedCompileJob* job); + + // Give the compiler a chance to perform low-latency initialization tasks of + // the given {function} on its instantiation. Note that only the runtime will + // offer this chance, optimized closure instantiation will not call this. + static void PostInstantiation(Handle<JSFunction> function, PretenureFlag); + + // Parser::Parse, then Compiler::Analyze. + static bool ParseAndAnalyze(ParseInfo* info); + // Rewrite, analyze scopes, and renumber. + static bool Analyze(ParseInfo* info); + // Adds deoptimization support, requires ParseAndAnalyze. + static bool EnsureDeoptimizationSupport(CompilationInfo* info); + + // =========================================================================== + // The following family of methods instantiates new functions for scripts or + // function literals. The decision whether those functions will be compiled, + // is left to the discretion of the compiler. + // + // Please note this interface returns shared function infos. This means you + // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a + // real function with a context. + + // Create a (bound) function for a String source within a context for eval. + MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval( + Handle<String> source, Handle<SharedFunctionInfo> outer_info, + Handle<Context> context, LanguageMode language_mode, + ParseRestriction restriction, int line_offset, int column_offset = 0, + Handle<Object> script_name = Handle<Object>(), + ScriptOriginOptions options = ScriptOriginOptions()); + + // Create a shared function info object for a String source within a context. + static Handle<SharedFunctionInfo> GetSharedFunctionInfoForScript( + Handle<String> source, Handle<Object> script_name, int line_offset, + int column_offset, ScriptOriginOptions resource_options, + Handle<Object> source_map_url, Handle<Context> context, + v8::Extension* extension, ScriptData** cached_data, + ScriptCompiler::CompileOptions compile_options, + NativesFlag is_natives_code, bool is_module); + + // Create a shared function info object for a Script that has already been + // parsed while the script was being loaded from a streamed source. + static Handle<SharedFunctionInfo> GetSharedFunctionInfoForStreamedScript( + Handle<Script> script, ParseInfo* info, int source_length); + + // Create a shared function info object (the code may be lazily compiled). + static Handle<SharedFunctionInfo> GetSharedFunctionInfo( + FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); + + // Create a shared function info object for a native function literal. + static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( + v8::Extension* extension, Handle<String> name); + + // =========================================================================== + // The following family of methods provides support for OSR. Code generated + // for entry via OSR might not be suitable for normal entry, hence will be + // returned directly to the caller. + // + // Please note this interface is the only part dealing with {Code} objects + // directly. Other methods are agnostic to {Code} and can use an interpreter + // instead of generating JIT code for a function at all. + + // Generate and return optimized code for OSR, or empty handle on failure. + MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCodeForOSR( + Handle<JSFunction> function, BailoutId osr_ast_id, + JavaScriptFrame* osr_frame); +}; struct InlinedFunctionInfo { InlinedFunctionInfo(int parent_id, SourcePosition inline_position, @@ -101,7 +197,6 @@ class CompilationInfo { Handle<Code> code() const { return code_; } Code::Flags code_flags() const { return code_flags_; } BailoutId osr_ast_id() const { return osr_ast_id_; } - Handle<Code> unoptimized_code() const { return unoptimized_code_; } int opt_count() const { return opt_count_; } int num_parameters() const; int num_parameters_including_this() const; @@ -116,6 +211,11 @@ class CompilationInfo { bool has_bytecode_array() const { return !bytecode_array_.is_null(); } Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } + Handle<AbstractCode> abstract_code() const { + return has_bytecode_array() ? Handle<AbstractCode>::cast(bytecode_array()) + : Handle<AbstractCode>::cast(code()); + } + bool is_tracking_positions() const { return track_positions_; } bool is_calling() const { @@ -218,14 +318,10 @@ class CompilationInfo { // Generate a pre-aged prologue if we are optimizing for size, which // will make code flushing more aggressive. Only apply to Code::FUNCTION, // since StaticMarkingVisitor::IsFlushable only flushes proper functions. - return FLAG_optimize_for_size && FLAG_age_code && !will_serialize() && - !is_debug() && output_code_kind() == Code::FUNCTION; + return FLAG_optimize_for_size && FLAG_age_code && !is_debug() && + output_code_kind() == Code::FUNCTION; } - void EnsureFeedbackVector(); - Handle<TypeFeedbackVector> feedback_vector() const { - return feedback_vector_; - } void SetCode(Handle<Code> code) { code_ = code; } void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) { @@ -261,10 +357,9 @@ class CompilationInfo { code_flags_ = Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION); } - void SetOptimizingForOsr(BailoutId osr_ast_id, Handle<Code> unoptimized) { + void SetOptimizingForOsr(BailoutId osr_ast_id) { SetOptimizing(); osr_ast_id_ = osr_ast_id; - unoptimized_code_ = unoptimized; } // Deoptimization support. @@ -288,7 +383,7 @@ class CompilationInfo { } void ReopenHandlesInNewHandleScope() { - unoptimized_code_ = Handle<Code>(*unoptimized_code_); + // Empty for now but will be needed once fields move from ParseInfo. } void AbortOptimization(BailoutReason reason) { @@ -377,12 +472,26 @@ class CompilationInfo { return Code::ExtractKindFromFlags(code_flags_); } + StackFrame::Type GetOutputStackFrameType() const; + protected: ParseInfo* parse_info_; void DisableFutureOptimization() { if (GetFlag(kDisableFutureOptimization) && has_shared_info()) { - shared_info()->DisableOptimization(bailout_reason()); + // If Crankshaft tried to optimize this function, bailed out, and + // doesn't want to try again, then use TurboFan next time. + if (!shared_info()->dont_crankshaft() && + bailout_reason() != kOptimizedTooManyTimes) { + shared_info()->set_dont_crankshaft(true); + if (FLAG_trace_opt) { + PrintF("[disabled Crankshaft for "); + shared_info()->ShortPrint(); + PrintF(", reason: %s]\n", GetBailoutReason(bailout_reason())); + } + } else { + shared_info()->DisableOptimization(bailout_reason()); + } } } @@ -421,16 +530,9 @@ class CompilationInfo { // The compiled code. Handle<Code> code_; - // Used by codegen, ultimately kept rooted by the SharedFunctionInfo. - Handle<TypeFeedbackVector> feedback_vector_; - // Compilation mode flag and whether deoptimization is allowed. Mode mode_; BailoutId osr_ast_id_; - // The unoptimized code we patched for OSR may not be the shared code - // afterwards, since we may need to compile it again to include deoptimization - // data. Keep track which code we patched. - Handle<Code> unoptimized_code_; // Holds the bytecode array generated by the interpreter. // TODO(rmcilroy/mstarzinger): Temporary work-around until compiler.cc is @@ -475,25 +577,7 @@ class CompilationInfo { }; -// A wrapper around a CompilationInfo that detaches the Handles from -// the underlying DeferredHandleScope and stores them in info_ on -// destruction. -class CompilationHandleScope BASE_EMBEDDED { - public: - explicit CompilationHandleScope(CompilationInfo* info) - : deferred_(info->isolate()), info_(info) {} - ~CompilationHandleScope() { - info_->set_deferred_handles(deferred_.Detach()); - } - - private: - DeferredHandleScope deferred_; - CompilationInfo* info_; -}; - - class HGraph; -class HOptimizedGraphBuilder; class LChunk; // A helper class that calls the three compilation phases in @@ -505,12 +589,7 @@ class LChunk; class OptimizedCompileJob: public ZoneObject { public: explicit OptimizedCompileJob(CompilationInfo* info) - : info_(info), - graph_builder_(NULL), - graph_(NULL), - chunk_(NULL), - last_status_(FAILED), - awaiting_install_(false) { } + : info_(info), graph_(NULL), chunk_(NULL), last_status_(FAILED) {} enum Status { FAILED, BAILED_OUT, SUCCEEDED @@ -534,23 +613,14 @@ class OptimizedCompileJob: public ZoneObject { return SetLastStatus(BAILED_OUT); } - void WaitForInstall() { - DCHECK(info_->is_osr()); - awaiting_install_ = true; - } - - bool IsWaitingForInstall() { return awaiting_install_; } - private: CompilationInfo* info_; - HOptimizedGraphBuilder* graph_builder_; HGraph* graph_; LChunk* chunk_; base::TimeDelta time_taken_to_create_graph_; base::TimeDelta time_taken_to_optimize_; base::TimeDelta time_taken_to_codegen_; Status last_status_; - bool awaiting_install_; MUST_USE_RESULT Status SetLastStatus(Status status) { last_status_ = status; @@ -575,106 +645,6 @@ class OptimizedCompileJob: public ZoneObject { }; }; - -// The V8 compiler -// -// General strategy: Source code is translated into an anonymous function w/o -// parameters which then can be executed. If the source code contains other -// functions, they will be compiled and allocated as part of the compilation -// of the source code. - -// Please note this interface returns shared function infos. This means you -// need to call Factory::NewFunctionFromSharedFunctionInfo before you have a -// real function with a context. - -class Compiler : public AllStatic { - public: - MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCode( - Handle<JSFunction> function); - MUST_USE_RESULT static MaybeHandle<Code> GetLazyCode( - Handle<JSFunction> function); - - static bool Compile(Handle<JSFunction> function, ClearExceptionFlag flag); - static bool CompileDebugCode(Handle<JSFunction> function); - static bool CompileDebugCode(Handle<SharedFunctionInfo> shared); - static void CompileForLiveEdit(Handle<Script> script); - - // Parser::Parse, then Compiler::Analyze. - static bool ParseAndAnalyze(ParseInfo* info); - // Rewrite, analyze scopes, and renumber. - static bool Analyze(ParseInfo* info); - // Adds deoptimization support, requires ParseAndAnalyze. - static bool EnsureDeoptimizationSupport(CompilationInfo* info); - - // Compile a String source within a context for eval. - MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval( - Handle<String> source, Handle<SharedFunctionInfo> outer_info, - Handle<Context> context, LanguageMode language_mode, - ParseRestriction restriction, int line_offset, int column_offset = 0, - Handle<Object> script_name = Handle<Object>(), - ScriptOriginOptions options = ScriptOriginOptions()); - - // Compile a String source within a context. - static Handle<SharedFunctionInfo> CompileScript( - Handle<String> source, Handle<Object> script_name, int line_offset, - int column_offset, ScriptOriginOptions resource_options, - Handle<Object> source_map_url, Handle<Context> context, - v8::Extension* extension, ScriptData** cached_data, - ScriptCompiler::CompileOptions compile_options, - NativesFlag is_natives_code, bool is_module); - - static Handle<SharedFunctionInfo> CompileStreamedScript(Handle<Script> script, - ParseInfo* info, - int source_length); - - // Create a shared function info object (the code may be lazily compiled). - static Handle<SharedFunctionInfo> GetSharedFunctionInfo( - FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer); - - // Create a shared function info object for a native function literal. - static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative( - v8::Extension* extension, Handle<String> name); - - enum ConcurrencyMode { NOT_CONCURRENT, CONCURRENT }; - - // Generate and return optimized code or start a concurrent optimization job. - // In the latter case, return the InOptimizationQueue builtin. On failure, - // return the empty handle. - MUST_USE_RESULT static MaybeHandle<Code> GetOptimizedCode( - Handle<JSFunction> function, ConcurrencyMode mode, - BailoutId osr_ast_id = BailoutId::None(), - JavaScriptFrame* osr_frame = nullptr); - - // Generate and return code from previously queued optimization job. - // On failure, return the empty handle. - MUST_USE_RESULT static MaybeHandle<Code> GetConcurrentlyOptimizedCode( - OptimizedCompileJob* job); -}; - - -class CompilationPhase BASE_EMBEDDED { - public: - CompilationPhase(const char* name, CompilationInfo* info); - ~CompilationPhase(); - - protected: - bool ShouldProduceTraceOutput() const; - - const char* name() const { return name_; } - CompilationInfo* info() const { return info_; } - Isolate* isolate() const { return info()->isolate(); } - Zone* zone() { return &zone_; } - - private: - const char* name_; - CompilationInfo* info_; - Zone zone_; - size_t info_zone_start_allocation_size_; - base::ElapsedTimer timer_; - - DISALLOW_COPY_AND_ASSIGN(CompilationPhase); -}; - } // namespace internal } // namespace v8 |