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/compiler.h" | 5 #include "src/compiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/ast/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 // with deoptimization support. | 136 // with deoptimization support. |
137 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); | 137 if (isolate_->serializer_enabled()) EnableDeoptimizationSupport(); |
138 | 138 |
139 if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing(); | 139 if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing(); |
140 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); | 140 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); |
141 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled(); | 141 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled(); |
142 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); | 142 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); |
143 if (FLAG_turbo_types) MarkAsTypingEnabled(); | 143 if (FLAG_turbo_types) MarkAsTypingEnabled(); |
144 | 144 |
145 if (has_shared_info()) { | 145 if (has_shared_info()) { |
146 if (shared_info()->is_compiled()) { | |
147 // We should initialize the CompilationInfo feedback vector from the | |
148 // passed in shared info, rather than creating a new one. | |
149 feedback_vector_ = Handle<TypeFeedbackVector>( | |
150 shared_info()->feedback_vector(), parse_info->isolate()); | |
151 } | |
152 if (shared_info()->never_compiled()) MarkAsFirstCompile(); | 146 if (shared_info()->never_compiled()) MarkAsFirstCompile(); |
153 } | 147 } |
154 } | 148 } |
155 | 149 |
156 | 150 |
157 CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate, | 151 CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate, |
158 Zone* zone, Code::Flags code_flags) | 152 Zone* zone, Code::Flags code_flags) |
159 : CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {} | 153 : CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {} |
160 | 154 |
161 CompilationInfo::CompilationInfo(ParseInfo* parse_info, const char* debug_name, | 155 CompilationInfo::CompilationInfo(ParseInfo* parse_info, const char* debug_name, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. | 209 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. |
216 bool CompilationInfo::ShouldSelfOptimize() { | 210 bool CompilationInfo::ShouldSelfOptimize() { |
217 return FLAG_crankshaft && | 211 return FLAG_crankshaft && |
218 !(literal()->flags() & AstProperties::kDontSelfOptimize) && | 212 !(literal()->flags() & AstProperties::kDontSelfOptimize) && |
219 !literal()->dont_optimize() && | 213 !literal()->dont_optimize() && |
220 literal()->scope()->AllowsLazyCompilation() && | 214 literal()->scope()->AllowsLazyCompilation() && |
221 (!has_shared_info() || !shared_info()->optimization_disabled()); | 215 (!has_shared_info() || !shared_info()->optimization_disabled()); |
222 } | 216 } |
223 | 217 |
224 | 218 |
225 void CompilationInfo::EnsureFeedbackVector() { | |
226 if (feedback_vector_.is_null()) { | |
227 Handle<TypeFeedbackMetadata> feedback_metadata = | |
228 TypeFeedbackMetadata::New(isolate(), literal()->feedback_vector_spec()); | |
229 feedback_vector_ = TypeFeedbackVector::New(isolate(), feedback_metadata); | |
230 } | |
231 | |
232 // It's very important that recompiles do not alter the structure of the | |
233 // type feedback vector. | |
234 CHECK(!feedback_vector_->metadata()->SpecDiffersFrom( | |
235 literal()->feedback_vector_spec())); | |
236 } | |
237 | |
238 | |
239 bool CompilationInfo::has_simple_parameters() { | 219 bool CompilationInfo::has_simple_parameters() { |
240 return scope()->has_simple_parameters(); | 220 return scope()->has_simple_parameters(); |
241 } | 221 } |
242 | 222 |
243 | 223 |
244 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, | 224 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, |
245 SourcePosition position, | 225 SourcePosition position, |
246 int parent_id) { | 226 int parent_id) { |
247 DCHECK(track_positions_); | 227 DCHECK(track_positions_); |
248 | 228 |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 String* script_name = script->name()->IsString() | 757 String* script_name = script->name()->IsString() |
778 ? String::cast(script->name()) | 758 ? String::cast(script->name()) |
779 : info->isolate()->heap()->empty_string(); | 759 : info->isolate()->heap()->empty_string(); |
780 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); | 760 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); |
781 PROFILE(info->isolate(), | 761 PROFILE(info->isolate(), |
782 CodeCreateEvent(log_tag, *abstract_code, *shared, info, script_name, | 762 CodeCreateEvent(log_tag, *abstract_code, *shared, info, script_name, |
783 line_num, column_num)); | 763 line_num, column_num)); |
784 } | 764 } |
785 } | 765 } |
786 | 766 |
767 void EnsureFeedbackVector(CompilationInfo* info) { | |
768 if (!info->has_shared_info()) return; | |
769 | |
770 // If no type feedback vector exists, we create one now. At this point the | |
771 // AstNumbering pass has already run. Note that we should reuse any existing | |
772 // feedback vector rather than creating a new one. | |
773 if (info->shared_info()->feedback_vector()->is_empty()) { | |
774 Handle<TypeFeedbackMetadata> feedback_metadata = TypeFeedbackMetadata::New( | |
775 info->isolate(), info->literal()->feedback_vector_spec()); | |
776 Handle<TypeFeedbackVector> feedback_vector = | |
777 TypeFeedbackVector::New(info->isolate(), feedback_metadata); | |
778 info->shared_info()->set_feedback_vector(*feedback_vector); | |
779 } | |
780 | |
781 // It's very important that recompiles do not alter the structure of the type | |
782 // feedback vector. Verify that the structure fits the function literal. | |
783 CHECK(!info->shared_info()->feedback_vector()->metadata()->SpecDiffersFrom( | |
784 info->literal()->feedback_vector_spec())); | |
785 } | |
786 | |
787 bool CompileUnoptimizedCode(CompilationInfo* info) { | 787 bool CompileUnoptimizedCode(CompilationInfo* info) { |
788 DCHECK(AllowCompilation::IsAllowed(info->isolate())); | 788 DCHECK(AllowCompilation::IsAllowed(info->isolate())); |
789 if (!Compiler::Analyze(info->parse_info()) || | 789 if (!Compiler::Analyze(info->parse_info()) || |
790 !(info->EnsureFeedbackVector(), FullCodeGenerator::MakeCode(info))) { | 790 !(EnsureFeedbackVector(info), FullCodeGenerator::MakeCode(info))) { |
791 Isolate* isolate = info->isolate(); | 791 Isolate* isolate = info->isolate(); |
792 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 792 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
793 return false; | 793 return false; |
794 } | 794 } |
795 return true; | 795 return true; |
796 } | 796 } |
797 | 797 |
798 bool UseIgnition(CompilationInfo* info) { | 798 bool UseIgnition(CompilationInfo* info) { |
799 // TODO(4681): Generator functions are not yet supported. | 799 // TODO(4681): Generator functions are not yet supported. |
800 if (info->shared_info()->is_generator()) { | 800 if (info->shared_info()->is_generator()) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
832 size += code->CodeSize(); | 832 size += code->CodeSize(); |
833 size += code->relocation_info()->Size(); | 833 size += code->relocation_info()->Size(); |
834 size += code->deoptimization_data()->Size(); | 834 size += code->deoptimization_data()->Size(); |
835 size += code->handler_table()->Size(); | 835 size += code->handler_table()->Size(); |
836 } | 836 } |
837 return size; | 837 return size; |
838 } | 838 } |
839 | 839 |
840 bool GenerateBaselineCode(CompilationInfo* info) { | 840 bool GenerateBaselineCode(CompilationInfo* info) { |
841 bool success; | 841 bool success; |
842 info->EnsureFeedbackVector(); | 842 EnsureFeedbackVector(info); |
843 if (FLAG_ignition && UseIgnition(info)) { | 843 if (FLAG_ignition && UseIgnition(info)) { |
844 success = interpreter::Interpreter::MakeBytecode(info); | 844 success = interpreter::Interpreter::MakeBytecode(info); |
845 } else { | 845 } else { |
846 success = FullCodeGenerator::MakeCode(info); | 846 success = FullCodeGenerator::MakeCode(info); |
847 } | 847 } |
848 if (success) { | 848 if (success) { |
849 Isolate* isolate = info->isolate(); | 849 Isolate* isolate = info->isolate(); |
850 Counters* counters = isolate->counters(); | 850 Counters* counters = isolate->counters(); |
851 counters->total_baseline_code_size()->Increment(CodeAndMetadataSize(info)); | 851 counters->total_baseline_code_size()->Increment(CodeAndMetadataSize(info)); |
852 counters->total_baseline_compile_count()->Increment(1); | 852 counters->total_baseline_compile_count()->Increment(1); |
(...skipping 12 matching lines...) Expand all Loading... | |
865 } | 865 } |
866 | 866 |
867 void InstallBaselineCompilationResult(CompilationInfo* info, | 867 void InstallBaselineCompilationResult(CompilationInfo* info, |
868 Handle<SharedFunctionInfo> shared, | 868 Handle<SharedFunctionInfo> shared, |
869 Handle<ScopeInfo> scope_info) { | 869 Handle<ScopeInfo> scope_info) { |
870 // Assert that we are not overwriting (possibly patched) debug code. | 870 // Assert that we are not overwriting (possibly patched) debug code. |
871 DCHECK(!shared->HasDebugCode()); | 871 DCHECK(!shared->HasDebugCode()); |
872 DCHECK(!info->code().is_null()); | 872 DCHECK(!info->code().is_null()); |
873 shared->ReplaceCode(*info->code()); | 873 shared->ReplaceCode(*info->code()); |
874 shared->set_scope_info(*scope_info); | 874 shared->set_scope_info(*scope_info); |
875 shared->set_feedback_vector(*info->feedback_vector()); | |
876 if (info->has_bytecode_array()) { | 875 if (info->has_bytecode_array()) { |
877 DCHECK(!shared->HasBytecodeArray()); // Only compiled once. | 876 DCHECK(!shared->HasBytecodeArray()); // Only compiled once. |
878 shared->set_bytecode_array(*info->bytecode_array()); | 877 shared->set_bytecode_array(*info->bytecode_array()); |
879 } | 878 } |
880 } | 879 } |
881 | 880 |
882 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCodeCommon( | 881 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCodeCommon( |
883 CompilationInfo* info) { | 882 CompilationInfo* info) { |
884 VMState<COMPILER> state(info->isolate()); | 883 VMState<COMPILER> state(info->isolate()); |
885 PostponeInterruptsScope postpone(info->isolate()); | 884 PostponeInterruptsScope postpone(info->isolate()); |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1453 parse_info->set_scope(info->scope()); | 1452 parse_info->set_scope(info->scope()); |
1454 parse_info->set_context(info->context()); | 1453 parse_info->set_context(info->context()); |
1455 unoptimized.EnableDeoptimizationSupport(); | 1454 unoptimized.EnableDeoptimizationSupport(); |
1456 // If the current code has reloc info for serialization, also include | 1455 // If the current code has reloc info for serialization, also include |
1457 // reloc info for serialization for the new code, so that deopt support | 1456 // reloc info for serialization for the new code, so that deopt support |
1458 // can be added without losing IC state. | 1457 // can be added without losing IC state. |
1459 if (shared->code()->kind() == Code::FUNCTION && | 1458 if (shared->code()->kind() == Code::FUNCTION && |
1460 shared->code()->has_reloc_info_for_serialization()) { | 1459 shared->code()->has_reloc_info_for_serialization()) { |
1461 unoptimized.PrepareForSerializing(); | 1460 unoptimized.PrepareForSerializing(); |
1462 } | 1461 } |
1463 unoptimized.EnsureFeedbackVector(); | 1462 EnsureFeedbackVector(&unoptimized); |
1464 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; | 1463 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; |
1465 | 1464 |
1466 shared->EnableDeoptimizationSupport(*unoptimized.code()); | 1465 shared->EnableDeoptimizationSupport(*unoptimized.code()); |
1467 shared->set_feedback_vector(*unoptimized.feedback_vector()); | |
1468 | 1466 |
1469 info->MarkAsCompiled(); | 1467 info->MarkAsCompiled(); |
1470 | 1468 |
1471 // The scope info might not have been set if a lazily compiled | 1469 // The scope info might not have been set if a lazily compiled |
1472 // function is inlined before being called for the first time. | 1470 // function is inlined before being called for the first time. |
1473 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { | 1471 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { |
1474 Handle<ScopeInfo> target_scope_info = | 1472 Handle<ScopeInfo> target_scope_info = |
1475 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); | 1473 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); |
1476 shared->set_scope_info(*target_scope_info); | 1474 shared->set_scope_info(*target_scope_info); |
1477 } | 1475 } |
(...skipping 13 matching lines...) Expand all Loading... | |
1491 VMState<COMPILER> state(info.isolate()); | 1489 VMState<COMPILER> state(info.isolate()); |
1492 | 1490 |
1493 // Get rid of old list of shared function infos. | 1491 // Get rid of old list of shared function infos. |
1494 info.MarkAsFirstCompile(); | 1492 info.MarkAsFirstCompile(); |
1495 info.MarkAsDebug(); | 1493 info.MarkAsDebug(); |
1496 info.parse_info()->set_global(); | 1494 info.parse_info()->set_global(); |
1497 if (!Parser::ParseStatic(info.parse_info())) return; | 1495 if (!Parser::ParseStatic(info.parse_info())) return; |
1498 | 1496 |
1499 LiveEditFunctionTracker tracker(info.isolate(), parse_info.literal()); | 1497 LiveEditFunctionTracker tracker(info.isolate(), parse_info.literal()); |
1500 if (!CompileUnoptimizedCode(&info)) return; | 1498 if (!CompileUnoptimizedCode(&info)) return; |
1501 if (info.has_shared_info()) { | |
Michael Starzinger
2016/04/05 12:55:43
This is genuinely dead code. Drive-by fix unrelate
| |
1502 Handle<ScopeInfo> scope_info = | |
1503 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | |
1504 info.shared_info()->set_scope_info(*scope_info); | |
1505 } | |
1506 tracker.RecordRootFunctionInfo(info.code()); | 1499 tracker.RecordRootFunctionInfo(info.code()); |
1507 } | 1500 } |
1508 | 1501 |
1509 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( | 1502 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
1510 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 1503 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
1511 Handle<Context> context, LanguageMode language_mode, | 1504 Handle<Context> context, LanguageMode language_mode, |
1512 ParseRestriction restriction, int line_offset, int column_offset, | 1505 ParseRestriction restriction, int line_offset, int column_offset, |
1513 Handle<Object> script_name, ScriptOriginOptions options) { | 1506 Handle<Object> script_name, ScriptOriginOptions options) { |
1514 Isolate* isolate = source->GetIsolate(); | 1507 Isolate* isolate = source->GetIsolate(); |
1515 int source_length = source->length(); | 1508 int source_length = source->length(); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1958 MaybeHandle<Code> code; | 1951 MaybeHandle<Code> code; |
1959 if (cached.code != nullptr) code = handle(cached.code); | 1952 if (cached.code != nullptr) code = handle(cached.code); |
1960 Handle<Context> native_context(function->context()->native_context()); | 1953 Handle<Context> native_context(function->context()->native_context()); |
1961 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1954 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1962 literals, BailoutId::None()); | 1955 literals, BailoutId::None()); |
1963 } | 1956 } |
1964 } | 1957 } |
1965 | 1958 |
1966 } // namespace internal | 1959 } // namespace internal |
1967 } // namespace v8 | 1960 } // namespace v8 |
OLD | NEW |