2012-02-14 14:14:51 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_COMPILER_H_
|
|
|
|
#define V8_COMPILER_H_
|
|
|
|
|
2016-07-25 10:24:45 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
2014-09-24 07:08:27 +00:00
|
|
|
#include "src/bailout-reason.h"
|
2015-04-20 15:22:02 +00:00
|
|
|
#include "src/compilation-dependencies.h"
|
2016-08-18 10:26:19 +00:00
|
|
|
#include "src/contexts.h"
|
|
|
|
#include "src/frames.h"
|
|
|
|
#include "src/isolate.h"
|
|
|
|
#include "src/objects-inl.h"
|
2016-07-08 08:48:22 +00:00
|
|
|
#include "src/source-position-table.h"
|
2016-01-15 12:11:35 +00:00
|
|
|
#include "src/source-position.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/zone.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2016-01-15 12:11:35 +00:00
|
|
|
// Forward declarations.
|
2016-03-08 12:07:27 +00:00
|
|
|
class CompilationInfo;
|
2016-04-27 17:54:16 +00:00
|
|
|
class CompilationJob;
|
2015-07-06 11:11:15 +00:00
|
|
|
class JavaScriptFrame;
|
2015-03-09 14:51:13 +00:00
|
|
|
class ParseInfo;
|
|
|
|
class ScriptData;
|
2013-03-07 15:46:14 +00:00
|
|
|
|
2016-03-08 12:07:27 +00:00
|
|
|
// 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 };
|
2016-07-25 09:42:48 +00:00
|
|
|
enum CompilationTier { INTERPRETED, BASELINE, OPTIMIZED };
|
2016-03-08 12:07:27 +00:00
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// 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);
|
2016-04-25 10:46:38 +00:00
|
|
|
static bool CompileBaseline(Handle<JSFunction> function);
|
2016-03-08 12:07:27 +00:00
|
|
|
static bool CompileOptimized(Handle<JSFunction> function, ConcurrencyMode);
|
|
|
|
static bool CompileDebugCode(Handle<JSFunction> function);
|
|
|
|
static bool CompileDebugCode(Handle<SharedFunctionInfo> shared);
|
2016-05-18 07:09:37 +00:00
|
|
|
static MaybeHandle<JSArray> CompileForLiveEdit(Handle<Script> script);
|
2016-03-08 12:07:27 +00:00
|
|
|
|
2016-04-27 17:54:16 +00:00
|
|
|
// Generate and install code from previously queued compilation job.
|
|
|
|
static void FinalizeCompilationJob(CompilationJob* job);
|
2016-03-08 12:07:27 +00:00
|
|
|
|
|
|
|
// 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);
|
2016-07-25 09:42:48 +00:00
|
|
|
// Ensures that bytecode is generated, calls ParseAndAnalyze internally.
|
|
|
|
static bool EnsureBytecode(CompilationInfo* info);
|
|
|
|
|
|
|
|
// The next compilation tier which the function should be compiled to for
|
|
|
|
// optimization. This is used as a hint by the runtime profiler.
|
|
|
|
static CompilationTier NextCompilationTier(JSFunction* function);
|
2016-03-08 12:07:27 +00:00
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
// 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,
|
2016-04-18 13:20:45 +00:00
|
|
|
ParseRestriction restriction, int eval_scope_position, int eval_position,
|
|
|
|
int line_offset = 0, int column_offset = 0,
|
2016-04-14 12:45:00 +00:00
|
|
|
Handle<Object> script_name = Handle<Object>(),
|
2016-03-08 12:07:27 +00:00
|
|
|
ScriptOriginOptions options = ScriptOriginOptions());
|
|
|
|
|
2016-07-20 13:29:04 +00:00
|
|
|
// Create a (bound) function for a String source within a context for eval.
|
|
|
|
MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromString(
|
|
|
|
Handle<Context> context, Handle<String> source,
|
|
|
|
ParseRestriction restriction);
|
|
|
|
|
2016-03-08 12:07:27 +00:00
|
|
|
// 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);
|
|
|
|
};
|
2014-07-10 10:28:05 +00:00
|
|
|
|
2015-02-17 09:44:44 +00:00
|
|
|
|
2010-02-03 16:12:55 +00:00
|
|
|
// CompilationInfo encapsulates some information known at compile time. It
|
|
|
|
// is constructed based on the resources available at compile-time.
|
2016-05-02 14:44:29 +00:00
|
|
|
class CompilationInfo final {
|
2010-01-29 11:55:40 +00:00
|
|
|
public:
|
2014-08-26 14:41:58 +00:00
|
|
|
// Various configuration flags for a compilation, as well as some properties
|
|
|
|
// of the compiled code produced by a compilation.
|
|
|
|
enum Flag {
|
2015-03-23 14:48:16 +00:00
|
|
|
kDeferredCalling = 1 << 0,
|
|
|
|
kNonDeferredCalling = 1 << 1,
|
|
|
|
kSavesCallerDoubles = 1 << 2,
|
|
|
|
kRequiresFrame = 1 << 3,
|
2015-03-23 19:11:19 +00:00
|
|
|
kMustNotHaveEagerFrame = 1 << 4,
|
|
|
|
kDeoptimizationSupport = 1 << 5,
|
|
|
|
kDebug = 1 << 6,
|
2015-07-20 14:53:28 +00:00
|
|
|
kSerializing = 1 << 7,
|
2015-09-25 11:33:28 +00:00
|
|
|
kFunctionContextSpecializing = 1 << 8,
|
2015-07-20 14:53:28 +00:00
|
|
|
kFrameSpecializing = 1 << 9,
|
2015-10-07 12:10:49 +00:00
|
|
|
kNativeContextSpecializing = 1 << 10,
|
|
|
|
kInliningEnabled = 1 << 11,
|
2016-04-11 12:56:47 +00:00
|
|
|
kDisableFutureOptimization = 1 << 12,
|
|
|
|
kSplittingEnabled = 1 << 13,
|
|
|
|
kDeoptimizationEnabled = 1 << 14,
|
|
|
|
kSourcePositionsEnabled = 1 << 15,
|
2016-04-25 06:49:44 +00:00
|
|
|
kBailoutOnUninitialized = 1 << 16,
|
|
|
|
kOptimizeFromBytecode = 1 << 17,
|
2016-06-02 09:20:50 +00:00
|
|
|
kTypeFeedbackEnabled = 1 << 18,
|
2016-08-01 06:59:33 +00:00
|
|
|
kAccessorInliningEnabled = 1 << 19,
|
2014-08-26 14:41:58 +00:00
|
|
|
};
|
|
|
|
|
2016-04-08 12:31:38 +00:00
|
|
|
CompilationInfo(ParseInfo* parse_info, Handle<JSFunction> closure);
|
2016-04-26 14:36:35 +00:00
|
|
|
CompilationInfo(Vector<const char> debug_name, Isolate* isolate, Zone* zone,
|
2016-01-20 15:17:39 +00:00
|
|
|
Code::Flags code_flags = Code::ComputeFlags(Code::STUB));
|
2016-05-02 14:44:29 +00:00
|
|
|
~CompilationInfo();
|
2012-07-06 09:31:31 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
ParseInfo* parse_info() const { return parse_info_; }
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
// TODO(titzer): inline and delete accessors of ParseInfo
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
Handle<Script> script() const;
|
2015-08-19 16:51:37 +00:00
|
|
|
FunctionLiteral* literal() const;
|
2016-08-05 14:30:54 +00:00
|
|
|
DeclarationScope* scope() const;
|
2015-03-09 14:51:13 +00:00
|
|
|
Handle<Context> context() const;
|
|
|
|
Handle<SharedFunctionInfo> shared_info() const;
|
|
|
|
bool has_shared_info() const;
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
2013-09-05 11:27:22 +00:00
|
|
|
Isolate* isolate() const {
|
2011-03-18 20:35:07 +00:00
|
|
|
return isolate_;
|
|
|
|
}
|
2013-09-09 16:34:40 +00:00
|
|
|
Zone* zone() { return zone_; }
|
|
|
|
bool is_osr() const { return !osr_ast_id_.IsNone(); }
|
2016-04-08 12:31:38 +00:00
|
|
|
Handle<JSFunction> closure() const { return closure_; }
|
2010-10-04 14:30:43 +00:00
|
|
|
Handle<Code> code() const { return code_; }
|
2016-01-20 15:17:39 +00:00
|
|
|
Code::Flags code_flags() const { return code_flags_; }
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId osr_ast_id() const { return osr_ast_id_; }
|
2016-05-10 09:47:50 +00:00
|
|
|
JavaScriptFrame* osr_frame() const { return osr_frame_; }
|
2012-12-18 16:25:45 +00:00
|
|
|
int num_parameters() const;
|
2015-05-11 11:45:02 +00:00
|
|
|
int num_parameters_including_this() const;
|
|
|
|
bool is_this_defined() const;
|
2010-10-04 11:35:46 +00:00
|
|
|
|
2013-11-15 10:52:05 +00:00
|
|
|
void set_parameter_count(int parameter_count) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsStub());
|
2013-11-15 10:52:05 +00:00
|
|
|
parameter_count_ = parameter_count;
|
|
|
|
}
|
2014-01-14 12:04:10 +00:00
|
|
|
|
2015-10-07 10:30:35 +00:00
|
|
|
bool has_bytecode_array() const { return !bytecode_array_.is_null(); }
|
|
|
|
Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }
|
|
|
|
|
2015-03-16 14:17:01 +00:00
|
|
|
bool is_tracking_positions() const { return track_positions_; }
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
bool is_calling() const {
|
2014-08-26 14:41:58 +00:00
|
|
|
return GetFlag(kDeferredCalling) || GetFlag(kNonDeferredCalling);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
void MarkAsDeferredCalling() { SetFlag(kDeferredCalling); }
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
bool is_deferred_calling() const { return GetFlag(kDeferredCalling); }
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
void MarkAsNonDeferredCalling() { SetFlag(kNonDeferredCalling); }
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
bool is_non_deferred_calling() const { return GetFlag(kNonDeferredCalling); }
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
void MarkAsSavesCallerDoubles() { SetFlag(kSavesCallerDoubles); }
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
bool saves_caller_doubles() const { return GetFlag(kSavesCallerDoubles); }
|
2013-02-04 12:01:59 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
void MarkAsRequiresFrame() { SetFlag(kRequiresFrame); }
|
2013-04-18 15:44:38 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
bool requires_frame() const { return GetFlag(kRequiresFrame); }
|
2013-04-18 15:44:38 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
void MarkMustNotHaveEagerFrame() { SetFlag(kMustNotHaveEagerFrame); }
|
2014-05-12 07:49:11 +00:00
|
|
|
|
|
|
|
bool GetMustNotHaveEagerFrame() const {
|
2014-08-26 14:41:58 +00:00
|
|
|
return GetFlag(kMustNotHaveEagerFrame);
|
2014-05-12 07:49:11 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 14:53:28 +00:00
|
|
|
// Compiles marked as debug produce unoptimized code with debug break slots.
|
|
|
|
// Inner functions that cannot be compiled w/o context are compiled eagerly.
|
2015-07-24 13:43:38 +00:00
|
|
|
// Always include deoptimization support to avoid having to recompile again.
|
|
|
|
void MarkAsDebug() {
|
|
|
|
SetFlag(kDebug);
|
|
|
|
SetFlag(kDeoptimizationSupport);
|
|
|
|
}
|
2014-05-12 13:47:01 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
bool is_debug() const { return GetFlag(kDebug); }
|
2014-05-12 13:47:01 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
void PrepareForSerializing() { SetFlag(kSerializing); }
|
2014-07-08 14:13:50 +00:00
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
bool will_serialize() const { return GetFlag(kSerializing); }
|
2014-07-08 14:13:50 +00:00
|
|
|
|
2015-09-25 11:33:28 +00:00
|
|
|
void MarkAsFunctionContextSpecializing() {
|
|
|
|
SetFlag(kFunctionContextSpecializing);
|
|
|
|
}
|
2014-08-26 15:17:57 +00:00
|
|
|
|
2015-09-25 11:33:28 +00:00
|
|
|
bool is_function_context_specializing() const {
|
|
|
|
return GetFlag(kFunctionContextSpecializing);
|
|
|
|
}
|
2014-08-26 15:17:57 +00:00
|
|
|
|
2015-07-06 11:11:15 +00:00
|
|
|
void MarkAsFrameSpecializing() { SetFlag(kFrameSpecializing); }
|
|
|
|
|
|
|
|
bool is_frame_specializing() const { return GetFlag(kFrameSpecializing); }
|
|
|
|
|
2015-10-07 12:10:49 +00:00
|
|
|
void MarkAsNativeContextSpecializing() {
|
|
|
|
SetFlag(kNativeContextSpecializing);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_native_context_specializing() const {
|
|
|
|
return GetFlag(kNativeContextSpecializing);
|
|
|
|
}
|
|
|
|
|
2015-04-23 09:04:37 +00:00
|
|
|
void MarkAsDeoptimizationEnabled() { SetFlag(kDeoptimizationEnabled); }
|
|
|
|
|
|
|
|
bool is_deoptimization_enabled() const {
|
|
|
|
return GetFlag(kDeoptimizationEnabled);
|
|
|
|
}
|
|
|
|
|
2016-06-02 09:20:50 +00:00
|
|
|
void MarkAsTypeFeedbackEnabled() { SetFlag(kTypeFeedbackEnabled); }
|
|
|
|
|
|
|
|
bool is_type_feedback_enabled() const {
|
|
|
|
return GetFlag(kTypeFeedbackEnabled);
|
|
|
|
}
|
|
|
|
|
2016-08-01 06:59:33 +00:00
|
|
|
void MarkAsAccessorInliningEnabled() { SetFlag(kAccessorInliningEnabled); }
|
|
|
|
|
|
|
|
bool is_accessor_inlining_enabled() const {
|
|
|
|
return GetFlag(kAccessorInliningEnabled);
|
|
|
|
}
|
|
|
|
|
2015-04-30 09:56:24 +00:00
|
|
|
void MarkAsSourcePositionsEnabled() { SetFlag(kSourcePositionsEnabled); }
|
|
|
|
|
|
|
|
bool is_source_positions_enabled() const {
|
|
|
|
return GetFlag(kSourcePositionsEnabled);
|
|
|
|
}
|
|
|
|
|
2014-08-28 08:39:24 +00:00
|
|
|
void MarkAsInliningEnabled() { SetFlag(kInliningEnabled); }
|
|
|
|
|
|
|
|
bool is_inlining_enabled() const { return GetFlag(kInliningEnabled); }
|
|
|
|
|
2015-02-03 14:50:40 +00:00
|
|
|
void MarkAsSplittingEnabled() { SetFlag(kSplittingEnabled); }
|
|
|
|
|
|
|
|
bool is_splitting_enabled() const { return GetFlag(kSplittingEnabled); }
|
|
|
|
|
2016-02-20 19:05:47 +00:00
|
|
|
void MarkAsBailoutOnUninitialized() { SetFlag(kBailoutOnUninitialized); }
|
|
|
|
|
|
|
|
bool is_bailout_on_uninitialized() const {
|
|
|
|
return GetFlag(kBailoutOnUninitialized);
|
|
|
|
}
|
|
|
|
|
2016-04-18 09:09:59 +00:00
|
|
|
void MarkAsOptimizeFromBytecode() { SetFlag(kOptimizeFromBytecode); }
|
|
|
|
|
|
|
|
bool is_optimizing_from_bytecode() const {
|
|
|
|
return GetFlag(kOptimizeFromBytecode);
|
|
|
|
}
|
|
|
|
|
2016-01-12 10:48:47 +00:00
|
|
|
bool GeneratePreagedPrologue() const {
|
|
|
|
// Generate a pre-aged prologue if we are optimizing for size, which
|
2016-01-14 11:48:11 +00:00
|
|
|
// will make code flushing more aggressive. Only apply to Code::FUNCTION,
|
|
|
|
// since StaticMarkingVisitor::IsFlushable only flushes proper functions.
|
2016-03-14 18:55:41 +00:00
|
|
|
return FLAG_optimize_for_size && FLAG_age_code && !is_debug() &&
|
|
|
|
output_code_kind() == Code::FUNCTION;
|
2014-05-12 13:47:01 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
void SetCode(Handle<Code> code) { code_ = code; }
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2015-10-07 10:30:35 +00:00
|
|
|
void SetBytecodeArray(Handle<BytecodeArray> bytecode_array) {
|
|
|
|
bytecode_array_ = bytecode_array;
|
|
|
|
}
|
|
|
|
|
2013-08-09 08:24:29 +00:00
|
|
|
bool ShouldTrapOnDeopt() const {
|
|
|
|
return (FLAG_trap_on_deopt && IsOptimizing()) ||
|
|
|
|
(FLAG_trap_on_stub_deopt && IsStub());
|
|
|
|
}
|
|
|
|
|
2015-11-27 16:59:28 +00:00
|
|
|
bool has_native_context() const {
|
|
|
|
return !closure().is_null() && (closure()->native_context() != nullptr);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 16:59:28 +00:00
|
|
|
Context* native_context() const {
|
|
|
|
return has_native_context() ? closure()->native_context() : nullptr;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 16:59:28 +00:00
|
|
|
bool has_global_object() const { return has_native_context(); }
|
2015-11-18 10:03:50 +00:00
|
|
|
|
2015-11-27 16:59:28 +00:00
|
|
|
JSGlobalObject* global_object() const {
|
|
|
|
return has_global_object() ? native_context()->global_object() : nullptr;
|
2015-11-18 10:03:50 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Accessors for the different compilation modes.
|
|
|
|
bool IsOptimizing() const { return mode_ == OPTIMIZE; }
|
2012-12-18 16:25:45 +00:00
|
|
|
bool IsStub() const { return mode_ == STUB; }
|
2016-02-10 10:27:59 +00:00
|
|
|
void SetOptimizing() {
|
2015-09-18 11:03:30 +00:00
|
|
|
DCHECK(has_shared_info());
|
2010-12-07 11:31:57 +00:00
|
|
|
SetMode(OPTIMIZE);
|
2014-02-13 16:09:28 +00:00
|
|
|
optimization_id_ = isolate()->NextOptimizationId();
|
2016-01-20 15:17:39 +00:00
|
|
|
code_flags_ =
|
|
|
|
Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2016-05-10 09:47:50 +00:00
|
|
|
void SetOptimizingForOsr(BailoutId osr_ast_id, JavaScriptFrame* osr_frame) {
|
2016-02-10 10:27:59 +00:00
|
|
|
SetOptimizing();
|
|
|
|
osr_ast_id_ = osr_ast_id;
|
2016-05-10 09:47:50 +00:00
|
|
|
osr_frame_ = osr_frame;
|
2016-02-10 10:27:59 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Deoptimization support.
|
2011-10-18 13:40:33 +00:00
|
|
|
bool HasDeoptimizationSupport() const {
|
2014-08-26 14:41:58 +00:00
|
|
|
return GetFlag(kDeoptimizationSupport);
|
2011-10-18 13:40:33 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
void EnableDeoptimizationSupport() {
|
2015-08-21 15:21:08 +00:00
|
|
|
DCHECK_EQ(BASE, mode_);
|
2014-08-26 14:41:58 +00:00
|
|
|
SetFlag(kDeoptimizationSupport);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2015-08-24 10:23:39 +00:00
|
|
|
bool ShouldEnsureSpaceForLazyDeopt() { return !IsStub(); }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-11-05 13:23:13 +00:00
|
|
|
bool ExpectsJSReceiverAsReceiver();
|
2015-08-27 20:31:25 +00:00
|
|
|
|
2014-11-21 17:28:18 +00:00
|
|
|
// Determines whether or not to insert a self-optimization header.
|
|
|
|
bool ShouldSelfOptimize();
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
void set_deferred_handles(DeferredHandles* deferred_handles) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(deferred_handles_ == NULL);
|
2012-07-06 09:31:31 +00:00
|
|
|
deferred_handles_ = deferred_handles;
|
|
|
|
}
|
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
void ReopenHandlesInNewHandleScope() {
|
2016-04-08 12:31:38 +00:00
|
|
|
closure_ = Handle<JSFunction>(*closure_);
|
2012-07-19 18:58:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 07:08:27 +00:00
|
|
|
void AbortOptimization(BailoutReason reason) {
|
2015-01-13 14:36:50 +00:00
|
|
|
DCHECK(reason != kNoReason);
|
|
|
|
if (bailout_reason_ == kNoReason) bailout_reason_ = reason;
|
2014-09-24 07:08:27 +00:00
|
|
|
SetFlag(kDisableFutureOptimization);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RetryOptimization(BailoutReason reason) {
|
2015-01-13 14:36:50 +00:00
|
|
|
DCHECK(reason != kNoReason);
|
|
|
|
if (GetFlag(kDisableFutureOptimization)) return;
|
|
|
|
bailout_reason_ = reason;
|
2014-09-24 07:08:27 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 09:53:11 +00:00
|
|
|
BailoutReason bailout_reason() const { return bailout_reason_; }
|
2012-08-28 07:18:06 +00:00
|
|
|
|
2012-11-29 07:38:00 +00:00
|
|
|
int prologue_offset() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_NE(Code::kPrologueOffsetNotSet, prologue_offset_);
|
2012-11-29 07:38:00 +00:00
|
|
|
return prologue_offset_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_prologue_offset(int prologue_offset) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(Code::kPrologueOffsetNotSet, prologue_offset_);
|
2012-11-29 07:38:00 +00:00
|
|
|
prologue_offset_ = prologue_offset;
|
|
|
|
}
|
|
|
|
|
2015-04-20 15:22:02 +00:00
|
|
|
CompilationDependencies* dependencies() { return &dependencies_; }
|
2013-06-12 09:43:22 +00:00
|
|
|
|
2014-02-13 16:09:28 +00:00
|
|
|
int optimization_id() const { return optimization_id_; }
|
|
|
|
|
2015-02-02 10:19:52 +00:00
|
|
|
int osr_expr_stack_height() { return osr_expr_stack_height_; }
|
|
|
|
void set_osr_expr_stack_height(int height) {
|
|
|
|
DCHECK(height >= 0);
|
|
|
|
osr_expr_stack_height_ = height;
|
|
|
|
}
|
|
|
|
|
2015-08-07 11:38:20 +00:00
|
|
|
bool has_simple_parameters();
|
2015-02-14 00:14:46 +00:00
|
|
|
|
2015-10-21 15:05:13 +00:00
|
|
|
struct InlinedFunctionHolder {
|
|
|
|
Handle<SharedFunctionInfo> shared_info;
|
|
|
|
|
|
|
|
// Root that holds the unoptimized code of the inlined function alive
|
|
|
|
// (and out of reach of code flushing) until we finish compilation.
|
|
|
|
// Do not remove.
|
|
|
|
Handle<Code> inlined_code_object_root;
|
|
|
|
|
|
|
|
explicit InlinedFunctionHolder(
|
|
|
|
Handle<SharedFunctionInfo> inlined_shared_info)
|
|
|
|
: shared_info(inlined_shared_info),
|
|
|
|
inlined_code_object_root(inlined_shared_info->code()) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<InlinedFunctionHolder> InlinedFunctionList;
|
2015-06-11 05:23:06 +00:00
|
|
|
InlinedFunctionList const& inlined_functions() const {
|
|
|
|
return inlined_functions_;
|
|
|
|
}
|
2015-10-21 15:05:13 +00:00
|
|
|
|
2015-06-11 05:23:06 +00:00
|
|
|
void AddInlinedFunction(Handle<SharedFunctionInfo> inlined_function) {
|
2015-10-21 15:05:13 +00:00
|
|
|
inlined_functions_.push_back(InlinedFunctionHolder(inlined_function));
|
2015-06-11 05:23:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-25 10:24:45 +00:00
|
|
|
std::unique_ptr<char[]> GetDebugName() const;
|
2015-08-24 10:23:39 +00:00
|
|
|
|
2016-01-20 15:17:39 +00:00
|
|
|
Code::Kind output_code_kind() const {
|
|
|
|
return Code::ExtractKindFromFlags(code_flags_);
|
|
|
|
}
|
2015-09-23 14:00:23 +00:00
|
|
|
|
[runtime] Unify and simplify how frames are marked
Before this CL, various code stubs used different techniques
for marking their frames to enable stack-crawling and other
access to data in the frame. All of them were based on a abuse
of the "standard" frame representation, e.g. storing the a
context pointer immediately below the frame's fp, and a
function pointer after that. Although functional, this approach
tends to make stubs and builtins do an awkward, unnecessary
dance to appear like standard frames, even if they have
nothing to do with JavaScript execution.
This CL attempts to improve this by:
* Ensuring that there are only two fundamentally different
types of frames, a "standard" frame and a "typed" frame.
Standard frames, as before, contain both a context and
function pointer. Typed frames contain only a minimum
of a smi marker in the position immediately below the fp
where the context is in standard frames.
* Only interpreted, full codegen, and optimized Crankshaft and
TurboFan JavaScript frames use the "standard" format. All
other frames use the type frame format with an explicit
marker.
* Typed frames can contain one or more values below the
type marker. There is new magic macro machinery in
frames.h that simplifies defining the offsets of these fields
in typed frames.
* A new flag in the CallDescriptor enables specifying whether
a frame is a standard frame or a typed frame. Secondary
register location spilling is now only enabled for standard
frames.
* A zillion places in the code have been updated to deal with
the fact that most code stubs and internal frames use the
typed frame format. This includes changes in the
deoptimizer, debugger, and liveedit.
* StandardFrameConstants::kMarkerOffset is deprecated,
(CommonFrameConstants::kContextOrFrameTypeOffset
and StandardFrameConstants::kFrameOffset are now used
in its stead).
LOG=N
Review URL: https://codereview.chromium.org/1696043002
Cr-Commit-Position: refs/heads/master@{#34571}
2016-03-08 08:35:44 +00:00
|
|
|
StackFrame::Type GetOutputStackFrameType() const;
|
|
|
|
|
2016-05-04 15:57:34 +00:00
|
|
|
int GetDeclareGlobalsFlags() const;
|
|
|
|
|
2016-07-08 08:48:22 +00:00
|
|
|
SourcePositionTableBuilder::RecordingMode SourcePositionRecordingMode() const;
|
|
|
|
|
2010-10-04 11:35:46 +00:00
|
|
|
private:
|
2010-12-07 11:31:57 +00:00
|
|
|
// Compilation mode.
|
|
|
|
// BASE is generated by the full codegen, optionally prepared for bailouts.
|
|
|
|
// OPTIMIZE is optimized code generated by the Hydrogen-based backend.
|
|
|
|
enum Mode {
|
|
|
|
BASE,
|
|
|
|
OPTIMIZE,
|
2013-08-12 14:10:25 +00:00
|
|
|
STUB
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
2016-04-26 14:36:35 +00:00
|
|
|
CompilationInfo(ParseInfo* parse_info, Vector<const char> debug_name,
|
2016-01-20 15:17:39 +00:00
|
|
|
Code::Flags code_flags, Mode mode, Isolate* isolate,
|
2015-08-24 10:23:39 +00:00
|
|
|
Zone* zone);
|
2015-03-19 12:39:43 +00:00
|
|
|
|
2016-07-14 13:05:15 +00:00
|
|
|
ParseInfo* parse_info_;
|
2015-03-19 12:39:43 +00:00
|
|
|
Isolate* isolate_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
void SetMode(Mode mode) {
|
|
|
|
mode_ = mode;
|
|
|
|
}
|
|
|
|
|
2014-08-26 14:41:58 +00:00
|
|
|
void SetFlag(Flag flag) { flags_ |= flag; }
|
|
|
|
|
|
|
|
void SetFlag(Flag flag, bool value) {
|
|
|
|
flags_ = value ? flags_ | flag : flags_ & ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
|
2010-10-04 11:35:46 +00:00
|
|
|
|
|
|
|
unsigned flags_;
|
|
|
|
|
2016-01-20 15:17:39 +00:00
|
|
|
Code::Flags code_flags_;
|
2015-09-23 14:00:23 +00:00
|
|
|
|
2016-04-08 12:31:38 +00:00
|
|
|
Handle<JSFunction> closure_;
|
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
// The compiled code.
|
|
|
|
Handle<Code> code_;
|
2010-09-30 08:48:37 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Compilation mode flag and whether deoptimization is allowed.
|
|
|
|
Mode mode_;
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId osr_ast_id_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-10-07 10:30:35 +00:00
|
|
|
// Holds the bytecode array generated by the interpreter.
|
|
|
|
// TODO(rmcilroy/mstarzinger): Temporary work-around until compiler.cc is
|
|
|
|
// refactored to avoid us needing to carry the BytcodeArray around.
|
|
|
|
Handle<BytecodeArray> bytecode_array_;
|
|
|
|
|
2012-06-20 08:58:41 +00:00
|
|
|
// The zone from which the compilation pipeline working on this
|
|
|
|
// CompilationInfo allocates.
|
|
|
|
Zone* zone_;
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
DeferredHandles* deferred_handles_;
|
|
|
|
|
2015-04-20 15:22:02 +00:00
|
|
|
// Dependencies for this compilation, e.g. stable maps.
|
|
|
|
CompilationDependencies dependencies_;
|
2013-06-12 09:43:22 +00:00
|
|
|
|
2013-08-02 09:53:11 +00:00
|
|
|
BailoutReason bailout_reason_;
|
2012-08-28 07:18:06 +00:00
|
|
|
|
2012-11-29 07:38:00 +00:00
|
|
|
int prologue_offset_;
|
|
|
|
|
2015-03-16 14:17:01 +00:00
|
|
|
bool track_positions_;
|
2013-05-14 22:51:33 +00:00
|
|
|
|
2015-06-11 05:23:06 +00:00
|
|
|
InlinedFunctionList inlined_functions_;
|
|
|
|
|
2013-11-15 10:52:05 +00:00
|
|
|
// Number of parameters used for compilation of stubs that require arguments.
|
|
|
|
int parameter_count_;
|
|
|
|
|
2014-02-13 16:09:28 +00:00
|
|
|
int optimization_id_;
|
|
|
|
|
2015-02-02 10:19:52 +00:00
|
|
|
int osr_expr_stack_height_;
|
|
|
|
|
2015-07-06 11:11:15 +00:00
|
|
|
// The current OSR frame for specialization or {nullptr}.
|
|
|
|
JavaScriptFrame* osr_frame_ = nullptr;
|
|
|
|
|
2016-04-26 14:36:35 +00:00
|
|
|
Vector<const char> debug_name_;
|
2015-08-24 10:23:39 +00:00
|
|
|
|
2010-10-04 11:35:46 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
|
2010-01-29 11:55:40 +00:00
|
|
|
};
|
|
|
|
|
2016-04-11 10:01:09 +00:00
|
|
|
// A base class for compilation jobs intended to run concurrent to the main
|
|
|
|
// thread. The job is split into three phases which are called in sequence on
|
|
|
|
// different threads and with different limitations:
|
2016-08-22 11:48:59 +00:00
|
|
|
// 1) PrepareJob: Runs on main thread. No major limitations.
|
|
|
|
// 2) ExecuteJob: Runs concurrently. No heap allocation or handle derefs.
|
|
|
|
// 3) FinalizeJob: Runs on main thread. No dependency changes.
|
2016-04-11 10:01:09 +00:00
|
|
|
//
|
2016-08-22 11:48:59 +00:00
|
|
|
// Each of the three phases can either fail or succeed. The current state of
|
|
|
|
// the job can be checked using {state()}.
|
2016-04-27 17:54:16 +00:00
|
|
|
class CompilationJob {
|
2012-07-17 16:24:40 +00:00
|
|
|
public:
|
2016-08-22 11:48:59 +00:00
|
|
|
enum Status { SUCCEEDED, FAILED };
|
|
|
|
enum class State {
|
|
|
|
kReadyToPrepare,
|
|
|
|
kReadyToExecute,
|
|
|
|
kReadyToFinalize,
|
|
|
|
kSucceeded,
|
|
|
|
kFailed,
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit CompilationJob(CompilationInfo* info, const char* compiler_name,
|
|
|
|
State initial_state = State::kReadyToPrepare)
|
|
|
|
: info_(info), compiler_name_(compiler_name), state_(initial_state) {}
|
2016-04-27 17:54:16 +00:00
|
|
|
virtual ~CompilationJob() {}
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Prepare the compile job. Must be called on the main thread.
|
|
|
|
MUST_USE_RESULT Status PrepareJob();
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Executes the compile job. Can be called off the main thread.
|
|
|
|
MUST_USE_RESULT Status ExecuteJob();
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Finalizes the compile job. Must be called on the main thread.
|
|
|
|
MUST_USE_RESULT Status FinalizeJob();
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Report a transient failure, try again next time. Should only be called on
|
|
|
|
// optimization compilation jobs.
|
2014-09-24 07:08:27 +00:00
|
|
|
Status RetryOptimization(BailoutReason reason) {
|
2016-08-22 11:48:59 +00:00
|
|
|
DCHECK(info_->IsOptimizing());
|
2014-09-24 07:08:27 +00:00
|
|
|
info_->RetryOptimization(reason);
|
2016-08-22 11:48:59 +00:00
|
|
|
state_ = State::kFailed;
|
|
|
|
return FAILED;
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
// Report a persistent failure, disable future optimization on the function.
|
|
|
|
// Should only be called on optimization compilation jobs.
|
2014-09-24 07:08:27 +00:00
|
|
|
Status AbortOptimization(BailoutReason reason) {
|
2016-08-22 11:48:59 +00:00
|
|
|
DCHECK(info_->IsOptimizing());
|
2014-09-24 07:08:27 +00:00
|
|
|
info_->AbortOptimization(reason);
|
2016-08-22 11:48:59 +00:00
|
|
|
state_ = State::kFailed;
|
|
|
|
return FAILED;
|
2012-07-19 18:58:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 10:01:09 +00:00
|
|
|
void RecordOptimizationStats();
|
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
State state() const { return state_; }
|
|
|
|
CompilationInfo* info() const { return info_; }
|
|
|
|
Isolate* isolate() const { return info()->isolate(); }
|
2016-04-11 10:01:09 +00:00
|
|
|
|
2016-08-22 11:48:59 +00:00
|
|
|
protected:
|
2016-08-18 17:06:37 +00:00
|
|
|
// Overridden by the actual implementation.
|
2016-08-22 11:48:59 +00:00
|
|
|
virtual Status PrepareJobImpl() = 0;
|
|
|
|
virtual Status ExecuteJobImpl() = 0;
|
|
|
|
virtual Status FinalizeJobImpl() = 0;
|
|
|
|
|
|
|
|
// Registers weak object to optimized code dependencies.
|
|
|
|
// TODO(turbofan): Move this to pipeline.cc once Crankshaft dies.
|
|
|
|
void RegisterWeakObjectsInOptimizedCode(Handle<Code> code);
|
2016-08-18 17:06:37 +00:00
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
private:
|
|
|
|
CompilationInfo* info_;
|
2016-08-22 11:48:59 +00:00
|
|
|
base::TimeDelta time_taken_to_prepare_;
|
|
|
|
base::TimeDelta time_taken_to_execute_;
|
|
|
|
base::TimeDelta time_taken_to_finalize_;
|
2016-04-11 12:06:41 +00:00
|
|
|
const char* compiler_name_;
|
2016-08-22 11:48:59 +00:00
|
|
|
State state_;
|
|
|
|
|
|
|
|
MUST_USE_RESULT Status UpdateState(Status status, State next_state) {
|
|
|
|
if (status == SUCCEEDED) {
|
|
|
|
state_ = next_state;
|
|
|
|
} else {
|
|
|
|
state_ = State::kFailed;
|
|
|
|
}
|
|
|
|
return status;
|
2012-07-17 16:24:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#endif // V8_COMPILER_H_
|