blob: 86d5de3aec6856acdddbaef03f2fef5e4100cb78 [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 Block6ded16b2010-05-10 14:33:55 +010035#include "data-flow.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000036#include "debug.h"
Leon Clarked91b9f72010-01-27 17:25:45 +000037#include "full-codegen.h"
Ben Murdochb8e0da22011-05-16 14:20:40 +010038#include "gdb-jit.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010039#include "hydrogen.h"
Steve Block1e0659c2011-05-24 12:43:12 +010040#include "lithium.h"
Steve Block6ded16b2010-05-10 14:33:55 +010041#include "liveedit.h"
Ben Murdochf87a2032010-10-22 12:50:53 +010042#include "parser.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000043#include "rewriter.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010044#include "runtime-profiler.h"
Ben Murdoch3bec4d22010-07-22 14:51:16 +010045#include "scopeinfo.h"
Ben Murdochf87a2032010-10-22 12:50:53 +010046#include "scopes.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010047#include "vm-state-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000048
49namespace v8 {
50namespace internal {
51
Ben Murdochf87a2032010-10-22 12:50:53 +010052
53CompilationInfo::CompilationInfo(Handle<Script> script)
Steve Block44f0eee2011-05-26 01:26:41 +010054 : isolate_(script->GetIsolate()),
55 flags_(0),
Ben Murdochf87a2032010-10-22 12:50:53 +010056 function_(NULL),
57 scope_(NULL),
58 script_(script),
59 extension_(NULL),
Ben Murdochb0fe1622011-05-05 13:52:32 +010060 pre_parse_data_(NULL),
61 supports_deoptimization_(false),
62 osr_ast_id_(AstNode::kNoNumber) {
63 Initialize(NONOPT);
Ben Murdochf87a2032010-10-22 12:50:53 +010064}
65
66
67CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info)
Steve Block44f0eee2011-05-26 01:26:41 +010068 : isolate_(shared_info->GetIsolate()),
69 flags_(IsLazy::encode(true)),
Ben Murdochf87a2032010-10-22 12:50:53 +010070 function_(NULL),
71 scope_(NULL),
72 shared_info_(shared_info),
73 script_(Handle<Script>(Script::cast(shared_info->script()))),
74 extension_(NULL),
Ben Murdochb0fe1622011-05-05 13:52:32 +010075 pre_parse_data_(NULL),
76 supports_deoptimization_(false),
77 osr_ast_id_(AstNode::kNoNumber) {
78 Initialize(BASE);
Ben Murdochf87a2032010-10-22 12:50:53 +010079}
80
81
82CompilationInfo::CompilationInfo(Handle<JSFunction> closure)
Steve Block44f0eee2011-05-26 01:26:41 +010083 : isolate_(closure->GetIsolate()),
84 flags_(IsLazy::encode(true)),
Ben Murdochf87a2032010-10-22 12:50:53 +010085 function_(NULL),
86 scope_(NULL),
87 closure_(closure),
88 shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
89 script_(Handle<Script>(Script::cast(shared_info_->script()))),
90 extension_(NULL),
Ben Murdochb0fe1622011-05-05 13:52:32 +010091 pre_parse_data_(NULL),
92 supports_deoptimization_(false),
93 osr_ast_id_(AstNode::kNoNumber) {
94 Initialize(BASE);
Ben Murdochf87a2032010-10-22 12:50:53 +010095}
96
97
Ben Murdochb8e0da22011-05-16 14:20:40 +010098void CompilationInfo::DisableOptimization() {
99 if (FLAG_optimize_closures) {
100 // If we allow closures optimizations and it's an optimizable closure
101 // mark it correspondingly.
102 bool is_closure = closure_.is_null() && !scope_->HasTrivialOuterContext();
103 if (is_closure) {
104 bool is_optimizable_closure =
105 !scope_->outer_scope_calls_eval() && !scope_->inside_with();
106 if (is_optimizable_closure) {
107 SetMode(BASE);
108 return;
109 }
110 }
111 }
112
113 SetMode(NONOPT);
114}
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.
Leon Clarkef7060e22010-06-03 12:02:55 +0100125static bool AlwaysFullCompiler() {
126#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100127 Isolate* isolate = Isolate::Current();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100128 if (V8::UseCrankshaft()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100129 return FLAG_always_full_compiler || isolate->debug()->has_break_points();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100130 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100131 return FLAG_always_full_compiler || isolate->debugger()->IsDebuggerActive();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100132 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100133#else
134 return FLAG_always_full_compiler;
135#endif
136}
137
Steve Block3ce2e202009-11-05 08:53:23 +0000138
Ben Murdochb0fe1622011-05-05 13:52:32 +0100139static void FinishOptimization(Handle<JSFunction> function, int64_t start) {
140 int opt_count = function->shared()->opt_count();
141 function->shared()->set_opt_count(opt_count + 1);
142 double ms = static_cast<double>(OS::Ticks() - start) / 1000;
143 if (FLAG_trace_opt) {
144 PrintF("[optimizing: ");
145 function->PrintName();
146 PrintF(" / %" V8PRIxPTR, reinterpret_cast<intptr_t>(*function));
147 PrintF(" - took %0.3f ms]\n", ms);
148 }
149 if (FLAG_trace_opt_stats) {
150 static double compilation_time = 0.0;
151 static int compiled_functions = 0;
152 static int code_size = 0;
153
154 compilation_time += ms;
155 compiled_functions++;
156 code_size += function->shared()->SourceSize();
157 PrintF("Compiled: %d functions with %d byte source size in %fms.\n",
158 compiled_functions,
159 code_size,
160 compilation_time);
161 }
162}
163
164
165static void AbortAndDisable(CompilationInfo* info) {
166 // Disable optimization for the shared function info and mark the
167 // code as non-optimizable. The marker on the shared function info
168 // is there because we flush non-optimized code thereby loosing the
169 // non-optimizable information for the code. When the code is
170 // regenerated and set on the shared function info it is marked as
171 // non-optimizable if optimization is disabled for the shared
172 // function info.
173 Handle<SharedFunctionInfo> shared = info->shared_info();
174 shared->set_optimization_disabled(true);
175 Handle<Code> code = Handle<Code>(shared->code());
176 ASSERT(code->kind() == Code::FUNCTION);
177 code->set_optimizable(false);
178 info->SetCode(code);
Steve Block44f0eee2011-05-26 01:26:41 +0100179 Isolate* isolate = code->GetIsolate();
180 isolate->compilation_cache()->MarkForLazyOptimizing(info->closure());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100181 if (FLAG_trace_opt) {
182 PrintF("[disabled optimization for: ");
183 info->closure()->PrintName();
184 PrintF(" / %" V8PRIxPTR "]\n",
185 reinterpret_cast<intptr_t>(*info->closure()));
186 }
187}
188
189
190static bool MakeCrankshaftCode(CompilationInfo* info) {
191 // Test if we can optimize this function when asked to. We can only
192 // do this after the scopes are computed.
193 if (!info->AllowOptimize()) info->DisableOptimization();
194
195 // In case we are not optimizing simply return the code from
196 // the full code generator.
197 if (!info->IsOptimizing()) {
198 return FullCodeGenerator::MakeCode(info);
199 }
200
201 // We should never arrive here if there is not code object on the
202 // shared function object.
203 Handle<Code> code(info->shared_info()->code());
204 ASSERT(code->kind() == Code::FUNCTION);
205
Steve Block44f0eee2011-05-26 01:26:41 +0100206 // We should never arrive here if optimization has been disabled on the
207 // shared function info.
208 ASSERT(!info->shared_info()->optimization_disabled());
209
Ben Murdochb0fe1622011-05-05 13:52:32 +0100210 // Fall back to using the full code generator if it's not possible
211 // to use the Hydrogen-based optimizing compiler. We already have
212 // generated code for this from the shared function object.
213 if (AlwaysFullCompiler() || !FLAG_use_hydrogen) {
214 info->SetCode(code);
215 return true;
216 }
217
218 // Limit the number of times we re-compile a functions with
219 // the optimizing compiler.
Ben Murdochb8e0da22011-05-16 14:20:40 +0100220 const int kMaxOptCount =
221 FLAG_deopt_every_n_times == 0 ? Compiler::kDefaultMaxOptCount : 1000;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100222 if (info->shared_info()->opt_count() > kMaxOptCount) {
223 AbortAndDisable(info);
224 // True indicates the compilation pipeline is still going, not
225 // necessarily that we optimized the code.
226 return true;
227 }
228
229 // Due to an encoding limit on LUnallocated operands in the Lithium
230 // language, we cannot optimize functions with too many formal parameters
231 // or perform on-stack replacement for function with too many
232 // stack-allocated local variables.
233 //
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100234 // The encoding is as a signed value, with parameters and receiver using
235 // the negative indices and locals the non-negative ones.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100236 const int limit = LUnallocated::kMaxFixedIndices / 2;
237 Scope* scope = info->scope();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100238 if ((scope->num_parameters() + 1) > limit ||
239 scope->num_stack_slots() > limit) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100240 AbortAndDisable(info);
241 // True indicates the compilation pipeline is still going, not
242 // necessarily that we optimized the code.
243 return true;
244 }
245
246 // Take --hydrogen-filter into account.
247 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
248 Handle<String> name = info->function()->debug_name();
249 bool match = filter.is_empty() || name->IsEqualTo(filter);
250 if (!match) {
251 info->SetCode(code);
252 return true;
253 }
254
255 // Recompile the unoptimized version of the code if the current version
256 // doesn't have deoptimization support. Alternatively, we may decide to
257 // run the full code generator to get a baseline for the compile-time
258 // performance of the hydrogen-based compiler.
259 int64_t start = OS::Ticks();
260 bool should_recompile = !info->shared_info()->has_deoptimization_support();
Steve Block44f0eee2011-05-26 01:26:41 +0100261 if (should_recompile || FLAG_hydrogen_stats) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100262 HPhase phase(HPhase::kFullCodeGen);
263 CompilationInfo unoptimized(info->shared_info());
264 // Note that we use the same AST that we will use for generating the
265 // optimized code.
266 unoptimized.SetFunction(info->function());
267 unoptimized.SetScope(info->scope());
268 if (should_recompile) unoptimized.EnableDeoptimizationSupport();
269 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized);
270 if (should_recompile) {
271 if (!succeeded) return false;
272 Handle<SharedFunctionInfo> shared = info->shared_info();
273 shared->EnableDeoptimizationSupport(*unoptimized.code());
274 // The existing unoptimized code was replaced with the new one.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100275 Compiler::RecordFunctionCompilation(
276 Logger::LAZY_COMPILE_TAG, &unoptimized, shared);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100277 }
278 }
279
280 // Check that the unoptimized, shared code is ready for
281 // optimizations. When using the always_opt flag we disregard the
282 // optimizable marker in the code object and optimize anyway. This
283 // is safe as long as the unoptimized code has deoptimization
284 // support.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100285 ASSERT(FLAG_always_opt || code->optimizable());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100286 ASSERT(info->shared_info()->has_deoptimization_support());
287
288 if (FLAG_trace_hydrogen) {
289 PrintF("-----------------------------------------------------------\n");
290 PrintF("Compiling method %s using hydrogen\n", *name->ToCString());
291 HTracer::Instance()->TraceCompilation(info->function());
292 }
293
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100294 Handle<Context> global_context(info->closure()->context()->global_context());
295 TypeFeedbackOracle oracle(code, global_context);
296 HGraphBuilder builder(info, &oracle);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100297 HPhase phase(HPhase::kTotal);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100298 HGraph* graph = builder.CreateGraph();
Steve Block44f0eee2011-05-26 01:26:41 +0100299 if (info->isolate()->has_pending_exception()) {
Steve Block1e0659c2011-05-24 12:43:12 +0100300 info->SetCode(Handle<Code>::null());
301 return false;
302 }
303
Ben Murdochb0fe1622011-05-05 13:52:32 +0100304 if (graph != NULL && FLAG_build_lithium) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100305 Handle<Code> optimized_code = graph->Compile(info);
306 if (!optimized_code.is_null()) {
307 info->SetCode(optimized_code);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100308 FinishOptimization(info->closure(), start);
309 return true;
310 }
311 }
312
313 // Compilation with the Hydrogen compiler failed. Keep using the
314 // shared code but mark it as unoptimizable.
315 AbortAndDisable(info);
316 // True indicates the compilation pipeline is still going, not necessarily
317 // that we optimized the code.
318 return true;
319}
320
321
Ben Murdochf87a2032010-10-22 12:50:53 +0100322static bool MakeCode(CompilationInfo* info) {
323 // Precondition: code has been parsed. Postcondition: the code field in
324 // the compilation info is set if compilation succeeded.
325 ASSERT(info->function() != NULL);
326
Ben Murdochb0fe1622011-05-05 13:52:32 +0100327 if (Rewriter::Rewrite(info) && Scope::Analyze(info)) {
328 if (V8::UseCrankshaft()) return MakeCrankshaftCode(info);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100329 // If crankshaft is not supported fall back to full code generator
330 // for all compilation.
331 return FullCodeGenerator::MakeCode(info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 }
333
Ben Murdochf87a2032010-10-22 12:50:53 +0100334 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000335}
336
337
Steve Block6ded16b2010-05-10 14:33:55 +0100338#ifdef ENABLE_DEBUGGER_SUPPORT
Ben Murdochf87a2032010-10-22 12:50:53 +0100339bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) {
340 // Precondition: code has been parsed. Postcondition: the code field in
341 // the compilation info is set if compilation succeeded.
342 bool succeeded = MakeCode(info);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100343 if (!info->shared_info().is_null()) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100344 Handle<SerializedScopeInfo> scope_info =
345 SerializedScopeInfo::Create(info->scope());
346 info->shared_info()->set_scope_info(*scope_info);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100347 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100348 return succeeded;
Steve Block6ded16b2010-05-10 14:33:55 +0100349}
350#endif
351
352
Ben Murdochf87a2032010-10-22 12:50:53 +0100353static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000354 CompilationZoneScope zone_scope(DELETE_ON_EXIT);
355
Steve Block44f0eee2011-05-26 01:26:41 +0100356 Isolate* isolate = info->isolate();
357 PostponeInterruptsScope postpone(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000358
Steve Block44f0eee2011-05-26 01:26:41 +0100359 ASSERT(!isolate->global_context().is_null());
Ben Murdochf87a2032010-10-22 12:50:53 +0100360 Handle<Script> script = info->script();
Steve Block44f0eee2011-05-26 01:26:41 +0100361 script->set_context_data((*isolate->global_context())->data());
Steve Blocka7e24c12009-10-30 11:49:00 +0000362
Leon Clarke4515c472010-02-03 11:58:03 +0000363#ifdef ENABLE_DEBUGGER_SUPPORT
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800364 if (info->is_eval()) {
365 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL;
Ben Murdochf87a2032010-10-22 12:50:53 +0100366 script->set_compilation_type(Smi::FromInt(compilation_type));
Steve Blocka7e24c12009-10-30 11:49:00 +0000367 // For eval scripts add information on the function from which eval was
368 // called.
Ben Murdochf87a2032010-10-22 12:50:53 +0100369 if (info->is_eval()) {
Ben Murdoch8b112d22011-06-08 16:22:53 +0100370 StackTraceFrameIterator it(isolate);
Leon Clarke4515c472010-02-03 11:58:03 +0000371 if (!it.done()) {
372 script->set_eval_from_shared(
373 JSFunction::cast(it.frame()->function())->shared());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100374 Code* code = it.frame()->LookupCode();
Leon Clarke4515c472010-02-03 11:58:03 +0000375 int offset = static_cast<int>(
Steve Block44f0eee2011-05-26 01:26:41 +0100376 it.frame()->pc() - code->instruction_start());
Leon Clarke4515c472010-02-03 11:58:03 +0000377 script->set_eval_from_instructions_offset(Smi::FromInt(offset));
378 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000379 }
380 }
381
382 // Notify debugger
Steve Block44f0eee2011-05-26 01:26:41 +0100383 isolate->debugger()->OnBeforeCompile(script);
Steve Blocka7e24c12009-10-30 11:49:00 +0000384#endif
385
386 // Only allow non-global compiles for eval.
Ben Murdochf87a2032010-10-22 12:50:53 +0100387 ASSERT(info->is_eval() || info->is_global());
Steve Blocka7e24c12009-10-30 11:49:00 +0000388
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800389 if (!ParserApi::Parse(info)) return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000390
Steve Blocka7e24c12009-10-30 11:49:00 +0000391 // Measure how long it takes to do the compilation; only take the
392 // rest of the function into account to avoid overlap with the
393 // parsing statistics.
Ben Murdochf87a2032010-10-22 12:50:53 +0100394 HistogramTimer* rate = info->is_eval()
Steve Block44f0eee2011-05-26 01:26:41 +0100395 ? info->isolate()->counters()->compile_eval()
396 : info->isolate()->counters()->compile();
Steve Blocka7e24c12009-10-30 11:49:00 +0000397 HistogramTimerScope timer(rate);
398
399 // Compile the code.
Ben Murdochf87a2032010-10-22 12:50:53 +0100400 FunctionLiteral* lit = info->function();
Steve Block44f0eee2011-05-26 01:26:41 +0100401 LiveEditFunctionTracker live_edit_tracker(isolate, lit);
Ben Murdochf87a2032010-10-22 12:50:53 +0100402 if (!MakeCode(info)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100403 isolate->StackOverflow();
Steve Block6ded16b2010-05-10 14:33:55 +0100404 return Handle<SharedFunctionInfo>::null();
Steve Blocka7e24c12009-10-30 11:49:00 +0000405 }
406
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100407 // Allocate function.
Ben Murdochf87a2032010-10-22 12:50:53 +0100408 ASSERT(!info->code().is_null());
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100409 Handle<SharedFunctionInfo> result =
Steve Block44f0eee2011-05-26 01:26:41 +0100410 isolate->factory()->NewSharedFunctionInfo(
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100411 lit->name(),
412 lit->materialized_literal_count(),
413 info->code(),
414 SerializedScopeInfo::Create(info->scope()));
415
416 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
417 Compiler::SetFunctionInfo(result, lit, true, script);
418
Steve Block6ded16b2010-05-10 14:33:55 +0100419 if (script->name()->IsString()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100420 PROFILE(isolate, CodeCreateEvent(
Ben Murdochf87a2032010-10-22 12:50:53 +0100421 info->is_eval()
422 ? Logger::EVAL_TAG
423 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
424 *info->code(),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100425 *result,
Ben Murdochf87a2032010-10-22 12:50:53 +0100426 String::cast(script->name())));
Ben Murdochb8e0da22011-05-16 14:20:40 +0100427 GDBJIT(AddCode(Handle<String>(String::cast(script->name())),
428 script,
429 info->code()));
Steve Block6ded16b2010-05-10 14:33:55 +0100430 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100431 PROFILE(isolate, CodeCreateEvent(
Ben Murdochf87a2032010-10-22 12:50:53 +0100432 info->is_eval()
433 ? Logger::EVAL_TAG
434 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
435 *info->code(),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100436 *result,
Steve Block44f0eee2011-05-26 01:26:41 +0100437 isolate->heap()->empty_string()));
Ben Murdochb8e0da22011-05-16 14:20:40 +0100438 GDBJIT(AddCode(Handle<String>(), script, info->code()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000439 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000440
Steve Blocka7e24c12009-10-30 11:49:00 +0000441 // Hint to the runtime system used when allocating space for initial
442 // property space by setting the expected number of properties for
443 // the instances of the function.
Steve Block6ded16b2010-05-10 14:33:55 +0100444 SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count());
Steve Blocka7e24c12009-10-30 11:49:00 +0000445
446#ifdef ENABLE_DEBUGGER_SUPPORT
447 // Notify debugger
Steve Block44f0eee2011-05-26 01:26:41 +0100448 isolate->debugger()->OnAfterCompile(
449 script, Debugger::NO_AFTER_COMPILE_FLAGS);
Steve Blocka7e24c12009-10-30 11:49:00 +0000450#endif
451
Steve Block6ded16b2010-05-10 14:33:55 +0100452 live_edit_tracker.RecordFunctionInfo(result, lit);
453
454 return result;
Steve Blocka7e24c12009-10-30 11:49:00 +0000455}
456
457
Steve Block6ded16b2010-05-10 14:33:55 +0100458Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
459 Handle<Object> script_name,
460 int line_offset,
461 int column_offset,
462 v8::Extension* extension,
463 ScriptDataImpl* input_pre_data,
464 Handle<Object> script_data,
465 NativesFlag natives) {
Steve Block44f0eee2011-05-26 01:26:41 +0100466 Isolate* isolate = source->GetIsolate();
Steve Blocka7e24c12009-10-30 11:49:00 +0000467 int source_length = source->length();
Steve Block44f0eee2011-05-26 01:26:41 +0100468 isolate->counters()->total_load_size()->Increment(source_length);
469 isolate->counters()->total_compile_size()->Increment(source_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000470
471 // The VM is in the COMPILER state until exiting this function.
Steve Block44f0eee2011-05-26 01:26:41 +0100472 VMState state(isolate, COMPILER);
473
474 CompilationCache* compilation_cache = isolate->compilation_cache();
Steve Blocka7e24c12009-10-30 11:49:00 +0000475
476 // Do a lookup in the compilation cache but not for extensions.
Steve Block6ded16b2010-05-10 14:33:55 +0100477 Handle<SharedFunctionInfo> result;
Steve Blocka7e24c12009-10-30 11:49:00 +0000478 if (extension == NULL) {
Steve Block44f0eee2011-05-26 01:26:41 +0100479 result = compilation_cache->LookupScript(source,
480 script_name,
481 line_offset,
482 column_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000483 }
484
485 if (result.is_null()) {
Steve Block59151502010-09-22 15:07:15 +0100486 // No cache entry found. Do pre-parsing, if it makes sense, and compile
487 // the script.
488 // Building preparse data that is only used immediately after is only a
489 // saving if we might skip building the AST for lazily compiled functions.
490 // I.e., preparse data isn't relevant when the lazy flag is off, and
491 // for small sources, odds are that there aren't many functions
492 // that would be compiled lazily anyway, so we skip the preparse step
493 // in that case too.
Steve Blocka7e24c12009-10-30 11:49:00 +0000494 ScriptDataImpl* pre_data = input_pre_data;
Steve Block59151502010-09-22 15:07:15 +0100495 if (pre_data == NULL
Steve Block59151502010-09-22 15:07:15 +0100496 && source_length >= FLAG_min_preparse_length) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100497 if (source->IsExternalTwoByteString()) {
498 ExternalTwoByteStringUC16CharacterStream stream(
499 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
500 pre_data = ParserApi::PartialPreParse(&stream, extension);
501 } else {
502 GenericStringUC16CharacterStream stream(source, 0, source->length());
503 pre_data = ParserApi::PartialPreParse(&stream, extension);
504 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000505 }
506
507 // Create a script object describing the script to be compiled.
Steve Block44f0eee2011-05-26 01:26:41 +0100508 Handle<Script> script = FACTORY->NewScript(source);
Andrei Popescu31002712010-02-23 13:46:05 +0000509 if (natives == NATIVES_CODE) {
510 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
511 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000512 if (!script_name.is_null()) {
513 script->set_name(*script_name);
514 script->set_line_offset(Smi::FromInt(line_offset));
515 script->set_column_offset(Smi::FromInt(column_offset));
516 }
517
Steve Block44f0eee2011-05-26 01:26:41 +0100518 script->set_data(script_data.is_null() ? HEAP->undefined_value()
Andrei Popescu402d9372010-02-26 13:31:12 +0000519 : *script_data);
520
Steve Blocka7e24c12009-10-30 11:49:00 +0000521 // Compile the function and add it to the cache.
Ben Murdochf87a2032010-10-22 12:50:53 +0100522 CompilationInfo info(script);
523 info.MarkAsGlobal();
524 info.SetExtension(extension);
525 info.SetPreParseData(pre_data);
Steve Block44f0eee2011-05-26 01:26:41 +0100526 if (natives == NATIVES_CODE) info.MarkAsAllowingNativesSyntax();
Ben Murdochf87a2032010-10-22 12:50:53 +0100527 result = MakeFunctionInfo(&info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000528 if (extension == NULL && !result.is_null()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100529 compilation_cache->PutScript(source, result);
Steve Blocka7e24c12009-10-30 11:49:00 +0000530 }
531
532 // Get rid of the pre-parsing data (if necessary).
533 if (input_pre_data == NULL && pre_data != NULL) {
534 delete pre_data;
535 }
536 }
537
Steve Block44f0eee2011-05-26 01:26:41 +0100538 if (result.is_null()) isolate->ReportPendingMessages();
Steve Blocka7e24c12009-10-30 11:49:00 +0000539 return result;
540}
541
542
Steve Block6ded16b2010-05-10 14:33:55 +0100543Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
544 Handle<Context> context,
Steve Block1e0659c2011-05-24 12:43:12 +0100545 bool is_global,
546 StrictModeFlag strict_mode) {
Steve Block44f0eee2011-05-26 01:26:41 +0100547 Isolate* isolate = source->GetIsolate();
Steve Blocka7e24c12009-10-30 11:49:00 +0000548 int source_length = source->length();
Steve Block44f0eee2011-05-26 01:26:41 +0100549 isolate->counters()->total_eval_size()->Increment(source_length);
550 isolate->counters()->total_compile_size()->Increment(source_length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000551
552 // The VM is in the COMPILER state until exiting this function.
Steve Block44f0eee2011-05-26 01:26:41 +0100553 VMState state(isolate, COMPILER);
Steve Blocka7e24c12009-10-30 11:49:00 +0000554
Ben Murdochf87a2032010-10-22 12:50:53 +0100555 // Do a lookup in the compilation cache; if the entry is not there, invoke
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800556 // the compiler and add the result to the cache.
Steve Block6ded16b2010-05-10 14:33:55 +0100557 Handle<SharedFunctionInfo> result;
Steve Block44f0eee2011-05-26 01:26:41 +0100558 CompilationCache* compilation_cache = isolate->compilation_cache();
559 result = compilation_cache->LookupEval(source,
560 context,
561 is_global,
562 strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000563
564 if (result.is_null()) {
565 // Create a script object describing the script to be compiled.
Steve Block44f0eee2011-05-26 01:26:41 +0100566 Handle<Script> script = isolate->factory()->NewScript(source);
Ben Murdochf87a2032010-10-22 12:50:53 +0100567 CompilationInfo info(script);
568 info.MarkAsEval();
569 if (is_global) info.MarkAsGlobal();
Ben Murdoch8b112d22011-06-08 16:22:53 +0100570 if (strict_mode == kStrictMode) info.MarkAsStrictMode();
Ben Murdochf87a2032010-10-22 12:50:53 +0100571 info.SetCallingContext(context);
572 result = MakeFunctionInfo(&info);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800573 if (!result.is_null()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100574 CompilationCache* compilation_cache = isolate->compilation_cache();
Steve Block1e0659c2011-05-24 12:43:12 +0100575 // If caller is strict mode, the result must be strict as well,
576 // but not the other way around. Consider:
577 // eval("'use strict'; ...");
578 ASSERT(strict_mode == kNonStrictMode || result->strict_mode());
Steve Block44f0eee2011-05-26 01:26:41 +0100579 compilation_cache->PutEval(source, context, is_global, result);
Steve Blocka7e24c12009-10-30 11:49:00 +0000580 }
581 }
582
583 return result;
584}
585
586
Leon Clarke4515c472010-02-03 11:58:03 +0000587bool Compiler::CompileLazy(CompilationInfo* info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000588 CompilationZoneScope zone_scope(DELETE_ON_EXIT);
589
590 // The VM is in the COMPILER state until exiting this function.
Steve Block44f0eee2011-05-26 01:26:41 +0100591 VMState state(info->isolate(), COMPILER);
Steve Blocka7e24c12009-10-30 11:49:00 +0000592
Steve Block44f0eee2011-05-26 01:26:41 +0100593 Isolate* isolate = info->isolate();
594 PostponeInterruptsScope postpone(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000595
Leon Clarke4515c472010-02-03 11:58:03 +0000596 Handle<SharedFunctionInfo> shared = info->shared_info();
Ben Murdochf87a2032010-10-22 12:50:53 +0100597 int compiled_size = shared->end_position() - shared->start_position();
Steve Block44f0eee2011-05-26 01:26:41 +0100598 isolate->counters()->total_compile_size()->Increment(compiled_size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000599
Ben Murdochf87a2032010-10-22 12:50:53 +0100600 // Generate the AST for the lazily compiled function.
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800601 if (ParserApi::Parse(info)) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100602 // Measure how long it takes to do the lazy compilation; only take the
603 // rest of the function into account to avoid overlap with the lazy
604 // parsing statistics.
Steve Block44f0eee2011-05-26 01:26:41 +0100605 HistogramTimerScope timer(isolate->counters()->compile_lazy());
Steve Blocka7e24c12009-10-30 11:49:00 +0000606
Ben Murdoch8b112d22011-06-08 16:22:53 +0100607 // After parsing we know function's strict mode. Remember it.
608 if (info->function()->strict_mode()) {
609 shared->set_strict_mode(true);
610 info->MarkAsStrictMode();
611 }
612
Ben Murdochf87a2032010-10-22 12:50:53 +0100613 // Compile the code.
614 if (!MakeCode(info)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100615 if (!isolate->has_pending_exception()) {
616 isolate->StackOverflow();
Steve Block1e0659c2011-05-24 12:43:12 +0100617 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100618 } else {
619 ASSERT(!info->code().is_null());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100620 Handle<Code> code = info->code();
Steve Block44f0eee2011-05-26 01:26:41 +0100621 // Set optimizable to false if this is disallowed by the shared
622 // function info, e.g., we might have flushed the code and must
623 // reset this bit when lazy compiling the code again.
624 if (shared->optimization_disabled()) code->set_optimizable(false);
625
Ben Murdochb0fe1622011-05-05 13:52:32 +0100626 Handle<JSFunction> function = info->closure();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100627 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000628
Ben Murdochb0fe1622011-05-05 13:52:32 +0100629 if (info->IsOptimizing()) {
630 function->ReplaceCode(*code);
631 } else {
632 // Update the shared function info with the compiled code and the
633 // scope info. Please note, that the order of the shared function
634 // info initialization is important since set_scope_info might
635 // trigger a GC, causing the ASSERT below to be invalid if the code
636 // was flushed. By settting the code object last we avoid this.
637 Handle<SerializedScopeInfo> scope_info =
638 SerializedScopeInfo::Create(info->scope());
639 shared->set_scope_info(*scope_info);
640 shared->set_code(*code);
641 if (!function.is_null()) {
642 function->ReplaceCode(*code);
643 ASSERT(!function->IsOptimized());
644 }
645
646 // Set the expected number of properties for instances.
647 FunctionLiteral* lit = info->function();
648 int expected = lit->expected_property_count();
649 SetExpectedNofPropertiesFromEstimate(shared, expected);
650
651 // Set the optimization hints after performing lazy compilation, as
652 // these are not set when the function is set up as a lazily
653 // compiled function.
654 shared->SetThisPropertyAssignmentsInfo(
655 lit->has_only_simple_this_property_assignments(),
656 *lit->this_property_assignments());
657
658 // Check the function has compiled code.
659 ASSERT(shared->is_compiled());
660 shared->set_code_age(0);
661
Steve Block44f0eee2011-05-26 01:26:41 +0100662 if (info->AllowOptimize() && !shared->optimization_disabled()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100663 // If we're asked to always optimize, we compile the optimized
664 // version of the function right away - unless the debugger is
665 // active as it makes no sense to compile optimized code then.
Steve Block44f0eee2011-05-26 01:26:41 +0100666 if (FLAG_always_opt &&
667 !Isolate::Current()->debug()->has_break_points()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100668 CompilationInfo optimized(function);
669 optimized.SetOptimizing(AstNode::kNoNumber);
670 return CompileLazy(&optimized);
Steve Block44f0eee2011-05-26 01:26:41 +0100671 } else if (isolate->compilation_cache()->ShouldOptimizeEagerly(
672 function)) {
673 isolate->runtime_profiler()->OptimizeSoon(*function);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100674 }
675 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100676 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000677
Ben Murdochf87a2032010-10-22 12:50:53 +0100678 return true;
679 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000680 }
681
Ben Murdochf87a2032010-10-22 12:50:53 +0100682 ASSERT(info->code().is_null());
683 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000684}
685
686
Steve Block6ded16b2010-05-10 14:33:55 +0100687Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
Ben Murdochf87a2032010-10-22 12:50:53 +0100688 Handle<Script> script) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100689 // Precondition: code has been parsed and scopes have been analyzed.
690 CompilationInfo info(script);
691 info.SetFunction(literal);
692 info.SetScope(literal->scope());
693
Steve Block44f0eee2011-05-26 01:26:41 +0100694 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal);
Ben Murdochf87a2032010-10-22 12:50:53 +0100695 // Determine if the function can be lazily compiled. This is necessary to
696 // allow some of our builtin JS files to be lazily compiled. These
697 // builtins cannot be handled lazily by the parser, since we have to know
698 // if a function uses the special natives syntax, which is something the
699 // parser records.
Andrei Popescu402d9372010-02-26 13:31:12 +0000700 bool allow_lazy = literal->AllowsLazyCompilation() &&
Steve Block44f0eee2011-05-26 01:26:41 +0100701 !LiveEditFunctionTracker::IsActive(info.isolate());
Steve Blockd0582a62009-12-15 09:54:21 +0000702
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100703 Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty());
704
Steve Blockd0582a62009-12-15 09:54:21 +0000705 // Generate code
Steve Blockd0582a62009-12-15 09:54:21 +0000706 if (FLAG_lazy && allow_lazy) {
Steve Block44f0eee2011-05-26 01:26:41 +0100707 Handle<Code> code = info.isolate()->builtins()->LazyCompile();
Ben Murdochf87a2032010-10-22 12:50:53 +0100708 info.SetCode(code);
Ben Murdoch8b112d22011-06-08 16:22:53 +0100709 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) ||
710 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100711 ASSERT(!info.code().is_null());
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100712 scope_info = SerializedScopeInfo::Create(info.scope());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100713 } else {
714 return Handle<SharedFunctionInfo>::null();
Steve Blockd0582a62009-12-15 09:54:21 +0000715 }
716
Steve Block6ded16b2010-05-10 14:33:55 +0100717 // Create a shared function info object.
718 Handle<SharedFunctionInfo> result =
Steve Block44f0eee2011-05-26 01:26:41 +0100719 FACTORY->NewSharedFunctionInfo(literal->name(),
Steve Block6ded16b2010-05-10 14:33:55 +0100720 literal->materialized_literal_count(),
Ben Murdochf87a2032010-10-22 12:50:53 +0100721 info.code(),
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100722 scope_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100723 SetFunctionInfo(result, literal, false, script);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100724 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100725 result->set_allows_lazy_compilation(allow_lazy);
Steve Blockd0582a62009-12-15 09:54:21 +0000726
727 // Set the expected number of properties for instances and return
728 // the resulting function.
Steve Block6ded16b2010-05-10 14:33:55 +0100729 SetExpectedNofPropertiesFromEstimate(result,
Steve Blockd0582a62009-12-15 09:54:21 +0000730 literal->expected_property_count());
Steve Block6ded16b2010-05-10 14:33:55 +0100731 live_edit_tracker.RecordFunctionInfo(result, literal);
732 return result;
Steve Blockd0582a62009-12-15 09:54:21 +0000733}
734
735
736// Sets the function info on a function.
737// The start_position points to the first '(' character after the function name
738// in the full script source. When counting characters in the script source the
739// the first character is number 0 (not 1).
Steve Block6ded16b2010-05-10 14:33:55 +0100740void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
Steve Blockd0582a62009-12-15 09:54:21 +0000741 FunctionLiteral* lit,
742 bool is_toplevel,
743 Handle<Script> script) {
Steve Block6ded16b2010-05-10 14:33:55 +0100744 function_info->set_length(lit->num_parameters());
745 function_info->set_formal_parameter_count(lit->num_parameters());
746 function_info->set_script(*script);
747 function_info->set_function_token_position(lit->function_token_position());
748 function_info->set_start_position(lit->start_position());
749 function_info->set_end_position(lit->end_position());
750 function_info->set_is_expression(lit->is_expression());
751 function_info->set_is_toplevel(is_toplevel);
752 function_info->set_inferred_name(*lit->inferred_name());
753 function_info->SetThisPropertyAssignmentsInfo(
Steve Blockd0582a62009-12-15 09:54:21 +0000754 lit->has_only_simple_this_property_assignments(),
755 *lit->this_property_assignments());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100756 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
Steve Block1e0659c2011-05-24 12:43:12 +0100757 function_info->set_strict_mode(lit->strict_mode());
Steve Blockd0582a62009-12-15 09:54:21 +0000758}
759
760
Steve Block6ded16b2010-05-10 14:33:55 +0100761void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100762 CompilationInfo* info,
763 Handle<SharedFunctionInfo> shared) {
764 // SharedFunctionInfo is passed separately, because if CompilationInfo
765 // was created using Script object, it will not have it.
766
Ben Murdochf87a2032010-10-22 12:50:53 +0100767 // Log the code generation. If source information is available include
768 // script name and line number. Check explicitly whether logging is
769 // enabled as finding the line number is not free.
Steve Block44f0eee2011-05-26 01:26:41 +0100770 if (info->isolate()->logger()->is_logging() || CpuProfiler::is_profiling()) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100771 Handle<Script> script = info->script();
772 Handle<Code> code = info->code();
Steve Block44f0eee2011-05-26 01:26:41 +0100773 if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile))
774 return;
Andrei Popescu31002712010-02-23 13:46:05 +0000775 if (script->name()->IsString()) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100776 int line_num = GetScriptLineNumber(script, shared->start_position()) + 1;
Steve Block6ded16b2010-05-10 14:33:55 +0100777 USE(line_num);
Steve Block44f0eee2011-05-26 01:26:41 +0100778 PROFILE(info->isolate(),
779 CodeCreateEvent(Logger::ToNativeByScript(tag, *script),
Ben Murdochf87a2032010-10-22 12:50:53 +0100780 *code,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100781 *shared,
Ben Murdochf87a2032010-10-22 12:50:53 +0100782 String::cast(script->name()),
783 line_num));
Andrei Popescu31002712010-02-23 13:46:05 +0000784 } else {
Steve Block44f0eee2011-05-26 01:26:41 +0100785 PROFILE(info->isolate(),
786 CodeCreateEvent(Logger::ToNativeByScript(tag, *script),
Ben Murdochf87a2032010-10-22 12:50:53 +0100787 *code,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100788 *shared,
789 shared->DebugName()));
Andrei Popescu31002712010-02-23 13:46:05 +0000790 }
791 }
Ben Murdochb8e0da22011-05-16 14:20:40 +0100792
Ben Murdoch8b112d22011-06-08 16:22:53 +0100793 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
Ben Murdochb8e0da22011-05-16 14:20:40 +0100794 Handle<Script>(info->script()),
795 Handle<Code>(info->code())));
Andrei Popescu31002712010-02-23 13:46:05 +0000796}
Andrei Popescu31002712010-02-23 13:46:05 +0000797
Steve Blocka7e24c12009-10-30 11:49:00 +0000798} } // namespace v8::internal