blob: d82bcd0c7d9d796f025ea7050090722c3af82618 [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);
112 Isolate* isolate = code->GetIsolate();
113 isolate->compilation_cache()->MarkForLazyOptimizing(closure());
Ben Murdochb8e0da22011-05-16 14:20:40 +0100114}
115
116
Ben Murdochb0fe1622011-05-05 13:52:32 +0100117// Determine whether to use the full compiler for all code. If the flag
118// --always-full-compiler is specified this is the case. For the virtual frame
119// based compiler the full compiler is also used if a debugger is connected, as
120// the code from the full compiler supports mode precise break points. For the
121// crankshaft adaptive compiler debugging the optimized code is not possible at
122// all. However crankshaft support recompilation of functions, so in this case
123// the full compiler need not be be used if a debugger is attached, but only if
124// break points has actually been set.
Ben Murdoch257744e2011-11-30 15:57:28 +0000125static bool is_debugging_active() {
Leon Clarkef7060e22010-06-03 12:02:55 +0100126#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100127 Isolate* isolate = Isolate::Current();
Ben Murdoch257744e2011-11-30 15:57:28 +0000128 return V8::UseCrankshaft() ?
129 isolate->debug()->has_break_points() :
130 isolate->debugger()->IsDebuggerActive();
Leon Clarkef7060e22010-06-03 12:02:55 +0100131#else
Ben Murdoch257744e2011-11-30 15:57:28 +0000132 return false;
Leon Clarkef7060e22010-06-03 12:02:55 +0100133#endif
134}
135
Steve Block3ce2e202009-11-05 08:53:23 +0000136
Ben Murdoch257744e2011-11-30 15:57:28 +0000137static bool AlwaysFullCompiler() {
138 return FLAG_always_full_compiler || is_debugging_active();
139}
140
141
Ben Murdochb0fe1622011-05-05 13:52:32 +0100142static void FinishOptimization(Handle<JSFunction> function, int64_t start) {
143 int opt_count = function->shared()->opt_count();
144 function->shared()->set_opt_count(opt_count + 1);
145 double ms = static_cast<double>(OS::Ticks() - start) / 1000;
146 if (FLAG_trace_opt) {
147 PrintF("[optimizing: ");
148 function->PrintName();
149 PrintF(" / %" V8PRIxPTR, reinterpret_cast<intptr_t>(*function));
150 PrintF(" - took %0.3f ms]\n", ms);
151 }
152 if (FLAG_trace_opt_stats) {
153 static double compilation_time = 0.0;
154 static int compiled_functions = 0;
155 static int code_size = 0;
156
157 compilation_time += ms;
158 compiled_functions++;
159 code_size += function->shared()->SourceSize();
160 PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
161 compiled_functions,
162 code_size,
163 compilation_time);
164 }
165}
166
167
Ben Murdochb0fe1622011-05-05 13:52:32 +0100168static bool MakeCrankshaftCode(CompilationInfo* info) {
169 // Test if we can optimize this function when asked to. We can only
170 // do this after the scopes are computed.
171 if (!info->AllowOptimize()) info->DisableOptimization();
172
173 // In case we are not optimizing simply return the code from
174 // the full code generator.
175 if (!info->IsOptimizing()) {
176 return FullCodeGenerator::MakeCode(info);
177 }
178
179 // We should never arrive here if there is not code object on the
180 // shared function object.
181 Handle<Code> code(info->shared_info()->code());
182 ASSERT(code->kind() == Code::FUNCTION);
183
Steve Block44f0eee2011-05-26 01:26:41 +0100184 // We should never arrive here if optimization has been disabled on the
185 // shared function info.
186 ASSERT(!info->shared_info()->optimization_disabled());
187
Ben Murdochb0fe1622011-05-05 13:52:32 +0100188 // Fall back to using the full code generator if it's not possible
189 // to use the Hydrogen-based optimizing compiler. We already have
190 // generated code for this from the shared function object.
191 if (AlwaysFullCompiler() || !FLAG_use_hydrogen) {
192 info->SetCode(code);
193 return true;
194 }
195
196 // Limit the number of times we re-compile a functions with
197 // the optimizing compiler.
Ben Murdochb8e0da22011-05-16 14:20:40 +0100198 const int kMaxOptCount =
199 FLAG_deopt_every_n_times == 0 ? Compiler::kDefaultMaxOptCount : 1000;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100200 if (info->shared_info()->opt_count() > kMaxOptCount) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000201 info->AbortOptimization();
202 Handle<JSFunction> closure = info->closure();
203 info->shared_info()->DisableOptimization(*closure);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100204 // True indicates the compilation pipeline is still going, not
205 // necessarily that we optimized the code.
206 return true;
207 }
208
209 // Due to an encoding limit on LUnallocated operands in the Lithium
210 // language, we cannot optimize functions with too many formal parameters
211 // or perform on-stack replacement for function with too many
212 // stack-allocated local variables.
213 //
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100214 // The encoding is as a signed value, with parameters and receiver using
215 // the negative indices and locals the non-negative ones.
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +0100216 const int parameter_limit = -LUnallocated::kMinFixedIndex;
217 const int locals_limit = LUnallocated::kMaxFixedIndex;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100218 Scope* scope = info->scope();
Ben Murdoch7d3e7fc2011-07-12 16:37:06 +0100219 if ((scope->num_parameters() + 1) > parameter_limit ||
220 (info->osr_ast_id() != AstNode::kNoNumber &&
221 scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit)) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000222 info->AbortOptimization();
223 Handle<JSFunction> closure = info->closure();
224 info->shared_info()->DisableOptimization(*closure);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100225 // True indicates the compilation pipeline is still going, not
226 // necessarily that we optimized the code.
227 return true;
228 }
229
230 // Take --hydrogen-filter into account.
231 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
232 Handle<String> name = info->function()->debug_name();
233 bool match = filter.is_empty() || name->IsEqualTo(filter);
234 if (!match) {
235 info->SetCode(code);
236 return true;
237 }
238
239 // Recompile the unoptimized version of the code if the current version
240 // doesn't have deoptimization support. Alternatively, we may decide to
241 // run the full code generator to get a baseline for the compile-time
242 // performance of the hydrogen-based compiler.
243 int64_t start = OS::Ticks();
244 bool should_recompile = !info->shared_info()->has_deoptimization_support();
Steve Block44f0eee2011-05-26 01:26:41 +0100245 if (should_recompile || FLAG_hydrogen_stats) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100246 HPhase phase(HPhase::kFullCodeGen);
247 CompilationInfo unoptimized(info->shared_info());
248 // Note that we use the same AST that we will use for generating the
249 // optimized code.
250 unoptimized.SetFunction(info->function());
251 unoptimized.SetScope(info->scope());
252 if (should_recompile) unoptimized.EnableDeoptimizationSupport();
253 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized);
254 if (should_recompile) {
255 if (!succeeded) return false;
256 Handle<SharedFunctionInfo> shared = info->shared_info();
257 shared->EnableDeoptimizationSupport(*unoptimized.code());
258 // The existing unoptimized code was replaced with the new one.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100259 Compiler::RecordFunctionCompilation(
260 Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100261 }
262 }
263
264 // Check that the unoptimized, shared code is ready for
265 // optimizations. When using the always_opt flag we disregard the
266 // optimizable marker in the code object and optimize anyway. This
267 // is safe as long as the unoptimized code has deoptimization
268 // support.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100269 ASSERT(FLAG_always_opt || code->optimizable());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100270 ASSERT(info->shared_info()->has_deoptimization_support());
271
272 if (FLAG_trace_hydrogen) {
273 PrintF("-----------------------------------------------------------\n");
274 PrintF("Compiling method %s using hydrogen\n", *name->ToCString());
275 HTracer::Instance()->TraceCompilation(info->function());
276 }
277
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100278 Handle<Context> global_context(info->closure()->context()->global_context());
279 TypeFeedbackOracle oracle(code, global_context);
280 HGraphBuilder builder(info, &oracle);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100281 HPhase phase(HPhase::kTotal);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100282 HGraph* graph = builder.CreateGraph();
Steve Block44f0eee2011-05-26 01:26:41 +0100283 if (info->isolate()->has_pending_exception()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100284 info->SetCode(Handle<Code>::null());
285 return false;
286 }
287
Ben Murdochb0fe1622011-05-05 13:52:32 +0100288 if (graph != NULL && FLAG_build_lithium) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100289 Handle<Code> optimized_code = graph->Compile(info);
290 if (!optimized_code.is_null()) {
291 info->SetCode(optimized_code);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100292 FinishOptimization(info->closure(), start);
293 return true;
294 }
295 }
296
Ben Murdoch257744e2011-11-30 15:57:28 +0000297 // Keep using the shared code.
298 info->AbortOptimization();
299 if (!builder.inline_bailout()) {
300 // Mark the shared code as unoptimizable unless it was an inlined
301 // function that bailed out.
302 Handle<JSFunction> closure = info->closure();
303 info->shared_info()->DisableOptimization(*closure);
304 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100305 // True indicates the compilation pipeline is still going, not necessarily
306 // that we optimized the code.
307 return true;
308}
309
310
Ben Murdoch257744e2011-11-30 15:57:28 +0000311static bool GenerateCode(CompilationInfo* info) {
312 return V8::UseCrankshaft() ?
313 MakeCrankshaftCode(info) :
314 FullCodeGenerator::MakeCode(info);
315}
316
317
Ben Murdochf87a2032010-10-22 12:50:53 +0100318static bool MakeCode(CompilationInfo* info) {
319 // Precondition: code has been parsed. Postcondition: the code field in
320 // the compilation info is set if compilation succeeded.
321 ASSERT(info->function() != NULL);
Ben Murdoch257744e2011-11-30 15:57:28 +0000322 return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000323}
324
325
Steve Block6ded16b2010-05-10 14:33:55 +0100326#ifdef ENABLE_DEBUGGER_SUPPORT
Ben Murdochf87a2032010-10-22 12:50:53 +0100327bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) {
328 // Precondition: code has been parsed. Postcondition: the code field in
329 // the compilation info is set if compilation succeeded.
330 bool succeeded = MakeCode(info);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100331 if (!info->shared_info().is_null()) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100332 Handle<SerializedScopeInfo> scope_info =
333 SerializedScopeInfo::Create(info->scope());
334 info->shared_info()->set_scope_info(*scope_info);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100335 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100336 return succeeded;
Steve Block6ded16b2010-05-10 14:33:55 +0100337}
338#endif
339
340
Ben Murdochf87a2032010-10-22 12:50:53 +0100341static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
Steve Block44f0eee2011-05-26 01:26:41 +0100342 Isolate* isolate = info->isolate();
Ben Murdoch257744e2011-11-30 15:57:28 +0000343 CompilationZoneScope zone_scope(isolate, DELETE_ON_EXIT);
Steve Block44f0eee2011-05-26 01:26:41 +0100344 PostponeInterruptsScope postpone(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000345
Steve Block44f0eee2011-05-26 01:26:41 +0100346 ASSERT(!isolate->global_context().is_null());
Ben Murdochf87a2032010-10-22 12:50:53 +0100347 Handle<Script> script = info->script();
Steve Block44f0eee2011-05-26 01:26:41 +0100348 script->set_context_data((*isolate->global_context())->data());
Steve Blocka7e24c12009-10-30 11:49:00 +0000349
Leon Clarke4515c472010-02-03 11:58:03 +0000350#ifdef ENABLE_DEBUGGER_SUPPORT
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800351 if (info->is_eval()) {
352 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL;
Ben Murdochf87a2032010-10-22 12:50:53 +0100353 script->set_compilation_type(Smi::FromInt(compilation_type));
Steve Blocka7e24c12009-10-30 11:49:00 +0000354 // For eval scripts add information on the function from which eval was
355 // called.
Ben Murdochf87a2032010-10-22 12:50:53 +0100356 if (info->is_eval()) {
Ben Murdoch8b112d22011-06-08 16:22:53 +0100357 StackTraceFrameIterator it(isolate);
Leon Clarke4515c472010-02-03 11:58:03 +0000358 if (!it.done()) {
359 script->set_eval_from_shared(
360 JSFunction::cast(it.frame()->function())->shared());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100361 Code* code = it.frame()->LookupCode();
Leon Clarke4515c472010-02-03 11:58:03 +0000362 int offset = static_cast<int>(
Steve Block44f0eee2011-05-26 01:26:41 +0100363 it.frame()->pc() - code->instruction_start());
Leon Clarke4515c472010-02-03 11:58:03 +0000364 script->set_eval_from_instructions_offset(Smi::FromInt(offset));
365 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000366 }
367 }
368
369 // Notify debugger
Steve Block44f0eee2011-05-26 01:26:41 +0100370 isolate->debugger()->OnBeforeCompile(script);
Steve Blocka7e24c12009-10-30 11:49:00 +0000371#endif
372
373 // Only allow non-global compiles for eval.
Ben Murdochf87a2032010-10-22 12:50:53 +0100374 ASSERT(info->is_eval() || info->is_global());
Steve Blocka7e24c12009-10-30 11:49:00 +0000375
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800376 if (!ParserApi::Parse(info)) return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000377
Steve Blocka7e24c12009-10-30 11:49:00 +0000378 // Measure how long it takes to do the compilation; only take the
379 // rest of the function into account to avoid overlap with the
380 // parsing statistics.
Ben Murdochf87a2032010-10-22 12:50:53 +0100381 HistogramTimer* rate = info->is_eval()
Steve Block44f0eee2011-05-26 01:26:41 +0100382 ? info->isolate()->counters()->compile_eval()
383 : info->isolate()->counters()->compile();
Steve Blocka7e24c12009-10-30 11:49:00 +0000384 HistogramTimerScope timer(rate);
385
386 // Compile the code.
Ben Murdochf87a2032010-10-22 12:50:53 +0100387 FunctionLiteral* lit = info->function();
Steve Block44f0eee2011-05-26 01:26:41 +0100388 LiveEditFunctionTracker live_edit_tracker(isolate, lit);
Ben Murdochf87a2032010-10-22 12:50:53 +0100389 if (!MakeCode(info)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100390 isolate->StackOverflow();
Steve Block6ded16b2010-05-10 14:33:55 +0100391 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000392 }
393
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100394 // Allocate function.
Ben Murdochf87a2032010-10-22 12:50:53 +0100395 ASSERT(!info->code().is_null());
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100396 Handle<SharedFunctionInfo> result =
Steve Block44f0eee2011-05-26 01:26:41 +0100397 isolate->factory()->NewSharedFunctionInfo(
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100398 lit->name(),
399 lit->materialized_literal_count(),
400 info->code(),
401 SerializedScopeInfo::Create(info->scope()));
402
403 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
404 Compiler::SetFunctionInfo(result, lit, true, script);
405
Steve Block6ded16b2010-05-10 14:33:55 +0100406 if (script->name()->IsString()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100407 PROFILE(isolate, CodeCreateEvent(
Ben Murdochf87a2032010-10-22 12:50:53 +0100408 info->is_eval()
409 ? Logger::EVAL_TAG
410 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
411 *info->code(),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100412 *result,
Ben Murdochf87a2032010-10-22 12:50:53 +0100413 String::cast(script->name())));
Ben Murdochb8e0da22011-05-16 14:20:40 +0100414 GDBJIT(AddCode(Handle<String>(String::cast(script->name())),
415 script,
416 info->code()));
Steve Block6ded16b2010-05-10 14:33:55 +0100417 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100418 PROFILE(isolate, CodeCreateEvent(
Ben Murdochf87a2032010-10-22 12:50:53 +0100419 info->is_eval()
420 ? Logger::EVAL_TAG
421 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
422 *info->code(),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100423 *result,
Steve Block44f0eee2011-05-26 01:26:41 +0100424 isolate->heap()->empty_string()));
Ben Murdochb8e0da22011-05-16 14:20:40 +0100425 GDBJIT(AddCode(Handle<String>(), script, info->code()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000426 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000427
Steve Blocka7e24c12009-10-30 11:49:00 +0000428 // Hint to the runtime system used when allocating space for initial
429 // property space by setting the expected number of properties for
430 // the instances of the function.
Steve Block6ded16b2010-05-10 14:33:55 +0100431 SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count());
Steve Blocka7e24c12009-10-30 11:49:00 +0000432
433#ifdef ENABLE_DEBUGGER_SUPPORT
434 // Notify debugger
Steve Block44f0eee2011-05-26 01:26:41 +0100435 isolate->debugger()->OnAfterCompile(
436 script, Debugger::NO_AFTER_COMPILE_FLAGS);
Steve Blocka7e24c12009-10-30 11:49:00 +0000437#endif
438
Steve Block6ded16b2010-05-10 14:33:55 +0100439 live_edit_tracker.RecordFunctionInfo(result, lit);
440
441 return result;
Steve Blocka7e24c12009-10-30 11:49:00 +0000442}
443
444
Steve Block6ded16b2010-05-10 14:33:55 +0100445Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
446 Handle<Object> script_name,
447 int line_offset,
448 int column_offset,
449 v8::Extension* extension,
450 ScriptDataImpl* input_pre_data,
451 Handle<Object> script_data,
452 NativesFlag natives) {
Steve Block44f0eee2011-05-26 01:26:41 +0100453 Isolate* isolate = source->GetIsolate();
Steve Blocka7e24c12009-10-30 11:49:00 +0000454 int source_length = source->length();
Steve Block44f0eee2011-05-26 01:26:41 +0100455 isolate->counters()->total_load_size()->Increment(source_length);
456 isolate->counters()->total_compile_size()->Increment(source_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000457
458 // The VM is in the COMPILER state until exiting this function.
Steve Block44f0eee2011-05-26 01:26:41 +0100459 VMState state(isolate, COMPILER);
460
461 CompilationCache* compilation_cache = isolate->compilation_cache();
Steve Blocka7e24c12009-10-30 11:49:00 +0000462
463 // Do a lookup in the compilation cache but not for extensions.
Steve Block6ded16b2010-05-10 14:33:55 +0100464 Handle<SharedFunctionInfo> result;
Steve Blocka7e24c12009-10-30 11:49:00 +0000465 if (extension == NULL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100466 result = compilation_cache->LookupScript(source,
467 script_name,
468 line_offset,
469 column_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000470 }
471
472 if (result.is_null()) {
Steve Block59151502010-09-22 15:07:15 +0100473 // No cache entry found. Do pre-parsing, if it makes sense, and compile
474 // the script.
475 // Building preparse data that is only used immediately after is only a
476 // saving if we might skip building the AST for lazily compiled functions.
477 // I.e., preparse data isn't relevant when the lazy flag is off, and
478 // for small sources, odds are that there aren't many functions
479 // that would be compiled lazily anyway, so we skip the preparse step
480 // in that case too.
Steve Blocka7e24c12009-10-30 11:49:00 +0000481 ScriptDataImpl* pre_data = input_pre_data;
Steve Block59151502010-09-22 15:07:15 +0100482 if (pre_data == NULL
Steve Block59151502010-09-22 15:07:15 +0100483 && source_length >= FLAG_min_preparse_length) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100484 if (source->IsExternalTwoByteString()) {
485 ExternalTwoByteStringUC16CharacterStream stream(
486 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
487 pre_data = ParserApi::PartialPreParse(&stream, extension);
488 } else {
489 GenericStringUC16CharacterStream stream(source, 0, source->length());
490 pre_data = ParserApi::PartialPreParse(&stream, extension);
491 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000492 }
493
494 // Create a script object describing the script to be compiled.
Steve Block44f0eee2011-05-26 01:26:41 +0100495 Handle<Script> script = FACTORY->NewScript(source);
Andrei Popescu31002712010-02-23 13:46:05 +0000496 if (natives == NATIVES_CODE) {
497 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
498 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000499 if (!script_name.is_null()) {
500 script->set_name(*script_name);
501 script->set_line_offset(Smi::FromInt(line_offset));
502 script->set_column_offset(Smi::FromInt(column_offset));
503 }
504
Steve Block44f0eee2011-05-26 01:26:41 +0100505 script->set_data(script_data.is_null() ? HEAP->undefined_value()
Andrei Popescu402d9372010-02-26 13:31:12 +0000506 : *script_data);
507
Steve Blocka7e24c12009-10-30 11:49:00 +0000508 // Compile the function and add it to the cache.
Ben Murdochf87a2032010-10-22 12:50:53 +0100509 CompilationInfo info(script);
510 info.MarkAsGlobal();
511 info.SetExtension(extension);
512 info.SetPreParseData(pre_data);
513 result = MakeFunctionInfo(&info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000514 if (extension == NULL && !result.is_null()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100515 compilation_cache->PutScript(source, result);
Steve Blocka7e24c12009-10-30 11:49:00 +0000516 }
517
518 // Get rid of the pre-parsing data (if necessary).
519 if (input_pre_data == NULL && pre_data != NULL) {
520 delete pre_data;
521 }
522 }
523
Steve Block44f0eee2011-05-26 01:26:41 +0100524 if (result.is_null()) isolate->ReportPendingMessages();
Steve Blocka7e24c12009-10-30 11:49:00 +0000525 return result;
526}
527
528
Steve Block6ded16b2010-05-10 14:33:55 +0100529Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
530 Handle<Context> context,
Steve Block1e0659c2011-05-24 12:43:12 +0100531 bool is_global,
532 StrictModeFlag strict_mode) {
Steve Block44f0eee2011-05-26 01:26:41 +0100533 Isolate* isolate = source->GetIsolate();
Steve Blocka7e24c12009-10-30 11:49:00 +0000534 int source_length = source->length();
Steve Block44f0eee2011-05-26 01:26:41 +0100535 isolate->counters()->total_eval_size()->Increment(source_length);
536 isolate->counters()->total_compile_size()->Increment(source_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000537
538 // The VM is in the COMPILER state until exiting this function.
Steve Block44f0eee2011-05-26 01:26:41 +0100539 VMState state(isolate, COMPILER);
Steve Blocka7e24c12009-10-30 11:49:00 +0000540
Ben Murdochf87a2032010-10-22 12:50:53 +0100541 // Do a lookup in the compilation cache; if the entry is not there, invoke
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800542 // the compiler and add the result to the cache.
Steve Block6ded16b2010-05-10 14:33:55 +0100543 Handle<SharedFunctionInfo> result;
Steve Block44f0eee2011-05-26 01:26:41 +0100544 CompilationCache* compilation_cache = isolate->compilation_cache();
545 result = compilation_cache->LookupEval(source,
546 context,
547 is_global,
548 strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000549
550 if (result.is_null()) {
551 // Create a script object describing the script to be compiled.
Steve Block44f0eee2011-05-26 01:26:41 +0100552 Handle<Script> script = isolate->factory()->NewScript(source);
Ben Murdochf87a2032010-10-22 12:50:53 +0100553 CompilationInfo info(script);
554 info.MarkAsEval();
555 if (is_global) info.MarkAsGlobal();
Ben Murdoch8b112d22011-06-08 16:22:53 +0100556 if (strict_mode == kStrictMode) info.MarkAsStrictMode();
Ben Murdochf87a2032010-10-22 12:50:53 +0100557 info.SetCallingContext(context);
558 result = MakeFunctionInfo(&info);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800559 if (!result.is_null()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100560 CompilationCache* compilation_cache = isolate->compilation_cache();
Steve Block1e0659c2011-05-24 12:43:12 +0100561 // If caller is strict mode, the result must be strict as well,
562 // but not the other way around. Consider:
563 // eval("'use strict'; ...");
564 ASSERT(strict_mode == kNonStrictMode || result->strict_mode());
Steve Block44f0eee2011-05-26 01:26:41 +0100565 compilation_cache->PutEval(source, context, is_global, result);
Steve Blocka7e24c12009-10-30 11:49:00 +0000566 }
567 }
568
569 return result;
570}
571
572
Leon Clarke4515c472010-02-03 11:58:03 +0000573bool Compiler::CompileLazy(CompilationInfo* info) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000574 Isolate* isolate = info->isolate();
575
576 CompilationZoneScope zone_scope(isolate, DELETE_ON_EXIT);
Steve Blocka7e24c12009-10-30 11:49:00 +0000577
578 // The VM is in the COMPILER state until exiting this function.
Ben Murdoch257744e2011-11-30 15:57:28 +0000579 VMState state(isolate, COMPILER);
Steve Blocka7e24c12009-10-30 11:49:00 +0000580
Steve Block44f0eee2011-05-26 01:26:41 +0100581 PostponeInterruptsScope postpone(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000582
Leon Clarke4515c472010-02-03 11:58:03 +0000583 Handle<SharedFunctionInfo> shared = info->shared_info();
Ben Murdochf87a2032010-10-22 12:50:53 +0100584 int compiled_size = shared->end_position() - shared->start_position();
Steve Block44f0eee2011-05-26 01:26:41 +0100585 isolate->counters()->total_compile_size()->Increment(compiled_size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000586
Ben Murdochf87a2032010-10-22 12:50:53 +0100587 // Generate the AST for the lazily compiled function.
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800588 if (ParserApi::Parse(info)) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100589 // Measure how long it takes to do the lazy compilation; only take the
590 // rest of the function into account to avoid overlap with the lazy
591 // parsing statistics.
Steve Block44f0eee2011-05-26 01:26:41 +0100592 HistogramTimerScope timer(isolate->counters()->compile_lazy());
Steve Blocka7e24c12009-10-30 11:49:00 +0000593
Ben Murdoch8b112d22011-06-08 16:22:53 +0100594 // After parsing we know function's strict mode. Remember it.
595 if (info->function()->strict_mode()) {
596 shared->set_strict_mode(true);
597 info->MarkAsStrictMode();
598 }
599
Ben Murdochf87a2032010-10-22 12:50:53 +0100600 // Compile the code.
601 if (!MakeCode(info)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100602 if (!isolate->has_pending_exception()) {
603 isolate->StackOverflow();
Steve Block1e0659c2011-05-24 12:43:12 +0100604 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100605 } else {
606 ASSERT(!info->code().is_null());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100607 Handle<Code> code = info->code();
Steve Block44f0eee2011-05-26 01:26:41 +0100608 // Set optimizable to false if this is disallowed by the shared
609 // function info, e.g., we might have flushed the code and must
610 // reset this bit when lazy compiling the code again.
611 if (shared->optimization_disabled()) code->set_optimizable(false);
612
Ben Murdochb0fe1622011-05-05 13:52:32 +0100613 Handle<JSFunction> function = info->closure();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100614 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000615
Ben Murdochb0fe1622011-05-05 13:52:32 +0100616 if (info->IsOptimizing()) {
617 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);
Steve Block44f0eee2011-05-26 01:26:41 +0100658 } else if (isolate->compilation_cache()->ShouldOptimizeEagerly(
659 function)) {
660 isolate->runtime_profiler()->OptimizeSoon(*function);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100661 }
662 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100663 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000664
Ben Murdochf87a2032010-10-22 12:50:53 +0100665 return true;
666 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000667 }
668
Ben Murdochf87a2032010-10-22 12:50:53 +0100669 ASSERT(info->code().is_null());
670 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000671}
672
673
Steve Block6ded16b2010-05-10 14:33:55 +0100674Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
Ben Murdochf87a2032010-10-22 12:50:53 +0100675 Handle<Script> script) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100676 // Precondition: code has been parsed and scopes have been analyzed.
677 CompilationInfo info(script);
678 info.SetFunction(literal);
679 info.SetScope(literal->scope());
Ben Murdoch257744e2011-11-30 15:57:28 +0000680 if (literal->scope()->is_strict_mode()) info.MarkAsStrictMode();
Ben Murdochf87a2032010-10-22 12:50:53 +0100681
Steve Block44f0eee2011-05-26 01:26:41 +0100682 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal);
Ben Murdochf87a2032010-10-22 12:50:53 +0100683 // Determine if the function can be lazily compiled. This is necessary to
684 // allow some of our builtin JS files to be lazily compiled. These
685 // builtins cannot be handled lazily by the parser, since we have to know
686 // if a function uses the special natives syntax, which is something the
687 // parser records.
Andrei Popescu402d9372010-02-26 13:31:12 +0000688 bool allow_lazy = literal->AllowsLazyCompilation() &&
Steve Block44f0eee2011-05-26 01:26:41 +0100689 !LiveEditFunctionTracker::IsActive(info.isolate());
Steve Blockd0582a62009-12-15 09:54:21 +0000690
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100691 Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty());
692
Steve Blockd0582a62009-12-15 09:54:21 +0000693 // Generate code
Steve Blockd0582a62009-12-15 09:54:21 +0000694 if (FLAG_lazy && allow_lazy) {
Steve Block44f0eee2011-05-26 01:26:41 +0100695 Handle<Code> code = info.isolate()->builtins()->LazyCompile();
Ben Murdochf87a2032010-10-22 12:50:53 +0100696 info.SetCode(code);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100697 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) ||
698 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100699 ASSERT(!info.code().is_null());
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100700 scope_info = SerializedScopeInfo::Create(info.scope());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100701 } else {
702 return Handle<SharedFunctionInfo>::null();
Steve Blockd0582a62009-12-15 09:54:21 +0000703 }
704
Steve Block6ded16b2010-05-10 14:33:55 +0100705 // Create a shared function info object.
706 Handle<SharedFunctionInfo> result =
Steve Block44f0eee2011-05-26 01:26:41 +0100707 FACTORY->NewSharedFunctionInfo(literal->name(),
Steve Block6ded16b2010-05-10 14:33:55 +0100708 literal->materialized_literal_count(),
Ben Murdochf87a2032010-10-22 12:50:53 +0100709 info.code(),
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100710 scope_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100711 SetFunctionInfo(result, literal, false, script);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100712 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100713 result->set_allows_lazy_compilation(allow_lazy);
Steve Blockd0582a62009-12-15 09:54:21 +0000714
715 // Set the expected number of properties for instances and return
716 // the resulting function.
Steve Block6ded16b2010-05-10 14:33:55 +0100717 SetExpectedNofPropertiesFromEstimate(result,
Steve Blockd0582a62009-12-15 09:54:21 +0000718 literal->expected_property_count());
Steve Block6ded16b2010-05-10 14:33:55 +0100719 live_edit_tracker.RecordFunctionInfo(result, literal);
720 return result;
Steve Blockd0582a62009-12-15 09:54:21 +0000721}
722
723
724// Sets the function info on a function.
725// The start_position points to the first '(' character after the function name
726// in the full script source. When counting characters in the script source the
727// the first character is number 0 (not 1).
Steve Block6ded16b2010-05-10 14:33:55 +0100728void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
Steve Blockd0582a62009-12-15 09:54:21 +0000729 FunctionLiteral* lit,
730 bool is_toplevel,
731 Handle<Script> script) {
Steve Block6ded16b2010-05-10 14:33:55 +0100732 function_info->set_length(lit->num_parameters());
733 function_info->set_formal_parameter_count(lit->num_parameters());
734 function_info->set_script(*script);
735 function_info->set_function_token_position(lit->function_token_position());
736 function_info->set_start_position(lit->start_position());
737 function_info->set_end_position(lit->end_position());
738 function_info->set_is_expression(lit->is_expression());
739 function_info->set_is_toplevel(is_toplevel);
740 function_info->set_inferred_name(*lit->inferred_name());
741 function_info->SetThisPropertyAssignmentsInfo(
Steve Blockd0582a62009-12-15 09:54:21 +0000742 lit->has_only_simple_this_property_assignments(),
743 *lit->this_property_assignments());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100744 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
Steve Block1e0659c2011-05-24 12:43:12 +0100745 function_info->set_strict_mode(lit->strict_mode());
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()),
784 Handle<Code>(info->code())));
Andrei Popescu31002712010-02-23 13:46:05 +0000785}
Andrei Popescu31002712010-02-23 13:46:05 +0000786
Steve Blocka7e24c12009-10-30 11:49:00 +0000787} } // namespace v8::internal