OLD | NEW |
---|---|
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 Loading... | |
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()), |
62 osr_ast_id_(BailoutId::None()), | 63 osr_ast_id_(BailoutId::None()), |
63 parameter_count_(0), | 64 parameter_count_(0), |
64 optimization_id_(-1), | 65 optimization_id_(-1), |
65 ast_value_factory_(NULL), | 66 ast_value_factory_(NULL), |
66 ast_value_factory_owned_(false) { | 67 ast_value_factory_owned_(false) { |
67 Initialize(isolate, STUB, zone); | 68 Initialize(isolate, STUB, zone); |
68 } | 69 } |
69 | 70 |
70 | 71 |
71 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, | 72 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
72 Zone* zone) | 73 Zone* zone) |
73 : flags_(kLazy | kThisHasUses), | 74 : flags_(kLazy | kThisHasUses), |
74 shared_info_(shared_info), | 75 shared_info_(shared_info), |
75 script_(Handle<Script>(Script::cast(shared_info->script()))), | 76 script_(Handle<Script>(Script::cast(shared_info->script()))), |
77 source_stream_(NULL), | |
76 osr_ast_id_(BailoutId::None()), | 78 osr_ast_id_(BailoutId::None()), |
77 parameter_count_(0), | 79 parameter_count_(0), |
78 optimization_id_(-1), | 80 optimization_id_(-1), |
79 ast_value_factory_(NULL), | 81 ast_value_factory_(NULL), |
80 ast_value_factory_owned_(false) { | 82 ast_value_factory_owned_(false) { |
81 Initialize(script_->GetIsolate(), BASE, zone); | 83 Initialize(script_->GetIsolate(), BASE, zone); |
82 } | 84 } |
83 | 85 |
84 | 86 |
85 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) | 87 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, Zone* zone) |
86 : flags_(kLazy | kThisHasUses), | 88 : flags_(kLazy | kThisHasUses), |
87 closure_(closure), | 89 closure_(closure), |
88 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 90 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
89 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 91 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
92 source_stream_(NULL), | |
90 context_(closure->context()), | 93 context_(closure->context()), |
91 osr_ast_id_(BailoutId::None()), | 94 osr_ast_id_(BailoutId::None()), |
92 parameter_count_(0), | 95 parameter_count_(0), |
93 optimization_id_(-1), | 96 optimization_id_(-1), |
94 ast_value_factory_(NULL), | 97 ast_value_factory_(NULL), |
95 ast_value_factory_owned_(false) { | 98 ast_value_factory_owned_(false) { |
96 Initialize(script_->GetIsolate(), BASE, zone); | 99 Initialize(script_->GetIsolate(), BASE, zone); |
97 } | 100 } |
98 | 101 |
99 | 102 |
100 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, | 103 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, Isolate* isolate, |
101 Zone* zone) | 104 Zone* zone) |
102 : flags_(kLazy | kThisHasUses), | 105 : flags_(kLazy | kThisHasUses), |
106 source_stream_(NULL), | |
103 osr_ast_id_(BailoutId::None()), | 107 osr_ast_id_(BailoutId::None()), |
104 parameter_count_(0), | 108 parameter_count_(0), |
105 optimization_id_(-1), | 109 optimization_id_(-1), |
106 ast_value_factory_(NULL), | 110 ast_value_factory_(NULL), |
107 ast_value_factory_owned_(false) { | 111 ast_value_factory_owned_(false) { |
108 Initialize(isolate, STUB, zone); | 112 Initialize(isolate, STUB, zone); |
109 code_stub_ = stub; | 113 code_stub_ = stub; |
110 } | 114 } |
111 | 115 |
112 | 116 |
117 CompilationInfo::CompilationInfo(ScriptCompiler::ExternalSourceStream* stream, | |
118 Isolate* isolate, Zone* zone) | |
119 : flags_(kThisHasUses), | |
120 source_stream_(stream), | |
121 osr_ast_id_(BailoutId::None()), | |
122 parameter_count_(0), | |
123 optimization_id_(-1), | |
124 ast_value_factory_(NULL), | |
125 ast_value_factory_owned_(false) { | |
126 Initialize(isolate, BASE, zone); | |
127 } | |
128 | |
129 | |
113 void CompilationInfo::Initialize(Isolate* isolate, | 130 void CompilationInfo::Initialize(Isolate* isolate, |
114 Mode mode, | 131 Mode mode, |
115 Zone* zone) { | 132 Zone* zone) { |
116 isolate_ = isolate; | 133 isolate_ = isolate; |
117 function_ = NULL; | 134 function_ = NULL; |
118 scope_ = NULL; | 135 scope_ = NULL; |
119 global_scope_ = NULL; | 136 global_scope_ = NULL; |
120 extension_ = NULL; | 137 extension_ = NULL; |
121 cached_data_ = NULL; | 138 cached_data_ = NULL; |
122 compile_options_ = ScriptCompiler::kNoCompileOptions; | 139 compile_options_ = ScriptCompiler::kNoCompileOptions; |
123 zone_ = zone; | 140 zone_ = zone; |
124 deferred_handles_ = NULL; | 141 deferred_handles_ = NULL; |
125 code_stub_ = NULL; | 142 code_stub_ = NULL; |
126 prologue_offset_ = Code::kPrologueOffsetNotSet; | 143 prologue_offset_ = Code::kPrologueOffsetNotSet; |
127 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); | 144 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); |
128 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() | 145 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() |
129 ? new List<OffsetRange>(2) : NULL; | 146 ? new List<OffsetRange>(2) : NULL; |
130 for (int i = 0; i < DependentCode::kGroupCount; i++) { | 147 for (int i = 0; i < DependentCode::kGroupCount; i++) { |
131 dependencies_[i] = NULL; | 148 dependencies_[i] = NULL; |
132 } | 149 } |
133 if (mode == STUB) { | 150 if (mode == STUB) { |
134 mode_ = STUB; | 151 mode_ = STUB; |
135 return; | 152 return; |
136 } | 153 } |
137 mode_ = mode; | 154 mode_ = mode; |
138 abort_due_to_dependency_ = false; | 155 abort_due_to_dependency_ = false; |
139 if (script_->type()->value() == Script::TYPE_NATIVE) MarkAsNative(); | 156 if (!script_.is_null() && script_->type()->value() == Script::TYPE_NATIVE) { |
157 MarkAsNative(); | |
158 } | |
140 if (isolate_->debug()->is_active()) MarkAsDebug(); | 159 if (isolate_->debug()->is_active()) MarkAsDebug(); |
141 if (FLAG_context_specialization) MarkAsContextSpecializing(); | 160 if (FLAG_context_specialization) MarkAsContextSpecializing(); |
142 if (FLAG_turbo_types) MarkAsTypingEnabled(); | 161 if (FLAG_turbo_types) MarkAsTypingEnabled(); |
143 | 162 |
144 if (!shared_info_.is_null()) { | 163 if (!shared_info_.is_null()) { |
145 DCHECK(strict_mode() == SLOPPY); | 164 DCHECK(strict_mode() == SLOPPY); |
146 SetStrictMode(shared_info_->strict_mode()); | 165 SetStrictMode(shared_info_->strict_mode()); |
147 } | 166 } |
148 set_bailout_reason(kUnknown); | 167 set_bailout_reason(kUnknown); |
149 | 168 |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 if (!CompileUnoptimizedCode(&info)) return; | 822 if (!CompileUnoptimizedCode(&info)) return; |
804 if (!info.shared_info().is_null()) { | 823 if (!info.shared_info().is_null()) { |
805 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), | 824 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info.scope(), |
806 info.zone()); | 825 info.zone()); |
807 info.shared_info()->set_scope_info(*scope_info); | 826 info.shared_info()->set_scope_info(*scope_info); |
808 } | 827 } |
809 tracker.RecordRootFunctionInfo(info.code()); | 828 tracker.RecordRootFunctionInfo(info.code()); |
810 } | 829 } |
811 | 830 |
812 | 831 |
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) { | 832 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { |
821 Isolate* isolate = info->isolate(); | 833 Isolate* isolate = info->isolate(); |
822 PostponeInterruptsScope postpone(isolate); | 834 PostponeInterruptsScope postpone(isolate); |
823 DCHECK(!isolate->native_context().is_null()); | 835 DCHECK(!isolate->native_context().is_null()); |
824 Handle<Script> script = info->script(); | 836 Handle<Script> script = info->script(); |
825 | 837 |
826 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 838 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
827 FixedArray* array = isolate->native_context()->embedder_data(); | 839 FixedArray* array = isolate->native_context()->embedder_data(); |
828 script->set_context_data(array->get(0)); | 840 script->set_context_data(array->get(0)); |
829 | 841 |
830 isolate->debug()->OnBeforeCompile(script); | 842 isolate->debug()->OnBeforeCompile(script); |
831 | 843 |
832 DCHECK(info->is_eval() || info->is_global()); | 844 DCHECK(info->is_eval() || info->is_global()); |
833 | 845 |
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; | 846 Handle<SharedFunctionInfo> result; |
852 | 847 |
853 { VMState<COMPILER> state(info->isolate()); | 848 { VMState<COMPILER> state(info->isolate()); |
854 if (!Parser::Parse(info, parse_allow_lazy)) { | 849 if (info->function() == NULL) { |
855 return Handle<SharedFunctionInfo>::null(); | 850 // Parse the script if needed (if it's already parsed, function() returns |
851 // non-NULL. | |
852 bool parse_allow_lazy = | |
853 (info->compile_options() == ScriptCompiler::kConsumeParserCache || | |
854 String::cast(script->source())->length() > | |
855 FLAG_min_preparse_length) && | |
856 !Compiler::DebuggerWantsEagerCompilation(info); | |
857 | |
858 if (!parse_allow_lazy && | |
859 (info->compile_options() == ScriptCompiler::kProduceParserCache || | |
860 info->compile_options() == ScriptCompiler::kConsumeParserCache)) { | |
861 // We are going to parse eagerly, but we either 1) have cached data | |
862 // produced | |
Sven Panne
2014/09/01 09:07:46
Funny spacing.
marja
2014/09/01 11:58:17
Done.
| |
863 // by lazy parsing or 2) are asked to generate cached data. We cannot | |
864 // use | |
865 // the existing data, since it won't contain all the symbols we need for | |
866 // eager parsing. In addition, it doesn't make sense to produce the data | |
867 // when parsing eagerly. That data would contain all symbols, but no | |
868 // functions, so it cannot be used to aid lazy parsing later. | |
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 26 matching lines...) Expand all Loading... | |
892 PROFILE(isolate, CodeCreateEvent( | 910 PROFILE(isolate, CodeCreateEvent( |
893 log_tag, *info->code(), *result, info, *script_name)); | 911 log_tag, *info->code(), *result, info, *script_name)); |
894 GDBJIT(AddCode(script_name, script, info->code(), info)); | 912 GDBJIT(AddCode(script_name, script, info->code(), info)); |
895 | 913 |
896 // Hint to the runtime system used when allocating space for initial | 914 // Hint to the runtime system used when allocating space for initial |
897 // property space by setting the expected number of properties for | 915 // property space by setting the expected number of properties for |
898 // the instances of the function. | 916 // the instances of the function. |
899 SetExpectedNofPropertiesFromEstimate(result, | 917 SetExpectedNofPropertiesFromEstimate(result, |
900 lit->expected_property_count()); | 918 lit->expected_property_count()); |
901 | 919 |
902 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); | 920 if (!script.is_null()) |
921 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); | |
903 | 922 |
904 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); | 923 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); |
905 } | 924 } |
906 | 925 |
907 isolate->debug()->OnAfterCompile(script); | 926 isolate->debug()->OnAfterCompile(script); |
908 | 927 |
909 return result; | 928 return result; |
910 } | 929 } |
911 | 930 |
912 | 931 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1049 } | 1068 } |
1050 | 1069 |
1051 if (result.is_null()) isolate->ReportPendingMessages(); | 1070 if (result.is_null()) isolate->ReportPendingMessages(); |
1052 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { | 1071 } else if (result->ic_age() != isolate->heap()->global_ic_age()) { |
1053 result->ResetForNewContext(isolate->heap()->global_ic_age()); | 1072 result->ResetForNewContext(isolate->heap()->global_ic_age()); |
1054 } | 1073 } |
1055 return result; | 1074 return result; |
1056 } | 1075 } |
1057 | 1076 |
1058 | 1077 |
1078 Handle<SharedFunctionInfo> Compiler::CompileStreamedScript( | |
1079 CompilationInfo* info, int source_length) { | |
1080 Isolate* isolate = info->isolate(); | |
1081 isolate->counters()->total_load_size()->Increment(source_length); | |
1082 isolate->counters()->total_compile_size()->Increment(source_length); | |
1083 | |
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 | |
1087 if (FLAG_use_strict) info->SetStrictMode(STRICT); | |
1088 | |
1089 Handle<SharedFunctionInfo> result = CompileToplevel(info); | |
1090 | |
1091 if (result.is_null()) isolate->ReportPendingMessages(); | |
1092 return result; | |
1093 } | |
1094 | |
1095 | |
1059 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( | 1096 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo( |
1060 FunctionLiteral* literal, Handle<Script> script, | 1097 FunctionLiteral* literal, Handle<Script> script, |
1061 CompilationInfo* outer_info) { | 1098 CompilationInfo* outer_info) { |
1062 // Precondition: code has been parsed and scopes have been analyzed. | 1099 // Precondition: code has been parsed and scopes have been analyzed. |
1063 CompilationInfoWithZone info(script); | 1100 CompilationInfoWithZone info(script); |
1064 info.SetFunction(literal); | 1101 info.SetFunction(literal); |
1065 info.PrepareForCompilation(literal->scope()); | 1102 info.PrepareForCompilation(literal->scope()); |
1066 info.SetStrictMode(literal->scope()->strict_mode()); | 1103 info.SetStrictMode(literal->scope()->strict_mode()); |
1067 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1104 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
1068 | 1105 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 log_tag, *code, *shared, info, script_name, line_num, column_num)); | 1385 log_tag, *code, *shared, info, script_name, line_num, column_num)); |
1349 } | 1386 } |
1350 | 1387 |
1351 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 1388 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
1352 Handle<Script>(info->script()), | 1389 Handle<Script>(info->script()), |
1353 Handle<Code>(info->code()), | 1390 Handle<Code>(info->code()), |
1354 info)); | 1391 info)); |
1355 } | 1392 } |
1356 | 1393 |
1357 | 1394 |
1395 bool Compiler::DebuggerWantsEagerCompilation(CompilationInfo* info, | |
1396 bool allow_lazy_without_ctx) { | |
1397 return LiveEditFunctionTracker::IsActive(info->isolate()) || | |
1398 (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx); | |
1399 } | |
1400 | |
1401 | |
1358 CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) | 1402 CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) |
1359 : name_(name), info_(info), zone_(info->isolate()) { | 1403 : name_(name), info_(info), zone_(info->isolate()) { |
1360 if (FLAG_hydrogen_stats) { | 1404 if (FLAG_hydrogen_stats) { |
1361 info_zone_start_allocation_size_ = info->zone()->allocation_size(); | 1405 info_zone_start_allocation_size_ = info->zone()->allocation_size(); |
1362 timer_.Start(); | 1406 timer_.Start(); |
1363 } | 1407 } |
1364 } | 1408 } |
1365 | 1409 |
1366 | 1410 |
1367 CompilationPhase::~CompilationPhase() { | 1411 CompilationPhase::~CompilationPhase() { |
(...skipping 11 matching lines...) Expand all Loading... | |
1379 AllowHandleDereference allow_deref; | 1423 AllowHandleDereference allow_deref; |
1380 bool tracing_on = info()->IsStub() | 1424 bool tracing_on = info()->IsStub() |
1381 ? FLAG_trace_hydrogen_stubs | 1425 ? FLAG_trace_hydrogen_stubs |
1382 : (FLAG_trace_hydrogen && | 1426 : (FLAG_trace_hydrogen && |
1383 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1427 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1384 return (tracing_on && | 1428 return (tracing_on && |
1385 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1429 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1386 } | 1430 } |
1387 | 1431 |
1388 } } // namespace v8::internal | 1432 } } // namespace v8::internal |
OLD | NEW |