2012-02-08 09:56:33 +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
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/compiler.h"
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2015-03-19 12:39:43 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2015-11-26 16:22:34 +00:00
|
|
|
#include "src/ast/ast-numbering.h"
|
|
|
|
#include "src/ast/prettyprinter.h"
|
|
|
|
#include "src/ast/scopeinfo.h"
|
|
|
|
#include "src/ast/scopes.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/bootstrapper.h"
|
|
|
|
#include "src/codegen.h"
|
|
|
|
#include "src/compilation-cache.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/pipeline.h"
|
2015-10-20 13:25:47 +00:00
|
|
|
#include "src/crankshaft/hydrogen.h"
|
|
|
|
#include "src/crankshaft/lithium.h"
|
|
|
|
#include "src/crankshaft/typing.h"
|
2015-07-31 11:07:50 +00:00
|
|
|
#include "src/debug/debug.h"
|
|
|
|
#include "src/debug/liveedit.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/deoptimizer.h"
|
2015-07-24 10:11:46 +00:00
|
|
|
#include "src/full-codegen/full-codegen.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/gdb-jit.h"
|
2015-08-18 13:46:43 +00:00
|
|
|
#include "src/interpreter/interpreter.h"
|
2015-09-01 09:25:19 +00:00
|
|
|
#include "src/isolate-inl.h"
|
2015-08-11 07:34:10 +00:00
|
|
|
#include "src/log-inl.h"
|
2014-11-28 04:08:48 +00:00
|
|
|
#include "src/messages.h"
|
2015-11-26 16:22:34 +00:00
|
|
|
#include "src/parsing/parser.h"
|
|
|
|
#include "src/parsing/rewriter.h"
|
|
|
|
#include "src/parsing/scanner-character-streams.h"
|
2015-09-28 19:34:08 +00:00
|
|
|
#include "src/profiler/cpu-profiler.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/runtime-profiler.h"
|
2016-03-01 14:42:57 +00:00
|
|
|
#include "src/snapshot/code-serializer.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/vm-state-inl.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
|
|
|
|
2015-02-17 12:26:05 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
#define PARSE_INFO_GETTER(type, name) \
|
|
|
|
type CompilationInfo::name() const { \
|
|
|
|
CHECK(parse_info()); \
|
|
|
|
return parse_info()->name(); \
|
2014-07-10 10:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
#define PARSE_INFO_GETTER_WITH_DEFAULT(type, name, def) \
|
|
|
|
type CompilationInfo::name() const { \
|
|
|
|
return parse_info() ? parse_info()->name() : def; \
|
|
|
|
}
|
2010-10-04 11:35:46 +00:00
|
|
|
|
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
PARSE_INFO_GETTER(Handle<Script>, script)
|
|
|
|
PARSE_INFO_GETTER(bool, is_eval)
|
|
|
|
PARSE_INFO_GETTER(bool, is_native)
|
|
|
|
PARSE_INFO_GETTER(bool, is_module)
|
2015-08-19 16:51:37 +00:00
|
|
|
PARSE_INFO_GETTER(FunctionLiteral*, literal)
|
2015-04-30 09:10:21 +00:00
|
|
|
PARSE_INFO_GETTER_WITH_DEFAULT(LanguageMode, language_mode, STRICT)
|
2015-03-09 14:51:13 +00:00
|
|
|
PARSE_INFO_GETTER_WITH_DEFAULT(Handle<JSFunction>, closure,
|
|
|
|
Handle<JSFunction>::null())
|
|
|
|
PARSE_INFO_GETTER_WITH_DEFAULT(Scope*, scope, nullptr)
|
2016-04-08 08:28:57 +00:00
|
|
|
PARSE_INFO_GETTER_WITH_DEFAULT(Handle<Context>, context,
|
|
|
|
Handle<Context>::null())
|
2015-03-09 14:51:13 +00:00
|
|
|
PARSE_INFO_GETTER(Handle<SharedFunctionInfo>, shared_info)
|
|
|
|
|
|
|
|
#undef PARSE_INFO_GETTER
|
|
|
|
#undef PARSE_INFO_GETTER_WITH_DEFAULT
|
|
|
|
|
2016-03-04 10:44:31 +00:00
|
|
|
// 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_;
|
|
|
|
};
|
2015-03-09 14:51:13 +00:00
|
|
|
|
2015-03-24 14:17:05 +00:00
|
|
|
// Exactly like a CompilationInfo, except being allocated via {new} and it also
|
|
|
|
// creates and enters a Zone on construction and deallocates it on destruction.
|
|
|
|
class CompilationInfoWithZone : public CompilationInfo {
|
|
|
|
public:
|
|
|
|
explicit CompilationInfoWithZone(Handle<JSFunction> function)
|
2016-04-01 10:00:30 +00:00
|
|
|
: CompilationInfo(new ParseInfo(&zone_, function)),
|
|
|
|
zone_(function->GetIsolate()->allocator()) {}
|
2015-03-24 14:17:05 +00:00
|
|
|
|
|
|
|
// Virtual destructor because a CompilationInfoWithZone has to exit the
|
|
|
|
// zone scope and get rid of dependent maps even when the destructor is
|
|
|
|
// called when cast as a CompilationInfo.
|
|
|
|
virtual ~CompilationInfoWithZone() {
|
|
|
|
DisableFutureOptimization();
|
2015-04-20 15:22:02 +00:00
|
|
|
dependencies()->Rollback();
|
2015-03-24 14:17:05 +00:00
|
|
|
delete parse_info_;
|
|
|
|
parse_info_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Zone zone_;
|
|
|
|
};
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Implementation of CompilationInfo
|
2015-03-24 14:17:05 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
bool CompilationInfo::has_shared_info() const {
|
|
|
|
return parse_info_ && !parse_info_->shared_info().is_null();
|
2010-10-04 11:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
CompilationInfo::CompilationInfo(ParseInfo* parse_info)
|
2016-01-20 15:17:39 +00:00
|
|
|
: CompilationInfo(parse_info, nullptr, Code::ComputeFlags(Code::FUNCTION),
|
|
|
|
BASE, parse_info->isolate(), parse_info->zone()) {
|
2014-10-14 09:59:24 +00:00
|
|
|
// Compiling for the snapshot typically results in different code than
|
|
|
|
// compiling later on. This means that code recompiled with deoptimization
|
|
|
|
// support won't be "equivalent" (as defined by SharedFunctionInfo::
|
|
|
|
// EnableDeoptimizationSupport), so it will replace the old code and all
|
|
|
|
// its type feedback. To avoid this, always compile functions in the snapshot
|
|
|
|
// with deoptimization support.
|
|
|
|
if (isolate_->serializer_enabled()) EnableDeoptimizationSupport();
|
|
|
|
|
2015-09-25 11:33:28 +00:00
|
|
|
if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing();
|
2014-09-11 09:02:18 +00:00
|
|
|
if (FLAG_turbo_inlining) MarkAsInliningEnabled();
|
2015-04-30 09:56:24 +00:00
|
|
|
if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled();
|
2015-02-03 14:50:40 +00:00
|
|
|
if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
|
2014-09-11 09:44:44 +00:00
|
|
|
if (FLAG_turbo_types) MarkAsTypingEnabled();
|
2014-05-12 13:47:01 +00:00
|
|
|
|
2015-06-25 12:19:55 +00:00
|
|
|
if (has_shared_info()) {
|
|
|
|
if (shared_info()->never_compiled()) MarkAsFirstCompile();
|
2014-04-30 10:51:01 +00:00
|
|
|
}
|
2010-10-04 11:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-24 10:23:39 +00:00
|
|
|
CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate,
|
2016-01-20 15:17:39 +00:00
|
|
|
Zone* zone, Code::Flags code_flags)
|
|
|
|
: CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {}
|
2015-03-19 12:39:43 +00:00
|
|
|
|
2016-01-20 15:17:39 +00:00
|
|
|
CompilationInfo::CompilationInfo(ParseInfo* parse_info, const char* debug_name,
|
|
|
|
Code::Flags code_flags, Mode mode,
|
2015-08-24 10:23:39 +00:00
|
|
|
Isolate* isolate, Zone* zone)
|
2015-03-19 12:39:43 +00:00
|
|
|
: parse_info_(parse_info),
|
|
|
|
isolate_(isolate),
|
|
|
|
flags_(0),
|
2016-01-20 15:17:39 +00:00
|
|
|
code_flags_(code_flags),
|
2015-03-19 12:39:43 +00:00
|
|
|
mode_(mode),
|
|
|
|
osr_ast_id_(BailoutId::None()),
|
|
|
|
zone_(zone),
|
|
|
|
deferred_handles_(nullptr),
|
2015-04-20 15:22:02 +00:00
|
|
|
dependencies_(isolate, zone),
|
2015-03-19 12:39:43 +00:00
|
|
|
bailout_reason_(kNoReason),
|
|
|
|
prologue_offset_(Code::kPrologueOffsetNotSet),
|
2015-03-24 12:46:13 +00:00
|
|
|
track_positions_(FLAG_hydrogen_track_positions ||
|
|
|
|
isolate->cpu_profiler()->is_profiling()),
|
2015-03-19 12:39:43 +00:00
|
|
|
parameter_count_(0),
|
|
|
|
optimization_id_(-1),
|
2015-06-24 06:21:47 +00:00
|
|
|
osr_expr_stack_height_(0),
|
2016-01-20 15:17:39 +00:00
|
|
|
debug_name_(debug_name) {}
|
2015-03-19 12:39:43 +00:00
|
|
|
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
CompilationInfo::~CompilationInfo() {
|
2015-03-09 14:51:13 +00:00
|
|
|
DisableFutureOptimization();
|
2012-07-06 09:31:31 +00:00
|
|
|
delete deferred_handles_;
|
2013-06-12 09:43:22 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Check that no dependent maps have been added or added dependent maps have
|
|
|
|
// been rolled back or committed.
|
2015-04-20 15:22:02 +00:00
|
|
|
DCHECK(dependencies()->IsEmpty());
|
2013-06-12 09:43:22 +00:00
|
|
|
#endif // DEBUG
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
int CompilationInfo::num_parameters() const {
|
2016-04-07 09:52:13 +00:00
|
|
|
return !IsStub() ? scope()->num_parameters() : parameter_count_;
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-11 11:45:02 +00:00
|
|
|
int CompilationInfo::num_parameters_including_this() const {
|
|
|
|
return num_parameters() + (is_this_defined() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CompilationInfo::is_this_defined() const { return !IsStub(); }
|
|
|
|
|
|
|
|
|
2014-11-21 17:28:18 +00:00
|
|
|
// Primitive functions are unlikely to be picked up by the stack-walking
|
|
|
|
// profiler, so they trigger their own optimization when they're called
|
|
|
|
// for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time.
|
|
|
|
bool CompilationInfo::ShouldSelfOptimize() {
|
2015-07-10 09:34:56 +00:00
|
|
|
return FLAG_crankshaft &&
|
2015-08-19 16:51:37 +00:00
|
|
|
!(literal()->flags() & AstProperties::kDontSelfOptimize) &&
|
|
|
|
!literal()->dont_optimize() &&
|
|
|
|
literal()->scope()->AllowsLazyCompilation() &&
|
2015-03-09 14:51:13 +00:00
|
|
|
(!has_shared_info() || !shared_info()->optimization_disabled());
|
2014-11-14 08:21:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 10:48:27 +00:00
|
|
|
|
2015-08-07 11:38:20 +00:00
|
|
|
bool CompilationInfo::has_simple_parameters() {
|
|
|
|
return scope()->has_simple_parameters();
|
2015-02-14 00:14:46 +00:00
|
|
|
}
|
2015-02-17 09:44:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
|
2015-03-11 13:51:18 +00:00
|
|
|
SourcePosition position,
|
|
|
|
int parent_id) {
|
2015-03-16 14:17:01 +00:00
|
|
|
DCHECK(track_positions_);
|
2015-02-17 09:44:44 +00:00
|
|
|
|
2015-03-19 12:39:43 +00:00
|
|
|
int inline_id = static_cast<int>(inlined_function_infos_.size());
|
2015-03-11 13:51:18 +00:00
|
|
|
InlinedFunctionInfo info(parent_id, position, UnboundScript::kNoScriptId,
|
|
|
|
shared->start_position());
|
|
|
|
if (!shared->script()->IsUndefined()) {
|
|
|
|
Handle<Script> script(Script::cast(shared->script()));
|
2015-09-28 13:10:13 +00:00
|
|
|
info.script_id = script->id();
|
2015-03-11 13:51:18 +00:00
|
|
|
|
2015-03-16 14:17:01 +00:00
|
|
|
if (FLAG_hydrogen_track_positions && !script->source()->IsUndefined()) {
|
2015-03-11 13:51:18 +00:00
|
|
|
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
|
|
|
|
OFStream os(tracing_scope.file());
|
|
|
|
os << "--- FUNCTION SOURCE (" << shared->DebugName()->ToCString().get()
|
|
|
|
<< ") id{" << optimization_id() << "," << inline_id << "} ---\n";
|
|
|
|
{
|
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
int start = shared->start_position();
|
|
|
|
int len = shared->end_position() - start;
|
|
|
|
String::SubStringRange source(String::cast(script->source()), start,
|
|
|
|
len);
|
|
|
|
for (const auto& c : source) {
|
|
|
|
os << AsReversiblyEscapedUC16(c);
|
|
|
|
}
|
2015-02-17 09:44:44 +00:00
|
|
|
}
|
2015-03-11 13:51:18 +00:00
|
|
|
|
|
|
|
os << "\n--- END ---\n";
|
2015-02-17 09:44:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-19 12:39:43 +00:00
|
|
|
inlined_function_infos_.push_back(info);
|
2015-02-17 09:44:44 +00:00
|
|
|
|
2015-03-16 14:17:01 +00:00
|
|
|
if (FLAG_hydrogen_track_positions && inline_id != 0) {
|
2015-02-17 09:44:44 +00:00
|
|
|
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
|
|
|
|
OFStream os(tracing_scope.file());
|
|
|
|
os << "INLINE (" << shared->DebugName()->ToCString().get() << ") id{"
|
2015-03-11 13:51:18 +00:00
|
|
|
<< optimization_id() << "," << inline_id << "} AS " << inline_id
|
|
|
|
<< " AT " << position << std::endl;
|
2015-02-17 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return inline_id;
|
|
|
|
}
|
2015-02-14 00:14:46 +00:00
|
|
|
|
|
|
|
|
2015-03-18 09:30:29 +00:00
|
|
|
void CompilationInfo::LogDeoptCallPosition(int pc_offset, int inlining_id) {
|
|
|
|
if (!track_positions_ || IsStub()) return;
|
2015-03-19 12:39:43 +00:00
|
|
|
DCHECK_LT(static_cast<size_t>(inlining_id), inlined_function_infos_.size());
|
|
|
|
inlined_function_infos_.at(inlining_id).deopt_pc_offsets.push_back(pc_offset);
|
2015-03-18 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-24 10:23:39 +00:00
|
|
|
base::SmartArrayPointer<char> CompilationInfo::GetDebugName() const {
|
2016-02-10 09:16:08 +00:00
|
|
|
if (parse_info() && parse_info()->literal()) {
|
2015-08-24 10:23:39 +00:00
|
|
|
AllowHandleDereference allow_deref;
|
2015-08-28 12:46:12 +00:00
|
|
|
return parse_info()->literal()->debug_name()->ToCString();
|
2015-08-24 10:23:39 +00:00
|
|
|
}
|
2016-02-10 09:16:08 +00:00
|
|
|
if (parse_info() && !parse_info()->shared_info().is_null()) {
|
|
|
|
return parse_info()->shared_info()->DebugName()->ToCString();
|
|
|
|
}
|
2015-08-28 12:46:12 +00:00
|
|
|
const char* str = debug_name_ ? debug_name_ : "unknown";
|
|
|
|
size_t len = strlen(str) + 1;
|
|
|
|
base::SmartArrayPointer<char> name(new char[len]);
|
|
|
|
memcpy(name.get(), str, len);
|
|
|
|
return name;
|
2015-08-24 10:23:39 +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 CompilationInfo::GetOutputStackFrameType() const {
|
|
|
|
switch (output_code_kind()) {
|
|
|
|
case Code::STUB:
|
2016-03-09 16:51:02 +00:00
|
|
|
case Code::BYTECODE_HANDLER:
|
[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
|
|
|
case Code::HANDLER:
|
|
|
|
case Code::BUILTIN:
|
|
|
|
return StackFrame::STUB;
|
|
|
|
case Code::WASM_FUNCTION:
|
|
|
|
return StackFrame::WASM;
|
|
|
|
case Code::JS_TO_WASM_FUNCTION:
|
|
|
|
return StackFrame::JS_TO_WASM;
|
|
|
|
case Code::WASM_TO_JS_FUNCTION:
|
|
|
|
return StackFrame::WASM_TO_JS;
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return StackFrame::NONE;
|
|
|
|
}
|
|
|
|
}
|
2015-08-24 10:23:39 +00:00
|
|
|
|
2015-11-05 13:23:13 +00:00
|
|
|
bool CompilationInfo::ExpectsJSReceiverAsReceiver() {
|
|
|
|
return is_sloppy(language_mode()) && !is_native();
|
2015-08-27 20:31:25 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
#if DEBUG
|
|
|
|
void CompilationInfo::PrintAstForTesting() {
|
|
|
|
PrintF("--- Source from AST ---\n%s\n",
|
|
|
|
PrettyPrinter(isolate()).PrintProgram(literal()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Implementation of OptimizedCompileJob
|
2015-08-27 20:31:25 +00:00
|
|
|
|
2013-11-29 10:02:32 +00:00
|
|
|
class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder {
|
2013-10-21 13:35:48 +00:00
|
|
|
public:
|
2013-11-29 10:02:32 +00:00
|
|
|
explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info)
|
2013-10-21 13:35:48 +00:00
|
|
|
: HOptimizedGraphBuilder(info) {
|
|
|
|
}
|
|
|
|
|
2015-03-03 08:42:27 +00:00
|
|
|
#define DEF_VISIT(type) \
|
2015-04-20 13:08:11 +00:00
|
|
|
void Visit##type(type* node) override { \
|
2015-03-03 08:42:27 +00:00
|
|
|
SourcePosition old_position = SourcePosition::Unknown(); \
|
|
|
|
if (node->position() != RelocInfo::kNoPosition) { \
|
|
|
|
old_position = source_position(); \
|
|
|
|
SetSourcePosition(node->position()); \
|
|
|
|
} \
|
|
|
|
HOptimizedGraphBuilder::Visit##type(node); \
|
|
|
|
if (!old_position.IsUnknown()) { \
|
|
|
|
set_source_position(old_position); \
|
|
|
|
} \
|
2013-10-21 13:35:48 +00:00
|
|
|
}
|
|
|
|
EXPRESSION_NODE_LIST(DEF_VISIT)
|
|
|
|
#undef DEF_VISIT
|
|
|
|
|
2015-03-03 08:42:27 +00:00
|
|
|
#define DEF_VISIT(type) \
|
2015-04-20 13:08:11 +00:00
|
|
|
void Visit##type(type* node) override { \
|
2015-03-03 08:42:27 +00:00
|
|
|
SourcePosition old_position = SourcePosition::Unknown(); \
|
|
|
|
if (node->position() != RelocInfo::kNoPosition) { \
|
|
|
|
old_position = source_position(); \
|
|
|
|
SetSourcePosition(node->position()); \
|
|
|
|
} \
|
|
|
|
HOptimizedGraphBuilder::Visit##type(node); \
|
|
|
|
if (!old_position.IsUnknown()) { \
|
|
|
|
set_source_position(old_position); \
|
|
|
|
} \
|
2013-10-21 13:35:48 +00:00
|
|
|
}
|
|
|
|
STATEMENT_NODE_LIST(DEF_VISIT)
|
|
|
|
#undef DEF_VISIT
|
|
|
|
|
2014-12-12 10:44:12 +00:00
|
|
|
#define DEF_VISIT(type) \
|
2015-04-20 13:08:11 +00:00
|
|
|
void Visit##type(type* node) override { \
|
2014-12-12 10:44:12 +00:00
|
|
|
HOptimizedGraphBuilder::Visit##type(node); \
|
2013-10-21 13:35:48 +00:00
|
|
|
}
|
|
|
|
DECLARATION_NODE_LIST(DEF_VISIT)
|
|
|
|
#undef DEF_VISIT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(info()->IsOptimizing());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-01-19 12:35:05 +00:00
|
|
|
// Do not use Crankshaft/TurboFan if we need to be able to set break points.
|
2015-07-20 14:53:28 +00:00
|
|
|
if (info()->shared_info()->HasDebugInfo()) {
|
|
|
|
return AbortOptimization(kFunctionBeingDebugged);
|
2014-06-26 06:32:51 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-04-30 14:50:41 +00:00
|
|
|
// Limit the number of times we try to optimize functions.
|
2011-01-18 13:43:48 +00:00
|
|
|
const int kMaxOptCount =
|
2012-08-16 11:40:03 +00:00
|
|
|
FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000;
|
2016-04-06 19:15:28 +00:00
|
|
|
if (info()->shared_info()->opt_count() > kMaxOptCount) {
|
2014-09-24 07:08:27 +00:00
|
|
|
return AbortOptimization(kOptimizedTooManyTimes);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// Check the whitelist for Crankshaft.
|
2016-03-22 10:01:04 +00:00
|
|
|
if (!info()->shared_info()->PassesFilter(FLAG_hydrogen_filter)) {
|
2013-12-23 14:30:35 +00:00
|
|
|
return AbortOptimization(kHydrogenFilter);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 14:24:49 +00:00
|
|
|
// Optimization requires a version of fullcode with deoptimization support.
|
2010-12-07 11:31:57 +00:00
|
|
|
// Recompile the unoptimized version of the code if the current version
|
2014-07-30 13:54:45 +00:00
|
|
|
// doesn't have deoptimization support already.
|
|
|
|
// Otherwise, if we are gathering compilation time and space statistics
|
|
|
|
// for hydrogen, gather baseline statistics for a fullcode compilation.
|
2012-07-17 16:24:40 +00:00
|
|
|
bool should_recompile = !info()->shared_info()->has_deoptimization_support();
|
2011-03-10 13:26:51 +00:00
|
|
|
if (should_recompile || FLAG_hydrogen_stats) {
|
2014-06-30 13:25:46 +00:00
|
|
|
base::ElapsedTimer timer;
|
2013-06-24 13:25:44 +00:00
|
|
|
if (FLAG_hydrogen_stats) {
|
2013-08-29 09:15:13 +00:00
|
|
|
timer.Start();
|
2013-06-24 13:25:44 +00:00
|
|
|
}
|
2014-09-18 09:02:36 +00:00
|
|
|
if (!Compiler::EnsureDeoptimizationSupport(info())) {
|
|
|
|
return SetLastStatus(FAILED);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2013-06-24 13:25:44 +00:00
|
|
|
if (FLAG_hydrogen_stats) {
|
2013-08-29 09:15:13 +00:00
|
|
|
isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed());
|
2013-06-24 13:25:44 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(info()->shared_info()->has_deoptimization_support());
|
2015-06-26 13:16:57 +00:00
|
|
|
DCHECK(!info()->is_first_compile());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2016-01-04 14:52:33 +00:00
|
|
|
bool optimization_disabled = info()->shared_info()->optimization_disabled();
|
2015-05-21 11:41:14 +00:00
|
|
|
bool dont_crankshaft = info()->shared_info()->dont_crankshaft();
|
2016-01-04 14:52:33 +00:00
|
|
|
|
|
|
|
// Check the enabling conditions for Turbofan.
|
|
|
|
// 1. "use asm" code.
|
|
|
|
bool is_turbofanable_asm = FLAG_turbo_asm &&
|
|
|
|
info()->shared_info()->asm_function() &&
|
|
|
|
!optimization_disabled;
|
|
|
|
|
|
|
|
// 2. Fallback for features unsupported by Crankshaft.
|
|
|
|
bool is_unsupported_by_crankshaft_but_turbofanable =
|
|
|
|
dont_crankshaft && strcmp(FLAG_turbo_filter, "~~") == 0 &&
|
|
|
|
!optimization_disabled;
|
|
|
|
|
|
|
|
// 3. Explicitly enabled by the command-line filter.
|
2016-03-22 10:01:04 +00:00
|
|
|
bool passes_turbo_filter =
|
|
|
|
info()->shared_info()->PassesFilter(FLAG_turbo_filter);
|
2016-01-04 14:52:33 +00:00
|
|
|
|
|
|
|
// If this is OSR request, OSR must be enabled by Turbofan.
|
|
|
|
bool passes_osr_test = FLAG_turbo_osr || !info()->is_osr();
|
|
|
|
|
|
|
|
if ((is_turbofanable_asm || is_unsupported_by_crankshaft_but_turbofanable ||
|
|
|
|
passes_turbo_filter) &&
|
|
|
|
passes_osr_test) {
|
2015-04-30 14:50:41 +00:00
|
|
|
// Use TurboFan for the compilation.
|
2014-12-19 11:47:17 +00:00
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
OFStream os(stdout);
|
|
|
|
os << "[compiling method " << Brief(*info()->closure())
|
2015-01-29 17:40:10 +00:00
|
|
|
<< " using TurboFan";
|
|
|
|
if (info()->is_osr()) os << " OSR";
|
|
|
|
os << "]" << std::endl;
|
2014-12-19 11:47:17 +00:00
|
|
|
}
|
2015-02-24 18:25:47 +00:00
|
|
|
|
|
|
|
if (info()->shared_info()->asm_function()) {
|
2015-07-06 11:11:15 +00:00
|
|
|
if (info()->osr_frame()) info()->MarkAsFrameSpecializing();
|
2015-09-25 11:33:28 +00:00
|
|
|
info()->MarkAsFunctionContextSpecializing();
|
2016-02-20 19:05:47 +00:00
|
|
|
} else {
|
|
|
|
if (!FLAG_always_opt) {
|
|
|
|
info()->MarkAsBailoutOnUninitialized();
|
|
|
|
}
|
|
|
|
if (FLAG_native_context_specialization) {
|
|
|
|
info()->MarkAsNativeContextSpecializing();
|
|
|
|
info()->MarkAsTypingEnabled();
|
|
|
|
}
|
2015-02-24 18:25:47 +00:00
|
|
|
}
|
2015-05-21 11:33:42 +00:00
|
|
|
if (!info()->shared_info()->asm_function() ||
|
|
|
|
FLAG_turbo_asm_deoptimization) {
|
|
|
|
info()->MarkAsDeoptimizationEnabled();
|
|
|
|
}
|
2015-02-24 18:25:47 +00:00
|
|
|
|
2014-12-19 11:47:17 +00:00
|
|
|
Timer t(this, &time_taken_to_create_graph_);
|
2014-07-30 13:54:45 +00:00
|
|
|
compiler::Pipeline pipeline(info());
|
|
|
|
pipeline.GenerateCode();
|
2014-08-01 10:47:01 +00:00
|
|
|
if (!info()->code().is_null()) {
|
|
|
|
return SetLastStatus(SUCCEEDED);
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 11:41:14 +00:00
|
|
|
if (!isolate()->use_crankshaft() || dont_crankshaft) {
|
2015-04-30 14:50:41 +00:00
|
|
|
// Crankshaft is entirely disabled.
|
|
|
|
return SetLastStatus(FAILED);
|
|
|
|
}
|
|
|
|
|
|
|
|
Scope* scope = info()->scope();
|
|
|
|
if (LUnallocated::TooManyParameters(scope->num_parameters())) {
|
|
|
|
// Crankshaft would require too many Lithium operands.
|
|
|
|
return AbortOptimization(kTooManyParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info()->is_osr() &&
|
|
|
|
LUnallocated::TooManyParametersOrStackSlots(scope->num_parameters(),
|
|
|
|
scope->num_stack_slots())) {
|
|
|
|
// Crankshaft would require too many Lithium operands.
|
|
|
|
return AbortOptimization(kTooManyParametersLocals);
|
|
|
|
}
|
2015-03-05 13:46:31 +00:00
|
|
|
|
2014-12-19 11:47:17 +00:00
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
OFStream os(stdout);
|
|
|
|
os << "[compiling method " << Brief(*info()->closure())
|
2015-01-29 17:40:10 +00:00
|
|
|
<< " using Crankshaft";
|
|
|
|
if (info()->is_osr()) os << " OSR";
|
|
|
|
os << "]" << std::endl;
|
2014-12-19 11:47:17 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
if (FLAG_trace_hydrogen) {
|
2013-03-06 07:25:46 +00:00
|
|
|
isolate()->GetHTracer()->TraceCompilation(info());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2013-05-27 13:59:20 +00:00
|
|
|
|
|
|
|
// Type-check the function.
|
2015-09-01 23:06:29 +00:00
|
|
|
AstTyper(info()->isolate(), info()->zone(), info()->closure(),
|
|
|
|
info()->scope(), info()->osr_ast_id(), info()->literal())
|
|
|
|
.Run();
|
2013-05-27 13:59:20 +00:00
|
|
|
|
2015-01-19 12:35:05 +00:00
|
|
|
// Optimization could have been disabled by the parser. Note that this check
|
|
|
|
// is only needed because the Hydrogen graph builder is missing some bailouts.
|
|
|
|
if (info()->shared_info()->optimization_disabled()) {
|
|
|
|
return AbortOptimization(
|
|
|
|
info()->shared_info()->disable_optimization_reason());
|
|
|
|
}
|
|
|
|
|
2016-03-02 17:27:06 +00:00
|
|
|
HOptimizedGraphBuilder* graph_builder =
|
|
|
|
(info()->is_tracking_positions() || FLAG_trace_ic)
|
|
|
|
? new (info()->zone()) HOptimizedGraphBuilderWithPositions(info())
|
|
|
|
: new (info()->zone()) HOptimizedGraphBuilder(info());
|
2012-11-19 14:20:57 +00:00
|
|
|
|
|
|
|
Timer t(this, &time_taken_to_create_graph_);
|
2016-03-02 17:27:06 +00:00
|
|
|
graph_ = graph_builder->CreateGraph();
|
2012-07-17 16:24:40 +00:00
|
|
|
|
2013-03-06 07:25:46 +00:00
|
|
|
if (isolate()->has_pending_exception()) {
|
2012-07-17 16:24:40 +00:00
|
|
|
return SetLastStatus(FAILED);
|
2011-02-11 14:26:56 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 07:08:27 +00:00
|
|
|
if (graph_ == NULL) return SetLastStatus(BAILED_OUT);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-04-20 15:22:02 +00:00
|
|
|
if (info()->dependencies()->HasAborted()) {
|
2014-09-24 07:08:27 +00:00
|
|
|
// Dependency has changed during graph creation. Let's try again later.
|
|
|
|
return RetryOptimization(kBailedOutDueToDependencyChange);
|
2013-08-12 14:10:25 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
return SetLastStatus(SUCCEEDED);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
OptimizedCompileJob::Status OptimizedCompileJob::OptimizeGraph() {
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation;
|
|
|
|
DisallowHandleAllocation no_handles;
|
|
|
|
DisallowHandleDereference no_deref;
|
2013-08-12 14:10:25 +00:00
|
|
|
DisallowCodeDependencyChange no_dependency_change;
|
2012-07-19 18:58:23 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(last_status() == SUCCEEDED);
|
2014-07-30 13:54:45 +00:00
|
|
|
// TODO(turbofan): Currently everything is done in the first phase.
|
|
|
|
if (!info()->code().is_null()) {
|
|
|
|
return last_status();
|
|
|
|
}
|
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
Timer t(this, &time_taken_to_optimize_);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(graph_ != NULL);
|
2013-08-02 09:53:11 +00:00
|
|
|
BailoutReason bailout_reason = kNoReason;
|
2013-12-23 14:30:35 +00:00
|
|
|
|
|
|
|
if (graph_->Optimize(&bailout_reason)) {
|
2012-07-17 16:24:40 +00:00
|
|
|
chunk_ = LChunk::NewChunk(graph_);
|
2013-12-23 14:30:35 +00:00
|
|
|
if (chunk_ != NULL) return SetLastStatus(SUCCEEDED);
|
|
|
|
} else if (bailout_reason != kNoReason) {
|
2016-03-02 17:27:06 +00:00
|
|
|
info_->AbortOptimization(bailout_reason);
|
2011-05-19 13:15:57 +00:00
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-09-24 07:08:27 +00:00
|
|
|
return SetLastStatus(BAILED_OUT);
|
2012-07-17 16:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-04 07:11:45 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void AddWeakObjectToCodeDependency(Isolate* isolate, Handle<HeapObject> object,
|
|
|
|
Handle<Code> code) {
|
|
|
|
Handle<WeakCell> cell = Code::WeakCellFor(code);
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(object));
|
|
|
|
dep = DependentCode::InsertWeakCode(dep, DependentCode::kWeakCodeGroup, cell);
|
|
|
|
heap->AddWeakObjectToCodeDependency(object, dep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegisterWeakObjectsInOptimizedCode(Handle<Code> code) {
|
|
|
|
// TODO(turbofan): Move this to pipeline.cc once Crankshaft dies.
|
|
|
|
Isolate* const isolate = code->GetIsolate();
|
|
|
|
DCHECK(code->is_optimized_code());
|
|
|
|
std::vector<Handle<Map>> maps;
|
|
|
|
std::vector<Handle<HeapObject>> objects;
|
|
|
|
{
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
int const mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
|
|
|
|
RelocInfo::ModeMask(RelocInfo::CELL);
|
|
|
|
for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
|
|
|
|
RelocInfo::Mode mode = it.rinfo()->rmode();
|
|
|
|
if (mode == RelocInfo::CELL &&
|
|
|
|
code->IsWeakObjectInOptimizedCode(it.rinfo()->target_cell())) {
|
|
|
|
objects.push_back(handle(it.rinfo()->target_cell(), isolate));
|
|
|
|
} else if (mode == RelocInfo::EMBEDDED_OBJECT &&
|
|
|
|
code->IsWeakObjectInOptimizedCode(
|
|
|
|
it.rinfo()->target_object())) {
|
|
|
|
Handle<HeapObject> object(HeapObject::cast(it.rinfo()->target_object()),
|
|
|
|
isolate);
|
|
|
|
if (object->IsMap()) {
|
|
|
|
maps.push_back(Handle<Map>::cast(object));
|
|
|
|
} else {
|
|
|
|
objects.push_back(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Handle<Map> map : maps) {
|
|
|
|
if (map->dependent_code()->IsEmpty(DependentCode::kWeakCodeGroup)) {
|
|
|
|
isolate->heap()->AddRetainedMap(map);
|
|
|
|
}
|
|
|
|
Map::AddDependentCode(map, DependentCode::kWeakCodeGroup, code);
|
|
|
|
}
|
|
|
|
for (Handle<HeapObject> object : objects) {
|
|
|
|
AddWeakObjectToCodeDependency(isolate, object, code);
|
|
|
|
}
|
|
|
|
code->set_can_have_weak_objects(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
OptimizedCompileJob::Status OptimizedCompileJob::GenerateCode() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(last_status() == SUCCEEDED);
|
2014-07-30 13:54:45 +00:00
|
|
|
// TODO(turbofan): Currently everything is done in the first phase.
|
|
|
|
if (!info()->code().is_null()) {
|
2015-05-08 09:13:09 +00:00
|
|
|
info()->dependencies()->Commit(info()->code());
|
2015-05-21 11:33:42 +00:00
|
|
|
if (info()->is_deoptimization_enabled()) {
|
2015-03-09 14:51:13 +00:00
|
|
|
info()->parse_info()->context()->native_context()->AddOptimizedCode(
|
|
|
|
*info()->code());
|
2016-01-04 07:11:45 +00:00
|
|
|
RegisterWeakObjectsInOptimizedCode(info()->code());
|
2014-10-26 10:24:49 +00:00
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
RecordOptimizationStats();
|
|
|
|
return last_status();
|
|
|
|
}
|
|
|
|
|
2015-04-20 15:22:02 +00:00
|
|
|
DCHECK(!info()->dependencies()->HasAborted());
|
2013-08-12 14:10:25 +00:00
|
|
|
DisallowCodeDependencyChange no_dependency_change;
|
2014-06-27 12:10:43 +00:00
|
|
|
DisallowJavascriptExecution no_js(isolate());
|
2012-11-19 14:20:57 +00:00
|
|
|
{ // Scope for timer.
|
|
|
|
Timer timer(this, &time_taken_to_codegen_);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(chunk_ != NULL);
|
|
|
|
DCHECK(graph_ != NULL);
|
2013-04-23 09:23:07 +00:00
|
|
|
// Deferred handles reference objects that were accessible during
|
|
|
|
// graph creation. To make sure that we don't encounter inconsistencies
|
|
|
|
// between graph creation and code generation, we disallow accessing
|
|
|
|
// objects through deferred handles during the latter, with exceptions.
|
2013-06-03 16:01:51 +00:00
|
|
|
DisallowDeferredHandleDereference no_deferred_handle_deref;
|
2013-04-18 09:50:46 +00:00
|
|
|
Handle<Code> optimized_code = chunk_->Codegen();
|
2012-11-19 14:20:57 +00:00
|
|
|
if (optimized_code.is_null()) {
|
2013-08-09 15:10:06 +00:00
|
|
|
if (info()->bailout_reason() == kNoReason) {
|
2014-09-24 07:08:27 +00:00
|
|
|
return AbortOptimization(kCodeGenerationFailed);
|
2013-08-02 09:53:11 +00:00
|
|
|
}
|
2014-09-24 07:08:27 +00:00
|
|
|
return SetLastStatus(BAILED_OUT);
|
2012-11-19 14:20:57 +00:00
|
|
|
}
|
2016-01-04 07:11:45 +00:00
|
|
|
RegisterWeakObjectsInOptimizedCode(optimized_code);
|
2012-11-19 14:20:57 +00:00
|
|
|
info()->SetCode(optimized_code);
|
2012-08-28 07:18:06 +00:00
|
|
|
}
|
2012-07-17 16:24:40 +00:00
|
|
|
RecordOptimizationStats();
|
2013-09-04 13:53:24 +00:00
|
|
|
// Add to the weak list of optimized code objects.
|
|
|
|
info()->context()->native_context()->AddOptimizedCode(*info()->code());
|
2012-07-17 16:24:40 +00:00
|
|
|
return SetLastStatus(SUCCEEDED);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
void OptimizedCompileJob::RecordOptimizationStats() {
|
|
|
|
Handle<JSFunction> function = info()->closure();
|
|
|
|
if (!function->IsOptimized()) {
|
|
|
|
// Concurrent recompilation and OSR may race. Increment only once.
|
|
|
|
int opt_count = function->shared()->opt_count();
|
|
|
|
function->shared()->set_opt_count(opt_count + 1);
|
2012-07-05 13:11:57 +00:00
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
double ms_creategraph = time_taken_to_create_graph_.InMillisecondsF();
|
|
|
|
double ms_optimize = time_taken_to_optimize_.InMillisecondsF();
|
|
|
|
double ms_codegen = time_taken_to_codegen_.InMillisecondsF();
|
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
PrintF("[optimizing ");
|
|
|
|
function->ShortPrint();
|
|
|
|
PrintF(" - took %0.3f, %0.3f, %0.3f ms]\n", ms_creategraph, ms_optimize,
|
|
|
|
ms_codegen);
|
2010-07-13 13:06:33 +00:00
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
if (FLAG_trace_opt_stats) {
|
|
|
|
static double compilation_time = 0.0;
|
|
|
|
static int compiled_functions = 0;
|
|
|
|
static int code_size = 0;
|
2010-03-05 22:08:58 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
compilation_time += (ms_creategraph + ms_optimize + ms_codegen);
|
|
|
|
compiled_functions++;
|
|
|
|
code_size += function->shared()->SourceSize();
|
|
|
|
PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
|
|
|
|
compiled_functions,
|
|
|
|
code_size,
|
|
|
|
compilation_time);
|
|
|
|
}
|
|
|
|
if (FLAG_hydrogen_stats) {
|
|
|
|
isolate()->GetHStatistics()->IncrementSubtotals(time_taken_to_create_graph_,
|
|
|
|
time_taken_to_optimize_,
|
|
|
|
time_taken_to_codegen_);
|
|
|
|
}
|
2013-01-15 10:16:52 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Local helper methods that make up the compilation pipeline.
|
|
|
|
|
|
|
|
namespace {
|
2013-01-15 10:16:52 +00:00
|
|
|
|
2013-10-16 11:52:03 +00:00
|
|
|
// Sets the expected number of properties based on estimate from compiler.
|
|
|
|
void SetExpectedNofPropertiesFromEstimate(Handle<SharedFunctionInfo> shared,
|
|
|
|
int estimate) {
|
|
|
|
// If no properties are added in the constructor, they are more likely
|
|
|
|
// to be added later.
|
|
|
|
if (estimate == 0) estimate = 2;
|
|
|
|
|
|
|
|
// TODO(yangguo): check whether those heuristics are still up-to-date.
|
|
|
|
// We do not shrink objects that go into a snapshot (yet), so we adjust
|
|
|
|
// the estimate conservatively.
|
2014-05-22 09:36:20 +00:00
|
|
|
if (shared->GetIsolate()->serializer_enabled()) {
|
2013-10-16 11:52:03 +00:00
|
|
|
estimate += 2;
|
2014-11-20 08:54:27 +00:00
|
|
|
} else {
|
2013-10-16 11:52:03 +00:00
|
|
|
// Inobject slack tracking will reclaim redundant inobject space later,
|
|
|
|
// so we can afford to adjust the estimate generously.
|
|
|
|
estimate += 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
shared->set_expected_nof_properties(estimate);
|
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
void MaybeDisableOptimization(Handle<SharedFunctionInfo> shared_info,
|
|
|
|
BailoutReason bailout_reason) {
|
2014-11-13 09:55:48 +00:00
|
|
|
if (bailout_reason != kNoReason) {
|
|
|
|
shared_info->DisableOptimization(bailout_reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
|
|
|
|
CompilationInfo* info,
|
|
|
|
Handle<SharedFunctionInfo> shared) {
|
2014-09-18 09:41:45 +00:00
|
|
|
// SharedFunctionInfo is passed separately, because if CompilationInfo
|
|
|
|
// was created using Script object, it will not have it.
|
|
|
|
|
|
|
|
// Log the code generation. If source information is available include
|
|
|
|
// script name and line number. Check explicitly whether logging is
|
|
|
|
// enabled as finding the line number is not free.
|
|
|
|
if (info->isolate()->logger()->is_logging_code_events() ||
|
|
|
|
info->isolate()->cpu_profiler()->is_profiling()) {
|
2015-03-09 14:51:13 +00:00
|
|
|
Handle<Script> script = info->parse_info()->script();
|
2016-02-26 11:04:04 +00:00
|
|
|
Handle<AbstractCode> abstract_code = info->abstract_code();
|
|
|
|
if (abstract_code.is_identical_to(
|
|
|
|
info->isolate()->builtins()->CompileLazy())) {
|
2014-09-18 09:41:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int line_num = Script::GetLineNumber(script, shared->start_position()) + 1;
|
|
|
|
int column_num =
|
|
|
|
Script::GetColumnNumber(script, shared->start_position()) + 1;
|
|
|
|
String* script_name = script->name()->IsString()
|
|
|
|
? String::cast(script->name())
|
|
|
|
: info->isolate()->heap()->empty_string();
|
|
|
|
Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script);
|
|
|
|
PROFILE(info->isolate(),
|
2016-02-26 11:04:04 +00:00
|
|
|
CodeCreateEvent(log_tag, *abstract_code, *shared, info, script_name,
|
2014-09-18 09:41:45 +00:00
|
|
|
line_num, column_num));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-05 14:29:56 +00:00
|
|
|
void EnsureFeedbackVector(CompilationInfo* info) {
|
|
|
|
if (!info->has_shared_info()) return;
|
|
|
|
|
|
|
|
// If no type feedback vector exists, we create one now. At this point the
|
2016-04-07 15:34:07 +00:00
|
|
|
// AstNumbering pass has already run. Note the snapshot can contain outdated
|
|
|
|
// vectors for a different configuration, hence we also recreate a new vector
|
|
|
|
// when the function is not compiled (i.e. no code was serialized).
|
|
|
|
if (info->shared_info()->feedback_vector()->is_empty() ||
|
|
|
|
!info->shared_info()->is_compiled()) {
|
2016-04-05 14:29:56 +00:00
|
|
|
Handle<TypeFeedbackMetadata> feedback_metadata = TypeFeedbackMetadata::New(
|
|
|
|
info->isolate(), info->literal()->feedback_vector_spec());
|
|
|
|
Handle<TypeFeedbackVector> feedback_vector =
|
|
|
|
TypeFeedbackVector::New(info->isolate(), feedback_metadata);
|
|
|
|
info->shared_info()->set_feedback_vector(*feedback_vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's very important that recompiles do not alter the structure of the type
|
|
|
|
// feedback vector. Verify that the structure fits the function literal.
|
|
|
|
CHECK(!info->shared_info()->feedback_vector()->metadata()->SpecDiffersFrom(
|
|
|
|
info->literal()->feedback_vector_spec()));
|
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
bool CompileUnoptimizedCode(CompilationInfo* info) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(AllowCompilation::IsAllowed(info->isolate()));
|
2015-03-09 14:51:13 +00:00
|
|
|
if (!Compiler::Analyze(info->parse_info()) ||
|
2016-04-05 14:29:56 +00:00
|
|
|
!(EnsureFeedbackVector(info), FullCodeGenerator::MakeCode(info))) {
|
2013-12-23 14:30:35 +00:00
|
|
|
Isolate* isolate = info->isolate();
|
|
|
|
if (!isolate->has_pending_exception()) isolate->StackOverflow();
|
|
|
|
return false;
|
2011-11-25 09:36:31 +00:00
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-07-16 07:07:30 +00:00
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
bool UseIgnition(CompilationInfo* info) {
|
2016-03-17 16:37:36 +00:00
|
|
|
// TODO(4681): Generator functions are not yet supported.
|
2016-04-05 14:07:15 +00:00
|
|
|
if (info->shared_info()->is_generator()) {
|
2015-12-14 20:57:38 +00:00
|
|
|
return false;
|
2015-11-06 18:52:32 +00:00
|
|
|
}
|
2015-12-14 20:57:38 +00:00
|
|
|
|
|
|
|
// Checks whether top level functions should be passed by the filter.
|
2016-04-05 14:07:15 +00:00
|
|
|
if (info->shared_info()->is_toplevel()) {
|
2015-12-14 20:57:38 +00:00
|
|
|
Vector<const char> filter = CStrVector(FLAG_ignition_filter);
|
|
|
|
return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally respect the filter.
|
2016-04-05 14:07:15 +00:00
|
|
|
return info->shared_info()->PassesFilter(FLAG_ignition_filter);
|
2015-12-14 20:57:38 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
int CodeAndMetadataSize(CompilationInfo* info) {
|
2016-02-02 16:47:58 +00:00
|
|
|
int size = 0;
|
|
|
|
if (info->has_bytecode_array()) {
|
|
|
|
Handle<BytecodeArray> bytecode_array = info->bytecode_array();
|
|
|
|
size += bytecode_array->BytecodeArraySize();
|
|
|
|
size += bytecode_array->constant_pool()->Size();
|
|
|
|
size += bytecode_array->handler_table()->Size();
|
|
|
|
size += bytecode_array->source_position_table()->Size();
|
|
|
|
} else {
|
|
|
|
Handle<Code> code = info->code();
|
|
|
|
size += code->CodeSize();
|
|
|
|
size += code->relocation_info()->Size();
|
|
|
|
size += code->deoptimization_data()->Size();
|
|
|
|
size += code->handler_table()->Size();
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
bool GenerateBaselineCode(CompilationInfo* info) {
|
2016-02-02 16:47:58 +00:00
|
|
|
bool success;
|
2016-04-05 14:29:56 +00:00
|
|
|
EnsureFeedbackVector(info);
|
2015-12-14 20:57:38 +00:00
|
|
|
if (FLAG_ignition && UseIgnition(info)) {
|
2016-02-02 16:47:58 +00:00
|
|
|
success = interpreter::Interpreter::MakeBytecode(info);
|
2015-12-14 20:57:38 +00:00
|
|
|
} else {
|
2016-02-02 16:47:58 +00:00
|
|
|
success = FullCodeGenerator::MakeCode(info);
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
Isolate* isolate = info->isolate();
|
|
|
|
Counters* counters = isolate->counters();
|
|
|
|
counters->total_baseline_code_size()->Increment(CodeAndMetadataSize(info));
|
|
|
|
counters->total_baseline_compile_count()->Increment(1);
|
2015-12-14 20:57:38 +00:00
|
|
|
}
|
2016-02-02 16:47:58 +00:00
|
|
|
return success;
|
2015-12-14 20:57:38 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
bool CompileBaselineCode(CompilationInfo* info) {
|
2015-12-14 20:57:38 +00:00
|
|
|
DCHECK(AllowCompilation::IsAllowed(info->isolate()));
|
|
|
|
if (!Compiler::Analyze(info->parse_info()) || !GenerateBaselineCode(info)) {
|
2015-08-18 13:46:43 +00:00
|
|
|
Isolate* isolate = info->isolate();
|
|
|
|
if (!isolate->has_pending_exception()) isolate->StackOverflow();
|
2015-12-14 20:57:38 +00:00
|
|
|
return false;
|
2015-08-18 13:46:43 +00:00
|
|
|
}
|
2015-12-14 20:57:38 +00:00
|
|
|
return true;
|
2015-08-18 13:46:43 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
void InstallBaselineCompilationResult(CompilationInfo* info,
|
|
|
|
Handle<SharedFunctionInfo> shared,
|
|
|
|
Handle<ScopeInfo> scope_info) {
|
2016-03-18 10:46:40 +00:00
|
|
|
// Assert that we are not overwriting (possibly patched) debug code.
|
|
|
|
DCHECK(!shared->HasDebugCode());
|
|
|
|
DCHECK(!info->code().is_null());
|
|
|
|
shared->ReplaceCode(*info->code());
|
|
|
|
shared->set_scope_info(*scope_info);
|
|
|
|
if (info->has_bytecode_array()) {
|
|
|
|
DCHECK(!shared->HasBytecodeArray()); // Only compiled once.
|
|
|
|
shared->set_bytecode_array(*info->bytecode_array());
|
|
|
|
}
|
|
|
|
}
|
2015-08-18 13:46:43 +00:00
|
|
|
|
2016-04-06 19:20:10 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) {
|
2013-12-23 14:30:35 +00:00
|
|
|
VMState<COMPILER> state(info->isolate());
|
|
|
|
PostponeInterruptsScope postpone(info->isolate());
|
2014-09-17 12:34:46 +00:00
|
|
|
|
|
|
|
// Parse and update CompilationInfo with the results.
|
2015-03-09 14:51:13 +00:00
|
|
|
if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>();
|
2014-09-17 12:34:46 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
2015-08-19 16:51:37 +00:00
|
|
|
FunctionLiteral* lit = info->literal();
|
2015-11-24 17:16:40 +00:00
|
|
|
DCHECK_EQ(shared->language_mode(), lit->language_mode());
|
2014-09-17 12:34:46 +00:00
|
|
|
SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count());
|
2014-11-13 09:55:48 +00:00
|
|
|
MaybeDisableOptimization(shared, lit->dont_optimize_reason());
|
2013-10-28 17:54:43 +00:00
|
|
|
|
2015-12-14 20:57:38 +00:00
|
|
|
// Compile either unoptimized code or bytecode for the interpreter.
|
|
|
|
if (!CompileBaselineCode(info)) return MaybeHandle<Code>();
|
2016-02-26 11:04:04 +00:00
|
|
|
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
|
2014-09-17 12:34:46 +00:00
|
|
|
|
|
|
|
// Update the shared function info with the scope info. Allocating the
|
|
|
|
// ScopeInfo object may cause a GC.
|
2015-01-23 15:19:34 +00:00
|
|
|
Handle<ScopeInfo> scope_info =
|
|
|
|
ScopeInfo::Create(info->isolate(), info->zone(), info->scope());
|
2014-09-17 12:34:46 +00:00
|
|
|
|
2016-03-18 10:46:40 +00:00
|
|
|
// Install compilation result on the shared function info
|
|
|
|
InstallBaselineCompilationResult(info, shared, scope_info);
|
2014-09-17 12:34:46 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
return info->code();
|
|
|
|
}
|
2013-10-28 17:54:43 +00:00
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap(
|
2014-09-22 12:32:47 +00:00
|
|
|
Handle<JSFunction> function, BailoutId osr_ast_id) {
|
2015-06-25 09:44:58 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
CodeAndLiterals cached = shared->SearchOptimizedCodeMap(
|
|
|
|
function->context()->native_context(), osr_ast_id);
|
|
|
|
if (cached.code != nullptr) {
|
|
|
|
// Caching of optimized code enabled and optimized code found.
|
|
|
|
if (cached.literals != nullptr) function->set_literals(cached.literals);
|
|
|
|
DCHECK(!cached.code->marked_for_deoptimization());
|
|
|
|
DCHECK(function->shared()->is_compiled());
|
|
|
|
return Handle<Code>(cached.code);
|
2014-09-22 12:32:47 +00:00
|
|
|
}
|
|
|
|
return MaybeHandle<Code>();
|
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) {
|
2014-09-22 12:32:47 +00:00
|
|
|
Handle<Code> code = info->code();
|
|
|
|
if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do.
|
|
|
|
|
2015-10-07 12:10:49 +00:00
|
|
|
// Function context specialization folds-in the function context,
|
|
|
|
// so no sharing can occur.
|
2015-09-25 11:33:28 +00:00
|
|
|
if (info->is_function_context_specializing()) return;
|
|
|
|
// Frame specialization implies function context specialization.
|
2015-07-06 11:11:15 +00:00
|
|
|
DCHECK(!info->is_frame_specializing());
|
2014-09-22 12:32:47 +00:00
|
|
|
|
Revert of [runtime] Introduce dedicated JSBoundFunction to represent bound functions. (patchset #14 id:260001 of https://codereview.chromium.org/1542963002/ )
Reason for revert:
Breaks arm64 sim nosnap: https://build.chromium.org/p/client.v8/builders/V8%20Linux%20-%20arm64%20-%20sim%20-%20nosnap%20-%20debug/builds/805/steps/Check/logs/function-bind
Original issue's description:
> [runtime] Introduce dedicated JSBoundFunction to represent bound functions.
>
> According to the ES2015 specification, bound functions are exotic
> objects, and thus don't need to be implemented as JSFunctions. So
> we introduce a new JSBoundFunction type to represent bound functions
> and make them optimizable. This already improves the performance of
> calling or constructing bound functions by 10-100x depending on the
> use case because we avoid the crazy dance between JavaScript and C++
> that was implemented in v8natives.js previously.
>
> There's still room for improvement in the performance of actually
> creating bound functions, which is also relevant in practice, but
> we already have a plan how to accomplish that later.
>
> The mips/mips64 ports were contributed by akos.palfi@imgtec.com.
>
> CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel
> BUG=chromium:535408, chromium:571299, v8:4629
> LOG=n
>
> Committed: https://crrev.com/ca8623eaa468cba65a5adafcdfb4615966f43ce2
> Cr-Commit-Position: refs/heads/master@{#33042}
TBR=cbruni@chromium.org,hpayer@chromium.org,yangguo@chromium.org,akos.palfi@imgtec.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=chromium:535408, chromium:571299, v8:4629
Review URL: https://codereview.chromium.org/1552473002
Cr-Commit-Position: refs/heads/master@{#33043}
2015-12-27 04:41:46 +00:00
|
|
|
// Cache optimized context-specific code.
|
2015-12-27 06:30:53 +00:00
|
|
|
Handle<JSFunction> function = info->closure();
|
2015-10-12 16:10:41 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
Handle<LiteralsArray> literals(function->literals());
|
|
|
|
Handle<Context> native_context(function->context()->native_context());
|
|
|
|
SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code,
|
|
|
|
literals, info->osr_ast_id());
|
2015-06-26 09:07:30 +00:00
|
|
|
|
2015-10-07 12:10:49 +00:00
|
|
|
// Do not cache (native) context-independent code compiled for OSR.
|
2015-06-26 09:07:30 +00:00
|
|
|
if (code->is_turbofanned() && info->is_osr()) return;
|
|
|
|
|
2015-10-07 12:10:49 +00:00
|
|
|
// Cache optimized (native) context-independent code.
|
|
|
|
if (FLAG_turbo_cache_shared_code && code->is_turbofanned() &&
|
|
|
|
!info->is_native_context_specializing()) {
|
2015-09-25 11:33:28 +00:00
|
|
|
DCHECK(!info->is_function_context_specializing());
|
2015-06-26 09:07:30 +00:00
|
|
|
DCHECK(info->osr_ast_id().IsNone());
|
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
SharedFunctionInfo::AddSharedCodeToOptimizedCodeMap(shared, code);
|
|
|
|
}
|
2014-09-22 12:32:47 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
bool Renumber(ParseInfo* parse_info) {
|
2015-03-09 14:51:13 +00:00
|
|
|
if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(),
|
2015-08-19 16:51:37 +00:00
|
|
|
parse_info->literal())) {
|
2015-01-23 15:19:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-03-09 14:51:13 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_info = parse_info->shared_info();
|
|
|
|
if (!shared_info.is_null()) {
|
2015-08-19 16:51:37 +00:00
|
|
|
FunctionLiteral* lit = parse_info->literal();
|
2015-03-09 14:51:13 +00:00
|
|
|
shared_info->set_ast_node_count(lit->ast_node_count());
|
|
|
|
MaybeDisableOptimization(shared_info, lit->dont_optimize_reason());
|
2016-03-01 15:12:56 +00:00
|
|
|
shared_info->set_dont_crankshaft(
|
|
|
|
shared_info->dont_crankshaft() ||
|
|
|
|
(lit->flags() & AstProperties::kDontCrankshaft));
|
2014-10-28 13:23:54 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-04 10:44:31 +00:00
|
|
|
bool GetOptimizedCodeNow(CompilationInfo* info) {
|
2015-10-26 15:33:02 +00:00
|
|
|
Isolate* isolate = info->isolate();
|
|
|
|
CanonicalHandleScope canonical(isolate);
|
2016-02-15 17:29:22 +00:00
|
|
|
TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate);
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.OptimizeCode");
|
2015-10-26 15:33:02 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
if (!Compiler::ParseAndAnalyze(info->parse_info())) return false;
|
2014-09-22 12:32:47 +00:00
|
|
|
|
2015-10-26 15:33:02 +00:00
|
|
|
TimerEventScope<TimerEventRecompileSynchronous> timer(isolate);
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.RecompileSynchronous");
|
2014-09-22 12:32:47 +00:00
|
|
|
|
|
|
|
OptimizedCompileJob job(info);
|
2014-09-24 07:08:27 +00:00
|
|
|
if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED ||
|
|
|
|
job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED ||
|
|
|
|
job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) {
|
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
PrintF("[aborted optimizing ");
|
|
|
|
info->closure()->ShortPrint();
|
|
|
|
PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason()));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-22 12:32:47 +00:00
|
|
|
|
|
|
|
// Success!
|
2015-10-26 15:33:02 +00:00
|
|
|
DCHECK(!isolate->has_pending_exception());
|
2014-09-22 12:32:47 +00:00
|
|
|
InsertCodeIntoOptimizedCodeMap(info);
|
|
|
|
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info,
|
|
|
|
info->shared_info());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-04 10:44:31 +00:00
|
|
|
bool GetOptimizedCodeLater(CompilationInfo* info) {
|
2014-09-22 12:32:47 +00:00
|
|
|
Isolate* isolate = info->isolate();
|
2015-10-26 15:33:02 +00:00
|
|
|
CanonicalHandleScope canonical(isolate);
|
2016-02-15 17:29:22 +00:00
|
|
|
TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate);
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.OptimizeCode");
|
2015-10-26 15:33:02 +00:00
|
|
|
|
2015-04-14 13:57:35 +00:00
|
|
|
if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) {
|
2014-09-22 12:32:47 +00:00
|
|
|
if (FLAG_trace_concurrent_recompilation) {
|
|
|
|
PrintF(" ** Compilation queue full, will retry optimizing ");
|
2014-09-24 07:08:27 +00:00
|
|
|
info->closure()->ShortPrint();
|
2014-09-22 12:32:47 +00:00
|
|
|
PrintF(" later.\n");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CompilationHandleScope handle_scope(info);
|
2015-03-09 14:51:13 +00:00
|
|
|
if (!Compiler::ParseAndAnalyze(info->parse_info())) return false;
|
|
|
|
|
|
|
|
// Reopen handles in the new CompilationHandleScope.
|
|
|
|
info->ReopenHandlesInNewHandleScope();
|
|
|
|
info->parse_info()->ReopenHandlesInNewHandleScope();
|
2014-09-22 12:32:47 +00:00
|
|
|
|
|
|
|
TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.RecompileSynchronous");
|
2014-09-22 12:32:47 +00:00
|
|
|
|
|
|
|
OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info);
|
|
|
|
OptimizedCompileJob::Status status = job->CreateGraph();
|
|
|
|
if (status != OptimizedCompileJob::SUCCEEDED) return false;
|
2015-04-14 13:57:35 +00:00
|
|
|
isolate->optimizing_compile_dispatcher()->QueueForOptimization(job);
|
2014-09-22 12:32:47 +00:00
|
|
|
|
|
|
|
if (FLAG_trace_concurrent_recompilation) {
|
|
|
|
PrintF(" ** Queued ");
|
2014-09-24 07:08:27 +00:00
|
|
|
info->closure()->ShortPrint();
|
2014-09-22 12:32:47 +00:00
|
|
|
if (info->is_osr()) {
|
|
|
|
PrintF(" for concurrent OSR at %d.\n", info->osr_ast_id().ToInt());
|
|
|
|
} else {
|
|
|
|
PrintF(" for concurrent optimization.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-04 16:10:55 +00:00
|
|
|
MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
|
|
|
|
Compiler::ConcurrencyMode mode,
|
|
|
|
BailoutId osr_ast_id = BailoutId::None(),
|
|
|
|
JavaScriptFrame* osr_frame = nullptr) {
|
|
|
|
Isolate* isolate = function->GetIsolate();
|
|
|
|
Handle<SharedFunctionInfo> shared(function->shared(), isolate);
|
|
|
|
if (shared->HasDebugInfo()) return MaybeHandle<Code>();
|
|
|
|
|
|
|
|
Handle<Code> cached_code;
|
|
|
|
if (GetCodeFromOptimizedCodeMap(function, osr_ast_id)
|
|
|
|
.ToHandle(&cached_code)) {
|
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
PrintF("[found optimized code for ");
|
|
|
|
function->ShortPrint();
|
|
|
|
if (!osr_ast_id.IsNone()) {
|
|
|
|
PrintF(" at OSR AST id %d", osr_ast_id.ToInt());
|
|
|
|
}
|
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
return cached_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(AllowCompilation::IsAllowed(isolate));
|
|
|
|
|
2016-03-18 12:08:27 +00:00
|
|
|
if (shared->is_compiled()) {
|
|
|
|
shared->code()->set_profiler_ticks(0);
|
2016-03-04 16:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(mstarzinger): We cannot properly deserialize a scope chain containing
|
|
|
|
// an eval scope and hence would fail at parsing the eval source again.
|
|
|
|
if (shared->disable_optimization_reason() == kEval) {
|
|
|
|
return MaybeHandle<Code>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(mstarzinger): We cannot properly deserialize a scope chain for the
|
|
|
|
// builtin context, hence Genesis::InstallExperimentalNatives would fail.
|
|
|
|
if (shared->is_toplevel() && isolate->bootstrapper()->IsActive()) {
|
|
|
|
return MaybeHandle<Code>();
|
|
|
|
}
|
|
|
|
|
|
|
|
base::SmartPointer<CompilationInfo> info(
|
|
|
|
new CompilationInfoWithZone(function));
|
|
|
|
VMState<COMPILER> state(isolate);
|
|
|
|
DCHECK(!isolate->has_pending_exception());
|
|
|
|
PostponeInterruptsScope postpone(isolate);
|
|
|
|
|
2016-03-18 07:57:22 +00:00
|
|
|
info->SetOptimizingForOsr(osr_ast_id);
|
2016-03-04 16:10:55 +00:00
|
|
|
|
|
|
|
if (mode == Compiler::CONCURRENT) {
|
|
|
|
if (GetOptimizedCodeLater(info.get())) {
|
|
|
|
info.Detach(); // The background recompile job owns this now.
|
|
|
|
return isolate->builtins()->InOptimizationQueue();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info->set_osr_frame(osr_frame);
|
|
|
|
if (GetOptimizedCodeNow(info.get())) return info->code();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isolate->has_pending_exception()) isolate->clear_pending_exception();
|
|
|
|
return MaybeHandle<Code>();
|
|
|
|
}
|
|
|
|
|
2016-03-04 10:44:31 +00:00
|
|
|
MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) {
|
2014-10-30 14:40:30 +00:00
|
|
|
Isolate* isolate = function->GetIsolate();
|
|
|
|
DCHECK(!isolate->has_pending_exception());
|
2014-09-17 15:29:42 +00:00
|
|
|
DCHECK(!function->is_compiled());
|
2016-02-15 17:29:22 +00:00
|
|
|
TimerEventScope<TimerEventCompileCode> compile_timer(isolate);
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.CompileCode");
|
2015-01-22 18:38:19 +00:00
|
|
|
AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy());
|
2014-10-30 14:40:30 +00:00
|
|
|
// If the debugger is active, do not compile with turbofan unless we can
|
|
|
|
// deopt from turbofan code.
|
|
|
|
if (FLAG_turbo_asm && function->shared()->asm_function() &&
|
2015-05-21 11:33:42 +00:00
|
|
|
(FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) &&
|
2015-02-24 18:25:47 +00:00
|
|
|
!FLAG_turbo_osr) {
|
2016-04-07 08:21:32 +00:00
|
|
|
Handle<Code> code;
|
|
|
|
if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT).ToHandle(&code)) {
|
2014-10-30 14:40:30 +00:00
|
|
|
DCHECK(function->shared()->is_compiled());
|
2016-04-07 08:21:32 +00:00
|
|
|
return code;
|
2014-10-30 14:40:30 +00:00
|
|
|
}
|
2014-09-19 12:50:50 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 15:29:42 +00:00
|
|
|
if (function->shared()->is_compiled()) {
|
|
|
|
return Handle<Code>(function->shared()->code());
|
|
|
|
}
|
|
|
|
|
|
|
|
CompilationInfoWithZone info(function);
|
|
|
|
Handle<Code> result;
|
2016-04-06 19:20:10 +00:00
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCode(&info), Code);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2015-03-05 13:46:31 +00:00
|
|
|
if (FLAG_always_opt) {
|
2014-04-22 14:55:47 +00:00
|
|
|
Handle<Code> opt_code;
|
2016-03-04 16:10:55 +00:00
|
|
|
if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
|
2016-01-18 10:23:49 +00:00
|
|
|
.ToHandle(&opt_code)) {
|
2014-04-22 14:55:47 +00:00
|
|
|
result = opt_code;
|
|
|
|
}
|
2013-10-28 17:54:43 +00:00
|
|
|
}
|
2012-03-15 11:51:26 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
return result;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-09-18 09:02:36 +00:00
|
|
|
|
2015-07-27 13:15:06 +00:00
|
|
|
bool CompileEvalForDebugging(Handle<JSFunction> function,
|
|
|
|
Handle<SharedFunctionInfo> shared) {
|
|
|
|
Handle<Script> script(Script::cast(shared->script()));
|
|
|
|
Handle<Context> context(function->context());
|
|
|
|
|
2016-04-01 10:00:30 +00:00
|
|
|
Zone zone(function->GetIsolate()->allocator());
|
2015-07-27 13:15:06 +00:00
|
|
|
ParseInfo parse_info(&zone, script);
|
|
|
|
CompilationInfo info(&parse_info);
|
|
|
|
Isolate* isolate = info.isolate();
|
|
|
|
|
|
|
|
parse_info.set_eval();
|
|
|
|
parse_info.set_context(context);
|
|
|
|
if (context->IsNativeContext()) parse_info.set_global();
|
|
|
|
parse_info.set_toplevel();
|
|
|
|
parse_info.set_allow_lazy_parsing(false);
|
|
|
|
parse_info.set_language_mode(shared->language_mode());
|
|
|
|
parse_info.set_parse_restriction(NO_PARSE_RESTRICTION);
|
|
|
|
info.MarkAsDebug();
|
|
|
|
|
|
|
|
VMState<COMPILER> state(info.isolate());
|
|
|
|
|
|
|
|
if (!Parser::ParseStatic(&parse_info)) {
|
|
|
|
isolate->clear_pending_exception();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-19 16:51:37 +00:00
|
|
|
FunctionLiteral* lit = parse_info.literal();
|
2015-07-27 13:15:06 +00:00
|
|
|
LiveEditFunctionTracker live_edit_tracker(isolate, lit);
|
|
|
|
|
|
|
|
if (!CompileUnoptimizedCode(&info)) {
|
|
|
|
isolate->clear_pending_exception();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
shared->ReplaceCode(*info.code());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CompileForDebugging(CompilationInfo* info) {
|
2015-07-20 14:53:28 +00:00
|
|
|
info->MarkAsDebug();
|
2016-04-06 19:20:10 +00:00
|
|
|
if (GetUnoptimizedCode(info).is_null()) {
|
2015-07-20 14:53:28 +00:00
|
|
|
info->isolate()->clear_pending_exception();
|
2015-07-27 13:15:06 +00:00
|
|
|
return false;
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
2015-07-27 13:15:06 +00:00
|
|
|
return true;
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) {
|
2015-08-11 08:20:29 +00:00
|
|
|
return shared->is_toplevel() && shared->script()->IsScript() &&
|
|
|
|
Script::cast(shared->script())->compilation_type() ==
|
|
|
|
Script::COMPILATION_TYPE_EVAL;
|
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral(
|
2016-03-18 10:46:40 +00:00
|
|
|
Isolate* isolate, FunctionLiteral* literal, Handle<Script> script) {
|
|
|
|
Handle<Code> code = isolate->builtins()->CompileLazy();
|
|
|
|
Handle<ScopeInfo> scope_info = handle(ScopeInfo::Empty(isolate));
|
|
|
|
Handle<SharedFunctionInfo> result = isolate->factory()->NewSharedFunctionInfo(
|
|
|
|
literal->name(), literal->materialized_literal_count(), literal->kind(),
|
|
|
|
code, scope_info);
|
|
|
|
SharedFunctionInfo::InitFromFunctionLiteral(result, literal);
|
|
|
|
SharedFunctionInfo::SetScript(result, script);
|
|
|
|
return result;
|
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
|
2013-12-23 14:30:35 +00:00
|
|
|
Isolate* isolate = info->isolate();
|
2016-02-15 17:29:22 +00:00
|
|
|
TimerEventScope<TimerEventCompileCode> timer(isolate);
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.CompileCode");
|
2013-12-23 15:41:44 +00:00
|
|
|
PostponeInterruptsScope postpone(isolate);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!isolate->native_context().is_null());
|
2015-03-09 14:51:13 +00:00
|
|
|
ParseInfo* parse_info = info->parse_info();
|
|
|
|
Handle<Script> script = parse_info->script();
|
2013-12-23 14:30:35 +00:00
|
|
|
|
|
|
|
// TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile?
|
|
|
|
FixedArray* array = isolate->native_context()->embedder_data();
|
2015-03-19 08:18:35 +00:00
|
|
|
script->set_context_data(array->get(v8::Context::kDebugIdIndex));
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-05-27 13:20:58 +00:00
|
|
|
isolate->debug()->OnBeforeCompile(script);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
DCHECK(parse_info->is_eval() || parse_info->is_global() ||
|
|
|
|
parse_info->is_module());
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
parse_info->set_toplevel();
|
2014-09-29 07:53:22 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<SharedFunctionInfo> result;
|
|
|
|
|
|
|
|
{ VMState<COMPILER> state(info->isolate());
|
2015-03-09 14:51:13 +00:00
|
|
|
if (parse_info->literal() == NULL) {
|
2015-08-19 16:51:37 +00:00
|
|
|
// Parse the script if needed (if it's already parsed, literal() is
|
2015-07-20 14:53:28 +00:00
|
|
|
// non-NULL). If compiling for debugging, we may eagerly compile inner
|
|
|
|
// functions, so do not parse lazily in that case.
|
2015-03-09 14:51:13 +00:00
|
|
|
ScriptCompiler::CompileOptions options = parse_info->compile_options();
|
|
|
|
bool parse_allow_lazy = (options == ScriptCompiler::kConsumeParserCache ||
|
|
|
|
String::cast(script->source())->length() >
|
|
|
|
FLAG_min_preparse_length) &&
|
2015-07-20 14:53:28 +00:00
|
|
|
!info->is_debug();
|
2014-09-12 09:12:08 +00:00
|
|
|
|
2016-03-14 18:55:41 +00:00
|
|
|
// Consider parsing eagerly when targeting the code cache.
|
|
|
|
parse_allow_lazy &= !(FLAG_serialize_eager && info->will_serialize());
|
|
|
|
|
2016-03-24 18:37:56 +00:00
|
|
|
// Consider parsing eagerly when targeting Ignition.
|
|
|
|
parse_allow_lazy &= !(FLAG_ignition && FLAG_ignition_eager &&
|
|
|
|
!isolate->serializer_enabled());
|
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
parse_info->set_allow_lazy_parsing(parse_allow_lazy);
|
2014-09-12 09:12:08 +00:00
|
|
|
if (!parse_allow_lazy &&
|
2015-03-09 14:51:13 +00:00
|
|
|
(options == ScriptCompiler::kProduceParserCache ||
|
|
|
|
options == ScriptCompiler::kConsumeParserCache)) {
|
2014-09-12 09:12:08 +00:00
|
|
|
// We are going to parse eagerly, but we either 1) have cached data
|
|
|
|
// produced by lazy parsing or 2) are asked to generate cached data.
|
|
|
|
// Eager parsing cannot benefit from cached data, and producing cached
|
|
|
|
// data while parsing eagerly is not implemented.
|
2015-03-09 14:51:13 +00:00
|
|
|
parse_info->set_cached_data(nullptr);
|
|
|
|
parse_info->set_compile_options(ScriptCompiler::kNoCompileOptions);
|
2014-09-12 09:12:08 +00:00
|
|
|
}
|
2015-03-09 14:51:13 +00:00
|
|
|
if (!Parser::ParseStatic(parse_info)) {
|
2014-09-12 09:12:08 +00:00
|
|
|
return Handle<SharedFunctionInfo>::null();
|
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 07:37:21 +00:00
|
|
|
DCHECK(!info->is_debug() || !parse_info->allow_lazy_parsing());
|
|
|
|
|
2015-06-25 12:19:55 +00:00
|
|
|
info->MarkAsFirstCompile();
|
|
|
|
|
2015-08-19 16:51:37 +00:00
|
|
|
FunctionLiteral* lit = parse_info->literal();
|
2013-12-23 14:30:35 +00:00
|
|
|
LiveEditFunctionTracker live_edit_tracker(isolate, lit);
|
|
|
|
|
|
|
|
// Measure how long it takes to do the compilation; only take the
|
|
|
|
// rest of the function into account to avoid overlap with the
|
|
|
|
// parsing statistics.
|
|
|
|
HistogramTimer* rate = info->is_eval()
|
|
|
|
? info->isolate()->counters()->compile_eval()
|
|
|
|
: info->isolate()->counters()->compile();
|
|
|
|
HistogramTimerScope timer(rate);
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", info->is_eval() ? "V8.CompileEval" : "V8.Compile");
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2016-03-18 10:46:40 +00:00
|
|
|
// Allocate a shared function info object.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position());
|
2016-03-18 10:46:40 +00:00
|
|
|
result = NewSharedFunctionInfoForLiteral(isolate, lit, script);
|
2015-02-11 14:51:59 +00:00
|
|
|
result->set_is_toplevel(true);
|
2015-08-11 08:20:29 +00:00
|
|
|
if (info->is_eval()) {
|
|
|
|
// Eval scripts cannot be (re-)compiled without context.
|
|
|
|
result->set_allows_lazy_compilation_without_context(false);
|
|
|
|
}
|
2016-04-05 14:07:15 +00:00
|
|
|
parse_info->set_shared_info(result);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2016-03-18 10:46:40 +00:00
|
|
|
// Compile the code.
|
|
|
|
if (!CompileBaselineCode(info)) {
|
|
|
|
return Handle<SharedFunctionInfo>::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install compilation result on the shared function info
|
|
|
|
Handle<ScopeInfo> scope_info =
|
|
|
|
ScopeInfo::Create(info->isolate(), info->zone(), info->scope());
|
|
|
|
InstallBaselineCompilationResult(info, result, scope_info);
|
|
|
|
|
2015-10-07 14:27:24 +00:00
|
|
|
Handle<String> script_name =
|
|
|
|
script->name()->IsString()
|
|
|
|
? Handle<String>(String::cast(script->name()))
|
|
|
|
: isolate->factory()->empty_string();
|
2013-12-23 14:30:35 +00:00
|
|
|
Logger::LogEventsAndTags log_tag = info->is_eval()
|
|
|
|
? Logger::EVAL_TAG
|
|
|
|
: Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script);
|
|
|
|
|
2016-02-26 11:04:04 +00:00
|
|
|
PROFILE(isolate, CodeCreateEvent(log_tag, *info->abstract_code(), *result,
|
|
|
|
info, *script_name));
|
2013-12-23 14:30:35 +00:00
|
|
|
|
|
|
|
// Hint to the runtime system used when allocating space for initial
|
|
|
|
// property space by setting the expected number of properties for
|
|
|
|
// the instances of the function.
|
|
|
|
SetExpectedNofPropertiesFromEstimate(result,
|
|
|
|
lit->expected_property_count());
|
|
|
|
|
2014-09-12 09:12:08 +00:00
|
|
|
if (!script.is_null())
|
|
|
|
script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
|
|
|
live_edit_tracker.RecordFunctionInfo(result, lit, info->zone());
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-18 13:56:57 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Implementation of Compiler
|
|
|
|
|
|
|
|
bool Compiler::Analyze(ParseInfo* info) {
|
|
|
|
DCHECK_NOT_NULL(info->literal());
|
|
|
|
if (!Rewriter::Rewrite(info)) return false;
|
|
|
|
if (!Scope::Analyze(info)) return false;
|
|
|
|
if (!Renumber(info)) return false;
|
|
|
|
DCHECK_NOT_NULL(info->scope());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compiler::ParseAndAnalyze(ParseInfo* info) {
|
|
|
|
if (!Parser::ParseStatic(info)) return false;
|
|
|
|
return Compiler::Analyze(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) {
|
|
|
|
if (function->is_compiled()) return true;
|
|
|
|
MaybeHandle<Code> maybe_code = GetLazyCode(function);
|
|
|
|
Handle<Code> code;
|
|
|
|
if (!maybe_code.ToHandle(&code)) {
|
|
|
|
if (flag == CLEAR_EXCEPTION) {
|
|
|
|
function->GetIsolate()->clear_pending_exception();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
DCHECK(code->IsJavaScriptCode());
|
|
|
|
function->ReplaceCode(*code);
|
|
|
|
DCHECK(function->is_compiled());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compiler::CompileOptimized(Handle<JSFunction> function,
|
|
|
|
ConcurrencyMode mode) {
|
|
|
|
Handle<Code> code;
|
|
|
|
if (GetOptimizedCode(function, mode).ToHandle(&code)) {
|
|
|
|
// Optimization succeeded, return optimized code.
|
|
|
|
function->ReplaceCode(*code);
|
|
|
|
} else {
|
|
|
|
// Optimization failed, get unoptimized code.
|
|
|
|
Isolate* isolate = function->GetIsolate();
|
|
|
|
if (isolate->has_pending_exception()) { // Possible stack overflow.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
code = Handle<Code>(function->shared()->code(), isolate);
|
|
|
|
if (code->kind() != Code::FUNCTION &&
|
|
|
|
code->kind() != Code::OPTIMIZED_FUNCTION) {
|
2016-04-06 19:20:10 +00:00
|
|
|
DCHECK(!isolate->has_pending_exception());
|
|
|
|
DCHECK(!function->is_compiled());
|
|
|
|
if (!function->shared()->is_compiled()) {
|
|
|
|
CompilationInfoWithZone info(function);
|
|
|
|
if (!GetUnoptimizedCode(&info).ToHandle(&code)) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-18 13:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function->ReplaceCode(*code);
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(function->code()->kind() == Code::FUNCTION ||
|
|
|
|
function->code()->kind() == Code::OPTIMIZED_FUNCTION ||
|
|
|
|
(function->code()->is_interpreter_entry_trampoline() &&
|
|
|
|
function->shared()->HasBytecodeArray()) ||
|
|
|
|
function->IsInOptimizationQueue());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compiler::CompileDebugCode(Handle<JSFunction> function) {
|
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
if (IsEvalToplevel(shared)) {
|
|
|
|
return CompileEvalForDebugging(function, shared);
|
|
|
|
} else {
|
|
|
|
CompilationInfoWithZone info(function);
|
|
|
|
return CompileForDebugging(&info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) {
|
|
|
|
DCHECK(shared->allows_lazy_compilation_without_context());
|
|
|
|
DCHECK(!IsEvalToplevel(shared));
|
2016-04-01 10:00:30 +00:00
|
|
|
Zone zone(shared->GetIsolate()->allocator());
|
2016-03-18 13:56:57 +00:00
|
|
|
ParseInfo parse_info(&zone, shared);
|
|
|
|
CompilationInfo info(&parse_info);
|
|
|
|
return CompileForDebugging(&info);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(turbofan): In the future, unoptimized code with deopt support could
|
|
|
|
// be generated lazily once deopt is triggered.
|
|
|
|
bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
|
|
|
|
DCHECK_NOT_NULL(info->literal());
|
2016-04-07 09:52:13 +00:00
|
|
|
DCHECK_NOT_NULL(info->scope());
|
2016-03-18 13:56:57 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
|
|
|
if (!shared->has_deoptimization_support()) {
|
|
|
|
// TODO(titzer): just reuse the ParseInfo for the unoptimized compile.
|
|
|
|
CompilationInfoWithZone unoptimized(info->closure());
|
|
|
|
// Note that we use the same AST that we will use for generating the
|
|
|
|
// optimized code.
|
|
|
|
ParseInfo* parse_info = unoptimized.parse_info();
|
|
|
|
parse_info->set_literal(info->literal());
|
|
|
|
parse_info->set_scope(info->scope());
|
|
|
|
parse_info->set_context(info->context());
|
|
|
|
unoptimized.EnableDeoptimizationSupport();
|
|
|
|
// If the current code has reloc info for serialization, also include
|
|
|
|
// reloc info for serialization for the new code, so that deopt support
|
|
|
|
// can be added without losing IC state.
|
|
|
|
if (shared->code()->kind() == Code::FUNCTION &&
|
|
|
|
shared->code()->has_reloc_info_for_serialization()) {
|
|
|
|
unoptimized.PrepareForSerializing();
|
|
|
|
}
|
2016-04-05 14:29:56 +00:00
|
|
|
EnsureFeedbackVector(&unoptimized);
|
2016-03-18 13:56:57 +00:00
|
|
|
if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
|
|
|
|
|
|
|
|
shared->EnableDeoptimizationSupport(*unoptimized.code());
|
|
|
|
|
|
|
|
info->MarkAsCompiled();
|
|
|
|
|
|
|
|
// The scope info might not have been set if a lazily compiled
|
|
|
|
// function is inlined before being called for the first time.
|
|
|
|
if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) {
|
|
|
|
Handle<ScopeInfo> target_scope_info =
|
|
|
|
ScopeInfo::Create(info->isolate(), info->zone(), info->scope());
|
|
|
|
shared->set_scope_info(*target_scope_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The existing unoptimized code was replaced with the new one.
|
|
|
|
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compiler::CompileForLiveEdit(Handle<Script> script) {
|
|
|
|
// TODO(635): support extensions.
|
2016-04-01 10:00:30 +00:00
|
|
|
Zone zone(script->GetIsolate()->allocator());
|
2016-03-18 13:56:57 +00:00
|
|
|
ParseInfo parse_info(&zone, script);
|
|
|
|
CompilationInfo info(&parse_info);
|
|
|
|
PostponeInterruptsScope postpone(info.isolate());
|
|
|
|
VMState<COMPILER> state(info.isolate());
|
|
|
|
|
|
|
|
// Get rid of old list of shared function infos.
|
|
|
|
info.MarkAsFirstCompile();
|
|
|
|
info.MarkAsDebug();
|
|
|
|
info.parse_info()->set_global();
|
|
|
|
if (!Parser::ParseStatic(info.parse_info())) return;
|
|
|
|
|
|
|
|
LiveEditFunctionTracker tracker(info.isolate(), parse_info.literal());
|
|
|
|
if (!CompileUnoptimizedCode(&info)) return;
|
|
|
|
tracker.RecordRootFunctionInfo(info.code());
|
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-04-17 05:41:58 +00:00
|
|
|
MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
|
2014-10-28 10:00:37 +00:00
|
|
|
Handle<String> source, Handle<SharedFunctionInfo> outer_info,
|
2015-02-04 09:34:05 +00:00
|
|
|
Handle<Context> context, LanguageMode language_mode,
|
2016-04-05 13:00:49 +00:00
|
|
|
ParseRestriction restriction, int line_offset, int column_offset,
|
|
|
|
Handle<Object> script_name, ScriptOriginOptions options) {
|
2013-12-23 14:30:35 +00:00
|
|
|
Isolate* isolate = source->GetIsolate();
|
|
|
|
int source_length = source->length();
|
|
|
|
isolate->counters()->total_eval_size()->Increment(source_length);
|
|
|
|
isolate->counters()->total_compile_size()->Increment(source_length);
|
|
|
|
|
|
|
|
CompilationCache* compilation_cache = isolate->compilation_cache();
|
2014-04-08 12:33:08 +00:00
|
|
|
MaybeHandle<SharedFunctionInfo> maybe_shared_info =
|
2015-02-04 09:34:05 +00:00
|
|
|
compilation_cache->LookupEval(source, outer_info, context, language_mode,
|
2016-04-05 13:00:49 +00:00
|
|
|
line_offset);
|
2014-04-08 12:33:08 +00:00
|
|
|
Handle<SharedFunctionInfo> shared_info;
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2015-07-27 13:15:06 +00:00
|
|
|
Handle<Script> script;
|
2014-04-08 12:33:08 +00:00
|
|
|
if (!maybe_shared_info.ToHandle(&shared_info)) {
|
2015-07-27 13:15:06 +00:00
|
|
|
script = isolate->factory()->NewScript(source);
|
2015-07-16 12:08:01 +00:00
|
|
|
if (!script_name.is_null()) {
|
|
|
|
script->set_name(*script_name);
|
2015-09-28 13:10:13 +00:00
|
|
|
script->set_line_offset(line_offset);
|
|
|
|
script->set_column_offset(column_offset);
|
2015-07-16 12:08:01 +00:00
|
|
|
}
|
|
|
|
script->set_origin_options(options);
|
2016-04-01 10:00:30 +00:00
|
|
|
Zone zone(isolate->allocator());
|
2015-03-24 14:17:05 +00:00
|
|
|
ParseInfo parse_info(&zone, script);
|
|
|
|
CompilationInfo info(&parse_info);
|
|
|
|
parse_info.set_eval();
|
|
|
|
if (context->IsNativeContext()) parse_info.set_global();
|
|
|
|
parse_info.set_language_mode(language_mode);
|
|
|
|
parse_info.set_parse_restriction(restriction);
|
|
|
|
parse_info.set_context(context);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2016-04-05 13:00:49 +00:00
|
|
|
Debug::RecordEvalCaller(script);
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
shared_info = CompileToplevel(&info);
|
|
|
|
|
|
|
|
if (shared_info.is_null()) {
|
2014-04-17 05:41:58 +00:00
|
|
|
return MaybeHandle<JSFunction>();
|
2013-12-23 14:30:35 +00:00
|
|
|
} else {
|
|
|
|
// Explicitly disable optimization for eval code. We're not yet prepared
|
|
|
|
// to handle eval-code in the optimizing compiler.
|
2015-01-08 13:13:39 +00:00
|
|
|
if (restriction != ONLY_SINGLE_FUNCTION_LITERAL) {
|
|
|
|
shared_info->DisableOptimization(kEval);
|
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-03-11 14:41:22 +00:00
|
|
|
// If caller is strict mode, the result must be in strict mode as well.
|
2015-02-04 09:34:05 +00:00
|
|
|
DCHECK(is_sloppy(language_mode) ||
|
|
|
|
is_strict(shared_info->language_mode()));
|
2015-06-19 18:55:47 +00:00
|
|
|
compilation_cache->PutEval(source, outer_info, context, shared_info,
|
2016-04-05 13:00:49 +00:00
|
|
|
line_offset);
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-27 13:15:06 +00:00
|
|
|
Handle<JSFunction> result =
|
|
|
|
isolate->factory()->NewFunctionFromSharedFunctionInfo(
|
|
|
|
shared_info, context, NOT_TENURED);
|
|
|
|
|
|
|
|
// OnAfterCompile has to be called after we create the JSFunction, which we
|
|
|
|
// may require to recompile the eval for debugging, if we find a function
|
|
|
|
// that contains break points in the eval script.
|
|
|
|
isolate->debug()->OnAfterCompile(script);
|
|
|
|
|
|
|
|
return result;
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 12:07:27 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
Handle<String> source, Handle<Object> script_name, int line_offset,
|
2015-05-19 03:11:33 +00:00
|
|
|
int column_offset, ScriptOriginOptions resource_options,
|
|
|
|
Handle<Object> source_map_url, Handle<Context> context,
|
|
|
|
v8::Extension* extension, ScriptData** cached_data,
|
2015-02-06 17:52:20 +00:00
|
|
|
ScriptCompiler::CompileOptions compile_options, NativesFlag natives,
|
|
|
|
bool is_module) {
|
2014-12-11 12:58:36 +00:00
|
|
|
Isolate* isolate = source->GetIsolate();
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
if (compile_options == ScriptCompiler::kNoCompileOptions) {
|
2014-03-19 13:24:13 +00:00
|
|
|
cached_data = NULL;
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
} else if (compile_options == ScriptCompiler::kProduceParserCache ||
|
|
|
|
compile_options == ScriptCompiler::kProduceCodeCache) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(cached_data && !*cached_data);
|
|
|
|
DCHECK(extension == NULL);
|
2014-12-11 12:58:36 +00:00
|
|
|
DCHECK(!isolate->debug()->is_loaded());
|
2014-03-19 13:24:13 +00:00
|
|
|
} else {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(compile_options == ScriptCompiler::kConsumeParserCache ||
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
compile_options == ScriptCompiler::kConsumeCodeCache);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(cached_data && *cached_data);
|
|
|
|
DCHECK(extension == NULL);
|
2014-03-19 13:24:13 +00:00
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
int source_length = source->length();
|
|
|
|
isolate->counters()->total_load_size()->Increment(source_length);
|
|
|
|
isolate->counters()->total_compile_size()->Increment(source_length);
|
|
|
|
|
2016-03-10 12:43:51 +00:00
|
|
|
LanguageMode language_mode = construct_language_mode(FLAG_use_strict);
|
2013-12-23 14:30:35 +00:00
|
|
|
CompilationCache* compilation_cache = isolate->compilation_cache();
|
|
|
|
|
|
|
|
// Do a lookup in the compilation cache but not for extensions.
|
2014-04-08 12:33:08 +00:00
|
|
|
MaybeHandle<SharedFunctionInfo> maybe_result;
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> result;
|
2008-09-11 10:51:52 +00:00
|
|
|
if (extension == NULL) {
|
2015-03-16 13:19:10 +00:00
|
|
|
// First check per-isolate compilation cache.
|
2015-01-26 10:56:53 +00:00
|
|
|
maybe_result = compilation_cache->LookupScript(
|
2015-05-19 03:11:33 +00:00
|
|
|
source, script_name, line_offset, column_offset, resource_options,
|
|
|
|
context, language_mode);
|
2015-01-26 10:56:53 +00:00
|
|
|
if (maybe_result.is_null() && FLAG_serialize_toplevel &&
|
2014-07-23 08:27:04 +00:00
|
|
|
compile_options == ScriptCompiler::kConsumeCodeCache &&
|
|
|
|
!isolate->debug()->is_loaded()) {
|
2015-03-16 13:19:10 +00:00
|
|
|
// Then check cached code provided by embedder.
|
2014-09-22 17:19:19 +00:00
|
|
|
HistogramTimerScope timer(isolate->counters()->compile_deserialize());
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.CompileDeserialize");
|
2014-10-15 14:04:53 +00:00
|
|
|
Handle<SharedFunctionInfo> result;
|
|
|
|
if (CodeSerializer::Deserialize(isolate, *cached_data, source)
|
|
|
|
.ToHandle(&result)) {
|
2015-03-16 13:19:10 +00:00
|
|
|
// Promote to per-isolate compilation cache.
|
|
|
|
compilation_cache->PutScript(source, context, language_mode, result);
|
2014-10-15 14:04:53 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
// Deserializer failed. Fall through to compile.
|
2014-07-08 09:04:08 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 10:35:38 +00:00
|
|
|
base::ElapsedTimer timer;
|
|
|
|
if (FLAG_profile_deserialization && FLAG_serialize_toplevel &&
|
|
|
|
compile_options == ScriptCompiler::kProduceCodeCache) {
|
|
|
|
timer.Start();
|
|
|
|
}
|
|
|
|
|
2014-04-08 12:33:08 +00:00
|
|
|
if (!maybe_result.ToHandle(&result)) {
|
2014-04-07 07:40:18 +00:00
|
|
|
// No cache entry found. Compile the script.
|
2008-09-11 10:51:52 +00:00
|
|
|
|
|
|
|
// Create a script object describing the script to be compiled.
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<Script> script = isolate->factory()->NewScript(source);
|
2010-03-17 08:14:59 +00:00
|
|
|
if (natives == NATIVES_CODE) {
|
2015-09-28 13:10:13 +00:00
|
|
|
script->set_type(Script::TYPE_NATIVE);
|
2015-08-21 09:12:57 +00:00
|
|
|
script->set_hide_source(true);
|
2016-02-05 12:33:20 +00:00
|
|
|
} else if (natives == EXTENSION_CODE) {
|
|
|
|
script->set_type(Script::TYPE_EXTENSION);
|
|
|
|
script->set_hide_source(true);
|
2010-03-17 08:14:59 +00:00
|
|
|
}
|
2008-09-11 10:51:52 +00:00
|
|
|
if (!script_name.is_null()) {
|
|
|
|
script->set_name(*script_name);
|
2015-09-28 13:10:13 +00:00
|
|
|
script->set_line_offset(line_offset);
|
|
|
|
script->set_column_offset(column_offset);
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
2015-05-19 03:11:33 +00:00
|
|
|
script->set_origin_options(resource_options);
|
2015-03-05 13:03:42 +00:00
|
|
|
if (!source_map_url.is_null()) {
|
|
|
|
script->set_source_mapping_url(*source_map_url);
|
|
|
|
}
|
2008-09-11 10:51:52 +00:00
|
|
|
|
|
|
|
// Compile the function and add it to the cache.
|
2016-04-01 10:00:30 +00:00
|
|
|
Zone zone(isolate->allocator());
|
2015-03-24 14:17:05 +00:00
|
|
|
ParseInfo parse_info(&zone, script);
|
|
|
|
CompilationInfo info(&parse_info);
|
2016-03-15 00:43:31 +00:00
|
|
|
if (is_module) {
|
2015-03-24 14:17:05 +00:00
|
|
|
parse_info.set_module();
|
2015-02-06 17:52:20 +00:00
|
|
|
} else {
|
2015-03-24 14:17:05 +00:00
|
|
|
parse_info.set_global();
|
2015-02-06 17:52:20 +00:00
|
|
|
}
|
2015-03-09 14:51:13 +00:00
|
|
|
if (compile_options != ScriptCompiler::kNoCompileOptions) {
|
2015-03-24 14:17:05 +00:00
|
|
|
parse_info.set_cached_data(cached_data);
|
2015-03-09 14:51:13 +00:00
|
|
|
}
|
2015-03-24 14:17:05 +00:00
|
|
|
parse_info.set_compile_options(compile_options);
|
|
|
|
parse_info.set_extension(extension);
|
|
|
|
parse_info.set_context(context);
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
if (FLAG_serialize_toplevel &&
|
|
|
|
compile_options == ScriptCompiler::kProduceCodeCache) {
|
2014-07-08 14:13:50 +00:00
|
|
|
info.PrepareForSerializing();
|
|
|
|
}
|
2015-02-10 19:12:51 +00:00
|
|
|
|
2015-03-24 14:17:05 +00:00
|
|
|
parse_info.set_language_mode(
|
2015-02-10 19:12:51 +00:00
|
|
|
static_cast<LanguageMode>(info.language_mode() | language_mode));
|
2013-12-23 14:30:35 +00:00
|
|
|
result = CompileToplevel(&info);
|
2015-06-19 18:55:47 +00:00
|
|
|
if (extension == NULL && !result.is_null()) {
|
2015-02-12 16:29:42 +00:00
|
|
|
compilation_cache->PutScript(source, context, language_mode, result);
|
2014-11-12 13:12:17 +00:00
|
|
|
if (FLAG_serialize_toplevel &&
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
compile_options == ScriptCompiler::kProduceCodeCache) {
|
2014-09-22 17:19:19 +00:00
|
|
|
HistogramTimerScope histogram_timer(
|
|
|
|
isolate->counters()->compile_serialize());
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.CompileSerialize");
|
2014-07-15 10:17:22 +00:00
|
|
|
*cached_data = CodeSerializer::Serialize(isolate, result, source);
|
2014-07-22 10:35:38 +00:00
|
|
|
if (FLAG_profile_deserialization) {
|
2014-10-23 08:43:17 +00:00
|
|
|
PrintF("[Compiling and serializing took %0.3f ms]\n",
|
|
|
|
timer.Elapsed().InMillisecondsF());
|
2014-07-22 10:35:38 +00:00
|
|
|
}
|
2014-07-08 09:04:08 +00:00
|
|
|
}
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
|
2015-07-27 13:15:06 +00:00
|
|
|
if (result.is_null()) {
|
|
|
|
isolate->ReportPendingMessages();
|
|
|
|
} else {
|
|
|
|
isolate->debug()->OnAfterCompile(script);
|
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
} else if (result->ic_age() != isolate->heap()->global_ic_age()) {
|
2014-07-08 09:04:08 +00:00
|
|
|
result->ResetForNewContext(isolate->heap()->global_ic_age());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-08 12:07:27 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForStreamedScript(
|
2015-03-09 14:51:13 +00:00
|
|
|
Handle<Script> script, ParseInfo* parse_info, int source_length) {
|
|
|
|
Isolate* isolate = script->GetIsolate();
|
|
|
|
// TODO(titzer): increment the counters in caller.
|
2014-09-12 09:12:08 +00:00
|
|
|
isolate->counters()->total_load_size()->Increment(source_length);
|
|
|
|
isolate->counters()->total_compile_size()->Increment(source_length);
|
|
|
|
|
2016-03-10 12:43:51 +00:00
|
|
|
LanguageMode language_mode = construct_language_mode(FLAG_use_strict);
|
2015-03-09 14:51:13 +00:00
|
|
|
parse_info->set_language_mode(
|
|
|
|
static_cast<LanguageMode>(parse_info->language_mode() | language_mode));
|
2015-02-10 19:12:51 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
CompilationInfo compile_info(parse_info);
|
2015-07-22 07:37:21 +00:00
|
|
|
|
2015-07-27 14:19:53 +00:00
|
|
|
// The source was parsed lazily, so compiling for debugging is not possible.
|
|
|
|
DCHECK(!compile_info.is_debug());
|
2015-07-22 07:37:21 +00:00
|
|
|
|
2015-07-27 13:15:06 +00:00
|
|
|
Handle<SharedFunctionInfo> result = CompileToplevel(&compile_info);
|
|
|
|
if (!result.is_null()) isolate->debug()->OnAfterCompile(script);
|
|
|
|
return result;
|
2014-09-12 09:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-25 12:19:55 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
|
2014-07-23 09:35:06 +00:00
|
|
|
FunctionLiteral* literal, Handle<Script> script,
|
|
|
|
CompilationInfo* outer_info) {
|
2013-12-23 14:30:35 +00:00
|
|
|
// Precondition: code has been parsed and scopes have been analyzed.
|
2015-06-26 13:53:26 +00:00
|
|
|
Isolate* isolate = outer_info->isolate();
|
2015-06-25 12:19:55 +00:00
|
|
|
MaybeHandle<SharedFunctionInfo> maybe_existing;
|
|
|
|
if (outer_info->is_first_compile()) {
|
|
|
|
// On the first compile, there are no existing shared function info for
|
2015-06-26 13:53:26 +00:00
|
|
|
// inner functions yet, so do not try to find them. All bets are off for
|
|
|
|
// live edit though.
|
2016-03-17 13:15:56 +00:00
|
|
|
SLOW_DCHECK(script->FindSharedFunctionInfo(literal).is_null() ||
|
|
|
|
isolate->debug()->live_edit_enabled());
|
2015-06-25 12:19:55 +00:00
|
|
|
} else {
|
|
|
|
maybe_existing = script->FindSharedFunctionInfo(literal);
|
|
|
|
}
|
|
|
|
// We found an existing shared function info. If it's already compiled,
|
|
|
|
// don't worry about compiling it, and simply return it. If it's not yet
|
|
|
|
// compiled, continue to decide whether to eagerly compile.
|
2015-07-20 14:53:28 +00:00
|
|
|
// Carry on if we are compiling eager to obtain code for debugging,
|
|
|
|
// unless we already have code with debut break slots.
|
2015-06-25 12:19:55 +00:00
|
|
|
Handle<SharedFunctionInfo> existing;
|
|
|
|
if (maybe_existing.ToHandle(&existing) && existing->is_compiled()) {
|
2015-07-20 14:53:28 +00:00
|
|
|
if (!outer_info->is_debug() || existing->HasDebugCode()) {
|
|
|
|
return existing;
|
|
|
|
}
|
2015-06-25 12:19:55 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 10:46:40 +00:00
|
|
|
// Allocate a shared function info object.
|
|
|
|
Handle<SharedFunctionInfo> result;
|
|
|
|
if (!maybe_existing.ToHandle(&result)) {
|
|
|
|
result = NewSharedFunctionInfoForLiteral(isolate, literal, script);
|
|
|
|
result->set_is_toplevel(false);
|
|
|
|
}
|
|
|
|
|
2016-04-01 10:00:30 +00:00
|
|
|
Zone zone(isolate->allocator());
|
2015-03-24 14:17:05 +00:00
|
|
|
ParseInfo parse_info(&zone, script);
|
|
|
|
CompilationInfo info(&parse_info);
|
|
|
|
parse_info.set_literal(literal);
|
2016-04-05 14:07:15 +00:00
|
|
|
parse_info.set_shared_info(result);
|
2015-03-24 14:17:05 +00:00
|
|
|
parse_info.set_scope(literal->scope());
|
|
|
|
parse_info.set_language_mode(literal->scope()->language_mode());
|
2014-07-23 09:35:06 +00:00
|
|
|
if (outer_info->will_serialize()) info.PrepareForSerializing();
|
2015-06-25 12:19:55 +00:00
|
|
|
if (outer_info->is_first_compile()) info.MarkAsFirstCompile();
|
2015-07-20 14:53:28 +00:00
|
|
|
if (outer_info->is_debug()) info.MarkAsDebug();
|
2009-08-13 10:25:35 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
LiveEditFunctionTracker live_edit_tracker(isolate, literal);
|
|
|
|
// Determine if the function can be lazily compiled. This is necessary to
|
|
|
|
// allow some of our builtin JS files to be lazily compiled. These
|
|
|
|
// builtins cannot be handled lazily by the parser, since we have to know
|
|
|
|
// if a function uses the special natives syntax, which is something the
|
|
|
|
// parser records.
|
|
|
|
// If the debugger requests compilation for break points, we cannot be
|
|
|
|
// aggressive about lazy compilation, because it might trigger compilation
|
|
|
|
// of functions without an outer context when setting a breakpoint through
|
|
|
|
// Debug::FindSharedFunctionInfoInScript.
|
|
|
|
bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext();
|
2015-07-20 14:53:28 +00:00
|
|
|
// Compile eagerly for live edit. When compiling debug code, eagerly compile
|
|
|
|
// unless we can lazily compile without the context.
|
|
|
|
bool allow_lazy = literal->AllowsLazyCompilation() &&
|
|
|
|
!LiveEditFunctionTracker::IsActive(isolate) &&
|
|
|
|
(!info.is_debug() || allow_lazy_without_ctx);
|
2012-02-14 14:14:51 +00:00
|
|
|
|
2015-06-25 12:19:55 +00:00
|
|
|
bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile();
|
|
|
|
|
2016-03-14 18:55:41 +00:00
|
|
|
// Consider compiling eagerly when targeting the code cache.
|
|
|
|
lazy &= !(FLAG_serialize_eager && info.will_serialize());
|
|
|
|
|
2016-03-24 18:37:56 +00:00
|
|
|
// Consider compiling eagerly when compiling bytecode for Ignition.
|
|
|
|
lazy &=
|
|
|
|
!(FLAG_ignition && FLAG_ignition_eager && !isolate->serializer_enabled());
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
// Generate code
|
2016-02-15 17:29:22 +00:00
|
|
|
TimerEventScope<TimerEventCompileCode> timer(isolate);
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.CompileCode");
|
2015-06-25 12:19:55 +00:00
|
|
|
if (lazy) {
|
2016-03-18 10:46:40 +00:00
|
|
|
info.SetCode(isolate->builtins()->CompileLazy());
|
2015-12-15 14:12:34 +00:00
|
|
|
} else if (Renumber(info.parse_info()) && GenerateBaselineCode(&info)) {
|
2015-12-14 20:57:38 +00:00
|
|
|
// Code generation will ensure that the feedback vector is present and
|
2014-11-14 08:21:13 +00:00
|
|
|
// appropriately sized.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!info.code().is_null());
|
2016-03-18 10:46:40 +00:00
|
|
|
Handle<ScopeInfo> scope_info =
|
|
|
|
ScopeInfo::Create(info.isolate(), info.zone(), info.scope());
|
2015-05-06 10:21:20 +00:00
|
|
|
if (literal->should_eager_compile() &&
|
|
|
|
literal->should_be_used_once_hint()) {
|
|
|
|
info.code()->MarkToBeExecutedOnce(isolate);
|
|
|
|
}
|
2016-03-18 10:46:40 +00:00
|
|
|
// Install compilation result on the shared function info.
|
|
|
|
InstallBaselineCompilationResult(&info, result, scope_info);
|
2012-03-26 13:08:08 +00:00
|
|
|
} else {
|
2013-12-23 14:30:35 +00:00
|
|
|
return Handle<SharedFunctionInfo>::null();
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
2008-12-05 08:35:52 +00:00
|
|
|
|
2015-06-25 12:19:55 +00:00
|
|
|
if (maybe_existing.is_null()) {
|
|
|
|
// If the outer function has been compiled before, we cannot be sure that
|
|
|
|
// shared function info for this function literal has been created for the
|
|
|
|
// first time. It may have already been compiled previously.
|
|
|
|
result->set_never_compiled(outer_info->is_first_compile() && lazy);
|
2015-02-11 14:51:59 +00:00
|
|
|
|
2015-06-25 12:19:55 +00:00
|
|
|
RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
|
|
|
|
result->set_allows_lazy_compilation(literal->AllowsLazyCompilation());
|
|
|
|
result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2015-06-25 12:19:55 +00:00
|
|
|
// Set the expected number of properties for instances and return
|
|
|
|
// the resulting function.
|
|
|
|
SetExpectedNofPropertiesFromEstimate(result,
|
|
|
|
literal->expected_property_count());
|
|
|
|
live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
|
2016-03-18 10:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 11:30:27 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative(
|
|
|
|
v8::Extension* extension, Handle<String> name) {
|
|
|
|
Isolate* isolate = name->GetIsolate();
|
|
|
|
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
|
|
|
|
|
|
|
|
// Compute the function template for the native function.
|
|
|
|
v8::Local<v8::FunctionTemplate> fun_template =
|
|
|
|
extension->GetNativeFunctionTemplate(v8_isolate,
|
|
|
|
v8::Utils::ToLocal(name));
|
|
|
|
DCHECK(!fun_template.IsEmpty());
|
|
|
|
|
|
|
|
// Instantiate the function and create a shared function info from it.
|
|
|
|
Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle(
|
|
|
|
*fun_template->GetFunction(v8_isolate->GetCurrentContext())
|
|
|
|
.ToLocalChecked()));
|
|
|
|
const int literals = fun->NumberOfLiterals();
|
|
|
|
Handle<Code> code = Handle<Code>(fun->shared()->code());
|
|
|
|
Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
|
|
|
|
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
|
|
|
|
name, literals, FunctionKind::kNormalFunction, code,
|
2016-03-18 10:46:40 +00:00
|
|
|
Handle<ScopeInfo>(fun->shared()->scope_info()));
|
2016-01-26 11:30:27 +00:00
|
|
|
shared->set_construct_stub(*construct_stub);
|
2016-03-18 10:46:40 +00:00
|
|
|
shared->set_feedback_vector(fun->shared()->feedback_vector());
|
2016-01-26 11:30:27 +00:00
|
|
|
|
|
|
|
// Copy the function data to the shared function info.
|
|
|
|
shared->set_function_data(fun->shared()->function_data());
|
|
|
|
int parameters = fun->shared()->internal_formal_parameter_count();
|
|
|
|
shared->set_internal_formal_parameter_count(parameters);
|
|
|
|
|
|
|
|
return shared;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2016-03-08 09:01:27 +00:00
|
|
|
MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function,
|
|
|
|
BailoutId osr_ast_id,
|
|
|
|
JavaScriptFrame* osr_frame) {
|
2016-03-04 16:10:55 +00:00
|
|
|
DCHECK(!osr_ast_id.IsNone());
|
2016-03-08 09:01:27 +00:00
|
|
|
DCHECK_NOT_NULL(osr_frame);
|
|
|
|
return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame);
|
2012-07-19 18:58:23 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 10:09:21 +00:00
|
|
|
void Compiler::FinalizeOptimizedCompileJob(OptimizedCompileJob* job) {
|
2013-12-23 14:30:35 +00:00
|
|
|
// Take ownership of compilation info. Deleting compilation info
|
|
|
|
// also tears down the zone and the recompile job.
|
2015-07-13 12:38:06 +00:00
|
|
|
base::SmartPointer<CompilationInfo> info(job->info());
|
2012-11-22 13:04:11 +00:00
|
|
|
Isolate* isolate = info->isolate();
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2013-04-24 14:44:08 +00:00
|
|
|
VMState<COMPILER> state(isolate);
|
2014-07-16 08:14:50 +00:00
|
|
|
TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
|
2016-02-18 06:12:45 +00:00
|
|
|
TRACE_EVENT0("v8", "V8.RecompileSynchronous");
|
2012-07-19 18:58:23 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
|
|
|
shared->code()->set_profiler_ticks(0);
|
|
|
|
|
2015-07-20 14:53:28 +00:00
|
|
|
DCHECK(!shared->HasDebugInfo());
|
|
|
|
|
2014-09-24 07:08:27 +00:00
|
|
|
// 1) Optimization on the concurrent thread may have failed.
|
2013-12-23 14:30:35 +00:00
|
|
|
// 2) The function may have already been optimized by OSR. Simply continue.
|
|
|
|
// Except when OSR already disabled optimization for some reason.
|
|
|
|
// 3) The code may have already been invalidated due to dependency change.
|
2015-07-20 14:53:28 +00:00
|
|
|
// 4) Code generation may have failed.
|
2014-09-24 07:08:27 +00:00
|
|
|
if (job->last_status() == OptimizedCompileJob::SUCCEEDED) {
|
|
|
|
if (shared->optimization_disabled()) {
|
|
|
|
job->RetryOptimization(kOptimizationDisabled);
|
2015-04-20 15:22:02 +00:00
|
|
|
} else if (info->dependencies()->HasAborted()) {
|
2014-09-24 07:08:27 +00:00
|
|
|
job->RetryOptimization(kBailedOutDueToDependencyChange);
|
|
|
|
} else if (job->GenerateCode() == OptimizedCompileJob::SUCCEEDED) {
|
|
|
|
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info.get(), shared);
|
2015-06-25 08:28:19 +00:00
|
|
|
if (shared->SearchOptimizedCodeMap(info->context()->native_context(),
|
|
|
|
info->osr_ast_id()).code == nullptr) {
|
2014-09-24 07:08:27 +00:00
|
|
|
InsertCodeIntoOptimizedCodeMap(info.get());
|
|
|
|
}
|
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
PrintF("[completed optimizing ");
|
|
|
|
info->closure()->ShortPrint();
|
|
|
|
PrintF("]\n");
|
|
|
|
}
|
2016-03-08 10:09:21 +00:00
|
|
|
info->closure()->ReplaceCode(*info->code());
|
|
|
|
return;
|
2014-09-24 07:08:27 +00:00
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
2009-11-04 17:59:24 +00:00
|
|
|
|
2014-09-24 07:08:27 +00:00
|
|
|
DCHECK(job->last_status() != OptimizedCompileJob::SUCCEEDED);
|
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
PrintF("[aborted optimizing ");
|
|
|
|
info->closure()->ShortPrint();
|
|
|
|
PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason()));
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
2016-03-08 10:09:21 +00:00
|
|
|
info->closure()->ReplaceCode(shared->code());
|
2009-11-04 17:59:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 16:26:08 +00:00
|
|
|
void Compiler::PostInstantiation(Handle<JSFunction> function,
|
|
|
|
PretenureFlag pretenure) {
|
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
|
|
|
|
if (FLAG_always_opt && shared->allows_lazy_compilation()) {
|
|
|
|
function->MarkForOptimization();
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeAndLiterals cached = shared->SearchOptimizedCodeMap(
|
|
|
|
function->context()->native_context(), BailoutId::None());
|
|
|
|
if (cached.code != nullptr) {
|
|
|
|
// Caching of optimized code enabled and optimized code found.
|
|
|
|
DCHECK(!cached.code->marked_for_deoptimization());
|
|
|
|
DCHECK(function->shared()->is_compiled());
|
|
|
|
function->ReplaceCode(cached.code);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cached.literals != nullptr) {
|
|
|
|
function->set_literals(cached.literals);
|
|
|
|
} else {
|
|
|
|
Isolate* isolate = function->GetIsolate();
|
|
|
|
int number_of_literals = shared->num_literals();
|
|
|
|
Handle<LiteralsArray> literals =
|
|
|
|
LiteralsArray::New(isolate, handle(shared->feedback_vector()),
|
|
|
|
number_of_literals, pretenure);
|
|
|
|
function->set_literals(*literals);
|
|
|
|
|
|
|
|
// Cache context-specific literals.
|
|
|
|
MaybeHandle<Code> code;
|
|
|
|
if (cached.code != nullptr) code = handle(cached.code);
|
|
|
|
Handle<Context> native_context(function->context()->native_context());
|
|
|
|
SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code,
|
|
|
|
literals, BailoutId::None());
|
|
|
|
}
|
|
|
|
}
|
2009-11-04 17:59:24 +00:00
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|