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

Side by Side Diff: src/compiler.cc

Issue 1632993003: Revert of Type Feedback Vector lives in the closure (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « src/compiler.h ('k') | src/compiler/access-builder.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/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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing(); 123 if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing();
124 if (FLAG_turbo_inlining) MarkAsInliningEnabled(); 124 if (FLAG_turbo_inlining) MarkAsInliningEnabled();
125 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled(); 125 if (FLAG_turbo_source_positions) MarkAsSourcePositionsEnabled();
126 if (FLAG_turbo_splitting) MarkAsSplittingEnabled(); 126 if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
127 if (FLAG_turbo_types) MarkAsTypingEnabled(); 127 if (FLAG_turbo_types) MarkAsTypingEnabled();
128 128
129 if (has_shared_info()) { 129 if (has_shared_info()) {
130 if (shared_info()->is_compiled()) { 130 if (shared_info()->is_compiled()) {
131 // We should initialize the CompilationInfo feedback vector from the 131 // We should initialize the CompilationInfo feedback vector from the
132 // passed in shared info, rather than creating a new one. 132 // passed in shared info, rather than creating a new one.
133 feedback_metadata_ = Handle<TypeFeedbackMetadata>( 133 feedback_vector_ = Handle<TypeFeedbackVector>(
134 shared_info()->feedback_metadata(), parse_info->isolate()); 134 shared_info()->feedback_vector(), parse_info->isolate());
135 } 135 }
136 if (shared_info()->never_compiled()) MarkAsFirstCompile(); 136 if (shared_info()->never_compiled()) MarkAsFirstCompile();
137 } 137 }
138 } 138 }
139 139
140 140
141 CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate, 141 CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate,
142 Zone* zone, Code::Flags code_flags) 142 Zone* zone, Code::Flags code_flags)
143 : CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {} 143 : CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {}
144 144
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // profiler, so they trigger their own optimization when they're called 198 // profiler, so they trigger their own optimization when they're called
199 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. 199 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time.
200 bool CompilationInfo::ShouldSelfOptimize() { 200 bool CompilationInfo::ShouldSelfOptimize() {
201 return FLAG_crankshaft && 201 return FLAG_crankshaft &&
202 !(literal()->flags() & AstProperties::kDontSelfOptimize) && 202 !(literal()->flags() & AstProperties::kDontSelfOptimize) &&
203 !literal()->dont_optimize() && 203 !literal()->dont_optimize() &&
204 literal()->scope()->AllowsLazyCompilation() && 204 literal()->scope()->AllowsLazyCompilation() &&
205 (!has_shared_info() || !shared_info()->optimization_disabled()); 205 (!has_shared_info() || !shared_info()->optimization_disabled());
206 } 206 }
207 207
208 void CompilationInfo::EnsureFeedbackMetadata() { 208
209 if (feedback_metadata_.is_null()) { 209 void CompilationInfo::EnsureFeedbackVector() {
210 feedback_metadata_ = 210 if (feedback_vector_.is_null()) {
211 Handle<TypeFeedbackMetadata> feedback_metadata =
211 TypeFeedbackMetadata::New(isolate(), literal()->feedback_vector_spec()); 212 TypeFeedbackMetadata::New(isolate(), literal()->feedback_vector_spec());
213 feedback_vector_ = TypeFeedbackVector::New(isolate(), feedback_metadata);
212 } 214 }
213 215
214 // It's very important that recompiles do not alter the structure of the 216 // It's very important that recompiles do not alter the structure of the
215 // type feedback vector. 217 // type feedback vector.
216 CHECK( 218 CHECK(!feedback_vector_->metadata()->SpecDiffersFrom(
217 !feedback_metadata_->SpecDiffersFrom(literal()->feedback_vector_spec())); 219 literal()->feedback_vector_spec()));
218 } 220 }
219 221
220 222
221 bool CompilationInfo::has_simple_parameters() { 223 bool CompilationInfo::has_simple_parameters() {
222 return scope()->has_simple_parameters(); 224 return scope()->has_simple_parameters();
223 } 225 }
224 226
225 227
226 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, 228 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
227 SourcePosition position, 229 SourcePosition position,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return SetLastStatus(FAILED); 376 return SetLastStatus(FAILED);
375 } 377 }
376 if (FLAG_hydrogen_stats) { 378 if (FLAG_hydrogen_stats) {
377 isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed()); 379 isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed());
378 } 380 }
379 } 381 }
380 382
381 DCHECK(info()->shared_info()->has_deoptimization_support()); 383 DCHECK(info()->shared_info()->has_deoptimization_support());
382 DCHECK(!info()->is_first_compile()); 384 DCHECK(!info()->is_first_compile());
383 385
384 // If we have a closure make sure it has the literals array at this point.
385 if (!info()->closure().is_null()) {
386 JSFunction::EnsureLiterals(info()->closure());
387 }
388
389 bool optimization_disabled = info()->shared_info()->optimization_disabled(); 386 bool optimization_disabled = info()->shared_info()->optimization_disabled();
390 bool dont_crankshaft = info()->shared_info()->dont_crankshaft(); 387 bool dont_crankshaft = info()->shared_info()->dont_crankshaft();
391 388
392 // Check the enabling conditions for Turbofan. 389 // Check the enabling conditions for Turbofan.
393 // 1. "use asm" code. 390 // 1. "use asm" code.
394 bool is_turbofanable_asm = FLAG_turbo_asm && 391 bool is_turbofanable_asm = FLAG_turbo_asm &&
395 info()->shared_info()->asm_function() && 392 info()->shared_info()->asm_function() &&
396 !optimization_disabled; 393 !optimization_disabled;
397 394
398 // 2. Fallback for features unsupported by Crankshaft. 395 // 2. Fallback for features unsupported by Crankshaft.
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( 780 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon(
784 CompilationInfo* info) { 781 CompilationInfo* info) {
785 VMState<COMPILER> state(info->isolate()); 782 VMState<COMPILER> state(info->isolate());
786 PostponeInterruptsScope postpone(info->isolate()); 783 PostponeInterruptsScope postpone(info->isolate());
787 784
788 // Parse and update CompilationInfo with the results. 785 // Parse and update CompilationInfo with the results.
789 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); 786 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>();
790 Handle<SharedFunctionInfo> shared = info->shared_info(); 787 Handle<SharedFunctionInfo> shared = info->shared_info();
791 FunctionLiteral* lit = info->literal(); 788 FunctionLiteral* lit = info->literal();
792 DCHECK_EQ(shared->language_mode(), lit->language_mode()); 789 DCHECK_EQ(shared->language_mode(), lit->language_mode());
793 shared->set_num_literals(lit->materialized_literal_count());
794 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); 790 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count());
795 MaybeDisableOptimization(shared, lit->dont_optimize_reason()); 791 MaybeDisableOptimization(shared, lit->dont_optimize_reason());
796 792
797 // Compile either unoptimized code or bytecode for the interpreter. 793 // Compile either unoptimized code or bytecode for the interpreter.
798 if (!CompileBaselineCode(info)) return MaybeHandle<Code>(); 794 if (!CompileBaselineCode(info)) return MaybeHandle<Code>();
799 if (info->code()->kind() == Code::FUNCTION) { // Only for full code. 795 if (info->code()->kind() == Code::FUNCTION) { // Only for full code.
800 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); 796 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
801 } 797 }
802 798
803 // Update the shared function info with the scope info. Allocating the 799 // Update the shared function info with the scope info. Allocating the
804 // ScopeInfo object may cause a GC. 800 // ScopeInfo object may cause a GC.
805 Handle<ScopeInfo> scope_info = 801 Handle<ScopeInfo> scope_info =
806 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); 802 ScopeInfo::Create(info->isolate(), info->zone(), info->scope());
807 shared->set_scope_info(*scope_info); 803 shared->set_scope_info(*scope_info);
808 804
809 // Update the code and feedback vector for the shared function info. 805 // Update the code and feedback vector for the shared function info.
810 shared->ReplaceCode(*info->code()); 806 shared->ReplaceCode(*info->code());
811 shared->set_feedback_metadata(*info->feedback_metadata()); 807 shared->set_feedback_vector(*info->feedback_vector());
812 if (info->has_bytecode_array()) { 808 if (info->has_bytecode_array()) {
813 DCHECK(shared->function_data()->IsUndefined()); 809 DCHECK(shared->function_data()->IsUndefined());
814 shared->set_function_data(*info->bytecode_array()); 810 shared->set_function_data(*info->bytecode_array());
815 } 811 }
816 812
817 return info->code(); 813 return info->code();
818 } 814 }
819 815
820 816
821 MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap( 817 MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 return Handle<Code>(function->shared()->code()); 1011 return Handle<Code>(function->shared()->code());
1016 } 1012 }
1017 1013
1018 CompilationInfoWithZone info(function); 1014 CompilationInfoWithZone info(function);
1019 Handle<Code> result; 1015 Handle<Code> result;
1020 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCodeCommon(&info), 1016 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCodeCommon(&info),
1021 Code); 1017 Code);
1022 1018
1023 if (FLAG_always_opt) { 1019 if (FLAG_always_opt) {
1024 Handle<Code> opt_code; 1020 Handle<Code> opt_code;
1025 JSFunction::EnsureLiterals(function);
1026 if (Compiler::GetOptimizedCode(function, Compiler::NOT_CONCURRENT) 1021 if (Compiler::GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
1027 .ToHandle(&opt_code)) { 1022 .ToHandle(&opt_code)) {
1028 result = opt_code; 1023 result = opt_code;
1029 } 1024 }
1030 } 1025 }
1031 1026
1032 return result; 1027 return result;
1033 } 1028 }
1034 1029
1035 1030
1036 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { 1031 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) {
1037 if (function->is_compiled()) return true; 1032 if (function->is_compiled()) return true;
1038 MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function); 1033 MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function);
1039 Handle<Code> code; 1034 Handle<Code> code;
1040 Isolate* isolate = function->GetIsolate();
1041 if (!maybe_code.ToHandle(&code)) { 1035 if (!maybe_code.ToHandle(&code)) {
1042 if (flag == CLEAR_EXCEPTION) { 1036 if (flag == CLEAR_EXCEPTION) {
1043 isolate->clear_pending_exception(); 1037 function->GetIsolate()->clear_pending_exception();
1044 } 1038 }
1045 return false; 1039 return false;
1046 } 1040 }
1047 function->ReplaceCode(*code); 1041 function->ReplaceCode(*code);
1048 DCHECK(function->is_compiled()); 1042 DCHECK(function->is_compiled());
1049 JSFunction::EnsureLiterals(function);
1050 return true; 1043 return true;
1051 } 1044 }
1052 1045
1053 1046
1054 // TODO(turbofan): In the future, unoptimized code with deopt support could 1047 // TODO(turbofan): In the future, unoptimized code with deopt support could
1055 // be generated lazily once deopt is triggered. 1048 // be generated lazily once deopt is triggered.
1056 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { 1049 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
1057 DCHECK_NOT_NULL(info->literal()); 1050 DCHECK_NOT_NULL(info->literal());
1058 DCHECK(info->has_scope()); 1051 DCHECK(info->has_scope());
1059 Handle<SharedFunctionInfo> shared = info->shared_info(); 1052 Handle<SharedFunctionInfo> shared = info->shared_info();
(...skipping 10 matching lines...) Expand all
1070 // If the current code has reloc info for serialization, also include 1063 // If the current code has reloc info for serialization, also include
1071 // reloc info for serialization for the new code, so that deopt support 1064 // reloc info for serialization for the new code, so that deopt support
1072 // can be added without losing IC state. 1065 // can be added without losing IC state.
1073 if (shared->code()->kind() == Code::FUNCTION && 1066 if (shared->code()->kind() == Code::FUNCTION &&
1074 shared->code()->has_reloc_info_for_serialization()) { 1067 shared->code()->has_reloc_info_for_serialization()) {
1075 unoptimized.PrepareForSerializing(); 1068 unoptimized.PrepareForSerializing();
1076 } 1069 }
1077 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; 1070 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
1078 1071
1079 shared->EnableDeoptimizationSupport(*unoptimized.code()); 1072 shared->EnableDeoptimizationSupport(*unoptimized.code());
1080 shared->set_feedback_metadata(*unoptimized.feedback_metadata()); 1073 shared->set_feedback_vector(*unoptimized.feedback_vector());
1081 1074
1082 info->MarkAsCompiled(); 1075 info->MarkAsCompiled();
1083 1076
1084 // The scope info might not have been set if a lazily compiled 1077 // The scope info might not have been set if a lazily compiled
1085 // function is inlined before being called for the first time. 1078 // function is inlined before being called for the first time.
1086 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { 1079 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) {
1087 Handle<ScopeInfo> target_scope_info = 1080 Handle<ScopeInfo> target_scope_info =
1088 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); 1081 ScopeInfo::Create(info->isolate(), info->zone(), info->scope());
1089 shared->set_scope_info(*target_scope_info); 1082 shared->set_scope_info(*target_scope_info);
1090 } 1083 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 1139
1147 static inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) { 1140 static inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) {
1148 return shared->is_toplevel() && shared->script()->IsScript() && 1141 return shared->is_toplevel() && shared->script()->IsScript() &&
1149 Script::cast(shared->script())->compilation_type() == 1142 Script::cast(shared->script())->compilation_type() ==
1150 Script::COMPILATION_TYPE_EVAL; 1143 Script::COMPILATION_TYPE_EVAL;
1151 } 1144 }
1152 1145
1153 1146
1154 bool Compiler::CompileDebugCode(Handle<JSFunction> function) { 1147 bool Compiler::CompileDebugCode(Handle<JSFunction> function) {
1155 Handle<SharedFunctionInfo> shared(function->shared()); 1148 Handle<SharedFunctionInfo> shared(function->shared());
1156 bool result;
1157 if (IsEvalToplevel(shared)) { 1149 if (IsEvalToplevel(shared)) {
1158 result = CompileEvalForDebugging(function, shared); 1150 return CompileEvalForDebugging(function, shared);
1159 } else { 1151 } else {
1160 CompilationInfoWithZone info(function); 1152 CompilationInfoWithZone info(function);
1161 result = CompileForDebugging(&info); 1153 return CompileForDebugging(&info);
1162 } 1154 }
1163 JSFunction::EnsureLiterals(function);
1164 return result;
1165 } 1155 }
1166 1156
1167 1157
1168 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { 1158 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) {
1169 DCHECK(shared->allows_lazy_compilation_without_context()); 1159 DCHECK(shared->allows_lazy_compilation_without_context());
1170 DCHECK(!IsEvalToplevel(shared)); 1160 DCHECK(!IsEvalToplevel(shared));
1171 Zone zone; 1161 Zone zone;
1172 ParseInfo parse_info(&zone, shared); 1162 ParseInfo parse_info(&zone, shared);
1173 CompilationInfo info(&parse_info); 1163 CompilationInfo info(&parse_info);
1174 return CompileForDebugging(&info); 1164 return CompileForDebugging(&info);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 if (!CompileBaselineCode(info)) { 1256 if (!CompileBaselineCode(info)) {
1267 return Handle<SharedFunctionInfo>::null(); 1257 return Handle<SharedFunctionInfo>::null();
1268 } 1258 }
1269 1259
1270 // Allocate function. 1260 // Allocate function.
1271 DCHECK(!info->code().is_null()); 1261 DCHECK(!info->code().is_null());
1272 result = isolate->factory()->NewSharedFunctionInfo( 1262 result = isolate->factory()->NewSharedFunctionInfo(
1273 lit->name(), lit->materialized_literal_count(), lit->kind(), 1263 lit->name(), lit->materialized_literal_count(), lit->kind(),
1274 info->code(), 1264 info->code(),
1275 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), 1265 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()),
1276 info->feedback_metadata()); 1266 info->feedback_vector());
1277 if (info->has_bytecode_array()) { 1267 if (info->has_bytecode_array()) {
1278 DCHECK(result->function_data()->IsUndefined()); 1268 DCHECK(result->function_data()->IsUndefined());
1279 result->set_function_data(*info->bytecode_array()); 1269 result->set_function_data(*info->bytecode_array());
1280 } 1270 }
1281 1271
1282 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); 1272 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position());
1283 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); 1273 SharedFunctionInfo::InitFromFunctionLiteral(result, lit);
1284 SharedFunctionInfo::SetScript(result, script); 1274 SharedFunctionInfo::SetScript(result, script);
1285 result->set_is_toplevel(true); 1275 result->set_is_toplevel(true);
1286 if (info->is_eval()) { 1276 if (info->is_eval()) {
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 !LiveEditFunctionTracker::IsActive(isolate) && 1583 !LiveEditFunctionTracker::IsActive(isolate) &&
1594 (!info.is_debug() || allow_lazy_without_ctx); 1584 (!info.is_debug() || allow_lazy_without_ctx);
1595 1585
1596 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile(); 1586 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile();
1597 1587
1598 // Generate code 1588 // Generate code
1599 Handle<ScopeInfo> scope_info; 1589 Handle<ScopeInfo> scope_info;
1600 if (lazy) { 1590 if (lazy) {
1601 Handle<Code> code = isolate->builtins()->CompileLazy(); 1591 Handle<Code> code = isolate->builtins()->CompileLazy();
1602 info.SetCode(code); 1592 info.SetCode(code);
1603 // There's no need in theory for a lazy-compiled function to have type 1593 // There's no need in theory for a lazy-compiled function to have a type
1604 // feedback metadata, but some parts of the system expect all 1594 // feedback vector, but some parts of the system expect all
1605 // SharedFunctionInfo instances to have one. 1595 // SharedFunctionInfo instances to have one. The size of the vector depends
1606 info.EnsureFeedbackMetadata(); 1596 // on how many feedback-needing nodes are in the tree, and when lazily
1597 // parsing we might not know that, if this function was never parsed before.
1598 // In that case the vector will be replaced the next time MakeCode is
1599 // called.
1600 info.EnsureFeedbackVector();
1607 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); 1601 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate));
1608 } else if (Renumber(info.parse_info()) && GenerateBaselineCode(&info)) { 1602 } else if (Renumber(info.parse_info()) && GenerateBaselineCode(&info)) {
1609 // Code generation will ensure that the feedback vector is present and 1603 // Code generation will ensure that the feedback vector is present and
1610 // appropriately sized. 1604 // appropriately sized.
1611 DCHECK(!info.code().is_null()); 1605 DCHECK(!info.code().is_null());
1612 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); 1606 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope());
1613 if (literal->should_eager_compile() && 1607 if (literal->should_eager_compile() &&
1614 literal->should_be_used_once_hint()) { 1608 literal->should_be_used_once_hint()) {
1615 info.code()->MarkToBeExecutedOnce(isolate); 1609 info.code()->MarkToBeExecutedOnce(isolate);
1616 } 1610 }
1617 } else { 1611 } else {
1618 return Handle<SharedFunctionInfo>::null(); 1612 return Handle<SharedFunctionInfo>::null();
1619 } 1613 }
1620 1614
1621 if (maybe_existing.is_null()) { 1615 if (maybe_existing.is_null()) {
1622 // Create a shared function info object. 1616 // Create a shared function info object.
1623 Handle<SharedFunctionInfo> result = 1617 Handle<SharedFunctionInfo> result =
1624 isolate->factory()->NewSharedFunctionInfo( 1618 isolate->factory()->NewSharedFunctionInfo(
1625 literal->name(), literal->materialized_literal_count(), 1619 literal->name(), literal->materialized_literal_count(),
1626 literal->kind(), info.code(), scope_info, info.feedback_metadata()); 1620 literal->kind(), info.code(), scope_info, info.feedback_vector());
1627 if (info.has_bytecode_array()) { 1621 if (info.has_bytecode_array()) {
1628 DCHECK(result->function_data()->IsUndefined()); 1622 DCHECK(result->function_data()->IsUndefined());
1629 result->set_function_data(*info.bytecode_array()); 1623 result->set_function_data(*info.bytecode_array());
1630 } 1624 }
1631 1625
1632 SharedFunctionInfo::InitFromFunctionLiteral(result, literal); 1626 SharedFunctionInfo::InitFromFunctionLiteral(result, literal);
1633 SharedFunctionInfo::SetScript(result, script); 1627 SharedFunctionInfo::SetScript(result, script);
1634 result->set_is_toplevel(false); 1628 result->set_is_toplevel(false);
1635 // If the outer function has been compiled before, we cannot be sure that 1629 // If the outer function has been compiled before, we cannot be sure that
1636 // shared function info for this function literal has been created for the 1630 // shared function info for this function literal has been created for the
1637 // first time. It may have already been compiled previously. 1631 // first time. It may have already been compiled previously.
1638 result->set_never_compiled(outer_info->is_first_compile() && lazy); 1632 result->set_never_compiled(outer_info->is_first_compile() && lazy);
1639 1633
1640 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); 1634 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
1641 result->set_allows_lazy_compilation(literal->AllowsLazyCompilation()); 1635 result->set_allows_lazy_compilation(literal->AllowsLazyCompilation());
1642 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); 1636 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
1643 1637
1644 // Set the expected number of properties for instances and return 1638 // Set the expected number of properties for instances and return
1645 // the resulting function. 1639 // the resulting function.
1646 SetExpectedNofPropertiesFromEstimate(result, 1640 SetExpectedNofPropertiesFromEstimate(result,
1647 literal->expected_property_count()); 1641 literal->expected_property_count());
1648 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); 1642 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
1649 return result; 1643 return result;
1650 } else if (!lazy) { 1644 } else if (!lazy) {
1651 // Assert that we are not overwriting (possibly patched) debug code. 1645 // Assert that we are not overwriting (possibly patched) debug code.
1652 DCHECK(!existing->HasDebugCode()); 1646 DCHECK(!existing->HasDebugCode());
1653 existing->ReplaceCode(*info.code()); 1647 existing->ReplaceCode(*info.code());
1654 existing->set_scope_info(*scope_info); 1648 existing->set_scope_info(*scope_info);
1655 existing->set_feedback_metadata(*info.feedback_metadata()); 1649 existing->set_feedback_vector(*info.feedback_vector());
1656 } 1650 }
1657 return existing; 1651 return existing;
1658 } 1652 }
1659 1653
1660 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( 1654 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative(
1661 v8::Extension* extension, Handle<String> name) { 1655 v8::Extension* extension, Handle<String> name) {
1662 Isolate* isolate = name->GetIsolate(); 1656 Isolate* isolate = name->GetIsolate();
1663 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 1657 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
1664 1658
1665 // Compute the function template for the native function. 1659 // Compute the function template for the native function.
1666 v8::Local<v8::FunctionTemplate> fun_template = 1660 v8::Local<v8::FunctionTemplate> fun_template =
1667 extension->GetNativeFunctionTemplate(v8_isolate, 1661 extension->GetNativeFunctionTemplate(v8_isolate,
1668 v8::Utils::ToLocal(name)); 1662 v8::Utils::ToLocal(name));
1669 DCHECK(!fun_template.IsEmpty()); 1663 DCHECK(!fun_template.IsEmpty());
1670 1664
1671 // Instantiate the function and create a shared function info from it. 1665 // Instantiate the function and create a shared function info from it.
1672 Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle( 1666 Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle(
1673 *fun_template->GetFunction(v8_isolate->GetCurrentContext()) 1667 *fun_template->GetFunction(v8_isolate->GetCurrentContext())
1674 .ToLocalChecked())); 1668 .ToLocalChecked()));
1675 const int literals = fun->NumberOfLiterals(); 1669 const int literals = fun->NumberOfLiterals();
1676 Handle<Code> code = Handle<Code>(fun->shared()->code()); 1670 Handle<Code> code = Handle<Code>(fun->shared()->code());
1677 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub()); 1671 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
1678 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo( 1672 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
1679 name, literals, FunctionKind::kNormalFunction, code, 1673 name, literals, FunctionKind::kNormalFunction, code,
1680 Handle<ScopeInfo>(fun->shared()->scope_info()), 1674 Handle<ScopeInfo>(fun->shared()->scope_info()),
1681 Handle<TypeFeedbackMetadata>(fun->shared()->feedback_metadata())); 1675 Handle<TypeFeedbackVector>(fun->shared()->feedback_vector()));
1682 shared->set_construct_stub(*construct_stub); 1676 shared->set_construct_stub(*construct_stub);
1683 1677
1684 // Copy the function data to the shared function info. 1678 // Copy the function data to the shared function info.
1685 shared->set_function_data(fun->shared()->function_data()); 1679 shared->set_function_data(fun->shared()->function_data());
1686 int parameters = fun->shared()->internal_formal_parameter_count(); 1680 int parameters = fun->shared()->internal_formal_parameter_count();
1687 shared->set_internal_formal_parameter_count(parameters); 1681 shared->set_internal_formal_parameter_count(parameters);
1688 1682
1689 return shared; 1683 return shared;
1690 } 1684 }
1691 1685
(...skipping 27 matching lines...) Expand all
1719 // The function was never compiled. Compile it unoptimized first. 1713 // The function was never compiled. Compile it unoptimized first.
1720 // TODO(titzer): reuse the AST and scope info from this compile. 1714 // TODO(titzer): reuse the AST and scope info from this compile.
1721 CompilationInfoWithZone unoptimized(function); 1715 CompilationInfoWithZone unoptimized(function);
1722 unoptimized.EnableDeoptimizationSupport(); 1716 unoptimized.EnableDeoptimizationSupport();
1723 if (!GetUnoptimizedCodeCommon(&unoptimized).ToHandle(&current_code)) { 1717 if (!GetUnoptimizedCodeCommon(&unoptimized).ToHandle(&current_code)) {
1724 return MaybeHandle<Code>(); 1718 return MaybeHandle<Code>();
1725 } 1719 }
1726 shared->ReplaceCode(*current_code); 1720 shared->ReplaceCode(*current_code);
1727 } 1721 }
1728 1722
1729 // At this point we know we've compiled the function, so make sure the closure
1730 // points to valid literals and type-feedback-vector.
1731 JSFunction::EnsureLiterals(function);
1732
1733 current_code->set_profiler_ticks(0); 1723 current_code->set_profiler_ticks(0);
1734 1724
1735 // TODO(mstarzinger): We cannot properly deserialize a scope chain containing 1725 // TODO(mstarzinger): We cannot properly deserialize a scope chain containing
1736 // an eval scope and hence would fail at parsing the eval source again. 1726 // an eval scope and hence would fail at parsing the eval source again.
1737 if (shared->disable_optimization_reason() == kEval) { 1727 if (shared->disable_optimization_reason() == kEval) {
1738 return MaybeHandle<Code>(); 1728 return MaybeHandle<Code>();
1739 } 1729 }
1740 1730
1741 // TODO(mstarzinger): We cannot properly deserialize a scope chain for the 1731 // TODO(mstarzinger): We cannot properly deserialize a scope chain for the
1742 // builtin context, hence Genesis::InstallExperimentalNatives would fail. 1732 // builtin context, hence Genesis::InstallExperimentalNatives would fail.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1847 } 1837 }
1848 1838
1849 #if DEBUG 1839 #if DEBUG
1850 void CompilationInfo::PrintAstForTesting() { 1840 void CompilationInfo::PrintAstForTesting() {
1851 PrintF("--- Source from AST ---\n%s\n", 1841 PrintF("--- Source from AST ---\n%s\n",
1852 PrettyPrinter(isolate()).PrintProgram(literal())); 1842 PrettyPrinter(isolate()).PrintProgram(literal()));
1853 } 1843 }
1854 #endif 1844 #endif
1855 } // namespace internal 1845 } // namespace internal
1856 } // namespace v8 1846 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler.h ('k') | src/compiler/access-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698