blob: abff8b68e624b0a63938e6a056e2dff6d87c5d2b [file] [log] [blame]
Ben Murdoch8b112d22011-06-08 16:22:53 +01001// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
Ben Murdochf87a2032010-10-22 12:50:53 +010030#include "compiler.h"
31
Steve Blocka7e24c12009-10-30 11:49:00 +000032#include "bootstrapper.h"
Ben Murdoch8b112d22011-06-08 16:22:53 +010033#include "codegen.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000034#include "compilation-cache.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000035#include "debug.h"
Leon Clarked91b9f72010-01-27 17:25:45 +000036#include "full-codegen.h"
Ben Murdochb8e0da22011-05-16 14:20:40 +010037#include "gdb-jit.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010038#include "hydrogen.h"
Steve Block1e0659c2011-05-24 12:43:12 +010039#include "lithium.h"
Steve Block6ded16b2010-05-10 14:33:55 +010040#include "liveedit.h"
Ben Murdochf87a2032010-10-22 12:50:53 +010041#include "parser.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000042#include "rewriter.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010043#include "runtime-profiler.h"
Ben Murdoch3bec4d22010-07-22 14:51:16 +010044#include "scopeinfo.h"
Ben Murdochf87a2032010-10-22 12:50:53 +010045#include "scopes.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010046#include "vm-state-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000047
48namespace v8 {
49namespace internal {
50
Ben Murdochf87a2032010-10-22 12:50:53 +010051
52CompilationInfo::CompilationInfo(Handle<Script> script)
Steve Block44f0eee2011-05-26 01:26:41 +010053 : isolate_(script->GetIsolate()),
54 flags_(0),
Ben Murdochf87a2032010-10-22 12:50:53 +010055 function_(NULL),
56 scope_(NULL),
57 script_(script),
58 extension_(NULL),
Ben Murdochb0fe1622011-05-05 13:52:32 +010059 pre_parse_data_(NULL),
60 supports_deoptimization_(false),
61 osr_ast_id_(AstNode::kNoNumber) {
62 Initialize(NONOPT);
Ben Murdochf87a2032010-10-22 12:50:53 +010063}
64
65
66CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info)
Steve Block44f0eee2011-05-26 01:26:41 +010067 : isolate_(shared_info->GetIsolate()),
68 flags_(IsLazy::encode(true)),
Ben Murdochf87a2032010-10-22 12:50:53 +010069 function_(NULL),
70 scope_(NULL),
71 shared_info_(shared_info),
72 script_(Handle<Script>(Script::cast(shared_info->script()))),
73 extension_(NULL),
Ben Murdochb0fe1622011-05-05 13:52:32 +010074 pre_parse_data_(NULL),
75 supports_deoptimization_(false),
76 osr_ast_id_(AstNode::kNoNumber) {
77 Initialize(BASE);
Ben Murdochf87a2032010-10-22 12:50:53 +010078}
79
80
81CompilationInfo::CompilationInfo(Handle<JSFunction> closure)
Steve Block44f0eee2011-05-26 01:26:41 +010082 : isolate_(closure->GetIsolate()),
83 flags_(IsLazy::encode(true)),
Ben Murdochf87a2032010-10-22 12:50:53 +010084 function_(NULL),
85 scope_(NULL),
86 closure_(closure),
87 shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
88 script_(Handle<Script>(Script::cast(shared_info_->script()))),
89 extension_(NULL),
Ben Murdochb0fe1622011-05-05 13:52:32 +010090 pre_parse_data_(NULL),
91 supports_deoptimization_(false),
92 osr_ast_id_(AstNode::kNoNumber) {
93 Initialize(BASE);
Ben Murdochf87a2032010-10-22 12:50:53 +010094}
95
96
Ben Murdoch257744e2011-11-30 15:57:28 +000097// Disable optimization for the rest of the compilation pipeline.
Ben Murdochb8e0da22011-05-16 14:20:40 +010098void CompilationInfo::DisableOptimization() {
Ben Murdoch257744e2011-11-30 15:57:28 +000099 bool is_optimizable_closure =
100 FLAG_optimize_closures &&
101 closure_.is_null() &&
102 !scope_->HasTrivialOuterContext() &&
103 !scope_->outer_scope_calls_non_strict_eval() &&
104 !scope_->inside_with();
105 SetMode(is_optimizable_closure ? BASE : NONOPT);
106}
Ben Murdochb8e0da22011-05-16 14:20:40 +0100107
Ben Murdoch257744e2011-11-30 15:57:28 +0000108
109void CompilationInfo::AbortOptimization() {
110 Handle<Code> code(shared_info()->code());
111 SetCode(code);
Ben Murdochb8e0da22011-05-16 14:20:40 +0100112}
113
114
Ben Murdochb0fe1622011-05-05 13:52:32 +0100115// Determine whether to use the full compiler for all code. If the flag
116// --always-full-compiler is specified this is the case. For the virtual frame
117// based compiler the full compiler is also used if a debugger is connected, as
118// the code from the full compiler supports mode precise break points. For the
119// crankshaft adaptive compiler debugging the optimized code is not possible at
120// all. However crankshaft support recompilation of functions, so in this case
121// the full compiler need not be be used if a debugger is attached, but only if
122// break points has actually been set.
Ben Murdoch257744e2011-11-30 15:57:28 +0000123static bool is_debugging_active() {
Leon Clarkef7060e22010-06-03 12:02:55 +0100124#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100125 Isolate* isolate = Isolate::Current();
Ben Murdoch257744e2011-11-30 15:57:28 +0000126 return V8::UseCrankshaft() ?
127 isolate->debug()->has_break_points() :
128 isolate->debugger()->IsDebuggerActive();
Leon Clarkef7060e22010-06-03 12:02:55 +0100129#else
Ben Murdoch257744e2011-11-30 15:57:28 +0000130 return false;
Leon Clarkef7060e22010-06-03 12:02:55 +0100131#endif
132}
133
Steve Block3ce2e202009-11-05 08:53:23 +0000134
Ben Murdoch257744e2011-11-30 15:57:28 +0000135static bool AlwaysFullCompiler() {
136 return FLAG_always_full_compiler || is_debugging_active();
137}
138
139
Ben Murdochb0fe1622011-05-05 13:52:32 +0100140static void FinishOptimization(Handle<JSFunction> function, int64_t start) {
141 int opt_count = function->shared()->opt_count();
142 function->shared()->set_opt_count(opt_count + 1);
143 double ms = static_cast<double>(OS::Ticks() - start) / 1000;
144 if (FLAG_trace_opt) {
145 PrintF("[optimizing: ");
146 function->PrintName();
147 PrintF(" / %" V8PRIxPTR, reinterpret_cast<intptr_t>(*function));
148 PrintF(" - took %0.3f ms]\n", ms);
149 }
150 if (FLAG_trace_opt_stats) {
151 static double compilation_time = 0.0;
152 static int compiled_functions = 0;
153 static int code_size = 0;
154
155 compilation_time += ms;
156 compiled_functions++;
157 code_size += function->shared()->SourceSize();
158 PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
159 compiled_functions,
160 code_size,
161 compilation_time);
162 }
163}
164
165
Ben Murdochb0fe1622011-05-05 13:52:32 +0100166static bool MakeCrankshaftCode(CompilationInfo* info) {
167 // Test if we can optimize this function when asked to. We can only
168 // do this after the scopes are computed.
169 if (!info->AllowOptimize()) info->DisableOptimization();
170
171 // In case we are not optimizing simply return the code from
172 // the full code generator.
173 if (!info->IsOptimizing()) {
174 return FullCodeGenerator::MakeCode(info);
175 }
176
177 // We should never arrive here if there is not code object on the
178 // shared function object.
179 Handle<Code> code(info->shared_info()->code());
180 ASSERT(code->kind() == Code::FUNCTION);
181
Steve Block44f0eee2011-05-26 01:26:41 +0100182 // We should never arrive here if optimization has been disabled on the
183 // shared function info.
184 ASSERT(!info->shared_info()->optimization_disabled());
185
Ben Murdochb0fe1622011-05-05 13:52:32 +0100186 // Fall back to using the full code generator if it's not possible
187 // to use the Hydrogen-based optimizing compiler. We already have
188 // generated code for this from the shared function object.
189 if (AlwaysFullCompiler() || !FLAG_use_hydrogen) {
190 info->SetCode(code);
191 return true;
192 }
193
194 // Limit the number of times we re-compile a functions with
195 // the optimizing compiler.
Ben Murdochb8e0da22011-05-16 14:20:40 +0100196 const int kMaxOptCount =
197 FLAG_deopt_every_n_times == 0 ? Compiler::kDefaultMaxOptCount : 1000;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100198 if (info->shared_info()->opt_count() > kMaxOptCount) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000199 info->AbortOptimization();
200 Handle<JSFunction> closure = info->closure();
201 info->shared_info()->DisableOptimization(*closure);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100202 // True indicates the compilation pipeline is still going, not
203 // necessarily that we optimized the code.
204 return true;
205 }
206
207 // Due to an encoding limit on LUnallocated operands in the Lithium
208 // language, we cannot optimize functions with too many formal parameters
209 // or perform on-stack replacement for function with too many
210 // stack-allocated local variables.
211 //
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100212 // The encoding is as a signed value, with parameters and receiver using
213 // the negative indices and locals the non-negative ones.
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +0100214 const int parameter_limit = -LUnallocated::kMinFixedIndex;
215 const int locals_limit = LUnallocated::kMaxFixedIndex;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100216 Scope* scope = info->scope();
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +0100217 if ((scope->num_parameters() + 1) > parameter_limit ||
218 (info->osr_ast_id() != AstNode::kNoNumber &&
219 scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit)) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000220 info->AbortOptimization();
221 Handle<JSFunction> closure = info->closure();
222 info->shared_info()->DisableOptimization(*closure);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100223 // True indicates the compilation pipeline is still going, not
224 // necessarily that we optimized the code.
225 return true;
226 }
227
228 // Take --hydrogen-filter into account.
229 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
230 Handle<String> name = info->function()->debug_name();
231 bool match = filter.is_empty() || name->IsEqualTo(filter);
232 if (!match) {
233 info->SetCode(code);
234 return true;
235 }
236
237 // Recompile the unoptimized version of the code if the current version
238 // doesn't have deoptimization support. Alternatively, we may decide to
239 // run the full code generator to get a baseline for the compile-time
240 // performance of the hydrogen-based compiler.
241 int64_t start = OS::Ticks();
242 bool should_recompile = !info->shared_info()->has_deoptimization_support();
Steve Block44f0eee2011-05-26 01:26:41 +0100243 if (should_recompile || FLAG_hydrogen_stats) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100244 HPhase phase(HPhase::kFullCodeGen);
245 CompilationInfo unoptimized(info->shared_info());
246 // Note that we use the same AST that we will use for generating the
247 // optimized code.
248 unoptimized.SetFunction(info->function());
249 unoptimized.SetScope(info->scope());
250 if (should_recompile) unoptimized.EnableDeoptimizationSupport();
251 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized);
252 if (should_recompile) {
253 if (!succeeded) return false;
254 Handle<SharedFunctionInfo> shared = info->shared_info();
255 shared->EnableDeoptimizationSupport(*unoptimized.code());
256 // The existing unoptimized code was replaced with the new one.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100257 Compiler::RecordFunctionCompilation(
258 Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100259 }
260 }
261
262 // Check that the unoptimized, shared code is ready for
263 // optimizations. When using the always_opt flag we disregard the
264 // optimizable marker in the code object and optimize anyway. This
265 // is safe as long as the unoptimized code has deoptimization
266 // support.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100267 ASSERT(FLAG_always_opt || code->optimizable());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100268 ASSERT(info->shared_info()->has_deoptimization_support());
269
270 if (FLAG_trace_hydrogen) {
271 PrintF("-----------------------------------------------------------\n");
272 PrintF("Compiling method %s using hydrogen\n", *name->ToCString());
273 HTracer::Instance()->TraceCompilation(info->function());
274 }
275
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100276 Handle<Context> global_context(info->closure()->context()->global_context());
277 TypeFeedbackOracle oracle(code, global_context);
278 HGraphBuilder builder(info, &oracle);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100279 HPhase phase(HPhase::kTotal);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100280 HGraph* graph = builder.CreateGraph();
Steve Block44f0eee2011-05-26 01:26:41 +0100281 if (info->isolate()->has_pending_exception()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100282 info->SetCode(Handle<Code>::null());
283 return false;
284 }
285
Ben Murdochb0fe1622011-05-05 13:52:32 +0100286 if (graph != NULL && FLAG_build_lithium) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100287 Handle<Code> optimized_code = graph->Compile(info);
288 if (!optimized_code.is_null()) {
289 info->SetCode(optimized_code);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100290 FinishOptimization(info->closure(), start);
291 return true;
292 }
293 }
294
Ben Murdoch257744e2011-11-30 15:57:28 +0000295 // Keep using the shared code.
296 info->AbortOptimization();
297 if (!builder.inline_bailout()) {
298 // Mark the shared code as unoptimizable unless it was an inlined
299 // function that bailed out.
300 Handle<JSFunction> closure = info->closure();
301 info->shared_info()->DisableOptimization(*closure);
302 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100303 // True indicates the compilation pipeline is still going, not necessarily
304 // that we optimized the code.
305 return true;
306}
307
308
Ben Murdoch257744e2011-11-30 15:57:28 +0000309static bool GenerateCode(CompilationInfo* info) {
310 return V8::UseCrankshaft() ?
311 MakeCrankshaftCode(info) :
312 FullCodeGenerator::MakeCode(info);
313}
314
315
Ben Murdochf87a2032010-10-22 12:50:53 +0100316static bool MakeCode(CompilationInfo* info) {
317 // Precondition: code has been parsed. Postcondition: the code field in
318 // the compilation info is set if compilation succeeded.
319 ASSERT(info->function() != NULL);
Ben Murdoch257744e2011-11-30 15:57:28 +0000320 return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000321}
322
323
Steve Block6ded16b2010-05-10 14:33:55 +0100324#ifdef ENABLE_DEBUGGER_SUPPORT
Ben Murdochf87a2032010-10-22 12:50:53 +0100325bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) {
326 // Precondition: code has been parsed. Postcondition: the code field in
327 // the compilation info is set if compilation succeeded.
328 bool succeeded = MakeCode(info);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100329 if (!info->shared_info().is_null()) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100330 Handle<SerializedScopeInfo> scope_info =
331 SerializedScopeInfo::Create(info->scope());
332 info->shared_info()->set_scope_info(*scope_info);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100333 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100334 return succeeded;
Steve Block6ded16b2010-05-10 14:33:55 +0100335}
336#endif
337
338
Ben Murdochf87a2032010-10-22 12:50:53 +0100339static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
Steve Block44f0eee2011-05-26 01:26:41 +0100340 Isolate* isolate = info->isolate();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000341 ZoneScope zone_scope(isolate, DELETE_ON_EXIT);
Steve Block44f0eee2011-05-26 01:26:41 +0100342 PostponeInterruptsScope postpone(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000343
Steve Block44f0eee2011-05-26 01:26:41 +0100344 ASSERT(!isolate->global_context().is_null());
Ben Murdochf87a2032010-10-22 12:50:53 +0100345 Handle<Script> script = info->script();
Steve Block44f0eee2011-05-26 01:26:41 +0100346 script->set_context_data((*isolate->global_context())->data());
Steve Blocka7e24c12009-10-30 11:49:00 +0000347
Leon Clarke4515c472010-02-03 11:58:03 +0000348#ifdef ENABLE_DEBUGGER_SUPPORT
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800349 if (info->is_eval()) {
350 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL;
Ben Murdochf87a2032010-10-22 12:50:53 +0100351 script->set_compilation_type(Smi::FromInt(compilation_type));
Steve Blocka7e24c12009-10-30 11:49:00 +0000352 // For eval scripts add information on the function from which eval was
353 // called.
Ben Murdochf87a2032010-10-22 12:50:53 +0100354 if (info->is_eval()) {
Ben Murdoch8b112d22011-06-08 16:22:53 +0100355 StackTraceFrameIterator it(isolate);
Leon Clarke4515c472010-02-03 11:58:03 +0000356 if (!it.done()) {
357 script->set_eval_from_shared(
358 JSFunction::cast(it.frame()->function())->shared());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100359 Code* code = it.frame()->LookupCode();
Leon Clarke4515c472010-02-03 11:58:03 +0000360 int offset = static_cast<int>(
Steve Block44f0eee2011-05-26 01:26:41 +0100361 it.frame()->pc() - code->instruction_start());
Leon Clarke4515c472010-02-03 11:58:03 +0000362 script->set_eval_from_instructions_offset(Smi::FromInt(offset));
363 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000364 }
365 }
366
367 // Notify debugger
Steve Block44f0eee2011-05-26 01:26:41 +0100368 isolate->debugger()->OnBeforeCompile(script);
Steve Blocka7e24c12009-10-30 11:49:00 +0000369#endif
370
371 // Only allow non-global compiles for eval.
Ben Murdochf87a2032010-10-22 12:50:53 +0100372 ASSERT(info->is_eval() || info->is_global());
Steve Blocka7e24c12009-10-30 11:49:00 +0000373
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800374 if (!ParserApi::Parse(info)) return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000375
Steve Blocka7e24c12009-10-30 11:49:00 +0000376 // Measure how long it takes to do the compilation; only take the
377 // rest of the function into account to avoid overlap with the
378 // parsing statistics.
Ben Murdochf87a2032010-10-22 12:50:53 +0100379 HistogramTimer* rate = info->is_eval()
Steve Block44f0eee2011-05-26 01:26:41 +0100380 ? info->isolate()->counters()->compile_eval()
381 : info->isolate()->counters()->compile();
Steve Blocka7e24c12009-10-30 11:49:00 +0000382 HistogramTimerScope timer(rate);
383
384 // Compile the code.
Ben Murdochf87a2032010-10-22 12:50:53 +0100385 FunctionLiteral* lit = info->function();
Steve Block44f0eee2011-05-26 01:26:41 +0100386 LiveEditFunctionTracker live_edit_tracker(isolate, lit);
Ben Murdochf87a2032010-10-22 12:50:53 +0100387 if (!MakeCode(info)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100388 isolate->StackOverflow();
Steve Block6ded16b2010-05-10 14:33:55 +0100389 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 }
391
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100392 // Allocate function.
Ben Murdochf87a2032010-10-22 12:50:53 +0100393 ASSERT(!info->code().is_null());
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100394 Handle<SharedFunctionInfo> result =
Steve Block44f0eee2011-05-26 01:26:41 +0100395 isolate->factory()->NewSharedFunctionInfo(
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100396 lit->name(),
397 lit->materialized_literal_count(),
398 info->code(),
399 SerializedScopeInfo::Create(info->scope()));
400
401 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
402 Compiler::SetFunctionInfo(result, lit, true, script);
403
Steve Block6ded16b2010-05-10 14:33:55 +0100404 if (script->name()->IsString()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100405 PROFILE(isolate, CodeCreateEvent(
Ben Murdochf87a2032010-10-22 12:50:53 +0100406 info->is_eval()
407 ? Logger::EVAL_TAG
408 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
409 *info->code(),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100410 *result,
Ben Murdochf87a2032010-10-22 12:50:53 +0100411 String::cast(script->name())));
Ben Murdochb8e0da22011-05-16 14:20:40 +0100412 GDBJIT(AddCode(Handle<String>(String::cast(script->name())),
413 script,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000414 info->code(),
415 info));
Steve Block6ded16b2010-05-10 14:33:55 +0100416 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100417 PROFILE(isolate, CodeCreateEvent(
Ben Murdochf87a2032010-10-22 12:50:53 +0100418 info->is_eval()
419 ? Logger::EVAL_TAG
420 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
421 *info->code(),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100422 *result,
Steve Block44f0eee2011-05-26 01:26:41 +0100423 isolate->heap()->empty_string()));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000424 GDBJIT(AddCode(Handle<String>(), script, info->code(), info));
Steve Blocka7e24c12009-10-30 11:49:00 +0000425 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000426
Steve Blocka7e24c12009-10-30 11:49:00 +0000427 // Hint to the runtime system used when allocating space for initial
428 // property space by setting the expected number of properties for
429 // the instances of the function.
Steve Block6ded16b2010-05-10 14:33:55 +0100430 SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count());
Steve Blocka7e24c12009-10-30 11:49:00 +0000431
432#ifdef ENABLE_DEBUGGER_SUPPORT
433 // Notify debugger
Steve Block44f0eee2011-05-26 01:26:41 +0100434 isolate->debugger()->OnAfterCompile(
435 script, Debugger::NO_AFTER_COMPILE_FLAGS);
Steve Blocka7e24c12009-10-30 11:49:00 +0000436#endif
437
Steve Block6ded16b2010-05-10 14:33:55 +0100438 live_edit_tracker.RecordFunctionInfo(result, lit);
439
440 return result;
Steve Blocka7e24c12009-10-30 11:49:00 +0000441}
442
443
Steve Block6ded16b2010-05-10 14:33:55 +0100444Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
445 Handle<Object> script_name,
446 int line_offset,
447 int column_offset,
448 v8::Extension* extension,
449 ScriptDataImpl* input_pre_data,
450 Handle<Object> script_data,
451 NativesFlag natives) {
Steve Block44f0eee2011-05-26 01:26:41 +0100452 Isolate* isolate = source->GetIsolate();
Steve Blocka7e24c12009-10-30 11:49:00 +0000453 int source_length = source->length();
Steve Block44f0eee2011-05-26 01:26:41 +0100454 isolate->counters()->total_load_size()->Increment(source_length);
455 isolate->counters()->total_compile_size()->Increment(source_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000456
457 // The VM is in the COMPILER state until exiting this function.
Steve Block44f0eee2011-05-26 01:26:41 +0100458 VMState state(isolate, COMPILER);
459
460 CompilationCache* compilation_cache = isolate->compilation_cache();
Steve Blocka7e24c12009-10-30 11:49:00 +0000461
462 // Do a lookup in the compilation cache but not for extensions.
Steve Block6ded16b2010-05-10 14:33:55 +0100463 Handle<SharedFunctionInfo> result;
Steve Blocka7e24c12009-10-30 11:49:00 +0000464 if (extension == NULL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100465 result = compilation_cache->LookupScript(source,
466 script_name,
467 line_offset,
468 column_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000469 }
470
471 if (result.is_null()) {
Steve Block59151502010-09-22 15:07:15 +0100472 // No cache entry found. Do pre-parsing, if it makes sense, and compile
473 // the script.
474 // Building preparse data that is only used immediately after is only a
475 // saving if we might skip building the AST for lazily compiled functions.
476 // I.e., preparse data isn't relevant when the lazy flag is off, and
477 // for small sources, odds are that there aren't many functions
478 // that would be compiled lazily anyway, so we skip the preparse step
479 // in that case too.
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 ScriptDataImpl* pre_data = input_pre_data;
Steve Block59151502010-09-22 15:07:15 +0100481 if (pre_data == NULL
Steve Block59151502010-09-22 15:07:15 +0100482 && source_length >= FLAG_min_preparse_length) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100483 if (source->IsExternalTwoByteString()) {
484 ExternalTwoByteStringUC16CharacterStream stream(
485 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
486 pre_data = ParserApi::PartialPreParse(&stream, extension);
487 } else {
488 GenericStringUC16CharacterStream stream(source, 0, source->length());
489 pre_data = ParserApi::PartialPreParse(&stream, extension);
490 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000491 }
492
493 // Create a script object describing the script to be compiled.
Steve Block44f0eee2011-05-26 01:26:41 +0100494 Handle<Script> script = FACTORY->NewScript(source);
Andrei Popescu31002712010-02-23 13:46:05 +0000495 if (natives == NATIVES_CODE) {
496 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
497 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000498 if (!script_name.is_null()) {
499 script->set_name(*script_name);
500 script->set_line_offset(Smi::FromInt(line_offset));
501 script->set_column_offset(Smi::FromInt(column_offset));
502 }
503
Steve Block44f0eee2011-05-26 01:26:41 +0100504 script->set_data(script_data.is_null() ? HEAP->undefined_value()
Andrei Popescu402d9372010-02-26 13:31:12 +0000505 : *script_data);
506
Steve Blocka7e24c12009-10-30 11:49:00 +0000507 // Compile the function and add it to the cache.
Ben Murdochf87a2032010-10-22 12:50:53 +0100508 CompilationInfo info(script);
509 info.MarkAsGlobal();
510 info.SetExtension(extension);
511 info.SetPreParseData(pre_data);
512 result = MakeFunctionInfo(&info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000513 if (extension == NULL && !result.is_null()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100514 compilation_cache->PutScript(source, result);
Steve Blocka7e24c12009-10-30 11:49:00 +0000515 }
516
517 // Get rid of the pre-parsing data (if necessary).
518 if (input_pre_data == NULL && pre_data != NULL) {
519 delete pre_data;
520 }
521 }
522
Steve Block44f0eee2011-05-26 01:26:41 +0100523 if (result.is_null()) isolate->ReportPendingMessages();
Steve Blocka7e24c12009-10-30 11:49:00 +0000524 return result;
525}
526
527
Steve Block6ded16b2010-05-10 14:33:55 +0100528Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
529 Handle<Context> context,
Steve Block1e0659c2011-05-24 12:43:12 +0100530 bool is_global,
531 StrictModeFlag strict_mode) {
Steve Block44f0eee2011-05-26 01:26:41 +0100532 Isolate* isolate = source->GetIsolate();
Steve Blocka7e24c12009-10-30 11:49:00 +0000533 int source_length = source->length();
Steve Block44f0eee2011-05-26 01:26:41 +0100534 isolate->counters()->total_eval_size()->Increment(source_length);
535 isolate->counters()->total_compile_size()->Increment(source_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000536
537 // The VM is in the COMPILER state until exiting this function.
Steve Block44f0eee2011-05-26 01:26:41 +0100538 VMState state(isolate, COMPILER);
Steve Blocka7e24c12009-10-30 11:49:00 +0000539
Ben Murdochf87a2032010-10-22 12:50:53 +0100540 // Do a lookup in the compilation cache; if the entry is not there, invoke
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800541 // the compiler and add the result to the cache.
Steve Block6ded16b2010-05-10 14:33:55 +0100542 Handle<SharedFunctionInfo> result;
Steve Block44f0eee2011-05-26 01:26:41 +0100543 CompilationCache* compilation_cache = isolate->compilation_cache();
544 result = compilation_cache->LookupEval(source,
545 context,
546 is_global,
547 strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000548
549 if (result.is_null()) {
550 // Create a script object describing the script to be compiled.
Steve Block44f0eee2011-05-26 01:26:41 +0100551 Handle<Script> script = isolate->factory()->NewScript(source);
Ben Murdochf87a2032010-10-22 12:50:53 +0100552 CompilationInfo info(script);
553 info.MarkAsEval();
554 if (is_global) info.MarkAsGlobal();
Ben Murdoch8b112d22011-06-08 16:22:53 +0100555 if (strict_mode == kStrictMode) info.MarkAsStrictMode();
Ben Murdochf87a2032010-10-22 12:50:53 +0100556 info.SetCallingContext(context);
557 result = MakeFunctionInfo(&info);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800558 if (!result.is_null()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100559 CompilationCache* compilation_cache = isolate->compilation_cache();
Steve Block1e0659c2011-05-24 12:43:12 +0100560 // If caller is strict mode, the result must be strict as well,
561 // but not the other way around. Consider:
562 // eval("'use strict'; ...");
563 ASSERT(strict_mode == kNonStrictMode || result->strict_mode());
Steve Block44f0eee2011-05-26 01:26:41 +0100564 compilation_cache->PutEval(source, context, is_global, result);
Steve Blocka7e24c12009-10-30 11:49:00 +0000565 }
566 }
567
568 return result;
569}
570
571
Leon Clarke4515c472010-02-03 11:58:03 +0000572bool Compiler::CompileLazy(CompilationInfo* info) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000573 Isolate* isolate = info->isolate();
574
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000575 ZoneScope zone_scope(isolate, DELETE_ON_EXIT);
Steve Blocka7e24c12009-10-30 11:49:00 +0000576
577 // The VM is in the COMPILER state until exiting this function.
Ben Murdoch257744e2011-11-30 15:57:28 +0000578 VMState state(isolate, COMPILER);
Steve Blocka7e24c12009-10-30 11:49:00 +0000579
Steve Block44f0eee2011-05-26 01:26:41 +0100580 PostponeInterruptsScope postpone(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000581
Leon Clarke4515c472010-02-03 11:58:03 +0000582 Handle<SharedFunctionInfo> shared = info->shared_info();
Ben Murdochf87a2032010-10-22 12:50:53 +0100583 int compiled_size = shared->end_position() - shared->start_position();
Steve Block44f0eee2011-05-26 01:26:41 +0100584 isolate->counters()->total_compile_size()->Increment(compiled_size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000585
Ben Murdochf87a2032010-10-22 12:50:53 +0100586 // Generate the AST for the lazily compiled function.
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800587 if (ParserApi::Parse(info)) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100588 // Measure how long it takes to do the lazy compilation; only take the
589 // rest of the function into account to avoid overlap with the lazy
590 // parsing statistics.
Steve Block44f0eee2011-05-26 01:26:41 +0100591 HistogramTimerScope timer(isolate->counters()->compile_lazy());
Steve Blocka7e24c12009-10-30 11:49:00 +0000592
Ben Murdoch8b112d22011-06-08 16:22:53 +0100593 // After parsing we know function's strict mode. Remember it.
594 if (info->function()->strict_mode()) {
595 shared->set_strict_mode(true);
596 info->MarkAsStrictMode();
597 }
598
Ben Murdochf87a2032010-10-22 12:50:53 +0100599 // Compile the code.
600 if (!MakeCode(info)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100601 if (!isolate->has_pending_exception()) {
602 isolate->StackOverflow();
Steve Block1e0659c2011-05-24 12:43:12 +0100603 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100604 } else {
605 ASSERT(!info->code().is_null());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100606 Handle<Code> code = info->code();
Steve Block44f0eee2011-05-26 01:26:41 +0100607 // Set optimizable to false if this is disallowed by the shared
608 // function info, e.g., we might have flushed the code and must
609 // reset this bit when lazy compiling the code again.
610 if (shared->optimization_disabled()) code->set_optimizable(false);
611
Ben Murdochb0fe1622011-05-05 13:52:32 +0100612 Handle<JSFunction> function = info->closure();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100613 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000614
Ben Murdochb0fe1622011-05-05 13:52:32 +0100615 if (info->IsOptimizing()) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000616 ASSERT(shared->scope_info() != SerializedScopeInfo::Empty());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100617 function->ReplaceCode(*code);
618 } else {
619 // Update the shared function info with the compiled code and the
620 // scope info. Please note, that the order of the shared function
621 // info initialization is important since set_scope_info might
622 // trigger a GC, causing the ASSERT below to be invalid if the code
623 // was flushed. By settting the code object last we avoid this.
624 Handle<SerializedScopeInfo> scope_info =
625 SerializedScopeInfo::Create(info->scope());
626 shared->set_scope_info(*scope_info);
627 shared->set_code(*code);
628 if (!function.is_null()) {
629 function->ReplaceCode(*code);
630 ASSERT(!function->IsOptimized());
631 }
632
633 // Set the expected number of properties for instances.
634 FunctionLiteral* lit = info->function();
635 int expected = lit->expected_property_count();
636 SetExpectedNofPropertiesFromEstimate(shared, expected);
637
638 // Set the optimization hints after performing lazy compilation, as
639 // these are not set when the function is set up as a lazily
640 // compiled function.
641 shared->SetThisPropertyAssignmentsInfo(
642 lit->has_only_simple_this_property_assignments(),
643 *lit->this_property_assignments());
644
645 // Check the function has compiled code.
646 ASSERT(shared->is_compiled());
647 shared->set_code_age(0);
648
Steve Block44f0eee2011-05-26 01:26:41 +0100649 if (info->AllowOptimize() && !shared->optimization_disabled()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100650 // If we're asked to always optimize, we compile the optimized
651 // version of the function right away - unless the debugger is
652 // active as it makes no sense to compile optimized code then.
Steve Block44f0eee2011-05-26 01:26:41 +0100653 if (FLAG_always_opt &&
Ben Murdoch257744e2011-11-30 15:57:28 +0000654 !Isolate::Current()->DebuggerHasBreakPoints()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100655 CompilationInfo optimized(function);
656 optimized.SetOptimizing(AstNode::kNoNumber);
657 return CompileLazy(&optimized);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100658 }
659 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100660 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000661
Ben Murdochf87a2032010-10-22 12:50:53 +0100662 return true;
663 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000664 }
665
Ben Murdochf87a2032010-10-22 12:50:53 +0100666 ASSERT(info->code().is_null());
667 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000668}
669
670
Steve Block6ded16b2010-05-10 14:33:55 +0100671Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
Ben Murdochf87a2032010-10-22 12:50:53 +0100672 Handle<Script> script) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100673 // Precondition: code has been parsed and scopes have been analyzed.
674 CompilationInfo info(script);
675 info.SetFunction(literal);
676 info.SetScope(literal->scope());
Ben Murdoch257744e2011-11-30 15:57:28 +0000677 if (literal->scope()->is_strict_mode()) info.MarkAsStrictMode();
Ben Murdochf87a2032010-10-22 12:50:53 +0100678
Steve Block44f0eee2011-05-26 01:26:41 +0100679 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal);
Ben Murdochf87a2032010-10-22 12:50:53 +0100680 // Determine if the function can be lazily compiled. This is necessary to
681 // allow some of our builtin JS files to be lazily compiled. These
682 // builtins cannot be handled lazily by the parser, since we have to know
683 // if a function uses the special natives syntax, which is something the
684 // parser records.
Andrei Popescu402d9372010-02-26 13:31:12 +0000685 bool allow_lazy = literal->AllowsLazyCompilation() &&
Steve Block44f0eee2011-05-26 01:26:41 +0100686 !LiveEditFunctionTracker::IsActive(info.isolate());
Steve Blockd0582a62009-12-15 09:54:21 +0000687
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100688 Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty());
689
Steve Blockd0582a62009-12-15 09:54:21 +0000690 // Generate code
Steve Blockd0582a62009-12-15 09:54:21 +0000691 if (FLAG_lazy && allow_lazy) {
Steve Block44f0eee2011-05-26 01:26:41 +0100692 Handle<Code> code = info.isolate()->builtins()->LazyCompile();
Ben Murdochf87a2032010-10-22 12:50:53 +0100693 info.SetCode(code);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100694 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) ||
695 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100696 ASSERT(!info.code().is_null());
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100697 scope_info = SerializedScopeInfo::Create(info.scope());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100698 } else {
699 return Handle<SharedFunctionInfo>::null();
Steve Blockd0582a62009-12-15 09:54:21 +0000700 }
701
Steve Block6ded16b2010-05-10 14:33:55 +0100702 // Create a shared function info object.
703 Handle<SharedFunctionInfo> result =
Steve Block44f0eee2011-05-26 01:26:41 +0100704 FACTORY->NewSharedFunctionInfo(literal->name(),
Steve Block6ded16b2010-05-10 14:33:55 +0100705 literal->materialized_literal_count(),
Ben Murdochf87a2032010-10-22 12:50:53 +0100706 info.code(),
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100707 scope_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100708 SetFunctionInfo(result, literal, false, script);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100709 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100710 result->set_allows_lazy_compilation(allow_lazy);
Steve Blockd0582a62009-12-15 09:54:21 +0000711
712 // Set the expected number of properties for instances and return
713 // the resulting function.
Steve Block6ded16b2010-05-10 14:33:55 +0100714 SetExpectedNofPropertiesFromEstimate(result,
Steve Blockd0582a62009-12-15 09:54:21 +0000715 literal->expected_property_count());
Steve Block6ded16b2010-05-10 14:33:55 +0100716 live_edit_tracker.RecordFunctionInfo(result, literal);
717 return result;
Steve Blockd0582a62009-12-15 09:54:21 +0000718}
719
720
721// Sets the function info on a function.
722// The start_position points to the first '(' character after the function name
723// in the full script source. When counting characters in the script source the
724// the first character is number 0 (not 1).
Steve Block6ded16b2010-05-10 14:33:55 +0100725void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
Steve Blockd0582a62009-12-15 09:54:21 +0000726 FunctionLiteral* lit,
727 bool is_toplevel,
728 Handle<Script> script) {
Steve Block6ded16b2010-05-10 14:33:55 +0100729 function_info->set_length(lit->num_parameters());
730 function_info->set_formal_parameter_count(lit->num_parameters());
731 function_info->set_script(*script);
732 function_info->set_function_token_position(lit->function_token_position());
733 function_info->set_start_position(lit->start_position());
734 function_info->set_end_position(lit->end_position());
735 function_info->set_is_expression(lit->is_expression());
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000736 function_info->set_is_anonymous(lit->is_anonymous());
Steve Block6ded16b2010-05-10 14:33:55 +0100737 function_info->set_is_toplevel(is_toplevel);
738 function_info->set_inferred_name(*lit->inferred_name());
739 function_info->SetThisPropertyAssignmentsInfo(
Steve Blockd0582a62009-12-15 09:54:21 +0000740 lit->has_only_simple_this_property_assignments(),
741 *lit->this_property_assignments());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100742 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
Steve Block1e0659c2011-05-24 12:43:12 +0100743 function_info->set_strict_mode(lit->strict_mode());
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000744 function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
745 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
Steve Blockd0582a62009-12-15 09:54:21 +0000746}
747
748
Steve Block6ded16b2010-05-10 14:33:55 +0100749void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100750 CompilationInfo* info,
751 Handle<SharedFunctionInfo> shared) {
752 // SharedFunctionInfo is passed separately, because if CompilationInfo
753 // was created using Script object, it will not have it.
754
Ben Murdochf87a2032010-10-22 12:50:53 +0100755 // Log the code generation. If source information is available include
756 // script name and line number. Check explicitly whether logging is
757 // enabled as finding the line number is not free.
Ben Murdoch257744e2011-11-30 15:57:28 +0000758 if (info->isolate()->logger()->is_logging() ||
759 CpuProfiler::is_profiling(info->isolate())) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100760 Handle<Script> script = info->script();
761 Handle<Code> code = info->code();
Steve Block44f0eee2011-05-26 01:26:41 +0100762 if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile))
763 return;
Andrei Popescu31002712010-02-23 13:46:05 +0000764 if (script->name()->IsString()) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100765 int line_num = GetScriptLineNumber(script, shared->start_position()) + 1;
Steve Block6ded16b2010-05-10 14:33:55 +0100766 USE(line_num);
Steve Block44f0eee2011-05-26 01:26:41 +0100767 PROFILE(info->isolate(),
768 CodeCreateEvent(Logger::ToNativeByScript(tag, *script),
Ben Murdochf87a2032010-10-22 12:50:53 +0100769 *code,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100770 *shared,
Ben Murdochf87a2032010-10-22 12:50:53 +0100771 String::cast(script->name()),
772 line_num));
Andrei Popescu31002712010-02-23 13:46:05 +0000773 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100774 PROFILE(info->isolate(),
775 CodeCreateEvent(Logger::ToNativeByScript(tag, *script),
Ben Murdochf87a2032010-10-22 12:50:53 +0100776 *code,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100777 *shared,
778 shared->DebugName()));
Andrei Popescu31002712010-02-23 13:46:05 +0000779 }
780 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100781
Ben Murdoch8b112d22011-06-08 16:22:53 +0100782 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
Ben Murdochb8e0da22011-05-16 14:20:40 +0100783 Handle<Script>(info->script()),
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000784 Handle<Code>(info->code()),
785 info));
Andrei Popescu31002712010-02-23 13:46:05 +0000786}
Andrei Popescu31002712010-02-23 13:46:05 +0000787
Steve Blocka7e24c12009-10-30 11:49:00 +0000788} } // namespace v8::internal