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

Side by Side Diff: src/compiler.cc

Issue 8404030: Version 3.7.1 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « src/compiler.h ('k') | src/contexts.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 53
54 CompilationInfo::CompilationInfo(Handle<Script> script) 54 CompilationInfo::CompilationInfo(Handle<Script> script)
55 : isolate_(script->GetIsolate()), 55 : isolate_(script->GetIsolate()),
56 flags_(0), 56 flags_(0),
57 function_(NULL), 57 function_(NULL),
58 scope_(NULL), 58 scope_(NULL),
59 script_(script), 59 script_(script),
60 extension_(NULL), 60 extension_(NULL),
61 pre_parse_data_(NULL), 61 pre_parse_data_(NULL),
62 supports_deoptimization_(false),
63 osr_ast_id_(AstNode::kNoNumber) { 62 osr_ast_id_(AstNode::kNoNumber) {
64 Initialize(NONOPT); 63 Initialize(NONOPT);
65 } 64 }
66 65
67 66
68 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info) 67 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info)
69 : isolate_(shared_info->GetIsolate()), 68 : isolate_(shared_info->GetIsolate()),
70 flags_(IsLazy::encode(true)), 69 flags_(IsLazy::encode(true)),
71 function_(NULL), 70 function_(NULL),
72 scope_(NULL), 71 scope_(NULL),
73 shared_info_(shared_info), 72 shared_info_(shared_info),
74 script_(Handle<Script>(Script::cast(shared_info->script()))), 73 script_(Handle<Script>(Script::cast(shared_info->script()))),
75 extension_(NULL), 74 extension_(NULL),
76 pre_parse_data_(NULL), 75 pre_parse_data_(NULL),
77 supports_deoptimization_(false),
78 osr_ast_id_(AstNode::kNoNumber) { 76 osr_ast_id_(AstNode::kNoNumber) {
79 Initialize(BASE); 77 Initialize(BASE);
80 } 78 }
81 79
82 80
83 CompilationInfo::CompilationInfo(Handle<JSFunction> closure) 81 CompilationInfo::CompilationInfo(Handle<JSFunction> closure)
84 : isolate_(closure->GetIsolate()), 82 : isolate_(closure->GetIsolate()),
85 flags_(IsLazy::encode(true)), 83 flags_(IsLazy::encode(true)),
86 function_(NULL), 84 function_(NULL),
87 scope_(NULL), 85 scope_(NULL),
88 closure_(closure), 86 closure_(closure),
89 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), 87 shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
90 script_(Handle<Script>(Script::cast(shared_info_->script()))), 88 script_(Handle<Script>(Script::cast(shared_info_->script()))),
91 extension_(NULL), 89 extension_(NULL),
92 pre_parse_data_(NULL), 90 pre_parse_data_(NULL),
93 supports_deoptimization_(false),
94 osr_ast_id_(AstNode::kNoNumber) { 91 osr_ast_id_(AstNode::kNoNumber) {
95 Initialize(BASE); 92 Initialize(BASE);
96 } 93 }
97 94
98 95
99 // Disable optimization for the rest of the compilation pipeline. 96 // Disable optimization for the rest of the compilation pipeline.
100 void CompilationInfo::DisableOptimization() { 97 void CompilationInfo::DisableOptimization() {
101 bool is_optimizable_closure = 98 bool is_optimizable_closure =
102 FLAG_optimize_closures && 99 FLAG_optimize_closures &&
103 closure_.is_null() && 100 closure_.is_null() &&
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 Handle<JSFunction> closure = info->closure(); 299 Handle<JSFunction> closure = info->closure();
303 info->shared_info()->DisableOptimization(*closure); 300 info->shared_info()->DisableOptimization(*closure);
304 } 301 }
305 // True indicates the compilation pipeline is still going, not necessarily 302 // True indicates the compilation pipeline is still going, not necessarily
306 // that we optimized the code. 303 // that we optimized the code.
307 return true; 304 return true;
308 } 305 }
309 306
310 307
311 static bool GenerateCode(CompilationInfo* info) { 308 static bool GenerateCode(CompilationInfo* info) {
312 return V8::UseCrankshaft() ? 309 return info->IsCompilingForDebugging() || !V8::UseCrankshaft() ?
313 MakeCrankshaftCode(info) : 310 FullCodeGenerator::MakeCode(info) :
314 FullCodeGenerator::MakeCode(info); 311 MakeCrankshaftCode(info);
315 } 312 }
316 313
317 314
318 static bool MakeCode(CompilationInfo* info) { 315 static bool MakeCode(CompilationInfo* info) {
319 // Precondition: code has been parsed. Postcondition: the code field in 316 // Precondition: code has been parsed. Postcondition: the code field in
320 // the compilation info is set if compilation succeeded. 317 // the compilation info is set if compilation succeeded.
321 ASSERT(info->function() != NULL); 318 ASSERT(info->function() != NULL);
322 return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info); 319 return Rewriter::Rewrite(info) && Scope::Analyze(info) && GenerateCode(info);
323 } 320 }
324 321
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 if (result.is_null()) { 470 if (result.is_null()) {
474 // No cache entry found. Do pre-parsing, if it makes sense, and compile 471 // No cache entry found. Do pre-parsing, if it makes sense, and compile
475 // the script. 472 // the script.
476 // Building preparse data that is only used immediately after is only a 473 // Building preparse data that is only used immediately after is only a
477 // saving if we might skip building the AST for lazily compiled functions. 474 // saving if we might skip building the AST for lazily compiled functions.
478 // I.e., preparse data isn't relevant when the lazy flag is off, and 475 // I.e., preparse data isn't relevant when the lazy flag is off, and
479 // for small sources, odds are that there aren't many functions 476 // for small sources, odds are that there aren't many functions
480 // that would be compiled lazily anyway, so we skip the preparse step 477 // that would be compiled lazily anyway, so we skip the preparse step
481 // in that case too. 478 // in that case too.
482 ScriptDataImpl* pre_data = input_pre_data; 479 ScriptDataImpl* pre_data = input_pre_data;
483 bool harmony_scoping = natives != NATIVES_CODE && FLAG_harmony_scoping; 480 int flags = kNoParsingFlags;
481 if ((natives == NATIVES_CODE) || FLAG_allow_natives_syntax) {
482 flags |= kAllowNativesSyntax;
483 }
484 if (natives != NATIVES_CODE && FLAG_harmony_scoping) {
485 flags |= kHarmonyScoping;
486 }
484 if (pre_data == NULL 487 if (pre_data == NULL
485 && source_length >= FLAG_min_preparse_length) { 488 && source_length >= FLAG_min_preparse_length) {
486 if (source->IsExternalTwoByteString()) { 489 if (source->IsExternalTwoByteString()) {
487 ExternalTwoByteStringUC16CharacterStream stream( 490 ExternalTwoByteStringUC16CharacterStream stream(
488 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); 491 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
489 pre_data = ParserApi::PartialPreParse(&stream, 492 pre_data = ParserApi::PartialPreParse(&stream, extension, flags);
490 extension,
491 harmony_scoping);
492 } else { 493 } else {
493 GenericStringUC16CharacterStream stream(source, 0, source->length()); 494 GenericStringUC16CharacterStream stream(source, 0, source->length());
494 pre_data = ParserApi::PartialPreParse(&stream, 495 pre_data = ParserApi::PartialPreParse(&stream, extension, flags);
495 extension,
496 harmony_scoping);
497 } 496 }
498 } 497 }
499 498
500 // Create a script object describing the script to be compiled. 499 // Create a script object describing the script to be compiled.
501 Handle<Script> script = FACTORY->NewScript(source); 500 Handle<Script> script = FACTORY->NewScript(source);
502 if (natives == NATIVES_CODE) { 501 if (natives == NATIVES_CODE) {
503 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 502 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
504 } 503 }
505 if (!script_name.is_null()) { 504 if (!script_name.is_null()) {
506 script->set_name(*script_name); 505 script->set_name(*script_name);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 context, 551 context,
553 is_global, 552 is_global,
554 strict_mode); 553 strict_mode);
555 554
556 if (result.is_null()) { 555 if (result.is_null()) {
557 // Create a script object describing the script to be compiled. 556 // Create a script object describing the script to be compiled.
558 Handle<Script> script = isolate->factory()->NewScript(source); 557 Handle<Script> script = isolate->factory()->NewScript(source);
559 CompilationInfo info(script); 558 CompilationInfo info(script);
560 info.MarkAsEval(); 559 info.MarkAsEval();
561 if (is_global) info.MarkAsGlobal(); 560 if (is_global) info.MarkAsGlobal();
562 if (strict_mode == kStrictMode) info.MarkAsStrictMode(); 561 info.SetStrictModeFlag(strict_mode);
563 info.SetCallingContext(context); 562 info.SetCallingContext(context);
564 result = MakeFunctionInfo(&info); 563 result = MakeFunctionInfo(&info);
565 if (!result.is_null()) { 564 if (!result.is_null()) {
566 CompilationCache* compilation_cache = isolate->compilation_cache(); 565 CompilationCache* compilation_cache = isolate->compilation_cache();
567 // If caller is strict mode, the result must be strict as well, 566 // If caller is strict mode, the result must be strict as well,
568 // but not the other way around. Consider: 567 // but not the other way around. Consider:
569 // eval("'use strict'; ..."); 568 // eval("'use strict'; ...");
569 // TODO(keuchel): adapt this for extended mode.
570 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); 570 ASSERT(strict_mode == kNonStrictMode || result->strict_mode());
571 compilation_cache->PutEval(source, context, is_global, result); 571 compilation_cache->PutEval(source, context, is_global, result);
572 } 572 }
573 } 573 }
574 574
575 return result; 575 return result;
576 } 576 }
577 577
578 578
579 bool Compiler::CompileLazy(CompilationInfo* info) { 579 bool Compiler::CompileLazy(CompilationInfo* info) {
(...skipping 11 matching lines...) Expand all
591 isolate->counters()->total_compile_size()->Increment(compiled_size); 591 isolate->counters()->total_compile_size()->Increment(compiled_size);
592 592
593 // Generate the AST for the lazily compiled function. 593 // Generate the AST for the lazily compiled function.
594 if (ParserApi::Parse(info)) { 594 if (ParserApi::Parse(info)) {
595 // Measure how long it takes to do the lazy compilation; only take the 595 // Measure how long it takes to do the lazy compilation; only take the
596 // rest of the function into account to avoid overlap with the lazy 596 // rest of the function into account to avoid overlap with the lazy
597 // parsing statistics. 597 // parsing statistics.
598 HistogramTimerScope timer(isolate->counters()->compile_lazy()); 598 HistogramTimerScope timer(isolate->counters()->compile_lazy());
599 599
600 // After parsing we know function's strict mode. Remember it. 600 // After parsing we know function's strict mode. Remember it.
601 if (info->function()->strict_mode()) { 601 StrictModeFlag strict_mode = info->function()->strict_mode_flag();
602 shared->set_strict_mode(true); 602 ASSERT(info->strict_mode_flag() == kNonStrictMode ||
603 info->MarkAsStrictMode(); 603 info->strict_mode_flag() == strict_mode);
604 } 604 ASSERT(shared->strict_mode_flag() == kNonStrictMode ||
605 shared->strict_mode_flag() == strict_mode);
606 info->SetStrictModeFlag(strict_mode);
607 shared->set_strict_mode_flag(strict_mode);
605 608
606 // Compile the code. 609 // Compile the code.
607 if (!MakeCode(info)) { 610 if (!MakeCode(info)) {
608 if (!isolate->has_pending_exception()) { 611 if (!isolate->has_pending_exception()) {
609 isolate->StackOverflow(); 612 isolate->StackOverflow();
610 } 613 }
611 } else { 614 } else {
612 ASSERT(!info->code().is_null()); 615 ASSERT(!info->code().is_null());
613 Handle<Code> code = info->code(); 616 Handle<Code> code = info->code();
614 // Set optimizable to false if this is disallowed by the shared 617 // Set optimizable to false if this is disallowed by the shared
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 return false; 677 return false;
675 } 678 }
676 679
677 680
678 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, 681 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
679 Handle<Script> script) { 682 Handle<Script> script) {
680 // Precondition: code has been parsed and scopes have been analyzed. 683 // Precondition: code has been parsed and scopes have been analyzed.
681 CompilationInfo info(script); 684 CompilationInfo info(script);
682 info.SetFunction(literal); 685 info.SetFunction(literal);
683 info.SetScope(literal->scope()); 686 info.SetScope(literal->scope());
684 if (literal->scope()->is_strict_mode()) info.MarkAsStrictMode(); 687 info.SetStrictModeFlag(literal->scope()->strict_mode_flag());
685 688
686 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); 689 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal);
687 // Determine if the function can be lazily compiled. This is necessary to 690 // Determine if the function can be lazily compiled. This is necessary to
688 // allow some of our builtin JS files to be lazily compiled. These 691 // allow some of our builtin JS files to be lazily compiled. These
689 // builtins cannot be handled lazily by the parser, since we have to know 692 // builtins cannot be handled lazily by the parser, since we have to know
690 // if a function uses the special natives syntax, which is something the 693 // if a function uses the special natives syntax, which is something the
691 // parser records. 694 // parser records.
692 bool allow_lazy = literal->AllowsLazyCompilation() && 695 bool allow_lazy = literal->AllowsLazyCompilation() &&
693 !LiveEditFunctionTracker::IsActive(info.isolate()); 696 !LiveEditFunctionTracker::IsActive(info.isolate());
694 697
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 function_info->set_start_position(lit->start_position()); 743 function_info->set_start_position(lit->start_position());
741 function_info->set_end_position(lit->end_position()); 744 function_info->set_end_position(lit->end_position());
742 function_info->set_is_expression(lit->is_expression()); 745 function_info->set_is_expression(lit->is_expression());
743 function_info->set_is_anonymous(lit->is_anonymous()); 746 function_info->set_is_anonymous(lit->is_anonymous());
744 function_info->set_is_toplevel(is_toplevel); 747 function_info->set_is_toplevel(is_toplevel);
745 function_info->set_inferred_name(*lit->inferred_name()); 748 function_info->set_inferred_name(*lit->inferred_name());
746 function_info->SetThisPropertyAssignmentsInfo( 749 function_info->SetThisPropertyAssignmentsInfo(
747 lit->has_only_simple_this_property_assignments(), 750 lit->has_only_simple_this_property_assignments(),
748 *lit->this_property_assignments()); 751 *lit->this_property_assignments());
749 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); 752 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
750 function_info->set_strict_mode(lit->strict_mode()); 753 function_info->set_strict_mode_flag(lit->strict_mode_flag());
751 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); 754 function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
752 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); 755 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
753 } 756 }
754 757
755 758
756 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, 759 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
757 CompilationInfo* info, 760 CompilationInfo* info,
758 Handle<SharedFunctionInfo> shared) { 761 Handle<SharedFunctionInfo> shared) {
759 // SharedFunctionInfo is passed separately, because if CompilationInfo 762 // SharedFunctionInfo is passed separately, because if CompilationInfo
760 // was created using Script object, it will not have it. 763 // was created using Script object, it will not have it.
(...skipping 25 matching lines...) Expand all
786 } 789 }
787 } 790 }
788 791
789 GDBJIT(AddCode(Handle<String>(shared->DebugName()), 792 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
790 Handle<Script>(info->script()), 793 Handle<Script>(info->script()),
791 Handle<Code>(info->code()), 794 Handle<Code>(info->code()),
792 info)); 795 info));
793 } 796 }
794 797
795 } } // namespace v8::internal 798 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698