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

Side by Side Diff: src/compiler.cc

Issue 366153002: Add script streaming API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased again? Created 6 years, 3 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/parser.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 8
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 29 matching lines...) Expand all
40 CopyBytes(copy, data, length); 40 CopyBytes(copy, data, length);
41 data_ = copy; 41 data_ = copy;
42 AcquireDataOwnership(); 42 AcquireDataOwnership();
43 } 43 }
44 } 44 }
45 45
46 46
47 CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone) 47 CompilationInfo::CompilationInfo(Handle<Script> script, Zone* zone)
48 : flags_(kThisHasUses), 48 : flags_(kThisHasUses),
49 script_(script), 49 script_(script),
50 source_stream_(NULL),
50 osr_ast_id_(BailoutId::None()), 51 osr_ast_id_(BailoutId::None()),
51 parameter_count_(0), 52 parameter_count_(0),
52 optimization_id_(-1), 53 optimization_id_(-1),
53 ast_value_factory_(NULL), 54 ast_value_factory_(NULL),
54 ast_value_factory_owned_(false) { 55 ast_value_factory_owned_(false) {
55 Initialize(script->GetIsolate(), BASE, zone); 56 Initialize(script->GetIsolate(), BASE, zone);
56 } 57 }
57 58
58 59
59 CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone) 60 CompilationInfo::CompilationInfo(Isolate* isolate, Zone* zone)
60 : flags_(kThisHasUses), 61 : flags_(kThisHasUses),
61 script_(Handle<Script>::null()), 62 script_(Handle<Script>::null()),
63 source_stream_(NULL),
62 osr_ast_id_(BailoutId::None()), 64 osr_ast_id_(BailoutId::None()),
63 parameter_count_(0), 65 parameter_count_(0),
64 optimization_id_(-1), 66 optimization_id_(-1),
65 ast_value_factory_(NULL), 67 ast_value_factory_(NULL),
66 ast_value_factory_owned_(false) { 68 ast_value_factory_owned_(false) {
67 Initialize(isolate, STUB, zone); 69 Initialize(isolate, STUB, zone);
68 } 70 }
69 71
70 72
71 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, 73 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info,
72 Zone* zone) 74 Zone* zone)
73 : flags_(kLazy | kThisHasUses), 75 : flags_(kLazy | kThisHasUses),
74 shared_info_(shared_info), 76 shared_info_(shared_info),
75 script_(Handle<Script>(Script::cast(shared_info->script()))), 77 script_(Handle<Script>(Script::cast(shared_info->script()))),
78 source_stream_(NULL),
76 osr_ast_id_(BailoutId::None()), 79 osr_ast_id_(BailoutId::None()),
77 parameter_count_(0), 80 parameter_count_(0),
78 optimization_id_(-1), 81 optimization_id_(-1),
79 ast_value_factory_(NULL), 82 ast_value_factory_(NULL),
80 ast_value_factory_owned_(false) { 83 ast_value_factory_owned_(false) {
81 Initialize(script_->GetIsolate(), BASE, zone); 84 Initialize(script_->GetIsolate(), BASE, zone);
82 } 85 }
83 86
84 87
85 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) 88 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone)
86 : flags_(kLazy | kThisHasUses), 89 : flags_(kLazy | kThisHasUses),
87 closure_(closure), 90 closure_(closure),
88 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), 91 shared_info_(Handle<SharedFunctionInfo>(closure->shared())),
89 script_(Handle<Script>(Script::cast(shared_info_->script()))), 92 script_(Handle<Script>(Script::cast(shared_info_->script()))),
93 source_stream_(NULL),
90 context_(closure->context()), 94 context_(closure->context()),
91 osr_ast_id_(BailoutId::None()), 95 osr_ast_id_(BailoutId::None()),
92 parameter_count_(0), 96 parameter_count_(0),
93 optimization_id_(-1), 97 optimization_id_(-1),
94 ast_value_factory_(NULL), 98 ast_value_factory_(NULL),
95 ast_value_factory_owned_(false) { 99 ast_value_factory_owned_(false) {
96 Initialize(script_->GetIsolate(), BASE, zone); 100 Initialize(script_->GetIsolate(), BASE, zone);
97 } 101 }
98 102
99 103
100 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, 104 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate,
101 Zone* zone) 105 Zone* zone)
102 : flags_(kLazy | kThisHasUses), 106 : flags_(kLazy | kThisHasUses),
107 source_stream_(NULL),
103 osr_ast_id_(BailoutId::None()), 108 osr_ast_id_(BailoutId::None()),
104 parameter_count_(0), 109 parameter_count_(0),
105 optimization_id_(-1), 110 optimization_id_(-1),
106 ast_value_factory_(NULL), 111 ast_value_factory_(NULL),
107 ast_value_factory_owned_(false) { 112 ast_value_factory_owned_(false) {
108 Initialize(isolate, STUB, zone); 113 Initialize(isolate, STUB, zone);
109 code_stub_ = stub; 114 code_stub_ = stub;
110 } 115 }
111 116
112 117
118 CompilationInfo::CompilationInfo(
119 ScriptCompiler::ExternalSourceStream* stream,
120 ScriptCompiler::StreamedSource::Encoding encoding, Isolate* isolate,
121 Zone* zone)
122 : flags_(kThisHasUses),
123 source_stream_(stream),
124 source_stream_encoding_(encoding),
125 osr_ast_id_(BailoutId::None()),
126 parameter_count_(0),
127 optimization_id_(-1),
128 ast_value_factory_(NULL),
129 ast_value_factory_owned_(false) {
130 Initialize(isolate, BASE, zone);
131 }
132
133
113 void CompilationInfo::Initialize(Isolate* isolate, 134 void CompilationInfo::Initialize(Isolate* isolate,
114 Mode mode, 135 Mode mode,
115 Zone* zone) { 136 Zone* zone) {
116 isolate_ = isolate; 137 isolate_ = isolate;
117 function_ = NULL; 138 function_ = NULL;
118 scope_ = NULL; 139 scope_ = NULL;
119 global_scope_ = NULL; 140 global_scope_ = NULL;
120 extension_ = NULL; 141 extension_ = NULL;
121 cached_data_ = NULL; 142 cached_data_ = NULL;
122 compile_options_ = ScriptCompiler::kNoCompileOptions; 143 compile_options_ = ScriptCompiler::kNoCompileOptions;
123 zone_ = zone; 144 zone_ = zone;
124 deferred_handles_ = NULL; 145 deferred_handles_ = NULL;
125 code_stub_ = NULL; 146 code_stub_ = NULL;
126 prologue_offset_ = Code::kPrologueOffsetNotSet; 147 prologue_offset_ = Code::kPrologueOffsetNotSet;
127 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); 148 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count();
128 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() 149 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling()
129 ? new List<OffsetRange>(2) : NULL; 150 ? new List<OffsetRange>(2) : NULL;
130 for (int i = 0; i < DependentCode::kGroupCount; i++) { 151 for (int i = 0; i < DependentCode::kGroupCount; i++) {
131 dependencies_[i] = NULL; 152 dependencies_[i] = NULL;
132 } 153 }
133 if (mode == STUB) { 154 if (mode == STUB) {
134 mode_ = STUB; 155 mode_ = STUB;
135 return; 156 return;
136 } 157 }
137 mode_ = mode; 158 mode_ = mode;
138 abort_due_to_dependency_ = false; 159 abort_due_to_dependency_ = false;
139 if (script_->type()->value() == Script::TYPE_NATIVE) MarkAsNative(); 160 if (!script_.is_null() && script_->type()->value() == Script::TYPE_NATIVE) {
161 MarkAsNative();
162 }
140 if (isolate_->debug()->is_active()) MarkAsDebug(); 163 if (isolate_->debug()->is_active()) MarkAsDebug();
141 if (FLAG_context_specialization) MarkAsContextSpecializing(); 164 if (FLAG_context_specialization) MarkAsContextSpecializing();
142 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); 165 if (FLAG_turbo_inlining) MarkAsInliningEnabled();
143 #if !V8_TARGET_ARCH_ARM64 166 #if !V8_TARGET_ARCH_ARM64
144 // TODO(mstarzinger): Bugs in ARM64 back-end block enabling typed pipeline. 167 // TODO(mstarzinger): Bugs in ARM64 back-end block enabling typed pipeline.
145 if (FLAG_turbo_types) MarkAsTypingEnabled(); 168 if (FLAG_turbo_types) MarkAsTypingEnabled();
146 #endif 169 #endif
147 170
148 if (!shared_info_.is_null()) { 171 if (!shared_info_.is_null()) {
149 DCHECK(strict_mode() == SLOPPY); 172 DCHECK(strict_mode() == SLOPPY);
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 if (!CompileUnoptimizedCode(&info)) return; 826 if (!CompileUnoptimizedCode(&info)) return;
804 if (!info.shared_info().is_null()) { 827 if (!info.shared_info().is_null()) {
805 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), 828 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(),
806 info.zone()); 829 info.zone());
807 info.shared_info()->set_scope_info(*scope_info); 830 info.shared_info()->set_scope_info(*scope_info);
808 } 831 }
809 tracker.RecordRootFunctionInfo(info.code()); 832 tracker.RecordRootFunctionInfo(info.code());
810 } 833 }
811 834
812 835
813 static bool DebuggerWantsEagerCompilation(CompilationInfo* info,
814 bool allow_lazy_without_ctx = false) {
815 return LiveEditFunctionTracker::IsActive(info->isolate()) ||
816 (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx);
817 }
818
819
820 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { 836 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
821 Isolate* isolate = info->isolate(); 837 Isolate* isolate = info->isolate();
822 PostponeInterruptsScope postpone(isolate); 838 PostponeInterruptsScope postpone(isolate);
823 DCHECK(!isolate->native_context().is_null()); 839 DCHECK(!isolate->native_context().is_null());
824 Handle<Script> script = info->script(); 840 Handle<Script> script = info->script();
825 841
826 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? 842 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile?
827 FixedArray* array = isolate->native_context()->embedder_data(); 843 FixedArray* array = isolate->native_context()->embedder_data();
828 script->set_context_data(array->get(0)); 844 script->set_context_data(array->get(0));
829 845
830 isolate->debug()->OnBeforeCompile(script); 846 isolate->debug()->OnBeforeCompile(script);
831 847
832 DCHECK(info->is_eval() || info->is_global()); 848 DCHECK(info->is_eval() || info->is_global());
833 849
834 bool parse_allow_lazy =
835 (info->compile_options() == ScriptCompiler::kConsumeParserCache ||
836 String::cast(script->source())->length() > FLAG_min_preparse_length) &&
837 !DebuggerWantsEagerCompilation(info);
838
839 if (!parse_allow_lazy &&
840 (info->compile_options() == ScriptCompiler::kProduceParserCache ||
841 info->compile_options() == ScriptCompiler::kConsumeParserCache)) {
842 // We are going to parse eagerly, but we either 1) have cached data produced
843 // by lazy parsing or 2) are asked to generate cached data. We cannot use
844 // the existing data, since it won't contain all the symbols we need for
845 // eager parsing. In addition, it doesn't make sense to produce the data
846 // when parsing eagerly. That data would contain all symbols, but no
847 // functions, so it cannot be used to aid lazy parsing later.
848 info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions);
849 }
850
851 Handle<SharedFunctionInfo> result; 850 Handle<SharedFunctionInfo> result;
852 851
853 { VMState<COMPILER> state(info->isolate()); 852 { VMState<COMPILER> state(info->isolate());
854 if (!Parser::Parse(info, parse_allow_lazy)) { 853 if (info->function() == NULL) {
855 return Handle<SharedFunctionInfo>::null(); 854 // Parse the script if needed (if it's already parsed, function() is
855 // non-NULL).
856 bool parse_allow_lazy =
857 (info->compile_options() == ScriptCompiler::kConsumeParserCache ||
858 String::cast(script->source())->length() >
859 FLAG_min_preparse_length) &&
860 !Compiler::DebuggerWantsEagerCompilation(info);
861
862 if (!parse_allow_lazy &&
863 (info->compile_options() == ScriptCompiler::kProduceParserCache ||
864 info->compile_options() == ScriptCompiler::kConsumeParserCache)) {
865 // We are going to parse eagerly, but we either 1) have cached data
866 // produced by lazy parsing or 2) are asked to generate cached data.
867 // Eager parsing cannot benefit from cached data, and producing cached
868 // data while parsing eagerly is not implemented.
869 info->SetCachedData(NULL, ScriptCompiler::kNoCompileOptions);
870 }
871 if (!Parser::Parse(info, parse_allow_lazy)) {
872 return Handle<SharedFunctionInfo>::null();
873 }
856 } 874 }
857 875
858 FunctionLiteral* lit = info->function(); 876 FunctionLiteral* lit = info->function();
859 LiveEditFunctionTracker live_edit_tracker(isolate, lit); 877 LiveEditFunctionTracker live_edit_tracker(isolate, lit);
860 878
861 // Measure how long it takes to do the compilation; only take the 879 // Measure how long it takes to do the compilation; only take the
862 // rest of the function into account to avoid overlap with the 880 // rest of the function into account to avoid overlap with the
863 // parsing statistics. 881 // parsing statistics.
864 HistogramTimer* rate = info->is_eval() 882 HistogramTimer* rate = info->is_eval()
865 ? info->isolate()->counters()->compile_eval() 883 ? info->isolate()->counters()->compile_eval()
(...skipping 25 matching lines...) Expand all
891 PROFILE(isolate, CodeCreateEvent( 909 PROFILE(isolate, CodeCreateEvent(
892 log_tag, *info->code(), *result, info, *script_name)); 910 log_tag, *info->code(), *result, info, *script_name));
893 GDBJIT(AddCode(script_name, script, info->code(), info)); 911 GDBJIT(AddCode(script_name, script, info->code(), info));
894 912
895 // Hint to the runtime system used when allocating space for initial 913 // Hint to the runtime system used when allocating space for initial
896 // property space by setting the expected number of properties for 914 // property space by setting the expected number of properties for
897 // the instances of the function. 915 // the instances of the function.
898 SetExpectedNofPropertiesFromEstimate(result, 916 SetExpectedNofPropertiesFromEstimate(result,
899 lit->expected_property_count()); 917 lit->expected_property_count());
900 918
901 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); 919 if (!script.is_null())
920 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
902 921
903 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); 922 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone());
904 } 923 }
905 924
906 isolate->debug()->OnAfterCompile(script); 925 isolate->debug()->OnAfterCompile(script);
907 926
908 return result; 927 return result;
909 } 928 }
910 929
911 930
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 } 1067 }
1049 1068
1050 if (result.is_null()) isolate->ReportPendingMessages(); 1069 if (result.is_null()) isolate->ReportPendingMessages();
1051 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { 1070 } else if (result->ic_age() != isolate->heap()->global_ic_age()) {
1052 result->ResetForNewContext(isolate->heap()->global_ic_age()); 1071 result->ResetForNewContext(isolate->heap()->global_ic_age());
1053 } 1072 }
1054 return result; 1073 return result;
1055 } 1074 }
1056 1075
1057 1076
1077 Handle<SharedFunctionInfo> Compiler::CompileStreamedScript(
1078 CompilationInfo* info, int source_length) {
1079 Isolate* isolate = info->isolate();
1080 isolate->counters()->total_load_size()->Increment(source_length);
1081 isolate->counters()->total_compile_size()->Increment(source_length);
1082
1083 if (FLAG_use_strict) info->SetStrictMode(STRICT);
1084 // TODO(marja): FLAG_serialize_toplevel is not honoured and won't be; when the
1085 // real code caching lands, streaming needs to be adapted to use it.
1086 return CompileToplevel(info);
1087 }
1088
1089
1058 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( 1090 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(
1059 FunctionLiteral* literal, Handle<Script> script, 1091 FunctionLiteral* literal, Handle<Script> script,
1060 CompilationInfo* outer_info) { 1092 CompilationInfo* outer_info) {
1061 // Precondition: code has been parsed and scopes have been analyzed. 1093 // Precondition: code has been parsed and scopes have been analyzed.
1062 CompilationInfoWithZone info(script); 1094 CompilationInfoWithZone info(script);
1063 info.SetFunction(literal); 1095 info.SetFunction(literal);
1064 info.PrepareForCompilation(literal->scope()); 1096 info.PrepareForCompilation(literal->scope());
1065 info.SetStrictMode(literal->scope()->strict_mode()); 1097 info.SetStrictMode(literal->scope()->strict_mode());
1066 if (outer_info->will_serialize()) info.PrepareForSerializing(); 1098 if (outer_info->will_serialize()) info.PrepareForSerializing();
1067 1099
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 log_tag, *code, *shared, info, script_name, line_num, column_num)); 1387 log_tag, *code, *shared, info, script_name, line_num, column_num));
1356 } 1388 }
1357 1389
1358 GDBJIT(AddCode(Handle<String>(shared->DebugName()), 1390 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
1359 Handle<Script>(info->script()), 1391 Handle<Script>(info->script()),
1360 Handle<Code>(info->code()), 1392 Handle<Code>(info->code()),
1361 info)); 1393 info));
1362 } 1394 }
1363 1395
1364 1396
1397 bool Compiler::DebuggerWantsEagerCompilation(CompilationInfo* info,
1398 bool allow_lazy_without_ctx) {
1399 return LiveEditFunctionTracker::IsActive(info->isolate()) ||
1400 (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx);
1401 }
1402
1403
1365 CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) 1404 CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info)
1366 : name_(name), info_(info), zone_(info->isolate()) { 1405 : name_(name), info_(info), zone_(info->isolate()) {
1367 if (FLAG_hydrogen_stats) { 1406 if (FLAG_hydrogen_stats) {
1368 info_zone_start_allocation_size_ = info->zone()->allocation_size(); 1407 info_zone_start_allocation_size_ = info->zone()->allocation_size();
1369 timer_.Start(); 1408 timer_.Start();
1370 } 1409 }
1371 } 1410 }
1372 1411
1373 1412
1374 CompilationPhase::~CompilationPhase() { 1413 CompilationPhase::~CompilationPhase() {
(...skipping 11 matching lines...) Expand all
1386 AllowHandleDereference allow_deref; 1425 AllowHandleDereference allow_deref;
1387 bool tracing_on = info()->IsStub() 1426 bool tracing_on = info()->IsStub()
1388 ? FLAG_trace_hydrogen_stubs 1427 ? FLAG_trace_hydrogen_stubs
1389 : (FLAG_trace_hydrogen && 1428 : (FLAG_trace_hydrogen &&
1390 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); 1429 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter));
1391 return (tracing_on && 1430 return (tracing_on &&
1392 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); 1431 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL);
1393 } 1432 }
1394 1433
1395 } } // namespace v8::internal 1434 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698