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/v8.h"
|
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
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
#include "src/ast-numbering.h"
|
2014-11-28 04:08:48 +00:00
|
|
|
#include "src/ast-this-access-visitor.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"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/cpu-profiler.h"
|
|
|
|
#include "src/debug.h"
|
|
|
|
#include "src/deoptimizer.h"
|
|
|
|
#include "src/full-codegen.h"
|
|
|
|
#include "src/gdb-jit.h"
|
|
|
|
#include "src/hydrogen.h"
|
|
|
|
#include "src/isolate-inl.h"
|
|
|
|
#include "src/lithium.h"
|
|
|
|
#include "src/liveedit.h"
|
2014-11-28 04:08:48 +00:00
|
|
|
#include "src/messages.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/parser.h"
|
|
|
|
#include "src/rewriter.h"
|
|
|
|
#include "src/runtime-profiler.h"
|
|
|
|
#include "src/scanner-character-streams.h"
|
|
|
|
#include "src/scopeinfo.h"
|
|
|
|
#include "src/scopes.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/typing.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
|
|
|
|
2010-10-04 11:35:46 +00:00
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
ScriptData::ScriptData(const byte* data, int length)
|
2014-11-17 12:16:27 +00:00
|
|
|
: owns_data_(false), rejected_(false), data_(data), length_(length) {
|
2014-07-10 10:28:05 +00:00
|
|
|
if (!IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)) {
|
|
|
|
byte* copy = NewArray<byte>(length);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsAligned(reinterpret_cast<intptr_t>(copy), kPointerAlignment));
|
2014-07-10 10:28:05 +00:00
|
|
|
CopyBytes(copy, data, length);
|
|
|
|
data_ = copy;
|
|
|
|
AcquireDataOwnership();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 11:12:29 +00:00
|
|
|
CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
|
2014-08-26 14:41:58 +00:00
|
|
|
: flags_(kThisHasUses),
|
2010-10-04 11:35:46 +00:00
|
|
|
script_(script),
|
2014-09-12 09:12:08 +00:00
|
|
|
source_stream_(NULL),
|
2013-09-04 12:55:59 +00:00
|
|
|
osr_ast_id_(BailoutId::None()),
|
2014-01-14 12:04:10 +00:00
|
|
|
parameter_count_(0),
|
2014-06-24 14:03:24 +00:00
|
|
|
optimization_id_(-1),
|
|
|
|
ast_value_factory_(NULL),
|
2014-10-01 11:41:19 +00:00
|
|
|
ast_value_factory_owned_(false),
|
|
|
|
aborted_due_to_dependency_change_(false) {
|
2013-06-27 13:03:01 +00:00
|
|
|
Initialize(script->GetIsolate(), BASE, zone);
|
2010-10-04 11:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone)
|
2014-08-26 14:41:58 +00:00
|
|
|
: flags_(kThisHasUses),
|
2014-07-30 13:54:45 +00:00
|
|
|
script_(Handle<Script>::null()),
|
2014-09-12 09:12:08 +00:00
|
|
|
source_stream_(NULL),
|
2014-07-30 13:54:45 +00:00
|
|
|
osr_ast_id_(BailoutId::None()),
|
|
|
|
parameter_count_(0),
|
|
|
|
optimization_id_(-1),
|
|
|
|
ast_value_factory_(NULL),
|
2014-10-01 11:41:19 +00:00
|
|
|
ast_value_factory_owned_(false),
|
|
|
|
aborted_due_to_dependency_change_(false) {
|
2014-07-30 13:54:45 +00:00
|
|
|
Initialize(isolate, STUB, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-20 08:58:41 +00:00
|
|
|
CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
|
2013-06-27 13:03:01 +00:00
|
|
|
Zone* zone)
|
2014-08-26 14:41:58 +00:00
|
|
|
: flags_(kLazy | kThisHasUses),
|
2010-10-04 11:35:46 +00:00
|
|
|
shared_info_(shared_info),
|
|
|
|
script_(Handle<Script>(Script::cast(shared_info->script()))),
|
2014-09-12 09:12:08 +00:00
|
|
|
source_stream_(NULL),
|
2013-09-04 12:55:59 +00:00
|
|
|
osr_ast_id_(BailoutId::None()),
|
2014-01-14 12:04:10 +00:00
|
|
|
parameter_count_(0),
|
2014-06-24 14:03:24 +00:00
|
|
|
optimization_id_(-1),
|
|
|
|
ast_value_factory_(NULL),
|
2014-10-01 11:41:19 +00:00
|
|
|
ast_value_factory_owned_(false),
|
|
|
|
aborted_due_to_dependency_change_(false) {
|
2013-06-27 13:03:01 +00:00
|
|
|
Initialize(script_->GetIsolate(), BASE, zone);
|
2010-10-04 11:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 11:12:29 +00:00
|
|
|
CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
|
2014-08-26 14:41:58 +00:00
|
|
|
: flags_(kLazy | kThisHasUses),
|
2010-10-04 11:35:46 +00:00
|
|
|
closure_(closure),
|
|
|
|
shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
|
|
|
|
script_(Handle<Script>(Script::cast(shared_info_->script()))),
|
2014-09-12 09:12:08 +00:00
|
|
|
source_stream_(NULL),
|
2012-08-28 11:25:08 +00:00
|
|
|
context_(closure->context()),
|
2013-09-04 12:55:59 +00:00
|
|
|
osr_ast_id_(BailoutId::None()),
|
2014-01-14 12:04:10 +00:00
|
|
|
parameter_count_(0),
|
2014-06-24 14:03:24 +00:00
|
|
|
optimization_id_(-1),
|
|
|
|
ast_value_factory_(NULL),
|
2014-10-01 11:41:19 +00:00
|
|
|
ast_value_factory_owned_(false),
|
|
|
|
aborted_due_to_dependency_change_(false) {
|
2013-06-27 13:03:01 +00:00
|
|
|
Initialize(script_->GetIsolate(), BASE, zone);
|
2012-11-29 07:38:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-22 11:12:29 +00:00
|
|
|
CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate,
|
2013-06-27 13:03:01 +00:00
|
|
|
Zone* zone)
|
2014-08-26 14:41:58 +00:00
|
|
|
: flags_(kLazy | kThisHasUses),
|
2014-09-12 09:12:08 +00:00
|
|
|
source_stream_(NULL),
|
2013-09-04 12:55:59 +00:00
|
|
|
osr_ast_id_(BailoutId::None()),
|
2014-01-14 12:04:10 +00:00
|
|
|
parameter_count_(0),
|
2014-06-24 14:03:24 +00:00
|
|
|
optimization_id_(-1),
|
|
|
|
ast_value_factory_(NULL),
|
2014-10-01 11:41:19 +00:00
|
|
|
ast_value_factory_owned_(false),
|
|
|
|
aborted_due_to_dependency_change_(false) {
|
2013-06-27 13:03:01 +00:00
|
|
|
Initialize(isolate, STUB, zone);
|
2012-12-18 16:25:45 +00:00
|
|
|
code_stub_ = stub;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-12 09:12:08 +00:00
|
|
|
CompilationInfo::CompilationInfo(
|
|
|
|
ScriptCompiler::ExternalSourceStream* stream,
|
|
|
|
ScriptCompiler::StreamedSource::Encoding encoding, Isolate* isolate,
|
|
|
|
Zone* zone)
|
|
|
|
: flags_(kThisHasUses),
|
|
|
|
source_stream_(stream),
|
|
|
|
source_stream_encoding_(encoding),
|
|
|
|
osr_ast_id_(BailoutId::None()),
|
|
|
|
parameter_count_(0),
|
|
|
|
optimization_id_(-1),
|
|
|
|
ast_value_factory_(NULL),
|
2014-10-01 11:41:19 +00:00
|
|
|
ast_value_factory_owned_(false),
|
|
|
|
aborted_due_to_dependency_change_(false) {
|
2014-09-12 09:12:08 +00:00
|
|
|
Initialize(isolate, BASE, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-24 13:37:46 +00:00
|
|
|
void CompilationInfo::Initialize(Isolate* isolate,
|
|
|
|
Mode mode,
|
2013-06-27 13:03:01 +00:00
|
|
|
Zone* zone) {
|
2012-12-18 16:25:45 +00:00
|
|
|
isolate_ = isolate;
|
2012-11-29 07:38:00 +00:00
|
|
|
function_ = NULL;
|
|
|
|
scope_ = NULL;
|
2014-11-12 11:34:09 +00:00
|
|
|
script_scope_ = NULL;
|
2012-11-29 07:38:00 +00:00
|
|
|
extension_ = NULL;
|
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
|
|
|
compile_options_ = ScriptCompiler::kNoCompileOptions;
|
2012-11-29 07:38:00 +00:00
|
|
|
zone_ = zone;
|
|
|
|
deferred_handles_ = NULL;
|
2012-12-18 16:25:45 +00:00
|
|
|
code_stub_ = NULL;
|
2013-10-23 13:48:04 +00:00
|
|
|
prologue_offset_ = Code::kPrologueOffsetNotSet;
|
2013-01-23 13:52:00 +00:00
|
|
|
opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count();
|
2013-05-14 22:51:33 +00:00
|
|
|
no_frame_ranges_ = isolate->cpu_profiler()->is_profiling()
|
|
|
|
? new List<OffsetRange>(2) : NULL;
|
2013-06-12 09:43:22 +00:00
|
|
|
for (int i = 0; i < DependentCode::kGroupCount; i++) {
|
2013-06-26 16:17:12 +00:00
|
|
|
dependencies_[i] = NULL;
|
2013-06-12 09:43:22 +00:00
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
if (mode == STUB) {
|
|
|
|
mode_ = STUB;
|
|
|
|
return;
|
|
|
|
}
|
2013-10-23 08:57:54 +00:00
|
|
|
mode_ = mode;
|
2014-09-12 09:12:08 +00:00
|
|
|
if (!script_.is_null() && script_->type()->value() == Script::TYPE_NATIVE) {
|
|
|
|
MarkAsNative();
|
|
|
|
}
|
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();
|
|
|
|
|
2014-05-27 13:20:58 +00:00
|
|
|
if (isolate_->debug()->is_active()) MarkAsDebug();
|
2014-08-26 17:04:34 +00:00
|
|
|
if (FLAG_context_specialization) MarkAsContextSpecializing();
|
2014-09-11 09:02:18 +00:00
|
|
|
if (FLAG_turbo_inlining) MarkAsInliningEnabled();
|
2014-09-11 09:44:44 +00:00
|
|
|
if (FLAG_turbo_types) MarkAsTypingEnabled();
|
2014-05-12 13:47:01 +00:00
|
|
|
|
2012-11-29 07:38:00 +00:00
|
|
|
if (!shared_info_.is_null()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(strict_mode() == SLOPPY);
|
2014-03-11 14:41:22 +00:00
|
|
|
SetStrictMode(shared_info_->strict_mode());
|
2012-11-29 07:38:00 +00:00
|
|
|
}
|
2015-01-13 14:36:50 +00:00
|
|
|
bailout_reason_ = kNoReason;
|
2014-04-30 10:51:01 +00:00
|
|
|
|
|
|
|
if (!shared_info().is_null() && shared_info()->is_compiled()) {
|
|
|
|
// We should initialize the CompilationInfo feedback vector from the
|
|
|
|
// passed in shared info, rather than creating a new one.
|
2014-09-18 09:59:53 +00:00
|
|
|
feedback_vector_ =
|
|
|
|
Handle<TypeFeedbackVector>(shared_info()->feedback_vector(), isolate);
|
2014-04-30 10:51:01 +00:00
|
|
|
}
|
2010-10-04 11:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
CompilationInfo::~CompilationInfo() {
|
2014-09-24 07:08:27 +00:00
|
|
|
if (GetFlag(kDisableFutureOptimization)) {
|
|
|
|
shared_info()->DisableOptimization(bailout_reason());
|
|
|
|
}
|
2012-07-06 09:31:31 +00:00
|
|
|
delete deferred_handles_;
|
2013-05-14 22:51:33 +00:00
|
|
|
delete no_frame_ranges_;
|
2014-06-24 14:03:24 +00:00
|
|
|
if (ast_value_factory_owned_) delete ast_value_factory_;
|
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.
|
|
|
|
for (int i = 0; i < DependentCode::kGroupCount; i++) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(NULL, dependencies_[i]);
|
2013-06-12 09:43:22 +00:00
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-26 16:17:12 +00:00
|
|
|
void CompilationInfo::CommitDependencies(Handle<Code> code) {
|
2013-06-12 09:43:22 +00:00
|
|
|
for (int i = 0; i < DependentCode::kGroupCount; i++) {
|
2013-06-26 16:17:12 +00:00
|
|
|
ZoneList<Handle<HeapObject> >* group_objects = dependencies_[i];
|
|
|
|
if (group_objects == NULL) continue;
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!object_wrapper_.is_null());
|
2013-06-26 16:17:12 +00:00
|
|
|
for (int j = 0; j < group_objects->length(); j++) {
|
|
|
|
DependentCode::DependencyGroup group =
|
|
|
|
static_cast<DependentCode::DependencyGroup>(i);
|
|
|
|
DependentCode* dependent_code =
|
|
|
|
DependentCode::ForObject(group_objects->at(j), group);
|
|
|
|
dependent_code->UpdateToFinishedCode(group, this, *code);
|
2013-06-12 09:43:22 +00:00
|
|
|
}
|
2013-06-26 16:17:12 +00:00
|
|
|
dependencies_[i] = NULL; // Zone-allocated, no need to delete.
|
2013-06-12 09:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-26 16:17:12 +00:00
|
|
|
void CompilationInfo::RollbackDependencies() {
|
2013-06-12 09:43:22 +00:00
|
|
|
// Unregister from all dependent maps if not yet committed.
|
|
|
|
for (int i = 0; i < DependentCode::kGroupCount; i++) {
|
2013-06-26 16:17:12 +00:00
|
|
|
ZoneList<Handle<HeapObject> >* group_objects = dependencies_[i];
|
|
|
|
if (group_objects == NULL) continue;
|
|
|
|
for (int j = 0; j < group_objects->length(); j++) {
|
|
|
|
DependentCode::DependencyGroup group =
|
|
|
|
static_cast<DependentCode::DependencyGroup>(i);
|
|
|
|
DependentCode* dependent_code =
|
|
|
|
DependentCode::ForObject(group_objects->at(j), group);
|
|
|
|
dependent_code->RemoveCompilationInfo(group, this);
|
2013-06-12 09:43:22 +00:00
|
|
|
}
|
2013-06-26 16:17:12 +00:00
|
|
|
dependencies_[i] = NULL; // Zone-allocated, no need to delete.
|
2013-06-12 09:43:22 +00:00
|
|
|
}
|
2012-07-06 09:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
int CompilationInfo::num_parameters() const {
|
2013-11-15 10:52:05 +00:00
|
|
|
if (IsStub()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(parameter_count_ > 0);
|
2013-11-15 10:52:05 +00:00
|
|
|
return parameter_count_;
|
|
|
|
} else {
|
|
|
|
return scope()->num_parameters();
|
|
|
|
}
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CompilationInfo::num_heap_slots() const {
|
|
|
|
if (IsStub()) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return scope()->num_heap_slots();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Code::Flags CompilationInfo::flags() const {
|
|
|
|
if (IsStub()) {
|
2013-04-18 09:50:46 +00:00
|
|
|
return Code::ComputeFlags(code_stub()->GetCodeKind(),
|
|
|
|
code_stub()->GetICState(),
|
|
|
|
code_stub()->GetExtraICState(),
|
2014-02-14 15:15:08 +00:00
|
|
|
code_stub()->GetStubType());
|
2012-12-18 16:25:45 +00:00
|
|
|
} else {
|
|
|
|
return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
return FLAG_crankshaft &&
|
|
|
|
!function()->flags()->Contains(kDontSelfOptimize) &&
|
|
|
|
!function()->dont_optimize() &&
|
|
|
|
function()->scope()->AllowsLazyCompilation() &&
|
|
|
|
(shared_info().is_null() || !shared_info()->optimization_disabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
void CompilationInfo::PrepareForCompilation(Scope* scope) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(scope_ == NULL);
|
2014-02-10 21:38:17 +00:00
|
|
|
scope_ = scope;
|
2014-11-14 08:21:13 +00:00
|
|
|
}
|
|
|
|
|
2014-04-30 10:51:01 +00:00
|
|
|
|
2014-11-14 08:21:13 +00:00
|
|
|
void CompilationInfo::EnsureFeedbackVector() {
|
2014-04-30 10:51:01 +00:00
|
|
|
if (feedback_vector_.is_null()) {
|
2014-10-20 11:42:56 +00:00
|
|
|
feedback_vector_ = isolate()->factory()->NewTypeFeedbackVector(
|
2014-11-27 16:36:18 +00:00
|
|
|
function()->feedback_vector_spec());
|
2014-04-30 10:51:01 +00:00
|
|
|
}
|
2014-02-10 21:38:17 +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) {
|
|
|
|
}
|
|
|
|
|
2014-12-12 10:44:12 +00:00
|
|
|
#define DEF_VISIT(type) \
|
|
|
|
void Visit##type(type* node) OVERRIDE { \
|
|
|
|
if (node->position() != RelocInfo::kNoPosition) { \
|
|
|
|
SetSourcePosition(node->position()); \
|
|
|
|
} \
|
|
|
|
HOptimizedGraphBuilder::Visit##type(node); \
|
2013-10-21 13:35:48 +00:00
|
|
|
}
|
|
|
|
EXPRESSION_NODE_LIST(DEF_VISIT)
|
|
|
|
#undef DEF_VISIT
|
|
|
|
|
2014-12-12 10:44:12 +00:00
|
|
|
#define DEF_VISIT(type) \
|
|
|
|
void Visit##type(type* node) OVERRIDE { \
|
|
|
|
if (node->position() != RelocInfo::kNoPosition) { \
|
|
|
|
SetSourcePosition(node->position()); \
|
|
|
|
} \
|
|
|
|
HOptimizedGraphBuilder::Visit##type(node); \
|
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) \
|
|
|
|
void Visit##type(type* node) OVERRIDE { \
|
|
|
|
HOptimizedGraphBuilder::Visit##type(node); \
|
2013-10-21 13:35:48 +00:00
|
|
|
}
|
|
|
|
MODULE_NODE_LIST(DEF_VISIT)
|
|
|
|
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());
|
|
|
|
DCHECK(!info()->IsCompilingForDebugging());
|
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-01-19 16:51:39 +00:00
|
|
|
if (isolate()->debug()->has_break_points()) {
|
2014-09-24 07:08:27 +00:00
|
|
|
return RetryOptimization(kDebuggerHasBreakPoints);
|
2014-06-26 06:32:51 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Limit the number of times we re-compile a functions with
|
|
|
|
// the optimizing compiler.
|
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;
|
2013-01-23 13:52:00 +00:00
|
|
|
if (info()->opt_count() > kMaxOptCount) {
|
2014-09-24 07:08:27 +00:00
|
|
|
return AbortOptimization(kOptimizedTooManyTimes);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Due to an encoding limit on LUnallocated operands in the Lithium
|
|
|
|
// language, we cannot optimize functions with too many formal parameters
|
|
|
|
// or perform on-stack replacement for function with too many
|
|
|
|
// stack-allocated local variables.
|
|
|
|
//
|
2011-02-28 13:20:10 +00:00
|
|
|
// The encoding is as a signed value, with parameters and receiver using
|
|
|
|
// the negative indices and locals the non-negative ones.
|
2013-05-02 09:51:07 +00:00
|
|
|
const int parameter_limit = -LUnallocated::kMinFixedSlotIndex;
|
2012-07-17 16:24:40 +00:00
|
|
|
Scope* scope = info()->scope();
|
2012-08-28 07:18:06 +00:00
|
|
|
if ((scope->num_parameters() + 1) > parameter_limit) {
|
2014-09-24 07:08:27 +00:00
|
|
|
return AbortOptimization(kTooManyParameters);
|
2012-08-28 07:18:06 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 09:51:07 +00:00
|
|
|
const int locals_limit = LUnallocated::kMaxFixedSlotIndex;
|
2013-09-09 16:34:40 +00:00
|
|
|
if (info()->is_osr() &&
|
2012-08-28 07:18:06 +00:00
|
|
|
scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) {
|
2014-09-24 07:08:27 +00:00
|
|
|
return AbortOptimization(kTooManyParametersLocals);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 16:45:46 +00:00
|
|
|
if (scope->HasIllegalRedeclaration()) {
|
2014-09-24 07:08:27 +00:00
|
|
|
return AbortOptimization(kFunctionWithIllegalRedeclaration);
|
2014-03-31 16:45:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// Check the whitelist for Crankshaft.
|
2013-08-23 13:30:02 +00:00
|
|
|
if (!info()->closure()->PassesFilter(FLAG_hydrogen_filter)) {
|
2013-12-23 14:30:35 +00:00
|
|
|
return AbortOptimization(kHydrogenFilter);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// Crankshaft 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());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// Check the whitelist for TurboFan.
|
2014-09-22 12:32:47 +00:00
|
|
|
if ((FLAG_turbo_asm && info()->shared_info()->asm_function()) ||
|
|
|
|
info()->closure()->PassesFilter(FLAG_turbo_filter)) {
|
2014-12-19 11:47:17 +00:00
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
OFStream os(stdout);
|
|
|
|
os << "[compiling method " << Brief(*info()->closure())
|
|
|
|
<< " using TurboFan]" << std::endl;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-12-19 11:47:17 +00:00
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
OFStream os(stdout);
|
|
|
|
os << "[compiling method " << Brief(*info()->closure())
|
|
|
|
<< " using Crankshaft]" << std::endl;
|
|
|
|
}
|
|
|
|
|
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.
|
2013-06-12 17:20:37 +00:00
|
|
|
AstTyper::Run(info());
|
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());
|
|
|
|
}
|
|
|
|
|
2014-06-25 12:37:06 +00:00
|
|
|
graph_builder_ = (FLAG_hydrogen_track_positions || FLAG_trace_ic)
|
2013-11-29 10:02:32 +00:00
|
|
|
? new(info()->zone()) HOptimizedGraphBuilderWithPositions(info())
|
2013-10-21 13:35:48 +00:00
|
|
|
: new(info()->zone()) HOptimizedGraphBuilder(info());
|
2012-11-19 14:20:57 +00:00
|
|
|
|
|
|
|
Timer t(this, &time_taken_to_create_graph_);
|
2014-01-14 12:04:10 +00:00
|
|
|
info()->set_this_has_uses(false);
|
2012-07-17 16:24:40 +00:00
|
|
|
graph_ = graph_builder_->CreateGraph();
|
|
|
|
|
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
|
|
|
|
2013-08-12 14:10:25 +00:00
|
|
|
if (info()->HasAbortedDueToDependencyChange()) {
|
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) {
|
|
|
|
graph_builder_->Bailout(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
|
|
|
}
|
|
|
|
|
|
|
|
|
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()) {
|
2014-10-26 10:24:49 +00:00
|
|
|
if (FLAG_turbo_deoptimization) {
|
|
|
|
info()->context()->native_context()->AddOptimizedCode(*info()->code());
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
RecordOptimizationStats();
|
|
|
|
return last_status();
|
|
|
|
}
|
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!info()->HasAbortedDueToDependencyChange());
|
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
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-13 09:55:48 +00:00
|
|
|
static void MaybeDisableOptimization(Handle<SharedFunctionInfo> shared_info,
|
|
|
|
BailoutReason bailout_reason) {
|
|
|
|
if (bailout_reason != kNoReason) {
|
|
|
|
shared_info->DisableOptimization(bailout_reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
// Sets the function info on a function.
|
|
|
|
// The start_position points to the first '(' character after the function name
|
|
|
|
// in the full script source. When counting characters in the script source the
|
|
|
|
// the first character is number 0 (not 1).
|
|
|
|
static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
|
|
|
|
FunctionLiteral* lit,
|
|
|
|
bool is_toplevel,
|
|
|
|
Handle<Script> script) {
|
|
|
|
function_info->set_length(lit->parameter_count());
|
|
|
|
function_info->set_formal_parameter_count(lit->parameter_count());
|
|
|
|
function_info->set_script(*script);
|
|
|
|
function_info->set_function_token_position(lit->function_token_position());
|
|
|
|
function_info->set_start_position(lit->start_position());
|
|
|
|
function_info->set_end_position(lit->end_position());
|
|
|
|
function_info->set_is_expression(lit->is_expression());
|
|
|
|
function_info->set_is_anonymous(lit->is_anonymous());
|
|
|
|
function_info->set_is_toplevel(is_toplevel);
|
|
|
|
function_info->set_inferred_name(*lit->inferred_name());
|
|
|
|
function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
|
|
|
|
function_info->set_allows_lazy_compilation_without_context(
|
|
|
|
lit->AllowsLazyCompilationWithoutContext());
|
2014-03-11 14:41:22 +00:00
|
|
|
function_info->set_strict_mode(lit->strict_mode());
|
2013-12-23 14:30:35 +00:00
|
|
|
function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
|
|
|
|
function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
|
|
|
|
function_info->set_ast_node_count(lit->ast_node_count());
|
|
|
|
function_info->set_is_function(lit->is_function());
|
2014-11-13 09:55:48 +00:00
|
|
|
MaybeDisableOptimization(function_info, lit->dont_optimize_reason());
|
2013-12-23 14:30:35 +00:00
|
|
|
function_info->set_dont_cache(lit->flags()->Contains(kDontCache));
|
2014-09-10 16:39:42 +00:00
|
|
|
function_info->set_kind(lit->kind());
|
2014-11-28 04:08:48 +00:00
|
|
|
function_info->set_uses_super_property(lit->uses_super_property());
|
|
|
|
function_info->set_uses_super_constructor_call(
|
|
|
|
lit->uses_super_constructor_call());
|
2014-09-19 12:50:50 +00:00
|
|
|
function_info->set_asm_function(lit->scope()->asm_function());
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-18 09:41:45 +00:00
|
|
|
static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
|
|
|
|
CompilationInfo* info,
|
|
|
|
Handle<SharedFunctionInfo> shared) {
|
|
|
|
// 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()) {
|
|
|
|
Handle<Script> script = info->script();
|
|
|
|
Handle<Code> code = info->code();
|
|
|
|
if (code.is_identical_to(info->isolate()->builtins()->CompileLazy())) {
|
|
|
|
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(),
|
|
|
|
CodeCreateEvent(log_tag, *code, *shared, info, script_name,
|
|
|
|
line_num, column_num));
|
|
|
|
}
|
|
|
|
|
|
|
|
GDBJIT(AddCode(Handle<String>(shared->DebugName()),
|
|
|
|
Handle<Script>(info->script()), Handle<Code>(info->code()),
|
|
|
|
info));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
static bool CompileUnoptimizedCode(CompilationInfo* info) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(AllowCompilation::IsAllowed(info->isolate()));
|
2014-10-28 13:23:54 +00:00
|
|
|
if (!Compiler::Analyze(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
|
|
|
|
2013-10-28 17:54:43 +00:00
|
|
|
|
2014-04-22 14:55:47 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon(
|
|
|
|
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.
|
2014-04-22 14:55:47 +00:00
|
|
|
if (!Parser::Parse(info)) return MaybeHandle<Code>();
|
2014-09-17 12:34:46 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
|
|
|
FunctionLiteral* lit = info->function();
|
|
|
|
shared->set_strict_mode(lit->strict_mode());
|
|
|
|
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
|
|
|
|
2014-09-17 12:34:46 +00:00
|
|
|
// Compile unoptimized code.
|
2014-04-22 14:55:47 +00:00
|
|
|
if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>();
|
2014-09-17 12:34:46 +00:00
|
|
|
|
|
|
|
CHECK_EQ(Code::FUNCTION, info->code()->kind());
|
2014-09-18 09:41:45 +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.
|
|
|
|
Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone());
|
|
|
|
shared->set_scope_info(*scope_info);
|
|
|
|
|
|
|
|
// Update the code and feedback vector for the shared function info.
|
|
|
|
shared->ReplaceCode(*info->code());
|
|
|
|
if (shared->optimization_disabled()) info->code()->set_optimizable(false);
|
|
|
|
shared->set_feedback_vector(*info->feedback_vector());
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
return info->code();
|
|
|
|
}
|
2013-10-28 17:54:43 +00:00
|
|
|
|
|
|
|
|
2014-09-22 12:32:47 +00:00
|
|
|
MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap(
|
|
|
|
Handle<JSFunction> function, BailoutId osr_ast_id) {
|
|
|
|
if (FLAG_cache_optimized_code) {
|
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
// Bound functions are not cached.
|
|
|
|
if (shared->bound()) return MaybeHandle<Code>();
|
|
|
|
DisallowHeapAllocation no_gc;
|
|
|
|
int index = shared->SearchOptimizedCodeMap(
|
|
|
|
function->context()->native_context(), osr_ast_id);
|
|
|
|
if (index > 0) {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
FixedArray* literals = shared->GetLiteralsFromOptimizedCodeMap(index);
|
|
|
|
if (literals != NULL) function->set_literals(literals);
|
|
|
|
return Handle<Code>(shared->GetCodeFromOptimizedCodeMap(index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MaybeHandle<Code>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) {
|
|
|
|
Handle<Code> code = info->code();
|
|
|
|
if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do.
|
|
|
|
|
|
|
|
// Context specialization folds-in the context, so no sharing can occur.
|
|
|
|
if (code->is_turbofanned() && info->is_context_specializing()) return;
|
|
|
|
|
|
|
|
// Cache optimized code.
|
|
|
|
if (FLAG_cache_optimized_code) {
|
|
|
|
Handle<JSFunction> function = info->closure();
|
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
// Do not cache bound functions.
|
|
|
|
if (shared->bound()) return;
|
|
|
|
Handle<FixedArray> literals(function->literals());
|
|
|
|
Handle<Context> native_context(function->context()->native_context());
|
|
|
|
SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code,
|
|
|
|
literals, info->osr_ast_id());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-28 13:23:54 +00:00
|
|
|
static bool Renumber(CompilationInfo* info) {
|
|
|
|
if (!AstNumbering::Renumber(info->function(), info->zone())) return false;
|
|
|
|
if (!info->shared_info().is_null()) {
|
2014-11-13 09:55:48 +00:00
|
|
|
FunctionLiteral* lit = info->function();
|
|
|
|
info->shared_info()->set_ast_node_count(lit->ast_node_count());
|
|
|
|
MaybeDisableOptimization(info->shared_info(), lit->dont_optimize_reason());
|
|
|
|
info->shared_info()->set_dont_cache(lit->flags()->Contains(kDontCache));
|
2014-10-28 13:23:54 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-08 15:54:55 +00:00
|
|
|
static void ThrowSuperConstructorCheckError(CompilationInfo* info,
|
|
|
|
Statement* stmt) {
|
2014-11-28 04:08:48 +00:00
|
|
|
MaybeHandle<Object> obj = info->isolate()->factory()->NewTypeError(
|
|
|
|
"super_constructor_call", HandleVector<Object>(nullptr, 0));
|
|
|
|
Handle<Object> exception;
|
|
|
|
if (!obj.ToHandle(&exception)) return;
|
|
|
|
|
2014-12-08 15:54:55 +00:00
|
|
|
MessageLocation location(info->script(), stmt->position(), stmt->position());
|
2014-11-28 04:08:48 +00:00
|
|
|
USE(info->isolate()->Throw(*exception, &location));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool CheckSuperConstructorCall(CompilationInfo* info) {
|
|
|
|
FunctionLiteral* function = info->function();
|
|
|
|
if (!function->uses_super_constructor_call()) return true;
|
|
|
|
|
|
|
|
if (function->is_default_constructor()) return true;
|
|
|
|
|
|
|
|
ZoneList<Statement*>* body = function->body();
|
|
|
|
CHECK(body->length() > 0);
|
|
|
|
|
|
|
|
int super_call_index = 0;
|
|
|
|
// Allow 'use strict' and similiar and empty statements.
|
|
|
|
while (true) {
|
|
|
|
CHECK(super_call_index < body->length()); // We know there is a super call.
|
|
|
|
Statement* stmt = body->at(super_call_index);
|
|
|
|
if (stmt->IsExpressionStatement() &&
|
|
|
|
stmt->AsExpressionStatement()->expression()->IsLiteral()) {
|
|
|
|
super_call_index++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (stmt->IsEmptyStatement()) {
|
|
|
|
super_call_index++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-08 15:54:55 +00:00
|
|
|
Statement* stmt = body->at(super_call_index);
|
|
|
|
ExpressionStatement* exprStm = stmt->AsExpressionStatement();
|
2014-11-28 04:08:48 +00:00
|
|
|
if (exprStm == nullptr) {
|
2014-12-08 15:54:55 +00:00
|
|
|
ThrowSuperConstructorCheckError(info, stmt);
|
2014-11-28 04:08:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Call* callExpr = exprStm->expression()->AsCall();
|
|
|
|
if (callExpr == nullptr) {
|
2014-12-08 15:54:55 +00:00
|
|
|
ThrowSuperConstructorCheckError(info, stmt);
|
2014-11-28 04:08:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!callExpr->expression()->IsSuperReference()) {
|
2014-12-08 15:54:55 +00:00
|
|
|
ThrowSuperConstructorCheckError(info, stmt);
|
2014-11-28 04:08:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZoneList<Expression*>* arguments = callExpr->arguments();
|
|
|
|
|
|
|
|
AstThisAccessVisitor this_access_visitor(info->zone());
|
|
|
|
this_access_visitor.VisitExpressions(arguments);
|
|
|
|
|
|
|
|
if (this_access_visitor.HasStackOverflow()) return false;
|
|
|
|
if (this_access_visitor.UsesThis()) {
|
2014-12-08 15:54:55 +00:00
|
|
|
ThrowSuperConstructorCheckError(info, stmt);
|
2014-11-28 04:08:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-28 13:23:54 +00:00
|
|
|
bool Compiler::Analyze(CompilationInfo* info) {
|
|
|
|
DCHECK(info->function() != NULL);
|
2014-09-22 12:32:47 +00:00
|
|
|
if (!Rewriter::Rewrite(info)) return false;
|
|
|
|
if (!Scope::Analyze(info)) return false;
|
2014-10-28 13:23:54 +00:00
|
|
|
if (!Renumber(info)) return false;
|
2014-09-22 12:32:47 +00:00
|
|
|
DCHECK(info->scope() != NULL);
|
2014-11-28 04:08:48 +00:00
|
|
|
if (!CheckSuperConstructorCall(info)) return false;
|
2014-09-22 12:32:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-28 13:23:54 +00:00
|
|
|
bool Compiler::ParseAndAnalyze(CompilationInfo* info) {
|
|
|
|
if (!Parser::Parse(info)) return false;
|
|
|
|
return Compiler::Analyze(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-22 12:32:47 +00:00
|
|
|
static bool GetOptimizedCodeNow(CompilationInfo* info) {
|
2014-10-28 13:23:54 +00:00
|
|
|
if (!Compiler::ParseAndAnalyze(info)) return false;
|
2014-09-22 12:32:47 +00:00
|
|
|
|
|
|
|
TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
|
|
|
|
|
|
|
|
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!
|
|
|
|
DCHECK(!info->isolate()->has_pending_exception());
|
|
|
|
InsertCodeIntoOptimizedCodeMap(info);
|
|
|
|
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info,
|
|
|
|
info->shared_info());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool GetOptimizedCodeLater(CompilationInfo* info) {
|
|
|
|
Isolate* isolate = info->isolate();
|
|
|
|
if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) {
|
|
|
|
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);
|
2014-10-28 13:23:54 +00:00
|
|
|
if (!Compiler::ParseAndAnalyze(info)) return false;
|
2014-09-22 12:32:47 +00:00
|
|
|
info->SaveHandles(); // Copy handles to the compilation handle scope.
|
|
|
|
|
|
|
|
TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate());
|
|
|
|
|
|
|
|
OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info);
|
|
|
|
OptimizedCompileJob::Status status = job->CreateGraph();
|
|
|
|
if (status != OptimizedCompileJob::SUCCEEDED) return false;
|
|
|
|
isolate->optimizing_compiler_thread()->QueueForOptimization(job);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 14:55:47 +00:00
|
|
|
MaybeHandle<Code> Compiler::GetUnoptimizedCode(Handle<JSFunction> function) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!function->GetIsolate()->has_pending_exception());
|
|
|
|
DCHECK(!function->is_compiled());
|
2013-12-23 14:30:35 +00:00
|
|
|
if (function->shared()->is_compiled()) {
|
|
|
|
return Handle<Code>(function->shared()->code());
|
|
|
|
}
|
2013-10-28 17:54:43 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
CompilationInfoWithZone info(function);
|
2014-04-22 14:55:47 +00:00
|
|
|
Handle<Code> result;
|
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(info.isolate(), result,
|
|
|
|
GetUnoptimizedCodeCommon(&info),
|
|
|
|
Code);
|
2014-09-17 15:29:42 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaybeHandle<Code> Compiler::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());
|
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() &&
|
|
|
|
(FLAG_turbo_deoptimization || !isolate->debug()->is_active())) {
|
2014-09-19 12:50:50 +00:00
|
|
|
CompilationInfoWithZone info(function);
|
|
|
|
|
2014-10-30 14:40:30 +00:00
|
|
|
VMState<COMPILER> state(isolate);
|
|
|
|
PostponeInterruptsScope postpone(isolate);
|
2014-09-19 12:50:50 +00:00
|
|
|
|
2014-12-09 04:47:49 +00:00
|
|
|
info.SetOptimizing(BailoutId::None(), handle(function->shared()->code()));
|
2014-09-19 12:50:50 +00:00
|
|
|
info.MarkAsContextSpecializing();
|
2014-09-22 12:32:47 +00:00
|
|
|
|
2014-10-30 14:40:30 +00:00
|
|
|
if (GetOptimizedCodeNow(&info)) {
|
|
|
|
DCHECK(function->shared()->is_compiled());
|
|
|
|
return info.code();
|
|
|
|
}
|
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;
|
2014-10-30 14:40:30 +00:00
|
|
|
ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCodeCommon(&info),
|
|
|
|
Code);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2015-01-19 16:51:39 +00:00
|
|
|
if (FLAG_always_opt && isolate->use_crankshaft()) {
|
2014-04-22 14:55:47 +00:00
|
|
|
Handle<Code> opt_code;
|
|
|
|
if (Compiler::GetOptimizedCode(
|
|
|
|
function, result,
|
|
|
|
Compiler::NOT_CONCURRENT).ToHandle(&opt_code)) {
|
|
|
|
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
|
|
|
|
2010-04-28 11:38:43 +00:00
|
|
|
|
2014-04-22 14:55:47 +00:00
|
|
|
MaybeHandle<Code> Compiler::GetUnoptimizedCode(
|
|
|
|
Handle<SharedFunctionInfo> shared) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!shared->GetIsolate()->has_pending_exception());
|
|
|
|
DCHECK(!shared->is_compiled());
|
2013-12-23 14:30:35 +00:00
|
|
|
|
|
|
|
CompilationInfoWithZone info(shared);
|
2014-04-22 14:55:47 +00:00
|
|
|
return GetUnoptimizedCodeCommon(&info);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
bool Compiler::EnsureCompiled(Handle<JSFunction> function,
|
|
|
|
ClearExceptionFlag flag) {
|
|
|
|
if (function->is_compiled()) return true;
|
2014-09-17 15:29:42 +00:00
|
|
|
MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function);
|
2014-04-22 14:55:47 +00:00
|
|
|
Handle<Code> code;
|
|
|
|
if (!maybe_code.ToHandle(&code)) {
|
2013-12-23 14:30:35 +00:00
|
|
|
if (flag == CLEAR_EXCEPTION) {
|
|
|
|
function->GetIsolate()->clear_pending_exception();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
function->ReplaceCode(*code);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(function->is_compiled());
|
2013-12-23 14:30:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-09-18 09:02:36 +00:00
|
|
|
// TODO(turbofan): In the future, unoptimized code with deopt support could
|
|
|
|
// be generated lazily once deopt is triggered.
|
|
|
|
bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
|
2014-10-28 13:23:54 +00:00
|
|
|
DCHECK(info->function() != NULL);
|
|
|
|
DCHECK(info->scope() != NULL);
|
2014-09-18 09:02:36 +00:00
|
|
|
if (!info->shared_info()->has_deoptimization_support()) {
|
2014-11-20 16:20:48 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
|
|
|
CompilationInfoWithZone unoptimized(shared);
|
2014-09-18 09:02:36 +00:00
|
|
|
// Note that we use the same AST that we will use for generating the
|
|
|
|
// optimized code.
|
|
|
|
unoptimized.SetFunction(info->function());
|
|
|
|
unoptimized.PrepareForCompilation(info->scope());
|
|
|
|
unoptimized.SetContext(info->context());
|
|
|
|
unoptimized.EnableDeoptimizationSupport();
|
2014-11-20 16:20:48 +00:00
|
|
|
// 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();
|
|
|
|
}
|
2014-09-18 09:02:36 +00:00
|
|
|
if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
|
|
|
|
|
|
|
|
shared->EnableDeoptimizationSupport(*unoptimized.code());
|
|
|
|
shared->set_feedback_vector(*unoptimized.feedback_vector());
|
|
|
|
|
|
|
|
// 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->scope(), info->zone());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
// Compile full code for debugging. This code will have debug break slots
|
|
|
|
// and deoptimization information. Deoptimization information is required
|
|
|
|
// in case that an optimized version of this function is still activated on
|
|
|
|
// the stack. It will also make sure that the full code is compiled with
|
|
|
|
// the same flags as the previous version, that is flags which can change
|
|
|
|
// the code generated. The current method of mapping from already compiled
|
|
|
|
// full code without debug break slots to full code with debug break slots
|
|
|
|
// depends on the generated code is otherwise exactly the same.
|
|
|
|
// If compilation fails, just keep the existing code.
|
2014-09-17 15:29:42 +00:00
|
|
|
MaybeHandle<Code> Compiler::GetDebugCode(Handle<JSFunction> function) {
|
2013-12-23 14:30:35 +00:00
|
|
|
CompilationInfoWithZone info(function);
|
|
|
|
Isolate* isolate = info.isolate();
|
2013-04-24 14:44:08 +00:00
|
|
|
VMState<COMPILER> state(isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2014-05-12 13:47:01 +00:00
|
|
|
info.MarkAsDebug();
|
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!isolate->has_pending_exception());
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<Code> old_code(function->shared()->code());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(old_code->kind() == Code::FUNCTION);
|
|
|
|
DCHECK(!old_code->has_debug_break_slots());
|
2013-12-23 14:30:35 +00:00
|
|
|
|
|
|
|
info.MarkCompilingForDebugging();
|
|
|
|
if (old_code->is_compiled_optimizable()) {
|
|
|
|
info.EnableDeoptimizationSupport();
|
|
|
|
} else {
|
|
|
|
info.MarkNonOptimizable();
|
|
|
|
}
|
2014-04-22 14:55:47 +00:00
|
|
|
MaybeHandle<Code> maybe_new_code = GetUnoptimizedCodeCommon(&info);
|
|
|
|
Handle<Code> new_code;
|
|
|
|
if (!maybe_new_code.ToHandle(&new_code)) {
|
2013-12-23 14:30:35 +00:00
|
|
|
isolate->clear_pending_exception();
|
|
|
|
} else {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(old_code->is_compiled_optimizable(),
|
2013-12-23 14:30:35 +00:00
|
|
|
new_code->is_compiled_optimizable());
|
|
|
|
}
|
2014-04-22 14:55:47 +00:00
|
|
|
return maybe_new_code;
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Compiler::CompileForLiveEdit(Handle<Script> script) {
|
|
|
|
// TODO(635): support extensions.
|
|
|
|
CompilationInfoWithZone info(script);
|
2013-12-23 15:41:44 +00:00
|
|
|
PostponeInterruptsScope postpone(info.isolate());
|
2013-12-23 14:30:35 +00:00
|
|
|
VMState<COMPILER> state(info.isolate());
|
|
|
|
|
|
|
|
info.MarkAsGlobal();
|
|
|
|
if (!Parser::Parse(&info)) return;
|
|
|
|
|
|
|
|
LiveEditFunctionTracker tracker(info.isolate(), info.function());
|
|
|
|
if (!CompileUnoptimizedCode(&info)) return;
|
|
|
|
if (!info.shared_info().is_null()) {
|
|
|
|
Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(),
|
|
|
|
info.zone());
|
|
|
|
info.shared_info()->set_scope_info(*scope_info);
|
|
|
|
}
|
|
|
|
tracker.RecordRootFunctionInfo(info.code());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
|
|
|
|
Isolate* isolate = info->isolate();
|
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());
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<Script> script = info->script();
|
|
|
|
|
|
|
|
// TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile?
|
|
|
|
FixedArray* array = isolate->native_context()->embedder_data();
|
|
|
|
script->set_context_data(array->get(0));
|
|
|
|
|
2014-05-27 13:20:58 +00:00
|
|
|
isolate->debug()->OnBeforeCompile(script);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(info->is_eval() || info->is_global());
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-09-29 07:53:22 +00:00
|
|
|
info->MarkAsToplevel();
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<SharedFunctionInfo> result;
|
|
|
|
|
|
|
|
{ VMState<COMPILER> state(info->isolate());
|
2014-09-12 09:12:08 +00:00
|
|
|
if (info->function() == NULL) {
|
|
|
|
// Parse the script if needed (if it's already parsed, function() is
|
|
|
|
// non-NULL).
|
|
|
|
bool parse_allow_lazy =
|
|
|
|
(info->compile_options() == ScriptCompiler::kConsumeParserCache ||
|
|
|
|
String::cast(script->source())->length() >
|
|
|
|
FLAG_min_preparse_length) &&
|
|
|
|
!Compiler::DebuggerWantsEagerCompilation(info);
|
|
|
|
|
|
|
|
if (!parse_allow_lazy &&
|
|
|
|
(info->compile_options() == ScriptCompiler::kProduceParserCache ||
|
|
|
|
info->compile_options() == ScriptCompiler::kConsumeParserCache)) {
|
|
|
|
// 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.
|
|
|
|
info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions);
|
|
|
|
}
|
|
|
|
if (!Parser::Parse(info, parse_allow_lazy)) {
|
|
|
|
return Handle<SharedFunctionInfo>::null();
|
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionLiteral* lit = info->function();
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Compile the code.
|
|
|
|
if (!CompileUnoptimizedCode(info)) {
|
|
|
|
return Handle<SharedFunctionInfo>::null();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate function.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!info->code().is_null());
|
2013-12-23 14:30:35 +00:00
|
|
|
result = isolate->factory()->NewSharedFunctionInfo(
|
2014-09-10 16:39:42 +00:00
|
|
|
lit->name(), lit->materialized_literal_count(), lit->kind(),
|
|
|
|
info->code(), ScopeInfo::Create(info->scope(), info->zone()),
|
2014-04-30 10:51:01 +00:00
|
|
|
info->feedback_vector());
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position());
|
2013-12-23 14:30:35 +00:00
|
|
|
SetFunctionInfo(result, lit, true, script);
|
|
|
|
|
|
|
|
Handle<String> script_name = script->name()->IsString()
|
|
|
|
? Handle<String>(String::cast(script->name()))
|
|
|
|
: isolate->factory()->empty_string();
|
|
|
|
Logger::LogEventsAndTags log_tag = info->is_eval()
|
|
|
|
? Logger::EVAL_TAG
|
|
|
|
: Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script);
|
|
|
|
|
|
|
|
PROFILE(isolate, CodeCreateEvent(
|
|
|
|
log_tag, *info->code(), *result, info, *script_name));
|
|
|
|
GDBJIT(AddCode(script_name, script, info->code(), info));
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2014-06-26 15:12:04 +00:00
|
|
|
isolate->debug()->OnAfterCompile(script);
|
2013-12-23 14:30:35 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
Handle<Context> context, StrictMode strict_mode,
|
|
|
|
ParseRestriction restriction, int scope_position) {
|
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 =
|
2014-10-28 10:00:37 +00:00
|
|
|
compilation_cache->LookupEval(source, outer_info, context, strict_mode,
|
2014-04-08 12:33:08 +00:00
|
|
|
scope_position);
|
|
|
|
Handle<SharedFunctionInfo> shared_info;
|
2013-12-23 14:30:35 +00:00
|
|
|
|
2014-04-08 12:33:08 +00:00
|
|
|
if (!maybe_shared_info.ToHandle(&shared_info)) {
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<Script> script = isolate->factory()->NewScript(source);
|
|
|
|
CompilationInfoWithZone info(script);
|
|
|
|
info.MarkAsEval();
|
|
|
|
if (context->IsNativeContext()) info.MarkAsGlobal();
|
2014-03-11 14:41:22 +00:00
|
|
|
info.SetStrictMode(strict_mode);
|
2013-12-23 14:30:35 +00:00
|
|
|
info.SetParseRestriction(restriction);
|
|
|
|
info.SetContext(context);
|
|
|
|
|
|
|
|
Debug::RecordEvalCaller(script);
|
|
|
|
|
|
|
|
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.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(strict_mode == SLOPPY || shared_info->strict_mode() == STRICT);
|
2013-12-23 14:30:35 +00:00
|
|
|
if (!shared_info->dont_cache()) {
|
2014-10-28 10:00:37 +00:00
|
|
|
compilation_cache->PutEval(source, outer_info, context, shared_info,
|
|
|
|
scope_position);
|
2013-12-23 14:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
|
|
|
|
shared_info->ResetForNewContext(isolate->heap()->global_ic_age());
|
|
|
|
}
|
|
|
|
|
|
|
|
return isolate->factory()->NewFunctionFromSharedFunctionInfo(
|
|
|
|
shared_info, context, NOT_TENURED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-19 13:24:13 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::CompileScript(
|
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,
|
|
|
|
int column_offset, bool is_shared_cross_origin, Handle<Context> context,
|
|
|
|
v8::Extension* extension, ScriptData** cached_data,
|
|
|
|
ScriptCompiler::CompileOptions compile_options, NativesFlag natives) {
|
2014-12-11 12:58:36 +00:00
|
|
|
Isolate* isolate = source->GetIsolate();
|
2015-01-19 11:32:58 +00:00
|
|
|
HistogramTimerScope total(isolate->counters()->compile_script(), true);
|
2015-01-14 15:22:40 +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
|
|
|
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);
|
|
|
|
|
|
|
|
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) {
|
2014-07-22 10:35:38 +00:00
|
|
|
if (FLAG_serialize_toplevel &&
|
2014-07-23 08:27:04 +00:00
|
|
|
compile_options == ScriptCompiler::kConsumeCodeCache &&
|
|
|
|
!isolate->debug()->is_loaded()) {
|
2014-09-22 17:19:19 +00:00
|
|
|
HistogramTimerScope timer(isolate->counters()->compile_deserialize());
|
2014-10-15 14:04:53 +00:00
|
|
|
Handle<SharedFunctionInfo> result;
|
|
|
|
if (CodeSerializer::Deserialize(isolate, *cached_data, source)
|
|
|
|
.ToHandle(&result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
// Deserializer failed. Fall through to compile.
|
2014-07-22 10:35:38 +00:00
|
|
|
} else {
|
|
|
|
maybe_result = compilation_cache->LookupScript(
|
|
|
|
source, script_name, line_offset, column_offset,
|
|
|
|
is_shared_cross_origin, context);
|
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) {
|
|
|
|
script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
|
|
|
|
}
|
2008-09-11 10:51:52 +00:00
|
|
|
if (!script_name.is_null()) {
|
|
|
|
script->set_name(*script_name);
|
|
|
|
script->set_line_offset(Smi::FromInt(line_offset));
|
|
|
|
script->set_column_offset(Smi::FromInt(column_offset));
|
|
|
|
}
|
2013-07-30 17:05:50 +00:00
|
|
|
script->set_is_shared_cross_origin(is_shared_cross_origin);
|
2008-09-11 10:51:52 +00:00
|
|
|
|
|
|
|
// Compile the function and add it to the cache.
|
2012-06-20 08:58:41 +00:00
|
|
|
CompilationInfoWithZone info(script);
|
2010-10-04 11:35:46 +00:00
|
|
|
info.MarkAsGlobal();
|
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
|
|
|
info.SetCachedData(cached_data, compile_options);
|
2014-07-08 09:04:08 +00:00
|
|
|
info.SetExtension(extension);
|
2012-08-28 11:25:08 +00:00
|
|
|
info.SetContext(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();
|
|
|
|
}
|
2014-03-11 14:41:22 +00:00
|
|
|
if (FLAG_use_strict) info.SetStrictMode(STRICT);
|
2014-07-08 09:04:08 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
result = CompileToplevel(&info);
|
2012-07-09 08:59:03 +00:00
|
|
|
if (extension == NULL && !result.is_null() && !result->dont_cache()) {
|
2012-08-28 10:49:23 +00:00
|
|
|
compilation_cache->PutScript(source, context, 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());
|
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
|
|
|
|
2014-04-08 12:33:08 +00:00
|
|
|
if (result.is_null()) isolate->ReportPendingMessages();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-12 09:12:08 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::CompileStreamedScript(
|
|
|
|
CompilationInfo* info, int source_length) {
|
|
|
|
Isolate* isolate = info->isolate();
|
|
|
|
isolate->counters()->total_load_size()->Increment(source_length);
|
|
|
|
isolate->counters()->total_compile_size()->Increment(source_length);
|
|
|
|
|
|
|
|
if (FLAG_use_strict) info->SetStrictMode(STRICT);
|
|
|
|
// TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the
|
|
|
|
// real code caching lands, streaming needs to be adapted to use it.
|
|
|
|
return CompileToplevel(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-23 09:35:06 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
|
|
|
|
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.
|
|
|
|
CompilationInfoWithZone info(script);
|
|
|
|
info.SetFunction(literal);
|
2014-02-10 21:38:17 +00:00
|
|
|
info.PrepareForCompilation(literal->scope());
|
2014-03-11 14:41:22 +00:00
|
|
|
info.SetStrictMode(literal->scope()->strict_mode());
|
2014-07-23 09:35:06 +00:00
|
|
|
if (outer_info->will_serialize()) info.PrepareForSerializing();
|
2009-08-13 10:25:35 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
Isolate* isolate = info.isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
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();
|
|
|
|
bool allow_lazy = literal->AllowsLazyCompilation() &&
|
|
|
|
!DebuggerWantsEagerCompilation(&info, allow_lazy_without_ctx);
|
2012-02-14 14:14:51 +00:00
|
|
|
|
2014-09-29 07:53:22 +00:00
|
|
|
if (outer_info->is_toplevel() && outer_info->will_serialize()) {
|
|
|
|
// Make sure that if the toplevel code (possibly to be serialized),
|
2014-11-03 17:23:55 +00:00
|
|
|
// the inner function must be allowed to be compiled lazily.
|
2014-11-20 16:20:48 +00:00
|
|
|
// This is necessary to serialize toplevel code without inner functions.
|
2014-09-29 07:53:22 +00:00
|
|
|
DCHECK(allow_lazy);
|
|
|
|
}
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
// Generate code
|
|
|
|
Handle<ScopeInfo> scope_info;
|
|
|
|
if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) {
|
2014-09-17 15:29:42 +00:00
|
|
|
Handle<Code> code = isolate->builtins()->CompileLazy();
|
2013-12-23 14:30:35 +00:00
|
|
|
info.SetCode(code);
|
2014-11-14 08:21:13 +00:00
|
|
|
// There's no need in theory for a lazy-compiled function to have a type
|
|
|
|
// feedback vector, but some parts of the system expect all
|
|
|
|
// SharedFunctionInfo instances to have one. The size of the vector depends
|
|
|
|
// on how many feedback-needing nodes are in the tree, and when lazily
|
|
|
|
// parsing we might not know that, if this function was never parsed before.
|
|
|
|
// In that case the vector will be replaced the next time MakeCode is
|
|
|
|
// called.
|
|
|
|
info.EnsureFeedbackVector();
|
2013-12-23 14:30:35 +00:00
|
|
|
scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate));
|
2014-10-28 13:23:54 +00:00
|
|
|
} else if (Renumber(&info) && FullCodeGenerator::MakeCode(&info)) {
|
2014-11-14 08:21:13 +00:00
|
|
|
// MakeCode will ensure that the feedback vector is present and
|
|
|
|
// appropriately sized.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!info.code().is_null());
|
2013-12-23 14:30:35 +00:00
|
|
|
scope_info = ScopeInfo::Create(info.scope(), info.zone());
|
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
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
// Create a shared function info object.
|
2014-07-21 09:58:01 +00:00
|
|
|
Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo(
|
2014-09-10 16:39:42 +00:00
|
|
|
literal->name(), literal->materialized_literal_count(), literal->kind(),
|
|
|
|
info.code(), scope_info, info.feedback_vector());
|
2013-12-23 14:30:35 +00:00
|
|
|
SetFunctionInfo(result, literal, false, script);
|
|
|
|
RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
|
|
|
|
result->set_allows_lazy_compilation(allow_lazy);
|
|
|
|
result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
|
|
|
|
|
|
|
|
// 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());
|
2008-09-11 10:51:52 +00:00
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-22 14:55:47 +00:00
|
|
|
MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function,
|
|
|
|
Handle<Code> current_code,
|
|
|
|
ConcurrencyMode mode,
|
|
|
|
BailoutId osr_ast_id) {
|
|
|
|
Handle<Code> cached_code;
|
|
|
|
if (GetCodeFromOptimizedCodeMap(
|
|
|
|
function, osr_ast_id).ToHandle(&cached_code)) {
|
|
|
|
return cached_code;
|
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
|
|
|
|
SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(function));
|
|
|
|
Isolate* isolate = info->isolate();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(AllowCompilation::IsAllowed(isolate));
|
2013-04-24 14:44:08 +00:00
|
|
|
VMState<COMPILER> state(isolate);
|
2014-11-25 12:46:45 +00:00
|
|
|
DCHECK(isolate->use_crankshaft());
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!isolate->has_pending_exception());
|
2012-07-19 18:58:23 +00:00
|
|
|
PostponeInterruptsScope postpone(isolate);
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
2014-09-04 14:07:17 +00:00
|
|
|
if (shared->code()->kind() != Code::FUNCTION ||
|
|
|
|
ScopeInfo::Empty(isolate) == shared->scope_info()) {
|
2014-09-04 11:27:20 +00:00
|
|
|
// The function was never compiled. Compile it unoptimized first.
|
2014-09-18 08:47:13 +00:00
|
|
|
// TODO(titzer): reuse the AST and scope info from this compile.
|
2014-09-04 11:27:20 +00:00
|
|
|
CompilationInfoWithZone nested(function);
|
|
|
|
nested.EnableDeoptimizationSupport();
|
|
|
|
if (!GetUnoptimizedCodeCommon(&nested).ToHandle(¤t_code)) {
|
|
|
|
return MaybeHandle<Code>();
|
|
|
|
}
|
2014-09-05 15:31:33 +00:00
|
|
|
shared->ReplaceCode(*current_code);
|
2014-09-04 11:27:20 +00:00
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
current_code->set_profiler_ticks(0);
|
2012-07-19 18:58:23 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
info->SetOptimizing(osr_ast_id, current_code);
|
2012-07-19 18:58:23 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
if (mode == CONCURRENT) {
|
|
|
|
if (GetOptimizedCodeLater(info.get())) {
|
|
|
|
info.Detach(); // The background recompile job owns this now.
|
|
|
|
return isolate->builtins()->InOptimizationQueue();
|
2012-11-16 14:24:19 +00:00
|
|
|
}
|
2013-12-23 14:30:35 +00:00
|
|
|
} else {
|
|
|
|
if (GetOptimizedCodeNow(info.get())) return info->code();
|
|
|
|
}
|
2012-07-19 18:58:23 +00:00
|
|
|
|
2013-03-12 18:03:18 +00:00
|
|
|
if (isolate->has_pending_exception()) isolate->clear_pending_exception();
|
2014-04-22 14:55:47 +00:00
|
|
|
return MaybeHandle<Code>();
|
2012-07-19 18:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
Handle<Code> Compiler::GetConcurrentlyOptimizedCode(OptimizedCompileJob* job) {
|
|
|
|
// Take ownership of compilation info. Deleting compilation info
|
|
|
|
// also tears down the zone and the recompile job.
|
2013-09-25 10:01:18 +00:00
|
|
|
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());
|
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);
|
|
|
|
|
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.
|
|
|
|
// 4) Debugger may have been activated.
|
2014-09-24 07:08:27 +00:00
|
|
|
// 5) Code generation may have failed.
|
|
|
|
if (job->last_status() == OptimizedCompileJob::SUCCEEDED) {
|
|
|
|
if (shared->optimization_disabled()) {
|
|
|
|
job->RetryOptimization(kOptimizationDisabled);
|
|
|
|
} else if (info->HasAbortedDueToDependencyChange()) {
|
|
|
|
job->RetryOptimization(kBailedOutDueToDependencyChange);
|
2015-01-19 16:51:39 +00:00
|
|
|
} else if (isolate->debug()->has_break_points()) {
|
2014-09-24 07:08:27 +00:00
|
|
|
job->RetryOptimization(kDebuggerHasBreakPoints);
|
|
|
|
} else if (job->GenerateCode() == OptimizedCompileJob::SUCCEEDED) {
|
|
|
|
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info.get(), shared);
|
|
|
|
if (info->shared_info()->SearchOptimizedCodeMap(
|
|
|
|
info->context()->native_context(), info->osr_ast_id()) == -1) {
|
|
|
|
InsertCodeIntoOptimizedCodeMap(info.get());
|
|
|
|
}
|
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
PrintF("[completed optimizing ");
|
|
|
|
info->closure()->ShortPrint();
|
|
|
|
PrintF("]\n");
|
|
|
|
}
|
|
|
|
return Handle<Code>(*info->code());
|
|
|
|
}
|
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
|
|
|
}
|
2014-09-24 07:08:27 +00:00
|
|
|
return Handle<Code>::null();
|
2009-11-04 17:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-12 09:12:08 +00:00
|
|
|
bool Compiler::DebuggerWantsEagerCompilation(CompilationInfo* info,
|
|
|
|
bool allow_lazy_without_ctx) {
|
2014-10-29 10:28:11 +00:00
|
|
|
if (LiveEditFunctionTracker::IsActive(info->isolate())) return true;
|
|
|
|
Debug* debug = info->isolate()->debug();
|
|
|
|
bool debugging = debug->is_active() || debug->has_break_points();
|
|
|
|
return debugging && !allow_lazy_without_ctx;
|
2014-09-12 09:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-27 13:03:01 +00:00
|
|
|
CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info)
|
|
|
|
: name_(name), info_(info), zone_(info->isolate()) {
|
2013-06-25 12:22:26 +00:00
|
|
|
if (FLAG_hydrogen_stats) {
|
2013-06-27 13:03:01 +00:00
|
|
|
info_zone_start_allocation_size_ = info->zone()->allocation_size();
|
2013-08-29 09:15:13 +00:00
|
|
|
timer_.Start();
|
2013-06-25 12:22:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CompilationPhase::~CompilationPhase() {
|
|
|
|
if (FLAG_hydrogen_stats) {
|
2013-06-27 13:03:01 +00:00
|
|
|
unsigned size = zone()->allocation_size();
|
|
|
|
size += info_->zone()->allocation_size() - info_zone_start_allocation_size_;
|
2013-08-29 09:15:13 +00:00
|
|
|
isolate()->GetHStatistics()->SaveTiming(name_, timer_.Elapsed(), size);
|
2013-06-25 12:22:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CompilationPhase::ShouldProduceTraceOutput() const {
|
2013-07-24 12:38:52 +00:00
|
|
|
// Trace if the appropriate trace flag is set and the phase name's first
|
|
|
|
// character is in the FLAG_trace_phase command line parameter.
|
2013-08-27 08:49:27 +00:00
|
|
|
AllowHandleDereference allow_deref;
|
2013-08-23 13:30:02 +00:00
|
|
|
bool tracing_on = info()->IsStub()
|
|
|
|
? FLAG_trace_hydrogen_stubs
|
|
|
|
: (FLAG_trace_hydrogen &&
|
|
|
|
info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter));
|
2013-07-24 12:38:52 +00:00
|
|
|
return (tracing_on &&
|
2014-06-30 13:25:46 +00:00
|
|
|
base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
|
2013-06-25 12:22:26 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|