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

Side by Side Diff: src/compiler.cc

Issue 196133017: Experimental parser: merge r19949 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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
« 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 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "scopeinfo.h" 49 #include "scopeinfo.h"
50 #include "scopes.h" 50 #include "scopes.h"
51 #include "vm-state-inl.h" 51 #include "vm-state-inl.h"
52 52
53 namespace v8 { 53 namespace v8 {
54 namespace internal { 54 namespace internal {
55 55
56 56
57 CompilationInfo::CompilationInfo(Handle<Script> script, 57 CompilationInfo::CompilationInfo(Handle<Script> script,
58 Zone* zone) 58 Zone* zone)
59 : flags_(LanguageModeField::encode(CLASSIC_MODE)), 59 : flags_(StrictModeField::encode(SLOPPY)),
60 script_(script), 60 script_(script),
61 osr_ast_id_(BailoutId::None()), 61 osr_ast_id_(BailoutId::None()),
62 parameter_count_(0), 62 parameter_count_(0),
63 this_has_uses_(true), 63 this_has_uses_(true),
64 optimization_id_(-1) { 64 optimization_id_(-1) {
65 Initialize(script->GetIsolate(), BASE, zone); 65 Initialize(script->GetIsolate(), BASE, zone);
66 } 66 }
67 67
68 68
69 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, 69 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
70 Zone* zone) 70 Zone* zone)
71 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), 71 : flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)),
72 shared_info_(shared_info), 72 shared_info_(shared_info),
73 script_(Handle<Script>(Script::cast(shared_info->script()))), 73 script_(Handle<Script>(Script::cast(shared_info->script()))),
74 osr_ast_id_(BailoutId::None()), 74 osr_ast_id_(BailoutId::None()),
75 parameter_count_(0), 75 parameter_count_(0),
76 this_has_uses_(true), 76 this_has_uses_(true),
77 optimization_id_(-1) { 77 optimization_id_(-1) {
78 Initialize(script_->GetIsolate(), BASE, zone); 78 Initialize(script_->GetIsolate(), BASE, zone);
79 } 79 }
80 80
81 81
82 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, 82 CompilationInfo::CompilationInfo(Handle<JSFunction> closure,
83 Zone* zone) 83 Zone* zone)
84 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), 84 : flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)),
85 closure_(closure), 85 closure_(closure),
86 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), 86 shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
87 script_(Handle<Script>(Script::cast(shared_info_->script()))), 87 script_(Handle<Script>(Script::cast(shared_info_->script()))),
88 context_(closure->context()), 88 context_(closure->context()),
89 osr_ast_id_(BailoutId::None()), 89 osr_ast_id_(BailoutId::None()),
90 parameter_count_(0), 90 parameter_count_(0),
91 this_has_uses_(true), 91 this_has_uses_(true),
92 optimization_id_(-1) { 92 optimization_id_(-1) {
93 Initialize(script_->GetIsolate(), BASE, zone); 93 Initialize(script_->GetIsolate(), BASE, zone);
94 } 94 }
95 95
96 96
97 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, 97 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub,
98 Isolate* isolate, 98 Isolate* isolate,
99 Zone* zone) 99 Zone* zone)
100 : flags_(LanguageModeField::encode(CLASSIC_MODE) | 100 : flags_(StrictModeField::encode(SLOPPY) | IsLazy::encode(true)),
101 IsLazy::encode(true)),
102 osr_ast_id_(BailoutId::None()), 101 osr_ast_id_(BailoutId::None()),
103 parameter_count_(0), 102 parameter_count_(0),
104 this_has_uses_(true), 103 this_has_uses_(true),
105 optimization_id_(-1) { 104 optimization_id_(-1) {
106 Initialize(isolate, STUB, zone); 105 Initialize(isolate, STUB, zone);
107 code_stub_ = stub; 106 code_stub_ = stub;
108 } 107 }
109 108
110 109
111 void CompilationInfo::Initialize(Isolate* isolate, 110 void CompilationInfo::Initialize(Isolate* isolate,
(...skipping 18 matching lines...) Expand all
130 if (mode == STUB) { 129 if (mode == STUB) {
131 mode_ = STUB; 130 mode_ = STUB;
132 return; 131 return;
133 } 132 }
134 mode_ = mode; 133 mode_ = mode;
135 abort_due_to_dependency_ = false; 134 abort_due_to_dependency_ = false;
136 if (script_->type()->value() == Script::TYPE_NATIVE) { 135 if (script_->type()->value() == Script::TYPE_NATIVE) {
137 MarkAsNative(); 136 MarkAsNative();
138 } 137 }
139 if (!shared_info_.is_null()) { 138 if (!shared_info_.is_null()) {
140 ASSERT(language_mode() == CLASSIC_MODE); 139 ASSERT(strict_mode() == SLOPPY);
141 SetLanguageMode(shared_info_->language_mode()); 140 SetStrictMode(shared_info_->strict_mode());
142 } 141 }
143 set_bailout_reason(kUnknown); 142 set_bailout_reason(kUnknown);
144 } 143 }
145 144
146 145
147 CompilationInfo::~CompilationInfo() { 146 CompilationInfo::~CompilationInfo() {
148 delete deferred_handles_; 147 delete deferred_handles_;
149 delete no_frame_ranges_; 148 delete no_frame_ranges_;
150 #ifdef DEBUG 149 #ifdef DEBUG
151 // Check that no dependent maps have been added or added dependent maps have 150 // Check that no dependent maps have been added or added dependent maps have
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 220 }
222 } 221 }
223 222
224 223
225 // Disable optimization for the rest of the compilation pipeline. 224 // Disable optimization for the rest of the compilation pipeline.
226 void CompilationInfo::DisableOptimization() { 225 void CompilationInfo::DisableOptimization() {
227 bool is_optimizable_closure = 226 bool is_optimizable_closure =
228 FLAG_optimize_closures && 227 FLAG_optimize_closures &&
229 closure_.is_null() && 228 closure_.is_null() &&
230 !scope_->HasTrivialOuterContext() && 229 !scope_->HasTrivialOuterContext() &&
231 !scope_->outer_scope_calls_non_strict_eval() && 230 !scope_->outer_scope_calls_sloppy_eval() &&
232 !scope_->inside_with(); 231 !scope_->inside_with();
233 SetMode(is_optimizable_closure ? BASE : NONOPT); 232 SetMode(is_optimizable_closure ? BASE : NONOPT);
234 } 233 }
235 234
236 235
237 // Primitive functions are unlikely to be picked up by the stack-walking 236 // Primitive functions are unlikely to be picked up by the stack-walking
238 // profiler, so they trigger their own optimization when they're called 237 // profiler, so they trigger their own optimization when they're called
239 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. 238 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time.
240 bool CompilationInfo::ShouldSelfOptimize() { 239 bool CompilationInfo::ShouldSelfOptimize() {
241 return FLAG_crankshaft && 240 return FLAG_crankshaft &&
242 !function()->flags()->Contains(kDontSelfOptimize) && 241 !function()->flags()->Contains(kDontSelfOptimize) &&
243 !function()->dont_optimize() && 242 !function()->dont_optimize() &&
244 function()->scope()->AllowsLazyCompilation() && 243 function()->scope()->AllowsLazyCompilation() &&
245 (shared_info().is_null() || !shared_info()->optimization_disabled()); 244 (shared_info().is_null() || !shared_info()->optimization_disabled());
246 } 245 }
247 246
248 247
249 void CompilationInfo::PrepareForCompilation(Scope* scope) { 248 void CompilationInfo::PrepareForCompilation(Scope* scope) {
250 ASSERT(scope_ == NULL); 249 ASSERT(scope_ == NULL);
251 scope_ = scope; 250 scope_ = scope;
252 function()->ProcessFeedbackSlots(isolate_); 251 function()->ProcessFeedbackSlots(isolate_);
252 int length = function()->slot_count();
253 // Allocate the feedback vector too.
254 feedback_vector_ = isolate()->factory()->NewFixedArray(length, TENURED);
255 // Ensure we can skip the write barrier
256 ASSERT_EQ(isolate()->heap()->uninitialized_symbol(),
257 *TypeFeedbackInfo::UninitializedSentinel(isolate()));
258 for (int i = 0; i < length; i++) {
259 feedback_vector_->set(i,
260 *TypeFeedbackInfo::UninitializedSentinel(isolate()),
261 SKIP_WRITE_BARRIER);
262 }
253 } 263 }
254 264
255 265
256 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { 266 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder {
257 public: 267 public:
258 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) 268 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info)
259 : HOptimizedGraphBuilder(info) { 269 : HOptimizedGraphBuilder(info) {
260 } 270 }
261 271
262 #define DEF_VISIT(type) \ 272 #define DEF_VISIT(type) \
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 Handle<SharedFunctionInfo> shared = info->shared_info(); 574 Handle<SharedFunctionInfo> shared = info->shared_info();
565 Handle<ScopeInfo> scope_info = 575 Handle<ScopeInfo> scope_info =
566 ScopeInfo::Create(info->scope(), info->zone()); 576 ScopeInfo::Create(info->scope(), info->zone());
567 shared->set_scope_info(*scope_info); 577 shared->set_scope_info(*scope_info);
568 578
569 Handle<Code> code = info->code(); 579 Handle<Code> code = info->code();
570 CHECK(code->kind() == Code::FUNCTION); 580 CHECK(code->kind() == Code::FUNCTION);
571 shared->ReplaceCode(*code); 581 shared->ReplaceCode(*code);
572 if (shared->optimization_disabled()) code->set_optimizable(false); 582 if (shared->optimization_disabled()) code->set_optimizable(false);
573 583
584 shared->set_feedback_vector(*info->feedback_vector());
585
574 // Set the expected number of properties for instances. 586 // Set the expected number of properties for instances.
575 FunctionLiteral* lit = info->function(); 587 FunctionLiteral* lit = info->function();
576 int expected = lit->expected_property_count(); 588 int expected = lit->expected_property_count();
577 SetExpectedNofPropertiesFromEstimate(shared, expected); 589 SetExpectedNofPropertiesFromEstimate(shared, expected);
578 590
579 // Check the function has compiled code. 591 // Check the function has compiled code.
580 ASSERT(shared->is_compiled()); 592 ASSERT(shared->is_compiled());
581 shared->set_dont_optimize_reason(lit->dont_optimize_reason()); 593 shared->set_dont_optimize_reason(lit->dont_optimize_reason());
582 shared->set_dont_inline(lit->flags()->Contains(kDontInline)); 594 shared->set_dont_inline(lit->flags()->Contains(kDontInline));
583 shared->set_ast_node_count(lit->ast_node_count()); 595 shared->set_ast_node_count(lit->ast_node_count());
584 shared->set_language_mode(lit->language_mode()); 596 shared->set_strict_mode(lit->strict_mode());
585 } 597 }
586 598
587 599
588 // Sets the function info on a function. 600 // Sets the function info on a function.
589 // The start_position points to the first '(' character after the function name 601 // The start_position points to the first '(' character after the function name
590 // in the full script source. When counting characters in the script source the 602 // in the full script source. When counting characters in the script source the
591 // the first character is number 0 (not 1). 603 // the first character is number 0 (not 1).
592 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, 604 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
593 FunctionLiteral* lit, 605 FunctionLiteral* lit,
594 bool is_toplevel, 606 bool is_toplevel,
595 Handle<Script> script) { 607 Handle<Script> script) {
596 function_info->set_length(lit->parameter_count()); 608 function_info->set_length(lit->parameter_count());
597 function_info->set_formal_parameter_count(lit->parameter_count()); 609 function_info->set_formal_parameter_count(lit->parameter_count());
598 function_info->set_script(*script); 610 function_info->set_script(*script);
599 function_info->set_function_token_position(lit->function_token_position()); 611 function_info->set_function_token_position(lit->function_token_position());
600 function_info->set_start_position(lit->start_position()); 612 function_info->set_start_position(lit->start_position());
601 function_info->set_end_position(lit->end_position()); 613 function_info->set_end_position(lit->end_position());
602 function_info->set_is_expression(lit->is_expression()); 614 function_info->set_is_expression(lit->is_expression());
603 function_info->set_is_anonymous(lit->is_anonymous()); 615 function_info->set_is_anonymous(lit->is_anonymous());
604 function_info->set_is_toplevel(is_toplevel); 616 function_info->set_is_toplevel(is_toplevel);
605 function_info->set_inferred_name(*lit->inferred_name()); 617 function_info->set_inferred_name(*lit->inferred_name());
606 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); 618 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
607 function_info->set_allows_lazy_compilation_without_context( 619 function_info->set_allows_lazy_compilation_without_context(
608 lit->AllowsLazyCompilationWithoutContext()); 620 lit->AllowsLazyCompilationWithoutContext());
609 function_info->set_language_mode(lit->language_mode()); 621 function_info->set_strict_mode(lit->strict_mode());
610 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); 622 function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
611 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); 623 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
612 function_info->set_ast_node_count(lit->ast_node_count()); 624 function_info->set_ast_node_count(lit->ast_node_count());
613 function_info->set_is_function(lit->is_function()); 625 function_info->set_is_function(lit->is_function());
614 function_info->set_dont_optimize_reason(lit->dont_optimize_reason()); 626 function_info->set_dont_optimize_reason(lit->dont_optimize_reason());
615 function_info->set_dont_inline(lit->flags()->Contains(kDontInline)); 627 function_info->set_dont_inline(lit->flags()->Contains(kDontInline));
616 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); 628 function_info->set_dont_cache(lit->flags()->Contains(kDontCache));
617 function_info->set_is_generator(lit->is_generator()); 629 function_info->set_is_generator(lit->is_generator());
618 } 630 }
619 631
(...skipping 10 matching lines...) Expand all
630 return false; 642 return false;
631 } 643 }
632 return true; 644 return true;
633 } 645 }
634 646
635 647
636 static Handle<Code> GetUnoptimizedCodeCommon(CompilationInfo* info) { 648 static Handle<Code> GetUnoptimizedCodeCommon(CompilationInfo* info) {
637 VMState<COMPILER> state(info->isolate()); 649 VMState<COMPILER> state(info->isolate());
638 PostponeInterruptsScope postpone(info->isolate()); 650 PostponeInterruptsScope postpone(info->isolate());
639 if (!Parser::Parse(info)) return Handle<Code>::null(); 651 if (!Parser::Parse(info)) return Handle<Code>::null();
640 LanguageMode language_mode = info->function()->language_mode(); 652 info->SetStrictMode(info->function()->strict_mode());
641 info->SetLanguageMode(language_mode);
642 653
643 if (!CompileUnoptimizedCode(info)) return Handle<Code>::null(); 654 if (!CompileUnoptimizedCode(info)) return Handle<Code>::null();
644 Compiler::RecordFunctionCompilation( 655 Compiler::RecordFunctionCompilation(
645 Logger::LAZY_COMPILE_TAG, info, info->shared_info()); 656 Logger::LAZY_COMPILE_TAG, info, info->shared_info());
646 UpdateSharedFunctionInfo(info); 657 UpdateSharedFunctionInfo(info);
647 ASSERT_EQ(Code::FUNCTION, info->code()->kind()); 658 ASSERT_EQ(Code::FUNCTION, info->code()->kind());
648 return info->code(); 659 return info->code();
649 } 660 }
650 661
651 662
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 750
740 #ifdef ENABLE_DEBUGGER_SUPPORT 751 #ifdef ENABLE_DEBUGGER_SUPPORT
741 void Compiler::CompileForLiveEdit(Handle<Script> script) { 752 void Compiler::CompileForLiveEdit(Handle<Script> script) {
742 // TODO(635): support extensions. 753 // TODO(635): support extensions.
743 CompilationInfoWithZone info(script); 754 CompilationInfoWithZone info(script);
744 PostponeInterruptsScope postpone(info.isolate()); 755 PostponeInterruptsScope postpone(info.isolate());
745 VMState<COMPILER> state(info.isolate()); 756 VMState<COMPILER> state(info.isolate());
746 757
747 info.MarkAsGlobal(); 758 info.MarkAsGlobal();
748 if (!Parser::Parse(&info)) return; 759 if (!Parser::Parse(&info)) return;
749 LanguageMode language_mode = info.function()->language_mode(); 760 info.SetStrictMode(info.function()->strict_mode());
750 info.SetLanguageMode(language_mode);
751 761
752 LiveEditFunctionTracker tracker(info.isolate(), info.function()); 762 LiveEditFunctionTracker tracker(info.isolate(), info.function());
753 if (!CompileUnoptimizedCode(&info)) return; 763 if (!CompileUnoptimizedCode(&info)) return;
754 if (!info.shared_info().is_null()) { 764 if (!info.shared_info().is_null()) {
755 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), 765 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(),
756 info.zone()); 766 info.zone());
757 info.shared_info()->set_scope_info(*scope_info); 767 info.shared_info()->set_scope_info(*scope_info);
758 } 768 }
759 tracker.RecordRootFunctionInfo(info.code()); 769 tracker.RecordRootFunctionInfo(info.code());
760 } 770 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 return Handle<SharedFunctionInfo>::null(); 829 return Handle<SharedFunctionInfo>::null();
820 } 830 }
821 831
822 // Allocate function. 832 // Allocate function.
823 ASSERT(!info->code().is_null()); 833 ASSERT(!info->code().is_null());
824 result = isolate->factory()->NewSharedFunctionInfo( 834 result = isolate->factory()->NewSharedFunctionInfo(
825 lit->name(), 835 lit->name(),
826 lit->materialized_literal_count(), 836 lit->materialized_literal_count(),
827 lit->is_generator(), 837 lit->is_generator(),
828 info->code(), 838 info->code(),
829 ScopeInfo::Create(info->scope(), info->zone())); 839 ScopeInfo::Create(info->scope(), info->zone()),
840 info->feedback_vector());
830 841
831 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); 842 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
832 SetFunctionInfo(result, lit, true, script); 843 SetFunctionInfo(result, lit, true, script);
833 844
834 Handle<String> script_name = script->name()->IsString() 845 Handle<String> script_name = script->name()->IsString()
835 ? Handle<String>(String::cast(script->name())) 846 ? Handle<String>(String::cast(script->name()))
836 : isolate->factory()->empty_string(); 847 : isolate->factory()->empty_string();
837 Logger::LogEventsAndTags log_tag = info->is_eval() 848 Logger::LogEventsAndTags log_tag = info->is_eval()
838 ? Logger::EVAL_TAG 849 ? Logger::EVAL_TAG
839 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); 850 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script);
(...skipping 16 matching lines...) Expand all
856 #ifdef ENABLE_DEBUGGER_SUPPORT 867 #ifdef ENABLE_DEBUGGER_SUPPORT
857 isolate->debugger()->OnAfterCompile(script, Debugger::NO_AFTER_COMPILE_FLAGS); 868 isolate->debugger()->OnAfterCompile(script, Debugger::NO_AFTER_COMPILE_FLAGS);
858 #endif 869 #endif
859 870
860 return result; 871 return result;
861 } 872 }
862 873
863 874
864 Handle<JSFunction> Compiler::GetFunctionFromEval(Handle<String> source, 875 Handle<JSFunction> Compiler::GetFunctionFromEval(Handle<String> source,
865 Handle<Context> context, 876 Handle<Context> context,
866 LanguageMode language_mode, 877 StrictMode strict_mode,
867 ParseRestriction restriction, 878 ParseRestriction restriction,
868 int scope_position) { 879 int scope_position) {
869 Isolate* isolate = source->GetIsolate(); 880 Isolate* isolate = source->GetIsolate();
870 int source_length = source->length(); 881 int source_length = source->length();
871 isolate->counters()->total_eval_size()->Increment(source_length); 882 isolate->counters()->total_eval_size()->Increment(source_length);
872 isolate->counters()->total_compile_size()->Increment(source_length); 883 isolate->counters()->total_compile_size()->Increment(source_length);
873 884
874 CompilationCache* compilation_cache = isolate->compilation_cache(); 885 CompilationCache* compilation_cache = isolate->compilation_cache();
875 Handle<SharedFunctionInfo> shared_info = compilation_cache->LookupEval( 886 Handle<SharedFunctionInfo> shared_info = compilation_cache->LookupEval(
876 source, context, language_mode, scope_position); 887 source, context, strict_mode, scope_position);
877 888
878 if (shared_info.is_null()) { 889 if (shared_info.is_null()) {
879 Handle<Script> script = isolate->factory()->NewScript(source); 890 Handle<Script> script = isolate->factory()->NewScript(source);
880 CompilationInfoWithZone info(script); 891 CompilationInfoWithZone info(script);
881 info.MarkAsEval(); 892 info.MarkAsEval();
882 if (context->IsNativeContext()) info.MarkAsGlobal(); 893 if (context->IsNativeContext()) info.MarkAsGlobal();
883 info.SetLanguageMode(language_mode); 894 info.SetStrictMode(strict_mode);
884 info.SetParseRestriction(restriction); 895 info.SetParseRestriction(restriction);
885 info.SetContext(context); 896 info.SetContext(context);
886 897
887 #if ENABLE_DEBUGGER_SUPPORT 898 #if ENABLE_DEBUGGER_SUPPORT
888 Debug::RecordEvalCaller(script); 899 Debug::RecordEvalCaller(script);
889 #endif // ENABLE_DEBUGGER_SUPPORT 900 #endif // ENABLE_DEBUGGER_SUPPORT
890 901
891 shared_info = CompileToplevel(&info); 902 shared_info = CompileToplevel(&info);
892 903
893 if (shared_info.is_null()) { 904 if (shared_info.is_null()) {
894 return Handle<JSFunction>::null(); 905 return Handle<JSFunction>::null();
895 } else { 906 } else {
896 // Explicitly disable optimization for eval code. We're not yet prepared 907 // Explicitly disable optimization for eval code. We're not yet prepared
897 // to handle eval-code in the optimizing compiler. 908 // to handle eval-code in the optimizing compiler.
898 shared_info->DisableOptimization(kEval); 909 shared_info->DisableOptimization(kEval);
899 910
900 // If caller is strict mode, the result must be in strict mode or 911 // If caller is strict mode, the result must be in strict mode as well.
901 // extended mode as well, but not the other way around. Consider: 912 ASSERT(strict_mode == SLOPPY || shared_info->strict_mode() == STRICT);
902 // eval("'use strict'; ...");
903 ASSERT(language_mode != STRICT_MODE || !shared_info->is_classic_mode());
904 // If caller is in extended mode, the result must also be in
905 // extended mode.
906 ASSERT(language_mode != EXTENDED_MODE ||
907 shared_info->is_extended_mode());
908 if (!shared_info->dont_cache()) { 913 if (!shared_info->dont_cache()) {
909 compilation_cache->PutEval( 914 compilation_cache->PutEval(
910 source, context, shared_info, scope_position); 915 source, context, shared_info, scope_position);
911 } 916 }
912 } 917 }
913 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) { 918 } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
914 shared_info->ResetForNewContext(isolate->heap()->global_ic_age()); 919 shared_info->ResetForNewContext(isolate->heap()->global_ic_age());
915 } 920 }
916 921
917 return isolate->factory()->NewFunctionFromSharedFunctionInfo( 922 return isolate->factory()->NewFunctionFromSharedFunctionInfo(
918 shared_info, context, NOT_TENURED); 923 shared_info, context, NOT_TENURED);
919 } 924 }
920 925
921 926
922 Handle<SharedFunctionInfo> Compiler::CompileScript(Handle<String> source, 927 Handle<SharedFunctionInfo> Compiler::CompileScript(Handle<String> source,
923 Handle<Object> script_name, 928 Handle<Object> script_name,
924 int line_offset, 929 int line_offset,
925 int column_offset, 930 int column_offset,
926 bool is_shared_cross_origin, 931 bool is_shared_cross_origin,
927 Handle<Context> context, 932 Handle<Context> context,
928 v8::Extension* extension, 933 v8::Extension* extension,
929 ScriptDataImpl* pre_data, 934 ScriptDataImpl* pre_data,
930 Handle<Object> script_data,
931 NativesFlag natives) { 935 NativesFlag natives) {
932 Isolate* isolate = source->GetIsolate(); 936 Isolate* isolate = source->GetIsolate();
933 int source_length = source->length(); 937 int source_length = source->length();
934 isolate->counters()->total_load_size()->Increment(source_length); 938 isolate->counters()->total_load_size()->Increment(source_length);
935 isolate->counters()->total_compile_size()->Increment(source_length); 939 isolate->counters()->total_compile_size()->Increment(source_length);
936 940
937 CompilationCache* compilation_cache = isolate->compilation_cache(); 941 CompilationCache* compilation_cache = isolate->compilation_cache();
938 942
939 // Do a lookup in the compilation cache but not for extensions. 943 // Do a lookup in the compilation cache but not for extensions.
940 Handle<SharedFunctionInfo> result; 944 Handle<SharedFunctionInfo> result;
(...skipping 21 matching lines...) Expand all
962 if (natives == NATIVES_CODE) { 966 if (natives == NATIVES_CODE) {
963 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); 967 script->set_type(Smi::FromInt(Script::TYPE_NATIVE));
964 } 968 }
965 if (!script_name.is_null()) { 969 if (!script_name.is_null()) {
966 script->set_name(*script_name); 970 script->set_name(*script_name);
967 script->set_line_offset(Smi::FromInt(line_offset)); 971 script->set_line_offset(Smi::FromInt(line_offset));
968 script->set_column_offset(Smi::FromInt(column_offset)); 972 script->set_column_offset(Smi::FromInt(column_offset));
969 } 973 }
970 script->set_is_shared_cross_origin(is_shared_cross_origin); 974 script->set_is_shared_cross_origin(is_shared_cross_origin);
971 975
972 script->set_data(script_data.is_null() ? isolate->heap()->undefined_value()
973 : *script_data);
974
975 // Compile the function and add it to the cache. 976 // Compile the function and add it to the cache.
976 CompilationInfoWithZone info(script); 977 CompilationInfoWithZone info(script);
977 info.MarkAsGlobal(); 978 info.MarkAsGlobal();
978 info.SetExtension(extension); 979 info.SetExtension(extension);
979 info.SetPreParseData(pre_data); 980 info.SetPreParseData(pre_data);
980 info.SetContext(context); 981 info.SetContext(context);
981 if (FLAG_use_strict) { 982 if (FLAG_use_strict) info.SetStrictMode(STRICT);
982 info.SetLanguageMode(FLAG_harmony_scoping ? EXTENDED_MODE : STRICT_MODE);
983 }
984 result = CompileToplevel(&info); 983 result = CompileToplevel(&info);
985 if (extension == NULL && !result.is_null() && !result->dont_cache()) { 984 if (extension == NULL && !result.is_null() && !result->dont_cache()) {
986 compilation_cache->PutScript(source, context, result); 985 compilation_cache->PutScript(source, context, result);
987 } 986 }
988 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { 987 } else if (result->ic_age() != isolate->heap()->global_ic_age()) {
989 result->ResetForNewContext(isolate->heap()->global_ic_age()); 988 result->ResetForNewContext(isolate->heap()->global_ic_age());
990 } 989 }
991 990
992 if (result.is_null()) isolate->ReportPendingMessages(); 991 if (result.is_null()) isolate->ReportPendingMessages();
993 return result; 992 return result;
994 } 993 }
995 994
996 995
997 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, 996 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
998 Handle<Script> script) { 997 Handle<Script> script) {
999 // Precondition: code has been parsed and scopes have been analyzed. 998 // Precondition: code has been parsed and scopes have been analyzed.
1000 CompilationInfoWithZone info(script); 999 CompilationInfoWithZone info(script);
1001 info.SetFunction(literal); 1000 info.SetFunction(literal);
1002 info.PrepareForCompilation(literal->scope()); 1001 info.PrepareForCompilation(literal->scope());
1003 info.SetLanguageMode(literal->scope()->language_mode()); 1002 info.SetStrictMode(literal->scope()->strict_mode());
1004 1003
1005 Isolate* isolate = info.isolate(); 1004 Isolate* isolate = info.isolate();
1006 Factory* factory = isolate->factory(); 1005 Factory* factory = isolate->factory();
1007 LiveEditFunctionTracker live_edit_tracker(isolate, literal); 1006 LiveEditFunctionTracker live_edit_tracker(isolate, literal);
1008 // Determine if the function can be lazily compiled. This is necessary to 1007 // Determine if the function can be lazily compiled. This is necessary to
1009 // allow some of our builtin JS files to be lazily compiled. These 1008 // allow some of our builtin JS files to be lazily compiled. These
1010 // builtins cannot be handled lazily by the parser, since we have to know 1009 // builtins cannot be handled lazily by the parser, since we have to know
1011 // if a function uses the special natives syntax, which is something the 1010 // if a function uses the special natives syntax, which is something the
1012 // parser records. 1011 // parser records.
1013 // If the debugger requests compilation for break points, we cannot be 1012 // If the debugger requests compilation for break points, we cannot be
(...skipping 16 matching lines...) Expand all
1030 } else { 1029 } else {
1031 return Handle<SharedFunctionInfo>::null(); 1030 return Handle<SharedFunctionInfo>::null();
1032 } 1031 }
1033 1032
1034 // Create a shared function info object. 1033 // Create a shared function info object.
1035 Handle<SharedFunctionInfo> result = 1034 Handle<SharedFunctionInfo> result =
1036 factory->NewSharedFunctionInfo(literal->name(), 1035 factory->NewSharedFunctionInfo(literal->name(),
1037 literal->materialized_literal_count(), 1036 literal->materialized_literal_count(),
1038 literal->is_generator(), 1037 literal->is_generator(),
1039 info.code(), 1038 info.code(),
1040 scope_info); 1039 scope_info,
1040 info.feedback_vector());
1041 SetFunctionInfo(result, literal, false, script); 1041 SetFunctionInfo(result, literal, false, script);
1042 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); 1042 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
1043 result->set_allows_lazy_compilation(allow_lazy); 1043 result->set_allows_lazy_compilation(allow_lazy);
1044 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); 1044 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
1045 1045
1046 // Set the expected number of properties for instances and return 1046 // Set the expected number of properties for instances and return
1047 // the resulting function. 1047 // the resulting function.
1048 SetExpectedNofPropertiesFromEstimate(result, 1048 SetExpectedNofPropertiesFromEstimate(result,
1049 literal->expected_property_count()); 1049 literal->expected_property_count());
1050 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); 1050 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 Handle<FixedArray> literals(function->literals()); 1088 Handle<FixedArray> literals(function->literals());
1089 Handle<Context> native_context(function->context()->native_context()); 1089 Handle<Context> native_context(function->context()->native_context());
1090 SharedFunctionInfo::AddToOptimizedCodeMap( 1090 SharedFunctionInfo::AddToOptimizedCodeMap(
1091 shared, native_context, code, literals, info->osr_ast_id()); 1091 shared, native_context, code, literals, info->osr_ast_id());
1092 } 1092 }
1093 } 1093 }
1094 1094
1095 1095
1096 static bool CompileOptimizedPrologue(CompilationInfo* info) { 1096 static bool CompileOptimizedPrologue(CompilationInfo* info) {
1097 if (!Parser::Parse(info)) return false; 1097 if (!Parser::Parse(info)) return false;
1098 LanguageMode language_mode = info->function()->language_mode(); 1098 info->SetStrictMode(info->function()->strict_mode());
1099 info->SetLanguageMode(language_mode);
1100 1099
1101 if (!Rewriter::Rewrite(info)) return false; 1100 if (!Rewriter::Rewrite(info)) return false;
1102 if (!Scope::Analyze(info)) return false; 1101 if (!Scope::Analyze(info)) return false;
1103 ASSERT(info->scope() != NULL); 1102 ASSERT(info->scope() != NULL);
1104 return true; 1103 return true;
1105 } 1104 }
1106 1105
1107 1106
1108 static bool GetOptimizedCodeNow(CompilationInfo* info) { 1107 static bool GetOptimizedCodeNow(CompilationInfo* info) {
1109 if (!CompileOptimizedPrologue(info)) return false; 1108 if (!CompileOptimizedPrologue(info)) return false;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 AllowHandleDereference allow_deref; 1307 AllowHandleDereference allow_deref;
1309 bool tracing_on = info()->IsStub() 1308 bool tracing_on = info()->IsStub()
1310 ? FLAG_trace_hydrogen_stubs 1309 ? FLAG_trace_hydrogen_stubs
1311 : (FLAG_trace_hydrogen && 1310 : (FLAG_trace_hydrogen &&
1312 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); 1311 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter));
1313 return (tracing_on && 1312 return (tracing_on &&
1314 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); 1313 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
1315 } 1314 }
1316 1315
1317 } } // namespace v8::internal 1316 } } // 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