Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: src/compiler.cc

Issue 10534139: One Zone per CompilationInfo. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "runtime-profiler.h" 44 #include "runtime-profiler.h"
45 #include "scanner-character-streams.h" 45 #include "scanner-character-streams.h"
46 #include "scopeinfo.h" 46 #include "scopeinfo.h"
47 #include "scopes.h" 47 #include "scopes.h"
48 #include "vm-state-inl.h" 48 #include "vm-state-inl.h"
49 49
50 namespace v8 { 50 namespace v8 {
51 namespace internal { 51 namespace internal {
52 52
53 53
54 CompilationInfo::CompilationInfo(Handle<Script> script) 54 CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
55 : isolate_(script->GetIsolate()), 55 : isolate_(script->GetIsolate()),
56 flags_(LanguageModeField::encode(CLASSIC_MODE)), 56 flags_(LanguageModeField::encode(CLASSIC_MODE)),
57 function_(NULL), 57 function_(NULL),
58 scope_(NULL), 58 scope_(NULL),
59 global_scope_(NULL), 59 global_scope_(NULL),
60 script_(script), 60 script_(script),
61 extension_(NULL), 61 extension_(NULL),
62 pre_parse_data_(NULL), 62 pre_parse_data_(NULL),
63 osr_ast_id_(AstNode::kNoNumber) { 63 osr_ast_id_(AstNode::kNoNumber),
64 zone_(zone) {
64 Initialize(BASE); 65 Initialize(BASE);
65 } 66 }
66 67
67 68
68 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) 69 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
70 Zone* zone)
69 : isolate_(shared_info->GetIsolate()), 71 : isolate_(shared_info->GetIsolate()),
70 flags_(LanguageModeField::encode(CLASSIC_MODE) | 72 flags_(LanguageModeField::encode(CLASSIC_MODE) |
71 IsLazy::encode(true)), 73 IsLazy::encode(true)),
72 function_(NULL), 74 function_(NULL),
73 scope_(NULL), 75 scope_(NULL),
74 global_scope_(NULL), 76 global_scope_(NULL),
75 shared_info_(shared_info), 77 shared_info_(shared_info),
76 script_(Handle<Script>(Script::cast(shared_info->script()))), 78 script_(Handle<Script>(Script::cast(shared_info->script()))),
77 extension_(NULL), 79 extension_(NULL),
78 pre_parse_data_(NULL), 80 pre_parse_data_(NULL),
79 osr_ast_id_(AstNode::kNoNumber) { 81 osr_ast_id_(AstNode::kNoNumber),
82 zone_(zone) {
80 Initialize(BASE); 83 Initialize(BASE);
81 } 84 }
82 85
83 86
84 CompilationInfo::CompilationInfo(Handle<JSFunction> closure) 87 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
85 : isolate_(closure->GetIsolate()), 88 : isolate_(closure->GetIsolate()),
86 flags_(LanguageModeField::encode(CLASSIC_MODE) | 89 flags_(LanguageModeField::encode(CLASSIC_MODE) |
87 IsLazy::encode(true)), 90 IsLazy::encode(true)),
88 function_(NULL), 91 function_(NULL),
89 scope_(NULL), 92 scope_(NULL),
90 global_scope_(NULL), 93 global_scope_(NULL),
91 closure_(closure), 94 closure_(closure),
92 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), 95 shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
93 script_(Handle<Script>(Script::cast(shared_info_->script()))), 96 script_(Handle<Script>(Script::cast(shared_info_->script()))),
94 extension_(NULL), 97 extension_(NULL),
95 pre_parse_data_(NULL), 98 pre_parse_data_(NULL),
96 osr_ast_id_(AstNode::kNoNumber) { 99 osr_ast_id_(AstNode::kNoNumber),
100 zone_(zone) {
97 Initialize(BASE); 101 Initialize(BASE);
98 } 102 }
99 103
100 104
101 // Disable optimization for the rest of the compilation pipeline. 105 // Disable optimization for the rest of the compilation pipeline.
102 void CompilationInfo::DisableOptimization() { 106 void CompilationInfo::DisableOptimization() {
103 bool is_optimizable_closure = 107 bool is_optimizable_closure =
104 FLAG_optimize_closures && 108 FLAG_optimize_closures &&
105 closure_.is_null() && 109 closure_.is_null() &&
106 !scope_->HasTrivialOuterContext() && 110 !scope_->HasTrivialOuterContext() &&
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 259 }
256 260
257 // Recompile the unoptimized version of the code if the current version 261 // Recompile the unoptimized version of the code if the current version
258 // doesn't have deoptimization support. Alternatively, we may decide to 262 // doesn't have deoptimization support. Alternatively, we may decide to
259 // run the full code generator to get a baseline for the compile-time 263 // run the full code generator to get a baseline for the compile-time
260 // performance of the hydrogen-based compiler. 264 // performance of the hydrogen-based compiler.
261 int64_t start = OS::Ticks(); 265 int64_t start = OS::Ticks();
262 bool should_recompile = !info->shared_info()->has_deoptimization_support(); 266 bool should_recompile = !info->shared_info()->has_deoptimization_support();
263 if (should_recompile || FLAG_hydrogen_stats) { 267 if (should_recompile || FLAG_hydrogen_stats) {
264 HPhase phase(HPhase::kFullCodeGen); 268 HPhase phase(HPhase::kFullCodeGen);
265 CompilationInfo unoptimized(info->shared_info()); 269 Zone zone(info->isolate());
270 CompilationInfo unoptimized(info->shared_info(), &zone);
271 ZoneScope scope(&zone, DELETE_ON_EXIT);
266 // Note that we use the same AST that we will use for generating the 272 // Note that we use the same AST that we will use for generating the
267 // optimized code. 273 // optimized code.
268 unoptimized.SetFunction(info->function()); 274 unoptimized.SetFunction(info->function());
269 unoptimized.SetScope(info->scope()); 275 unoptimized.SetScope(info->scope());
270 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); 276 if (should_recompile) unoptimized.EnableDeoptimizationSupport();
271 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); 277 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized);
272 if (should_recompile) { 278 if (should_recompile) {
273 if (!succeeded) return false; 279 if (!succeeded) return false;
274 Handle<SharedFunctionInfo> shared = info->shared_info(); 280 Handle<SharedFunctionInfo> shared = info->shared_info();
275 shared->EnableDeoptimizationSupport(*unoptimized.code()); 281 shared->EnableDeoptimizationSupport(*unoptimized.code());
(...skipping 12 matching lines...) Expand all
288 ASSERT(info->shared_info()->has_deoptimization_support()); 294 ASSERT(info->shared_info()->has_deoptimization_support());
289 295
290 if (FLAG_trace_hydrogen) { 296 if (FLAG_trace_hydrogen) {
291 PrintF("-----------------------------------------------------------\n"); 297 PrintF("-----------------------------------------------------------\n");
292 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); 298 PrintF("Compiling method %s using hydrogen\n", *name->ToCString());
293 HTracer::Instance()->TraceCompilation(info->function()); 299 HTracer::Instance()->TraceCompilation(info->function());
294 } 300 }
295 301
296 Handle<Context> global_context(info->closure()->context()->global_context()); 302 Handle<Context> global_context(info->closure()->context()->global_context());
297 TypeFeedbackOracle oracle(code, global_context, info->isolate(), 303 TypeFeedbackOracle oracle(code, global_context, info->isolate(),
298 info->isolate()->zone()); 304 info->zone());
299 HGraphBuilder builder(info, &oracle, info->isolate()->zone()); 305 HGraphBuilder builder(info, &oracle);
300 HPhase phase(HPhase::kTotal); 306 HPhase phase(HPhase::kTotal);
301 HGraph* graph = builder.CreateGraph(); 307 HGraph* graph = builder.CreateGraph();
302 if (info->isolate()->has_pending_exception()) { 308 if (info->isolate()->has_pending_exception()) {
303 info->SetCode(Handle<Code>::null()); 309 info->SetCode(Handle<Code>::null());
304 return false; 310 return false;
305 } 311 }
306 312
307 if (graph != NULL) { 313 if (graph != NULL) {
308 Handle<Code> optimized_code = graph->Compile(info, graph->zone()); 314 Handle<Code> optimized_code = graph->Compile();
309 if (!optimized_code.is_null()) { 315 if (!optimized_code.is_null()) {
310 info->SetCode(optimized_code); 316 info->SetCode(optimized_code);
311 FinishOptimization(info->closure(), start); 317 FinishOptimization(info->closure(), start);
312 return true; 318 return true;
313 } 319 }
314 } 320 }
315 321
316 // Keep using the shared code. 322 // Keep using the shared code.
317 info->AbortOptimization(); 323 info->AbortOptimization();
318 if (!builder.inline_bailout()) { 324 if (!builder.inline_bailout()) {
(...skipping 22 matching lines...) Expand all
341 } 347 }
342 348
343 349
344 #ifdef ENABLE_DEBUGGER_SUPPORT 350 #ifdef ENABLE_DEBUGGER_SUPPORT
345 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) { 351 bool Compiler::MakeCodeForLiveEdit(CompilationInfo* info) {
346 // Precondition: code has been parsed. Postcondition: the code field in 352 // Precondition: code has been parsed. Postcondition: the code field in
347 // the compilation info is set if compilation succeeded. 353 // the compilation info is set if compilation succeeded.
348 bool succeeded = MakeCode(info); 354 bool succeeded = MakeCode(info);
349 if (!info->shared_info().is_null()) { 355 if (!info->shared_info().is_null()) {
350 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), 356 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(),
351 info->isolate()->zone()); 357 info->zone());
352 info->shared_info()->set_scope_info(*scope_info); 358 info->shared_info()->set_scope_info(*scope_info);
353 } 359 }
354 return succeeded; 360 return succeeded;
355 } 361 }
356 #endif 362 #endif
357 363
358 364
359 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { 365 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
360 Isolate* isolate = info->isolate(); 366 Isolate* isolate = info->isolate();
361 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); 367 ZoneScope zone_scope(info->zone(), DELETE_ON_EXIT);
362 PostponeInterruptsScope postpone(isolate); 368 PostponeInterruptsScope postpone(isolate);
363 369
364 ASSERT(!isolate->global_context().is_null()); 370 ASSERT(!isolate->global_context().is_null());
365 Handle<Script> script = info->script(); 371 Handle<Script> script = info->script();
366 script->set_context_data((*isolate->global_context())->data()); 372 script->set_context_data((*isolate->global_context())->data());
367 373
368 #ifdef ENABLE_DEBUGGER_SUPPORT 374 #ifdef ENABLE_DEBUGGER_SUPPORT
369 if (info->is_eval()) { 375 if (info->is_eval()) {
370 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL; 376 Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL;
371 script->set_compilation_type(Smi::FromInt(compilation_type)); 377 script->set_compilation_type(Smi::FromInt(compilation_type));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 return Handle<SharedFunctionInfo>::null(); 421 return Handle<SharedFunctionInfo>::null();
416 } 422 }
417 423
418 // Allocate function. 424 // Allocate function.
419 ASSERT(!info->code().is_null()); 425 ASSERT(!info->code().is_null());
420 Handle<SharedFunctionInfo> result = 426 Handle<SharedFunctionInfo> result =
421 isolate->factory()->NewSharedFunctionInfo( 427 isolate->factory()->NewSharedFunctionInfo(
422 lit->name(), 428 lit->name(),
423 lit->materialized_literal_count(), 429 lit->materialized_literal_count(),
424 info->code(), 430 info->code(),
425 ScopeInfo::Create(info->scope(), info->isolate()->zone())); 431 ScopeInfo::Create(info->scope(), info->zone()));
426 432
427 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); 433 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
428 Compiler::SetFunctionInfo(result, lit, true, script); 434 Compiler::SetFunctionInfo(result, lit, true, script);
429 435
430 if (script->name()->IsString()) { 436 if (script->name()->IsString()) {
431 PROFILE(isolate, CodeCreateEvent( 437 PROFILE(isolate, CodeCreateEvent(
432 info->is_eval() 438 info->is_eval()
433 ? Logger::EVAL_TAG 439 ? Logger::EVAL_TAG
434 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), 440 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
435 *info->code(), 441 *info->code(),
(...skipping 21 matching lines...) Expand all
457 463
458 script->set_compilation_state( 464 script->set_compilation_state(
459 Smi::FromInt(Script::COMPILATION_STATE_COMPILED)); 465 Smi::FromInt(Script::COMPILATION_STATE_COMPILED));
460 466
461 #ifdef ENABLE_DEBUGGER_SUPPORT 467 #ifdef ENABLE_DEBUGGER_SUPPORT
462 // Notify debugger 468 // Notify debugger
463 isolate->debugger()->OnAfterCompile( 469 isolate->debugger()->OnAfterCompile(
464 script, Debugger::NO_AFTER_COMPILE_FLAGS); 470 script, Debugger::NO_AFTER_COMPILE_FLAGS);
465 #endif 471 #endif
466 472
467 live_edit_tracker.RecordFunctionInfo(result, lit, isolate->zone()); 473 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone());
468 474
469 return result; 475 return result;
470 } 476 }
471 477
472 478
473 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, 479 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
474 Handle<Object> script_name, 480 Handle<Object> script_name,
475 int line_offset, 481 int line_offset,
476 int column_offset, 482 int column_offset,
477 v8::Extension* extension, 483 v8::Extension* extension,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 if (!script_name.is_null()) { 521 if (!script_name.is_null()) {
516 script->set_name(*script_name); 522 script->set_name(*script_name);
517 script->set_line_offset(Smi::FromInt(line_offset)); 523 script->set_line_offset(Smi::FromInt(line_offset));
518 script->set_column_offset(Smi::FromInt(column_offset)); 524 script->set_column_offset(Smi::FromInt(column_offset));
519 } 525 }
520 526
521 script->set_data(script_data.is_null() ? HEAP->undefined_value() 527 script->set_data(script_data.is_null() ? HEAP->undefined_value()
522 : *script_data); 528 : *script_data);
523 529
524 // Compile the function and add it to the cache. 530 // Compile the function and add it to the cache.
525 CompilationInfo info(script); 531 Zone zone(isolate);
532 CompilationInfo info(script, &zone);
533 ZoneScope scope(&zone, DELETE_ON_EXIT);
danno 2012/06/14 14:22:19 Here and elsewhere, shouldn't the ZoneScope be dir
sanjoy 2012/06/15 09:24:31 CompilationInfo doesn't care. I found this order
526 info.MarkAsGlobal(); 534 info.MarkAsGlobal();
527 info.SetExtension(extension); 535 info.SetExtension(extension);
528 info.SetPreParseData(pre_data); 536 info.SetPreParseData(pre_data);
529 if (FLAG_use_strict) { 537 if (FLAG_use_strict) {
530 info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE); 538 info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE);
531 } 539 }
532 result = MakeFunctionInfo(&info); 540 result = MakeFunctionInfo(&info);
533 if (extension == NULL && !result.is_null()) { 541 if (extension == NULL && !result.is_null()) {
534 compilation_cache->PutScript(source, result); 542 compilation_cache->PutScript(source, result);
535 } 543 }
(...skipping 27 matching lines...) Expand all
563 CompilationCache* compilation_cache = isolate->compilation_cache(); 571 CompilationCache* compilation_cache = isolate->compilation_cache();
564 result = compilation_cache->LookupEval(source, 572 result = compilation_cache->LookupEval(source,
565 context, 573 context,
566 is_global, 574 is_global,
567 language_mode, 575 language_mode,
568 scope_position); 576 scope_position);
569 577
570 if (result.is_null()) { 578 if (result.is_null()) {
571 // Create a script object describing the script to be compiled. 579 // Create a script object describing the script to be compiled.
572 Handle<Script> script = isolate->factory()->NewScript(source); 580 Handle<Script> script = isolate->factory()->NewScript(source);
573 CompilationInfo info(script); 581 Zone zone(isolate);
582 CompilationInfo info(script, &zone);
danno 2012/06/14 14:22:19 If the Zone and ZoneScope's lifecycle is tied to t
sanjoy 2012/06/15 09:24:31 Please see my comment on runtime.cc
583 ZoneScope scope(&zone, DELETE_ON_EXIT);
574 info.MarkAsEval(); 584 info.MarkAsEval();
575 if (is_global) info.MarkAsGlobal(); 585 if (is_global) info.MarkAsGlobal();
576 info.SetLanguageMode(language_mode); 586 info.SetLanguageMode(language_mode);
577 info.SetCallingContext(context); 587 info.SetCallingContext(context);
578 result = MakeFunctionInfo(&info); 588 result = MakeFunctionInfo(&info);
579 if (!result.is_null()) { 589 if (!result.is_null()) {
580 // Explicitly disable optimization for eval code. We're not yet prepared 590 // Explicitly disable optimization for eval code. We're not yet prepared
581 // to handle eval-code in the optimizing compiler. 591 // to handle eval-code in the optimizing compiler.
582 result->DisableOptimization(); 592 result->DisableOptimization();
583 593
(...skipping 14 matching lines...) Expand all
598 } 608 }
599 } 609 }
600 610
601 return result; 611 return result;
602 } 612 }
603 613
604 614
605 bool Compiler::CompileLazy(CompilationInfo* info) { 615 bool Compiler::CompileLazy(CompilationInfo* info) {
606 Isolate* isolate = info->isolate(); 616 Isolate* isolate = info->isolate();
607 617
608 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); 618 ZoneScope zone_scope(info->zone(), DELETE_ON_EXIT);
609 619
610 // The VM is in the COMPILER state until exiting this function. 620 // The VM is in the COMPILER state until exiting this function.
611 VMState state(isolate, COMPILER); 621 VMState state(isolate, COMPILER);
612 622
613 PostponeInterruptsScope postpone(isolate); 623 PostponeInterruptsScope postpone(isolate);
614 624
615 Handle<SharedFunctionInfo> shared = info->shared_info(); 625 Handle<SharedFunctionInfo> shared = info->shared_info();
616 int compiled_size = shared->end_position() - shared->start_position(); 626 int compiled_size = shared->end_position() - shared->start_position();
617 isolate->counters()->total_compile_size()->Increment(compiled_size); 627 isolate->counters()->total_compile_size()->Increment(compiled_size);
618 628
(...skipping 28 matching lines...) Expand all
647 if (info->IsOptimizing()) { 657 if (info->IsOptimizing()) {
648 ASSERT(shared->scope_info() != ScopeInfo::Empty()); 658 ASSERT(shared->scope_info() != ScopeInfo::Empty());
649 function->ReplaceCode(*code); 659 function->ReplaceCode(*code);
650 } else { 660 } else {
651 // Update the shared function info with the compiled code and the 661 // Update the shared function info with the compiled code and the
652 // scope info. Please note, that the order of the shared function 662 // scope info. Please note, that the order of the shared function
653 // info initialization is important since set_scope_info might 663 // info initialization is important since set_scope_info might
654 // trigger a GC, causing the ASSERT below to be invalid if the code 664 // trigger a GC, causing the ASSERT below to be invalid if the code
655 // was flushed. By setting the code object last we avoid this. 665 // was flushed. By setting the code object last we avoid this.
656 Handle<ScopeInfo> scope_info = 666 Handle<ScopeInfo> scope_info =
657 ScopeInfo::Create(info->scope(), info->isolate()->zone()); 667 ScopeInfo::Create(info->scope(), info->zone());
658 shared->set_scope_info(*scope_info); 668 shared->set_scope_info(*scope_info);
659 shared->set_code(*code); 669 shared->set_code(*code);
660 if (!function.is_null()) { 670 if (!function.is_null()) {
661 function->ReplaceCode(*code); 671 function->ReplaceCode(*code);
662 ASSERT(!function->IsOptimized()); 672 ASSERT(!function->IsOptimized());
663 } 673 }
664 674
665 // Set the expected number of properties for instances. 675 // Set the expected number of properties for instances.
666 FunctionLiteral* lit = info->function(); 676 FunctionLiteral* lit = info->function();
667 int expected = lit->expected_property_count(); 677 int expected = lit->expected_property_count();
(...skipping 14 matching lines...) Expand all
682 shared->set_ast_node_count(lit->ast_node_count()); 692 shared->set_ast_node_count(lit->ast_node_count());
683 693
684 if (V8::UseCrankshaft()&& 694 if (V8::UseCrankshaft()&&
685 !function.is_null() && 695 !function.is_null() &&
686 !shared->optimization_disabled()) { 696 !shared->optimization_disabled()) {
687 // If we're asked to always optimize, we compile the optimized 697 // If we're asked to always optimize, we compile the optimized
688 // version of the function right away - unless the debugger is 698 // version of the function right away - unless the debugger is
689 // active as it makes no sense to compile optimized code then. 699 // active as it makes no sense to compile optimized code then.
690 if (FLAG_always_opt && 700 if (FLAG_always_opt &&
691 !Isolate::Current()->DebuggerHasBreakPoints()) { 701 !Isolate::Current()->DebuggerHasBreakPoints()) {
692 CompilationInfo optimized(function); 702 Zone zone(function->GetIsolate());
703 CompilationInfo optimized(function, &zone);
704 ZoneScope scope(&zone, DELETE_ON_EXIT);
693 optimized.SetOptimizing(AstNode::kNoNumber); 705 optimized.SetOptimizing(AstNode::kNoNumber);
694 return CompileLazy(&optimized); 706 return CompileLazy(&optimized);
695 } 707 }
696 } 708 }
697 } 709 }
698 710
699 return true; 711 return true;
700 } 712 }
701 } 713 }
702 714
703 ASSERT(info->code().is_null()); 715 ASSERT(info->code().is_null());
704 return false; 716 return false;
705 } 717 }
706 718
707 719
708 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, 720 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
709 Handle<Script> script) { 721 Handle<Script> script) {
710 // Precondition: code has been parsed and scopes have been analyzed. 722 // Precondition: code has been parsed and scopes have been analyzed.
711 CompilationInfo info(script); 723 Zone zone(script->GetIsolate());
724 CompilationInfo info(script, &zone);
725 ZoneScope scope(&zone, DELETE_ON_EXIT);
712 info.SetFunction(literal); 726 info.SetFunction(literal);
713 info.SetScope(literal->scope()); 727 info.SetScope(literal->scope());
714 info.SetLanguageMode(literal->scope()->language_mode()); 728 info.SetLanguageMode(literal->scope()->language_mode());
715 729
716 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); 730 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal);
717 // Determine if the function can be lazily compiled. This is necessary to 731 // Determine if the function can be lazily compiled. This is necessary to
718 // allow some of our builtin JS files to be lazily compiled. These 732 // allow some of our builtin JS files to be lazily compiled. These
719 // builtins cannot be handled lazily by the parser, since we have to know 733 // builtins cannot be handled lazily by the parser, since we have to know
720 // if a function uses the special natives syntax, which is something the 734 // if a function uses the special natives syntax, which is something the
721 // parser records. 735 // parser records.
722 bool allow_lazy = literal->AllowsLazyCompilation() && 736 bool allow_lazy = literal->AllowsLazyCompilation() &&
723 !LiveEditFunctionTracker::IsActive(info.isolate()); 737 !LiveEditFunctionTracker::IsActive(info.isolate());
724 738
725 Handle<ScopeInfo> scope_info(ScopeInfo::Empty()); 739 Handle<ScopeInfo> scope_info(ScopeInfo::Empty());
726 740
727 // Generate code 741 // Generate code
728 if (FLAG_lazy && allow_lazy) { 742 if (FLAG_lazy && allow_lazy) {
729 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); 743 Handle<Code> code = info.isolate()->builtins()->LazyCompile();
730 info.SetCode(code); 744 info.SetCode(code);
731 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || 745 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) ||
732 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { 746 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) {
733 ASSERT(!info.code().is_null()); 747 ASSERT(!info.code().is_null());
734 scope_info = ScopeInfo::Create(info.scope(), info.isolate()->zone()); 748 scope_info = ScopeInfo::Create(info.scope(), info.zone());
735 } else { 749 } else {
736 return Handle<SharedFunctionInfo>::null(); 750 return Handle<SharedFunctionInfo>::null();
737 } 751 }
738 752
739 // Create a shared function info object. 753 // Create a shared function info object.
740 Handle<SharedFunctionInfo> result = 754 Handle<SharedFunctionInfo> result =
741 FACTORY->NewSharedFunctionInfo(literal->name(), 755 FACTORY->NewSharedFunctionInfo(literal->name(),
742 literal->materialized_literal_count(), 756 literal->materialized_literal_count(),
743 info.code(), 757 info.code(),
744 scope_info); 758 scope_info);
745 SetFunctionInfo(result, literal, false, script); 759 SetFunctionInfo(result, literal, false, script);
746 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); 760 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
747 result->set_allows_lazy_compilation(allow_lazy); 761 result->set_allows_lazy_compilation(allow_lazy);
748 762
749 // Set the expected number of properties for instances and return 763 // Set the expected number of properties for instances and return
750 // the resulting function. 764 // the resulting function.
751 SetExpectedNofPropertiesFromEstimate(result, 765 SetExpectedNofPropertiesFromEstimate(result,
752 literal->expected_property_count()); 766 literal->expected_property_count());
753 live_edit_tracker.RecordFunctionInfo(result, literal, info.isolate()->zone()); 767 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
754 return result; 768 return result;
755 } 769 }
756 770
757 771
758 // Sets the function info on a function. 772 // Sets the function info on a function.
759 // The start_position points to the first '(' character after the function name 773 // The start_position points to the first '(' character after the function name
760 // in the full script source. When counting characters in the script source the 774 // in the full script source. When counting characters in the script source the
761 // the first character is number 0 (not 1). 775 // the first character is number 0 (not 1).
762 void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, 776 void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
763 FunctionLiteral* lit, 777 FunctionLiteral* lit,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 834 }
821 } 835 }
822 836
823 GDBJIT(AddCode(Handle<String>(shared->DebugName()), 837 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
824 Handle<Script>(info->script()), 838 Handle<Script>(info->script()),
825 Handle<Code>(info->code()), 839 Handle<Code>(info->code()),
826 info)); 840 info));
827 } 841 }
828 842
829 } } // namespace v8::internal 843 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698