2012-02-08 09:56:33 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2010-10-01 14:10:47 +00:00
|
|
|
#include "compiler.h"
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "bootstrapper.h"
|
2011-04-07 14:42:37 +00:00
|
|
|
#include "codegen.h"
|
2008-09-11 10:51:52 +00:00
|
|
|
#include "compilation-cache.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "debug.h"
|
2010-01-20 16:28:21 +00:00
|
|
|
#include "full-codegen.h"
|
2011-01-18 16:11:01 +00:00
|
|
|
#include "gdb-jit.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "hydrogen.h"
|
2011-10-03 11:13:20 +00:00
|
|
|
#include "isolate-inl.h"
|
2011-01-19 13:55:56 +00:00
|
|
|
#include "lithium.h"
|
2010-03-08 13:01:24 +00:00
|
|
|
#include "liveedit.h"
|
2010-10-01 14:10:47 +00:00
|
|
|
#include "parser.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "rewriter.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "runtime-profiler.h"
|
2011-09-08 13:06:44 +00:00
|
|
|
#include "scanner-character-streams.h"
|
2010-07-13 13:06:33 +00:00
|
|
|
#include "scopeinfo.h"
|
2010-10-01 14:10:47 +00:00
|
|
|
#include "scopes.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "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
|
|
|
|
2012-06-20 08:58:41 +00:00
|
|
|
CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
|
2011-03-18 20:35:07 +00:00
|
|
|
: isolate_(script->GetIsolate()),
|
2011-11-24 15:17:04 +00:00
|
|
|
flags_(LanguageModeField::encode(CLASSIC_MODE)),
|
2010-10-04 11:35:46 +00:00
|
|
|
function_(NULL),
|
|
|
|
scope_(NULL),
|
2011-11-15 13:48:40 +00:00
|
|
|
global_scope_(NULL),
|
2010-10-04 11:35:46 +00:00
|
|
|
script_(script),
|
|
|
|
extension_(NULL),
|
2010-12-07 11:31:57 +00:00
|
|
|
pre_parse_data_(NULL),
|
2012-08-06 14:13:09 +00:00
|
|
|
osr_ast_id_(BailoutId::None()),
|
2012-07-06 09:31:31 +00:00
|
|
|
zone_(zone),
|
|
|
|
deferred_handles_(NULL) {
|
2012-02-14 14:14:51 +00:00
|
|
|
Initialize(BASE);
|
2010-10-04 11:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-20 08:58:41 +00:00
|
|
|
CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
|
|
|
|
Zone* zone)
|
2011-03-18 20:35:07 +00:00
|
|
|
: isolate_(shared_info->GetIsolate()),
|
2011-11-24 15:17:04 +00:00
|
|
|
flags_(LanguageModeField::encode(CLASSIC_MODE) |
|
|
|
|
IsLazy::encode(true)),
|
2010-10-04 11:35:46 +00:00
|
|
|
function_(NULL),
|
|
|
|
scope_(NULL),
|
2011-11-15 13:48:40 +00:00
|
|
|
global_scope_(NULL),
|
2010-10-04 11:35:46 +00:00
|
|
|
shared_info_(shared_info),
|
|
|
|
script_(Handle<Script>(Script::cast(shared_info->script()))),
|
|
|
|
extension_(NULL),
|
2010-12-07 11:31:57 +00:00
|
|
|
pre_parse_data_(NULL),
|
2012-08-06 14:13:09 +00:00
|
|
|
osr_ast_id_(BailoutId::None()),
|
2012-07-06 09:31:31 +00:00
|
|
|
zone_(zone),
|
|
|
|
deferred_handles_(NULL) {
|
2010-12-07 11:31:57 +00:00
|
|
|
Initialize(BASE);
|
2010-10-04 11:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-20 08:58:41 +00:00
|
|
|
CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
|
2011-03-18 20:35:07 +00:00
|
|
|
: isolate_(closure->GetIsolate()),
|
2011-11-24 15:17:04 +00:00
|
|
|
flags_(LanguageModeField::encode(CLASSIC_MODE) |
|
|
|
|
IsLazy::encode(true)),
|
2010-10-04 11:35:46 +00:00
|
|
|
function_(NULL),
|
|
|
|
scope_(NULL),
|
2011-11-15 13:48:40 +00:00
|
|
|
global_scope_(NULL),
|
2010-10-04 11:35:46 +00:00
|
|
|
closure_(closure),
|
|
|
|
shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
|
|
|
|
script_(Handle<Script>(Script::cast(shared_info_->script()))),
|
|
|
|
extension_(NULL),
|
2010-12-07 11:31:57 +00:00
|
|
|
pre_parse_data_(NULL),
|
2012-08-28 11:25:08 +00:00
|
|
|
context_(closure->context()),
|
2012-08-06 14:13:09 +00:00
|
|
|
osr_ast_id_(BailoutId::None()),
|
2012-07-06 09:31:31 +00:00
|
|
|
zone_(zone),
|
|
|
|
deferred_handles_(NULL) {
|
2010-12-07 11:31:57 +00:00
|
|
|
Initialize(BASE);
|
2010-10-04 11:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-06 09:31:31 +00:00
|
|
|
CompilationInfo::~CompilationInfo() {
|
|
|
|
delete deferred_handles_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-19 13:15:57 +00:00
|
|
|
// Disable optimization for the rest of the compilation pipeline.
|
2011-01-17 08:11:03 +00:00
|
|
|
void CompilationInfo::DisableOptimization() {
|
2011-05-06 11:02:23 +00:00
|
|
|
bool is_optimizable_closure =
|
|
|
|
FLAG_optimize_closures &&
|
|
|
|
closure_.is_null() &&
|
|
|
|
!scope_->HasTrivialOuterContext() &&
|
2011-05-11 11:26:11 +00:00
|
|
|
!scope_->outer_scope_calls_non_strict_eval() &&
|
2011-05-06 11:02:23 +00:00
|
|
|
!scope_->inside_with();
|
|
|
|
SetMode(is_optimizable_closure ? BASE : NONOPT);
|
2011-01-17 08:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-09 10:19:46 +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() {
|
2012-02-09 13:30:01 +00:00
|
|
|
return FLAG_self_optimization &&
|
2012-02-09 10:19:46 +00:00
|
|
|
FLAG_crankshaft &&
|
|
|
|
!function()->flags()->Contains(kDontSelfOptimize) &&
|
2012-02-27 08:11:04 +00:00
|
|
|
!function()->flags()->Contains(kDontOptimize) &&
|
2012-06-19 14:29:48 +00:00
|
|
|
function()->scope()->AllowsLazyCompilation() &&
|
2012-02-09 10:19:46 +00:00
|
|
|
(shared_info().is_null() || !shared_info()->optimization_disabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-19 13:15:57 +00:00
|
|
|
void CompilationInfo::AbortOptimization() {
|
|
|
|
Handle<Code> code(shared_info()->code());
|
|
|
|
SetCode(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Determine whether to use the full compiler for all code. If the flag
|
|
|
|
// --always-full-compiler is specified this is the case. For the virtual frame
|
|
|
|
// based compiler the full compiler is also used if a debugger is connected, as
|
|
|
|
// the code from the full compiler supports mode precise break points. For the
|
|
|
|
// crankshaft adaptive compiler debugging the optimized code is not possible at
|
|
|
|
// all. However crankshaft support recompilation of functions, so in this case
|
|
|
|
// the full compiler need not be be used if a debugger is attached, but only if
|
|
|
|
// break points has actually been set.
|
2012-06-19 14:29:48 +00:00
|
|
|
static bool IsDebuggerActive(Isolate* isolate) {
|
2010-05-25 14:08:17 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2011-05-06 11:02:23 +00:00
|
|
|
return V8::UseCrankshaft() ?
|
|
|
|
isolate->debug()->has_break_points() :
|
|
|
|
isolate->debugger()->IsDebuggerActive();
|
2010-05-25 14:08:17 +00:00
|
|
|
#else
|
2011-05-06 11:02:23 +00:00
|
|
|
return false;
|
2010-05-25 14:08:17 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
|
2012-06-19 14:29:48 +00:00
|
|
|
static bool AlwaysFullCompiler(Isolate* isolate) {
|
|
|
|
return FLAG_always_full_compiler || IsDebuggerActive(isolate);
|
2011-05-06 11:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
void OptimizingCompiler::RecordOptimizationStats() {
|
|
|
|
Handle<JSFunction> function = info()->closure();
|
2010-12-07 11:31:57 +00:00
|
|
|
int opt_count = function->shared()->opt_count();
|
|
|
|
function->shared()->set_opt_count(opt_count + 1);
|
2012-07-17 16:24:40 +00:00
|
|
|
double ms_creategraph =
|
|
|
|
static_cast<double>(time_taken_to_create_graph_) / 1000;
|
|
|
|
double ms_optimize = static_cast<double>(time_taken_to_optimize_) / 1000;
|
|
|
|
double ms_codegen = static_cast<double>(time_taken_to_codegen_) / 1000;
|
2010-12-09 13:12:23 +00:00
|
|
|
if (FLAG_trace_opt) {
|
|
|
|
PrintF("[optimizing: ");
|
|
|
|
function->PrintName();
|
|
|
|
PrintF(" / %" V8PRIxPTR, reinterpret_cast<intptr_t>(*function));
|
2012-07-17 16:24:40 +00:00
|
|
|
PrintF(" - took %0.3f, %0.3f, %0.3f ms]\n", ms_creategraph, ms_optimize,
|
|
|
|
ms_codegen);
|
2010-12-09 13:12:23 +00:00
|
|
|
}
|
|
|
|
if (FLAG_trace_opt_stats) {
|
|
|
|
static double compilation_time = 0.0;
|
|
|
|
static int compiled_functions = 0;
|
|
|
|
static int code_size = 0;
|
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
compilation_time += (ms_creategraph + ms_optimize + ms_codegen);
|
2010-12-09 13:12:23 +00:00
|
|
|
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);
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
// A return value of true indicates the compilation pipeline is still
|
|
|
|
// going, not necessarily that we optimized the code.
|
2010-12-07 11:31:57 +00:00
|
|
|
static bool MakeCrankshaftCode(CompilationInfo* info) {
|
2012-07-17 16:24:40 +00:00
|
|
|
OptimizingCompiler compiler(info);
|
|
|
|
OptimizingCompiler::Status status = compiler.CreateGraph();
|
|
|
|
|
|
|
|
if (status != OptimizingCompiler::SUCCEEDED) {
|
|
|
|
return status != OptimizingCompiler::FAILED;
|
|
|
|
}
|
|
|
|
status = compiler.OptimizeGraph();
|
|
|
|
if (status != OptimizingCompiler::SUCCEEDED) {
|
2012-07-19 18:58:23 +00:00
|
|
|
status = compiler.AbortOptimization();
|
2012-07-17 16:24:40 +00:00
|
|
|
return status != OptimizingCompiler::FAILED;
|
|
|
|
}
|
|
|
|
status = compiler.GenerateAndInstallCode();
|
|
|
|
return status != OptimizingCompiler::FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OptimizingCompiler::Status OptimizingCompiler::CreateGraph() {
|
2012-07-05 13:11:57 +00:00
|
|
|
ASSERT(V8::UseCrankshaft());
|
2012-07-17 16:24:40 +00:00
|
|
|
ASSERT(info()->IsOptimizing());
|
|
|
|
ASSERT(!info()->IsCompilingForDebugging());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
// We should never arrive here if there is no code object on the
|
2010-12-07 11:31:57 +00:00
|
|
|
// shared function object.
|
2012-07-17 16:24:40 +00:00
|
|
|
Handle<Code> code(info()->shared_info()->code());
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(code->kind() == Code::FUNCTION);
|
|
|
|
|
2011-03-28 05:57:27 +00:00
|
|
|
// We should never arrive here if optimization has been disabled on the
|
|
|
|
// shared function info.
|
2012-07-17 16:24:40 +00:00
|
|
|
ASSERT(!info()->shared_info()->optimization_disabled());
|
2011-03-28 05:57:27 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Fall back to using the full code generator if it's not possible
|
|
|
|
// to use the Hydrogen-based optimizing compiler. We already have
|
|
|
|
// generated code for this from the shared function object.
|
2012-07-17 16:24:40 +00:00
|
|
|
if (AlwaysFullCompiler(info()->isolate())) {
|
|
|
|
info()->SetCode(code);
|
|
|
|
return SetLastStatus(BAILED_OUT);
|
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;
|
2012-07-17 16:24:40 +00:00
|
|
|
if (info()->shared_info()->opt_count() > kMaxOptCount) {
|
2012-08-28 07:18:06 +00:00
|
|
|
info()->set_bailout_reason("optimized too many times");
|
2012-07-17 16:24:40 +00:00
|
|
|
return AbortOptimization();
|
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.
|
2011-06-22 13:08:40 +00:00
|
|
|
const int parameter_limit = -LUnallocated::kMinFixedIndex;
|
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) {
|
|
|
|
info()->set_bailout_reason("too many parameters");
|
|
|
|
return AbortOptimization();
|
|
|
|
}
|
|
|
|
|
|
|
|
const int locals_limit = LUnallocated::kMaxFixedIndex;
|
|
|
|
if (!info()->osr_ast_id().IsNone() &&
|
|
|
|
scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) {
|
|
|
|
info()->set_bailout_reason("too many parameters/locals");
|
2012-07-17 16:24:40 +00:00
|
|
|
return AbortOptimization();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Take --hydrogen-filter into account.
|
2012-07-17 16:24:40 +00:00
|
|
|
Handle<String> name = info()->function()->debug_name();
|
2012-03-14 09:45:17 +00:00
|
|
|
if (*FLAG_hydrogen_filter != '\0') {
|
|
|
|
Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
|
|
|
|
if ((filter[0] == '-'
|
|
|
|
&& name->IsEqualTo(filter.SubVector(1, filter.length())))
|
|
|
|
|| (filter[0] != '-' && !name->IsEqualTo(filter))) {
|
2012-07-17 16:24:40 +00:00
|
|
|
info()->SetCode(code);
|
|
|
|
return SetLastStatus(BAILED_OUT);
|
2012-03-14 09:45:17 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Recompile the unoptimized version of the code if the current version
|
|
|
|
// doesn't have deoptimization support. Alternatively, we may decide to
|
|
|
|
// run the full code generator to get a baseline for the compile-time
|
|
|
|
// performance of the hydrogen-based compiler.
|
2012-07-17 16:24:40 +00:00
|
|
|
Timer t(this, &time_taken_to_create_graph_);
|
|
|
|
bool should_recompile = !info()->shared_info()->has_deoptimization_support();
|
2011-03-10 13:26:51 +00:00
|
|
|
if (should_recompile || FLAG_hydrogen_stats) {
|
2010-12-07 11:31:57 +00:00
|
|
|
HPhase phase(HPhase::kFullCodeGen);
|
2012-07-17 16:24:40 +00:00
|
|
|
CompilationInfoWithZone unoptimized(info()->shared_info());
|
2010-12-07 11:31:57 +00:00
|
|
|
// Note that we use the same AST that we will use for generating the
|
|
|
|
// optimized code.
|
2012-07-17 16:24:40 +00:00
|
|
|
unoptimized.SetFunction(info()->function());
|
|
|
|
unoptimized.SetScope(info()->scope());
|
2012-08-28 11:25:08 +00:00
|
|
|
unoptimized.SetContext(info()->context());
|
2010-12-07 11:31:57 +00:00
|
|
|
if (should_recompile) unoptimized.EnableDeoptimizationSupport();
|
|
|
|
bool succeeded = FullCodeGenerator::MakeCode(&unoptimized);
|
|
|
|
if (should_recompile) {
|
2012-07-17 16:24:40 +00:00
|
|
|
if (!succeeded) return SetLastStatus(FAILED);
|
|
|
|
Handle<SharedFunctionInfo> shared = info()->shared_info();
|
2010-12-07 11:31:57 +00:00
|
|
|
shared->EnableDeoptimizationSupport(*unoptimized.code());
|
|
|
|
// The existing unoptimized code was replaced with the new one.
|
2011-02-22 16:31:24 +00:00
|
|
|
Compiler::RecordFunctionCompilation(
|
|
|
|
Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the unoptimized, shared code is ready for
|
|
|
|
// optimizations. When using the always_opt flag we disregard the
|
|
|
|
// optimizable marker in the code object and optimize anyway. This
|
|
|
|
// is safe as long as the unoptimized code has deoptimization
|
|
|
|
// support.
|
2011-02-18 14:22:29 +00:00
|
|
|
ASSERT(FLAG_always_opt || code->optimizable());
|
2012-07-17 16:24:40 +00:00
|
|
|
ASSERT(info()->shared_info()->has_deoptimization_support());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
if (FLAG_trace_hydrogen) {
|
|
|
|
PrintF("-----------------------------------------------------------\n");
|
|
|
|
PrintF("Compiling method %s using hydrogen\n", *name->ToCString());
|
2012-07-17 16:24:40 +00:00
|
|
|
HTracer::Instance()->TraceCompilation(info()->function());
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context(
|
|
|
|
info()->closure()->context()->native_context());
|
2012-07-17 16:24:40 +00:00
|
|
|
oracle_ = new(info()->zone()) TypeFeedbackOracle(
|
2012-08-17 09:03:08 +00:00
|
|
|
code, native_context, info()->isolate(), info()->zone());
|
2012-07-17 16:24:40 +00:00
|
|
|
graph_builder_ = new(info()->zone()) HGraphBuilder(info(), oracle_);
|
2010-12-07 11:31:57 +00:00
|
|
|
HPhase phase(HPhase::kTotal);
|
2012-07-17 16:24:40 +00:00
|
|
|
graph_ = graph_builder_->CreateGraph();
|
|
|
|
|
|
|
|
if (info()->isolate()->has_pending_exception()) {
|
|
|
|
info()->SetCode(Handle<Code>::null());
|
|
|
|
return SetLastStatus(FAILED);
|
2011-02-11 14:26:56 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
// The function being compiled may have bailed out due to an inline
|
|
|
|
// candidate bailing out. In such a case, we don't disable
|
|
|
|
// optimization on the shared_info.
|
|
|
|
ASSERT(!graph_builder_->inline_bailout() || graph_ == NULL);
|
|
|
|
if (graph_ == NULL) {
|
|
|
|
if (graph_builder_->inline_bailout()) {
|
|
|
|
info_->AbortOptimization();
|
|
|
|
return SetLastStatus(BAILED_OUT);
|
2012-07-12 15:10:34 +00:00
|
|
|
} else {
|
2012-07-17 16:24:40 +00:00
|
|
|
return AbortOptimization();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
return SetLastStatus(SUCCEEDED);
|
|
|
|
}
|
|
|
|
|
|
|
|
OptimizingCompiler::Status OptimizingCompiler::OptimizeGraph() {
|
2012-07-19 18:58:23 +00:00
|
|
|
AssertNoAllocation no_gc;
|
|
|
|
NoHandleAllocation no_handles;
|
|
|
|
|
2012-07-17 16:24:40 +00:00
|
|
|
ASSERT(last_status() == SUCCEEDED);
|
|
|
|
Timer t(this, &time_taken_to_optimize_);
|
|
|
|
ASSERT(graph_ != NULL);
|
|
|
|
SmartArrayPointer<char> bailout_reason;
|
|
|
|
if (!graph_->Optimize(&bailout_reason)) {
|
|
|
|
if (!bailout_reason.is_empty()) graph_builder_->Bailout(*bailout_reason);
|
2012-07-19 18:58:23 +00:00
|
|
|
return SetLastStatus(BAILED_OUT);
|
2012-07-17 16:24:40 +00:00
|
|
|
} else {
|
|
|
|
chunk_ = LChunk::NewChunk(graph_);
|
|
|
|
if (chunk_ == NULL) {
|
2012-07-19 18:58:23 +00:00
|
|
|
return SetLastStatus(BAILED_OUT);
|
2012-07-17 16:24:40 +00:00
|
|
|
}
|
2011-05-19 13:15:57 +00:00
|
|
|
}
|
2012-07-17 16:24:40 +00:00
|
|
|
return SetLastStatus(SUCCEEDED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() {
|
|
|
|
ASSERT(last_status() == SUCCEEDED);
|
|
|
|
Timer timer(this, &time_taken_to_codegen_);
|
|
|
|
ASSERT(chunk_ != NULL);
|
|
|
|
ASSERT(graph_ != NULL);
|
|
|
|
Handle<Code> optimized_code = chunk_->Codegen();
|
2012-08-28 07:18:06 +00:00
|
|
|
if (optimized_code.is_null()) {
|
|
|
|
info()->set_bailout_reason("code generation failed");
|
|
|
|
return AbortOptimization();
|
|
|
|
}
|
2012-07-17 16:24:40 +00:00
|
|
|
info()->SetCode(optimized_code);
|
|
|
|
RecordOptimizationStats();
|
|
|
|
return SetLastStatus(SUCCEEDED);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-06 11:02:23 +00:00
|
|
|
static bool GenerateCode(CompilationInfo* info) {
|
2012-07-05 13:11:57 +00:00
|
|
|
bool is_optimizing = V8::UseCrankshaft() &&
|
|
|
|
!info->IsCompilingForDebugging() &&
|
|
|
|
info->IsOptimizing();
|
|
|
|
if (is_optimizing) {
|
|
|
|
return MakeCrankshaftCode(info);
|
|
|
|
} else {
|
|
|
|
if (info->IsOptimizing()) {
|
|
|
|
// Have the CompilationInfo decide if the compilation should be
|
|
|
|
// BASE or NONOPT.
|
|
|
|
info->DisableOptimization();
|
|
|
|
}
|
|
|
|
return FullCodeGenerator::MakeCode(info);
|
|
|
|
}
|
2011-05-06 11:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
static bool MakeCode(CompilationInfo* info) {
|
|
|
|
// Precondition: code has been parsed. Postcondition: the code field in
|
|
|
|
// the compilation info is set if compilation succeeded.
|
|
|
|
ASSERT(info->function() != NULL);
|
2011-05-06 11:02:23 +00:00
|
|
|
return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-05 22:08:58 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2010-10-04 14:30:43 +00:00
|
|
|
bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) {
|
|
|
|
// Precondition: code has been parsed. Postcondition: the code field in
|
|
|
|
// the compilation info is set if compilation succeeded.
|
|
|
|
bool succeeded = MakeCode(info);
|
2010-07-13 13:06:33 +00:00
|
|
|
if (!info->shared_info().is_null()) {
|
2012-06-11 12:42:31 +00:00
|
|
|
Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(),
|
2012-06-20 08:58:41 +00:00
|
|
|
info->zone());
|
2010-09-23 08:27:51 +00:00
|
|
|
info->shared_info()->set_scope_info(*scope_info);
|
2010-07-13 13:06:33 +00:00
|
|
|
}
|
2010-10-04 14:30:43 +00:00
|
|
|
return succeeded;
|
2010-03-05 22:08:58 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = info->isolate();
|
2012-06-20 08:58:41 +00:00
|
|
|
ZoneScope zone_scope(info->zone(), DELETE_ON_EXIT);
|
2011-03-18 20:35:07 +00:00
|
|
|
PostponeInterruptsScope postpone(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
ASSERT(!isolate->native_context().is_null());
|
2010-10-04 11:35:46 +00:00
|
|
|
Handle<Script> script = info->script();
|
2012-11-13 12:27:03 +00:00
|
|
|
// TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile?
|
|
|
|
FixedArray* array = isolate->native_context()->embedder_data();
|
|
|
|
script->set_context_data(array->get(0));
|
2009-06-08 10:47:49 +00:00
|
|
|
|
2010-02-01 10:31:55 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2010-10-27 09:19:43 +00:00
|
|
|
if (info->is_eval()) {
|
|
|
|
Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL;
|
2010-09-30 08:48:37 +00:00
|
|
|
script->set_compilation_type(Smi::FromInt(compilation_type));
|
2009-06-08 10:47:49 +00:00
|
|
|
// For eval scripts add information on the function from which eval was
|
|
|
|
// called.
|
2010-10-04 11:35:46 +00:00
|
|
|
if (info->is_eval()) {
|
Simplify isolates access during stack iteration (WAS: Move SafeStackFrameIterator::active_count_...)
While trying to fix Mac and Windows versions for this change:
http://codereview.chromium.org/6771047/, I figured out, that we
already store an isolate in StackFrameIterator, so we can use it in
frame objects, instead of requiring it from caller.
I've changed iterators usage to the following scheme: whenever a
caller maintains an isolate pointer, it just passes it to stack
iterator, and no more worries about passing it to frame content
accessors. If a caller uses current isolate, it can omit passing it
to iterator, in this case, an iterator will use the current isolate,
too.
There was a special case with LiveEdit, which creates
detached copies of frame objects.
R=vitalyr@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6794019
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7499 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-04-05 09:01:47 +00:00
|
|
|
StackTraceFrameIterator it(isolate);
|
2010-02-01 12:56:56 +00:00
|
|
|
if (!it.done()) {
|
|
|
|
script->set_eval_from_shared(
|
|
|
|
JSFunction::cast(it.frame()->function())->shared());
|
Simplify isolates access during stack iteration (WAS: Move SafeStackFrameIterator::active_count_...)
While trying to fix Mac and Windows versions for this change:
http://codereview.chromium.org/6771047/, I figured out, that we
already store an isolate in StackFrameIterator, so we can use it in
frame objects, instead of requiring it from caller.
I've changed iterators usage to the following scheme: whenever a
caller maintains an isolate pointer, it just passes it to stack
iterator, and no more worries about passing it to frame content
accessors. If a caller uses current isolate, it can omit passing it
to iterator, in this case, an iterator will use the current isolate,
too.
There was a special case with LiveEdit, which creates
detached copies of frame objects.
R=vitalyr@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6794019
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7499 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-04-05 09:01:47 +00:00
|
|
|
Code* code = it.frame()->LookupCode();
|
2010-02-01 12:56:56 +00:00
|
|
|
int offset = static_cast<int>(
|
2011-03-18 20:35:07 +00:00
|
|
|
it.frame()->pc() - code->instruction_start());
|
2010-02-01 12:56:56 +00:00
|
|
|
script->set_eval_from_instructions_offset(Smi::FromInt(offset));
|
|
|
|
}
|
2009-06-08 10:47:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Notify debugger
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->debugger()->OnBeforeCompile(script);
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Only allow non-global compiles for eval.
|
2010-10-04 11:35:46 +00:00
|
|
|
ASSERT(info->is_eval() || info->is_global());
|
2011-11-25 09:36:31 +00:00
|
|
|
ParsingFlags flags = kNoParsingFlags;
|
|
|
|
if (info->pre_parse_data() != NULL ||
|
|
|
|
String::cast(script->source())->length() > FLAG_min_preparse_length) {
|
|
|
|
flags = kAllowLazy;
|
|
|
|
}
|
|
|
|
if (!ParserApi::Parse(info, flags)) {
|
|
|
|
return Handle<SharedFunctionInfo>::null();
|
|
|
|
}
|
2008-07-16 07:07:30 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// 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.
|
2010-10-04 11:35:46 +00:00
|
|
|
HistogramTimer* rate = info->is_eval()
|
2011-03-23 11:13:07 +00:00
|
|
|
? info->isolate()->counters()->compile_eval()
|
|
|
|
: info->isolate()->counters()->compile();
|
2009-03-13 16:06:31 +00:00
|
|
|
HistogramTimerScope timer(rate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Compile the code.
|
2010-10-04 11:35:46 +00:00
|
|
|
FunctionLiteral* lit = info->function();
|
2011-03-18 20:35:07 +00:00
|
|
|
LiveEditFunctionTracker live_edit_tracker(isolate, lit);
|
2010-10-04 14:30:43 +00:00
|
|
|
if (!MakeCode(info)) {
|
2011-12-05 14:43:28 +00:00
|
|
|
if (!isolate->has_pending_exception()) isolate->StackOverflow();
|
2010-03-23 06:04:44 +00:00
|
|
|
return Handle<SharedFunctionInfo>::null();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 16:31:24 +00:00
|
|
|
// Allocate function.
|
2010-10-04 14:30:43 +00:00
|
|
|
ASSERT(!info->code().is_null());
|
2011-02-22 16:31:24 +00:00
|
|
|
Handle<SharedFunctionInfo> result =
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->factory()->NewSharedFunctionInfo(
|
2011-02-22 16:31:24 +00:00
|
|
|
lit->name(),
|
|
|
|
lit->materialized_literal_count(),
|
|
|
|
info->code(),
|
2012-06-20 08:58:41 +00:00
|
|
|
ScopeInfo::Create(info->scope(), info->zone()));
|
2011-02-22 16:31:24 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
|
|
|
|
Compiler::SetFunctionInfo(result, lit, true, script);
|
|
|
|
|
2010-03-25 14:55:53 +00:00
|
|
|
if (script->name()->IsString()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate, CodeCreateEvent(
|
2010-10-04 11:35:46 +00:00
|
|
|
info->is_eval()
|
|
|
|
? Logger::EVAL_TAG
|
|
|
|
: Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
|
2010-10-04 14:30:43 +00:00
|
|
|
*info->code(),
|
2011-02-22 16:31:24 +00:00
|
|
|
*result,
|
2010-10-04 11:35:46 +00:00
|
|
|
String::cast(script->name())));
|
2011-01-18 16:11:01 +00:00
|
|
|
GDBJIT(AddCode(Handle<String>(String::cast(script->name())),
|
|
|
|
script,
|
2011-06-30 11:52:00 +00:00
|
|
|
info->code(),
|
|
|
|
info));
|
2010-03-25 14:55:53 +00:00
|
|
|
} else {
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(isolate, CodeCreateEvent(
|
2010-10-04 11:35:46 +00:00
|
|
|
info->is_eval()
|
|
|
|
? Logger::EVAL_TAG
|
|
|
|
: Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
|
2010-10-04 14:30:43 +00:00
|
|
|
*info->code(),
|
2011-02-22 16:31:24 +00:00
|
|
|
*result,
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->heap()->empty_string()));
|
2011-06-30 11:52:00 +00:00
|
|
|
GDBJIT(AddCode(Handle<String>(), script, info->code(), info));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hint to the runtime system used when allocating space for initial
|
|
|
|
// property space by setting the expected number of properties for
|
|
|
|
// the instances of the function.
|
2010-03-23 06:04:44 +00:00
|
|
|
SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-03-15 11:51:26 +00:00
|
|
|
script->set_compilation_state(
|
|
|
|
Smi::FromInt(Script::COMPILATION_STATE_COMPILED));
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2008-07-03 15:10:15 +00:00
|
|
|
// Notify debugger
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->debugger()->OnAfterCompile(
|
|
|
|
script, Debugger::NO_AFTER_COMPILE_FLAGS);
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-06-20 08:58:41 +00:00
|
|
|
live_edit_tracker.RecordFunctionInfo(result, lit, info->zone());
|
2010-04-28 11:38:43 +00:00
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
|
|
|
|
Handle<Object> script_name,
|
|
|
|
int line_offset,
|
|
|
|
int column_offset,
|
2012-08-28 10:49:23 +00:00
|
|
|
Handle<Context> context,
|
2010-03-23 06:04:44 +00:00
|
|
|
v8::Extension* extension,
|
2011-11-25 09:36:31 +00:00
|
|
|
ScriptDataImpl* pre_data,
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<Object> script_data,
|
|
|
|
NativesFlag natives) {
|
2011-03-23 11:13:07 +00:00
|
|
|
Isolate* isolate = source->GetIsolate();
|
2008-11-03 10:16:05 +00:00
|
|
|
int source_length = source->length();
|
2011-03-23 11:13:07 +00:00
|
|
|
isolate->counters()->total_load_size()->Increment(source_length);
|
|
|
|
isolate->counters()->total_compile_size()->Increment(source_length);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// The VM is in the COMPILER state until exiting this function.
|
2011-03-18 20:35:07 +00:00
|
|
|
VMState state(isolate, COMPILER);
|
|
|
|
|
|
|
|
CompilationCache* compilation_cache = isolate->compilation_cache();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-09-11 10:51:52 +00:00
|
|
|
// Do a lookup in the compilation cache but not for extensions.
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> result;
|
2008-09-11 10:51:52 +00:00
|
|
|
if (extension == NULL) {
|
2011-03-18 20:35:07 +00:00
|
|
|
result = compilation_cache->LookupScript(source,
|
|
|
|
script_name,
|
|
|
|
line_offset,
|
2012-08-28 10:49:23 +00:00
|
|
|
column_offset,
|
|
|
|
context);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-09-11 10:51:52 +00:00
|
|
|
if (result.is_null()) {
|
2010-09-08 10:33:15 +00:00
|
|
|
// No cache entry found. Do pre-parsing, if it makes sense, and compile
|
|
|
|
// the script.
|
|
|
|
// Building preparse data that is only used immediately after is only a
|
|
|
|
// saving if we might skip building the AST for lazily compiled functions.
|
|
|
|
// I.e., preparse data isn't relevant when the lazy flag is off, and
|
|
|
|
// for small sources, odds are that there aren't many functions
|
|
|
|
// that would be compiled lazily anyway, so we skip the preparse step
|
|
|
|
// in that case too.
|
2008-09-11 10:51:52 +00:00
|
|
|
|
|
|
|
// Create a script object describing the script to be compiled.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Script> script = 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));
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
script->set_data(script_data.is_null() ? HEAP->undefined_value()
|
2010-02-16 15:15:31 +00:00
|
|
|
: *script_data);
|
|
|
|
|
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();
|
|
|
|
info.SetExtension(extension);
|
|
|
|
info.SetPreParseData(pre_data);
|
2012-08-28 11:25:08 +00:00
|
|
|
info.SetContext(context);
|
2012-03-14 17:25:01 +00:00
|
|
|
if (FLAG_use_strict) {
|
|
|
|
info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE);
|
|
|
|
}
|
2010-10-04 14:30:43 +00:00
|
|
|
result = MakeFunctionInfo(&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);
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
2012-03-26 13:08:08 +00:00
|
|
|
} else {
|
|
|
|
if (result->ic_age() != HEAP->global_ic_age()) {
|
|
|
|
result->ResetForNewContext(HEAP->global_ic_age());
|
|
|
|
}
|
2012-11-08 12:18:11 +00:00
|
|
|
result->code()->MakeYoung();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
if (result.is_null()) isolate->ReportPendingMessages();
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
|
|
|
|
Handle<Context> context,
|
2011-02-04 18:15:49 +00:00
|
|
|
bool is_global,
|
2011-11-24 15:17:04 +00:00
|
|
|
LanguageMode language_mode,
|
2011-11-14 08:58:47 +00:00
|
|
|
int scope_position) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = source->GetIsolate();
|
2008-11-05 10:26:08 +00:00
|
|
|
int source_length = source->length();
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->counters()->total_eval_size()->Increment(source_length);
|
|
|
|
isolate->counters()->total_compile_size()->Increment(source_length);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// The VM is in the COMPILER state until exiting this function.
|
2011-03-18 20:35:07 +00:00
|
|
|
VMState state(isolate, COMPILER);
|
2008-09-11 10:51:52 +00:00
|
|
|
|
2010-10-04 11:35:46 +00:00
|
|
|
// Do a lookup in the compilation cache; if the entry is not there, invoke
|
2010-10-27 09:19:43 +00:00
|
|
|
// the compiler and add the result to the cache.
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> result;
|
2011-03-18 20:35:07 +00:00
|
|
|
CompilationCache* compilation_cache = isolate->compilation_cache();
|
|
|
|
result = compilation_cache->LookupEval(source,
|
|
|
|
context,
|
|
|
|
is_global,
|
2011-11-24 15:17:04 +00:00
|
|
|
language_mode,
|
2011-11-14 08:58:47 +00:00
|
|
|
scope_position);
|
2009-08-13 10:25:35 +00:00
|
|
|
|
2008-09-11 10:51:52 +00:00
|
|
|
if (result.is_null()) {
|
|
|
|
// Create a script object describing the script to be compiled.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Script> script = isolate->factory()->NewScript(source);
|
2012-06-20 08:58:41 +00:00
|
|
|
CompilationInfoWithZone info(script);
|
2010-10-04 11:35:46 +00:00
|
|
|
info.MarkAsEval();
|
|
|
|
if (is_global) info.MarkAsGlobal();
|
2011-11-24 15:17:04 +00:00
|
|
|
info.SetLanguageMode(language_mode);
|
2012-08-28 11:25:08 +00:00
|
|
|
info.SetContext(context);
|
2010-10-04 14:30:43 +00:00
|
|
|
result = MakeFunctionInfo(&info);
|
2010-10-27 09:19:43 +00:00
|
|
|
if (!result.is_null()) {
|
2012-02-14 14:14:51 +00:00
|
|
|
// Explicitly disable optimization for eval code. We're not yet prepared
|
|
|
|
// to handle eval-code in the optimizing compiler.
|
2012-08-28 07:18:06 +00:00
|
|
|
result->DisableOptimization("eval");
|
2012-02-14 14:14:51 +00:00
|
|
|
|
2011-11-24 15:17:04 +00:00
|
|
|
// If caller is strict mode, the result must be in strict mode or
|
|
|
|
// extended mode as well, but not the other way around. Consider:
|
2011-02-04 18:15:49 +00:00
|
|
|
// eval("'use strict'; ...");
|
2011-11-24 15:17:04 +00:00
|
|
|
ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode());
|
|
|
|
// If caller is in extended mode, the result must also be in
|
|
|
|
// extended mode.
|
|
|
|
ASSERT(language_mode != EXTENDED_MODE ||
|
|
|
|
result->is_extended_mode());
|
2012-07-09 08:59:03 +00:00
|
|
|
if (!result->dont_cache()) {
|
|
|
|
compilation_cache->PutEval(
|
|
|
|
source, context, is_global, result, scope_position);
|
|
|
|
}
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
2012-03-26 13:08:08 +00:00
|
|
|
} else {
|
|
|
|
if (result->ic_age() != HEAP->global_ic_age()) {
|
|
|
|
result->ResetForNewContext(HEAP->global_ic_age());
|
|
|
|
}
|
2012-11-08 12:18:11 +00:00
|
|
|
result->code()->MakeYoung();
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
2008-12-05 08:35:52 +00:00
|
|
|
|
2008-09-11 10:51:52 +00:00
|
|
|
return result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-19 18:58:23 +00:00
|
|
|
static bool InstallFullCode(CompilationInfo* info) {
|
|
|
|
// Update the shared function info with the compiled code and the
|
|
|
|
// scope info. Please note, that the order of the shared function
|
|
|
|
// info initialization is important since set_scope_info might
|
|
|
|
// trigger a GC, causing the ASSERT below to be invalid if the code
|
|
|
|
// was flushed. By setting the code object last we avoid this.
|
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
|
|
|
Handle<Code> code = info->code();
|
|
|
|
Handle<JSFunction> function = info->closure();
|
|
|
|
Handle<ScopeInfo> scope_info =
|
|
|
|
ScopeInfo::Create(info->scope(), info->zone());
|
|
|
|
shared->set_scope_info(*scope_info);
|
|
|
|
shared->set_code(*code);
|
|
|
|
if (!function.is_null()) {
|
|
|
|
function->ReplaceCode(*code);
|
|
|
|
ASSERT(!function->IsOptimized());
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-07-19 18:58:23 +00:00
|
|
|
// Set the expected number of properties for instances.
|
|
|
|
FunctionLiteral* lit = info->function();
|
|
|
|
int expected = lit->expected_property_count();
|
|
|
|
SetExpectedNofPropertiesFromEstimate(shared, expected);
|
|
|
|
|
|
|
|
// Set the optimization hints after performing lazy compilation, as
|
|
|
|
// these are not set when the function is set up as a lazily
|
|
|
|
// compiled function.
|
|
|
|
shared->SetThisPropertyAssignmentsInfo(
|
|
|
|
lit->has_only_simple_this_property_assignments(),
|
|
|
|
*lit->this_property_assignments());
|
|
|
|
|
|
|
|
// Check the function has compiled code.
|
|
|
|
ASSERT(shared->is_compiled());
|
|
|
|
shared->set_code_age(0);
|
|
|
|
shared->set_dont_optimize(lit->flags()->Contains(kDontOptimize));
|
|
|
|
shared->set_dont_inline(lit->flags()->Contains(kDontInline));
|
|
|
|
shared->set_ast_node_count(lit->ast_node_count());
|
|
|
|
|
2012-07-31 14:59:32 +00:00
|
|
|
if (V8::UseCrankshaft() &&
|
2012-07-19 18:58:23 +00:00
|
|
|
!function.is_null() &&
|
|
|
|
!shared->optimization_disabled()) {
|
|
|
|
// If we're asked to always optimize, we compile the optimized
|
|
|
|
// version of the function right away - unless the debugger is
|
|
|
|
// active as it makes no sense to compile optimized code then.
|
|
|
|
if (FLAG_always_opt &&
|
|
|
|
!Isolate::Current()->DebuggerHasBreakPoints()) {
|
|
|
|
CompilationInfoWithZone optimized(function);
|
2012-08-06 14:13:09 +00:00
|
|
|
optimized.SetOptimizing(BailoutId::None());
|
2012-07-19 18:58:23 +00:00
|
|
|
return Compiler::CompileLazy(&optimized);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-07-19 18:58:23 +00:00
|
|
|
static void InstallCodeCommon(CompilationInfo* info) {
|
2010-01-29 11:55:40 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
2012-07-19 18:58:23 +00:00
|
|
|
Handle<Code> code = info->code();
|
|
|
|
ASSERT(!code.is_null());
|
|
|
|
|
|
|
|
// Set optimizable to false if this is disallowed by the shared
|
|
|
|
// function info, e.g., we might have flushed the code and must
|
|
|
|
// reset this bit when lazy compiling the code again.
|
|
|
|
if (shared->optimization_disabled()) code->set_optimizable(false);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-07-19 18:58:23 +00:00
|
|
|
Compiler::RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) {
|
|
|
|
Handle<Code> code = info->code();
|
2012-09-14 10:41:31 +00:00
|
|
|
if (FLAG_cache_optimized_code &&
|
|
|
|
info->osr_ast_id().IsNone() &&
|
|
|
|
code->kind() == Code::OPTIMIZED_FUNCTION) {
|
|
|
|
Handle<JSFunction> function = info->closure();
|
2012-07-19 18:58:23 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(function->shared());
|
|
|
|
Handle<FixedArray> literals(function->literals());
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context(function->context()->native_context());
|
2012-07-19 18:58:23 +00:00
|
|
|
SharedFunctionInfo::AddToOptimizedCodeMap(
|
2012-08-17 09:03:08 +00:00
|
|
|
shared, native_context, code, literals);
|
2012-07-19 18:58:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool InstallCodeFromOptimizedCodeMap(CompilationInfo* info) {
|
2012-09-14 10:41:31 +00:00
|
|
|
if (FLAG_cache_optimized_code &&
|
|
|
|
info->osr_ast_id().IsNone() &&
|
|
|
|
info->IsOptimizing()) {
|
2012-07-19 18:58:23 +00:00
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
2012-06-14 14:06:22 +00:00
|
|
|
Handle<JSFunction> function = info->closure();
|
|
|
|
ASSERT(!function.is_null());
|
2012-08-17 09:03:08 +00:00
|
|
|
Handle<Context> native_context(function->context()->native_context());
|
|
|
|
int index = shared->SearchOptimizedCodeMap(*native_context);
|
2012-06-14 14:06:22 +00:00
|
|
|
if (index > 0) {
|
|
|
|
if (FLAG_trace_opt) {
|
2012-06-22 13:55:15 +00:00
|
|
|
PrintF("[found optimized code for: ");
|
2012-06-14 14:06:22 +00:00
|
|
|
function->PrintName();
|
2012-06-22 13:55:15 +00:00
|
|
|
PrintF(" / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(*function));
|
2012-06-14 14:06:22 +00:00
|
|
|
}
|
2012-06-22 13:55:15 +00:00
|
|
|
// Caching of optimized code enabled and optimized code found.
|
|
|
|
shared->InstallFromOptimizedCodeMap(*function, index);
|
2012-06-14 14:06:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-07-19 18:58:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Compiler::CompileLazy(CompilationInfo* info) {
|
|
|
|
Isolate* isolate = info->isolate();
|
|
|
|
|
|
|
|
ZoneScope zone_scope(info->zone(), DELETE_ON_EXIT);
|
|
|
|
|
|
|
|
// The VM is in the COMPILER state until exiting this function.
|
|
|
|
VMState state(isolate, COMPILER);
|
|
|
|
|
|
|
|
PostponeInterruptsScope postpone(isolate);
|
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
|
|
|
int compiled_size = shared->end_position() - shared->start_position();
|
|
|
|
isolate->counters()->total_compile_size()->Increment(compiled_size);
|
|
|
|
|
|
|
|
if (InstallCodeFromOptimizedCodeMap(info)) return true;
|
2012-06-14 14:06:22 +00:00
|
|
|
|
2010-10-04 11:35:46 +00:00
|
|
|
// Generate the AST for the lazily compiled function.
|
2011-11-25 09:36:31 +00:00
|
|
|
if (ParserApi::Parse(info, kNoParsingFlags)) {
|
2010-10-04 14:30:43 +00:00
|
|
|
// Measure how long it takes to do the lazy compilation; only take the
|
|
|
|
// rest of the function into account to avoid overlap with the lazy
|
|
|
|
// parsing statistics.
|
2011-03-18 20:35:07 +00:00
|
|
|
HistogramTimerScope timer(isolate->counters()->compile_lazy());
|
2010-10-04 14:30:43 +00:00
|
|
|
|
2011-11-24 15:17:04 +00:00
|
|
|
// After parsing we know the function's language mode. Remember it.
|
|
|
|
LanguageMode language_mode = info->function()->language_mode();
|
|
|
|
info->SetLanguageMode(language_mode);
|
|
|
|
shared->set_language_mode(language_mode);
|
2011-04-08 14:30:10 +00:00
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
// Compile the code.
|
|
|
|
if (!MakeCode(info)) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (!isolate->has_pending_exception()) {
|
|
|
|
isolate->StackOverflow();
|
2011-02-11 14:26:56 +00:00
|
|
|
}
|
2010-10-04 14:30:43 +00:00
|
|
|
} else {
|
2012-07-19 18:58:23 +00:00
|
|
|
InstallCodeCommon(info);
|
2010-10-04 14:30:43 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
if (info->IsOptimizing()) {
|
2012-07-19 18:58:23 +00:00
|
|
|
Handle<Code> code = info->code();
|
2011-11-03 10:36:55 +00:00
|
|
|
ASSERT(shared->scope_info() != ScopeInfo::Empty());
|
2012-07-19 18:58:23 +00:00
|
|
|
info->closure()->ReplaceCode(*code);
|
|
|
|
InsertCodeIntoOptimizedCodeMap(info);
|
|
|
|
return true;
|
2010-12-07 11:31:57 +00:00
|
|
|
} else {
|
2012-07-19 18:58:23 +00:00
|
|
|
return InstallFullCode(info);
|
2010-10-04 14:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-30 13:39:07 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
ASSERT(info->code().is_null());
|
|
|
|
return false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-19 18:58:23 +00:00
|
|
|
void Compiler::RecompileParallel(Handle<JSFunction> closure) {
|
|
|
|
if (closure->IsInRecompileQueue()) return;
|
2012-07-23 08:41:53 +00:00
|
|
|
ASSERT(closure->IsMarkedForParallelRecompilation());
|
2012-07-19 18:58:23 +00:00
|
|
|
|
|
|
|
Isolate* isolate = closure->GetIsolate();
|
|
|
|
if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) {
|
|
|
|
if (FLAG_trace_parallel_recompilation) {
|
|
|
|
PrintF(" ** Compilation queue, will retry opting on next run.\n");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(closure));
|
|
|
|
VMState state(isolate, PARALLEL_COMPILER_PROLOGUE);
|
|
|
|
PostponeInterruptsScope postpone(isolate);
|
|
|
|
|
|
|
|
Handle<SharedFunctionInfo> shared = info->shared_info();
|
|
|
|
int compiled_size = shared->end_position() - shared->start_position();
|
|
|
|
isolate->counters()->total_compile_size()->Increment(compiled_size);
|
2012-08-06 14:13:09 +00:00
|
|
|
info->SetOptimizing(BailoutId::None());
|
2012-07-19 18:58:23 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
CompilationHandleScope handle_scope(*info);
|
|
|
|
|
2012-11-16 14:24:19 +00:00
|
|
|
if (!FLAG_manual_parallel_recompilation &&
|
|
|
|
InstallCodeFromOptimizedCodeMap(*info)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-19 18:58:23 +00:00
|
|
|
|
|
|
|
if (ParserApi::Parse(*info, kNoParsingFlags)) {
|
|
|
|
LanguageMode language_mode = info->function()->language_mode();
|
|
|
|
info->SetLanguageMode(language_mode);
|
|
|
|
shared->set_language_mode(language_mode);
|
|
|
|
info->SaveHandles();
|
|
|
|
|
|
|
|
if (Rewriter::Rewrite(*info) && Scope::Analyze(*info)) {
|
|
|
|
OptimizingCompiler* compiler =
|
|
|
|
new(info->zone()) OptimizingCompiler(*info);
|
|
|
|
OptimizingCompiler::Status status = compiler->CreateGraph();
|
|
|
|
if (status == OptimizingCompiler::SUCCEEDED) {
|
|
|
|
isolate->optimizing_compiler_thread()->QueueForOptimization(compiler);
|
|
|
|
shared->code()->set_profiler_ticks(0);
|
|
|
|
closure->ReplaceCode(isolate->builtins()->builtin(
|
|
|
|
Builtins::kInRecompileQueue));
|
|
|
|
info.Detach();
|
|
|
|
} else if (status == OptimizingCompiler::BAILED_OUT) {
|
|
|
|
isolate->clear_pending_exception();
|
|
|
|
InstallFullCode(*info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isolate->has_pending_exception()) {
|
|
|
|
isolate->clear_pending_exception();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Compiler::InstallOptimizedCode(OptimizingCompiler* optimizing_compiler) {
|
|
|
|
SmartPointer<CompilationInfo> info(optimizing_compiler->info());
|
|
|
|
// If crankshaft succeeded, install the optimized code else install
|
|
|
|
// the unoptimized code.
|
|
|
|
OptimizingCompiler::Status status = optimizing_compiler->last_status();
|
|
|
|
if (status != OptimizingCompiler::SUCCEEDED) {
|
2012-08-28 07:18:06 +00:00
|
|
|
optimizing_compiler->info()->set_bailout_reason(
|
|
|
|
"failed/bailed out last time");
|
2012-07-19 18:58:23 +00:00
|
|
|
status = optimizing_compiler->AbortOptimization();
|
|
|
|
} else {
|
|
|
|
status = optimizing_compiler->GenerateAndInstallCode();
|
|
|
|
ASSERT(status == OptimizingCompiler::SUCCEEDED ||
|
|
|
|
status == OptimizingCompiler::BAILED_OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
InstallCodeCommon(*info);
|
|
|
|
if (status == OptimizingCompiler::SUCCEEDED) {
|
|
|
|
Handle<Code> code = info->code();
|
|
|
|
ASSERT(info->shared_info()->scope_info() != ScopeInfo::Empty());
|
|
|
|
info->closure()->ReplaceCode(*code);
|
|
|
|
if (info->shared_info()->SearchOptimizedCodeMap(
|
2012-08-17 09:03:08 +00:00
|
|
|
info->closure()->context()->native_context()) == -1) {
|
2012-07-19 18:58:23 +00:00
|
|
|
InsertCodeIntoOptimizedCodeMap(*info);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info->SetCode(Handle<Code>(info->shared_info()->code()));
|
|
|
|
InstallFullCode(*info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
|
2010-10-04 14:30:43 +00:00
|
|
|
Handle<Script> script) {
|
|
|
|
// Precondition: code has been parsed and scopes have been analyzed.
|
2012-06-20 08:58:41 +00:00
|
|
|
CompilationInfoWithZone info(script);
|
2010-10-04 14:30:43 +00:00
|
|
|
info.SetFunction(literal);
|
|
|
|
info.SetScope(literal->scope());
|
2011-11-24 15:17:04 +00:00
|
|
|
info.SetLanguageMode(literal->scope()->language_mode());
|
2010-10-04 14:30:43 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal);
|
2010-10-04 14:30:43 +00:00
|
|
|
// 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.
|
2012-06-19 14:29:48 +00:00
|
|
|
// 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
|
2012-09-03 14:23:00 +00:00
|
|
|
// Debug::FindSharedFunctionInfoInScript.
|
2012-06-19 14:29:48 +00:00
|
|
|
bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext();
|
2010-02-17 20:37:08 +00:00
|
|
|
bool allow_lazy = literal->AllowsLazyCompilation() &&
|
2012-06-19 14:29:48 +00:00
|
|
|
!LiveEditFunctionTracker::IsActive(info.isolate()) &&
|
|
|
|
(!info.isolate()->DebuggerHasBreakPoints() || allow_lazy_without_ctx);
|
2009-11-04 17:59:24 +00:00
|
|
|
|
2011-11-03 10:36:55 +00:00
|
|
|
Handle<ScopeInfo> scope_info(ScopeInfo::Empty());
|
2010-07-13 13:06:33 +00:00
|
|
|
|
2009-11-04 17:59:24 +00:00
|
|
|
// Generate code
|
2012-08-07 14:47:36 +00:00
|
|
|
if (FLAG_lazy && allow_lazy && !literal->is_parenthesized()) {
|
2011-03-23 13:40:07 +00:00
|
|
|
Handle<Code> code = info.isolate()->builtins()->LazyCompile();
|
2010-10-04 14:30:43 +00:00
|
|
|
info.SetCode(code);
|
2012-07-05 13:11:57 +00:00
|
|
|
} else if (GenerateCode(&info)) {
|
2010-12-07 11:31:57 +00:00
|
|
|
ASSERT(!info.code().is_null());
|
2012-06-20 08:58:41 +00:00
|
|
|
scope_info = ScopeInfo::Create(info.scope(), info.zone());
|
2011-04-01 19:46:21 +00:00
|
|
|
} else {
|
|
|
|
return Handle<SharedFunctionInfo>::null();
|
2009-11-04 17:59:24 +00:00
|
|
|
}
|
|
|
|
|
2010-04-19 12:39:07 +00:00
|
|
|
// Create a shared function info object.
|
2010-03-23 06:04:44 +00:00
|
|
|
Handle<SharedFunctionInfo> result =
|
2011-03-18 20:35:07 +00:00
|
|
|
FACTORY->NewSharedFunctionInfo(literal->name(),
|
2010-03-23 06:04:44 +00:00
|
|
|
literal->materialized_literal_count(),
|
2010-10-04 14:30:43 +00:00
|
|
|
info.code(),
|
2010-07-13 13:06:33 +00:00
|
|
|
scope_info);
|
2010-03-23 06:04:44 +00:00
|
|
|
SetFunctionInfo(result, literal, false, script);
|
2011-02-22 16:31:24 +00:00
|
|
|
RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
|
2010-12-07 11:31:57 +00:00
|
|
|
result->set_allows_lazy_compilation(allow_lazy);
|
2012-06-19 14:29:48 +00:00
|
|
|
result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
|
2009-11-04 17:59:24 +00:00
|
|
|
|
|
|
|
// Set the expected number of properties for instances and return
|
|
|
|
// the resulting function.
|
2010-03-23 06:04:44 +00:00
|
|
|
SetExpectedNofPropertiesFromEstimate(result,
|
2009-11-04 17:59:24 +00:00
|
|
|
literal->expected_property_count());
|
2012-06-20 08:58:41 +00:00
|
|
|
live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
|
2010-03-23 06:04:44 +00:00
|
|
|
return result;
|
2009-11-04 17:59:24 +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).
|
2010-03-23 06:04:44 +00:00
|
|
|
void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
|
2009-11-04 17:59:24 +00:00
|
|
|
FunctionLiteral* lit,
|
|
|
|
bool is_toplevel,
|
|
|
|
Handle<Script> script) {
|
2011-11-09 13:54:26 +00:00
|
|
|
function_info->set_length(lit->parameter_count());
|
|
|
|
function_info->set_formal_parameter_count(lit->parameter_count());
|
2010-03-23 06:04:44 +00:00
|
|
|
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());
|
2011-08-09 12:43:08 +00:00
|
|
|
function_info->set_is_anonymous(lit->is_anonymous());
|
2010-03-23 06:04:44 +00:00
|
|
|
function_info->set_is_toplevel(is_toplevel);
|
|
|
|
function_info->set_inferred_name(*lit->inferred_name());
|
|
|
|
function_info->SetThisPropertyAssignmentsInfo(
|
2009-11-04 17:59:24 +00:00
|
|
|
lit->has_only_simple_this_property_assignments(),
|
|
|
|
*lit->this_property_assignments());
|
2010-06-07 15:39:10 +00:00
|
|
|
function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
|
2012-06-19 14:29:48 +00:00
|
|
|
function_info->set_allows_lazy_compilation_without_context(
|
|
|
|
lit->AllowsLazyCompilationWithoutContext());
|
2011-11-24 15:17:04 +00:00
|
|
|
function_info->set_language_mode(lit->language_mode());
|
2011-06-16 14:12:58 +00:00
|
|
|
function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
|
|
|
|
function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
|
2012-02-08 09:56:33 +00:00
|
|
|
function_info->set_ast_node_count(lit->ast_node_count());
|
2012-02-14 14:14:51 +00:00
|
|
|
function_info->set_is_function(lit->is_function());
|
|
|
|
function_info->set_dont_optimize(lit->flags()->Contains(kDontOptimize));
|
2012-02-08 09:56:33 +00:00
|
|
|
function_info->set_dont_inline(lit->flags()->Contains(kDontInline));
|
2012-07-09 08:59:03 +00:00
|
|
|
function_info->set_dont_cache(lit->flags()->Contains(kDontCache));
|
2009-11-04 17:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-25 14:55:53 +00:00
|
|
|
void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
|
2011-02-22 16:31:24 +00:00
|
|
|
CompilationInfo* info,
|
|
|
|
Handle<SharedFunctionInfo> shared) {
|
|
|
|
// SharedFunctionInfo is passed separately, because if CompilationInfo
|
|
|
|
// was created using Script object, it will not have it.
|
|
|
|
|
2010-10-04 14:30:43 +00:00
|
|
|
// 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.
|
2012-08-28 14:43:28 +00:00
|
|
|
if (info->isolate()->logger()->is_logging_code_events() ||
|
2011-04-22 06:40:22 +00:00
|
|
|
CpuProfiler::is_profiling(info->isolate())) {
|
2010-10-04 14:30:43 +00:00
|
|
|
Handle<Script> script = info->script();
|
|
|
|
Handle<Code> code = info->code();
|
2011-03-23 13:40:07 +00:00
|
|
|
if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile))
|
2011-03-18 20:35:07 +00:00
|
|
|
return;
|
2010-02-04 15:35:42 +00:00
|
|
|
if (script->name()->IsString()) {
|
2011-02-22 16:31:24 +00:00
|
|
|
int line_num = GetScriptLineNumber(script, shared->start_position()) + 1;
|
2010-03-25 14:55:53 +00:00
|
|
|
USE(line_num);
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(info->isolate(),
|
|
|
|
CodeCreateEvent(Logger::ToNativeByScript(tag, *script),
|
2010-10-04 14:30:43 +00:00
|
|
|
*code,
|
2011-02-22 16:31:24 +00:00
|
|
|
*shared,
|
2010-10-04 14:30:43 +00:00
|
|
|
String::cast(script->name()),
|
|
|
|
line_num));
|
2010-02-04 15:35:42 +00:00
|
|
|
} else {
|
2011-03-18 20:35:07 +00:00
|
|
|
PROFILE(info->isolate(),
|
|
|
|
CodeCreateEvent(Logger::ToNativeByScript(tag, *script),
|
2010-10-04 14:30:43 +00:00
|
|
|
*code,
|
2011-02-22 16:31:24 +00:00
|
|
|
*shared,
|
|
|
|
shared->DebugName()));
|
2010-02-04 15:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-18 16:11:01 +00:00
|
|
|
|
2011-04-08 11:25:19 +00:00
|
|
|
GDBJIT(AddCode(Handle<String>(shared->DebugName()),
|
2011-01-18 16:11:01 +00:00
|
|
|
Handle<Script>(info->script()),
|
2011-06-30 11:52:00 +00:00
|
|
|
Handle<Code>(info->code()),
|
|
|
|
info));
|
2010-02-04 15:35:42 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|