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

Side by Side Diff: src/compiler.cc

Issue 1668103002: Type Feedback Vector lives in the closure (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Created 4 years, 10 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_vector_ = Handle<TypeFeedbackVector>( 133 feedback_metadata_ = Handle<TypeFeedbackMetadata>(
134 shared_info()->feedback_vector(), parse_info->isolate()); 134 shared_info()->feedback_metadata(), 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 208 void CompilationInfo::EnsureFeedbackMetadata() {
209 void CompilationInfo::EnsureFeedbackVector() { 209 if (feedback_metadata_.is_null()) {
210 if (feedback_vector_.is_null()) { 210 feedback_metadata_ =
211 Handle<TypeFeedbackMetadata> feedback_metadata =
212 TypeFeedbackMetadata::New(isolate(), literal()->feedback_vector_spec()); 211 TypeFeedbackMetadata::New(isolate(), literal()->feedback_vector_spec());
213 feedback_vector_ = TypeFeedbackVector::New(isolate(), feedback_metadata);
214 } 212 }
215 213
216 // It's very important that recompiles do not alter the structure of the 214 // It's very important that recompiles do not alter the structure of the
217 // type feedback vector. 215 // type feedback vector.
218 CHECK(!feedback_vector_->metadata()->SpecDiffersFrom( 216 CHECK(
219 literal()->feedback_vector_spec())); 217 !feedback_metadata_->SpecDiffersFrom(literal()->feedback_vector_spec()));
220 } 218 }
221 219
222 220
223 bool CompilationInfo::has_simple_parameters() { 221 bool CompilationInfo::has_simple_parameters() {
224 return scope()->has_simple_parameters(); 222 return scope()->has_simple_parameters();
225 } 223 }
226 224
227 225
228 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared, 226 int CompilationInfo::TraceInlinedFunction(Handle<SharedFunctionInfo> shared,
229 SourcePosition position, 227 SourcePosition position,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 return SetLastStatus(FAILED); 374 return SetLastStatus(FAILED);
377 } 375 }
378 if (FLAG_hydrogen_stats) { 376 if (FLAG_hydrogen_stats) {
379 isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed()); 377 isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed());
380 } 378 }
381 } 379 }
382 380
383 DCHECK(info()->shared_info()->has_deoptimization_support()); 381 DCHECK(info()->shared_info()->has_deoptimization_support());
384 DCHECK(!info()->is_first_compile()); 382 DCHECK(!info()->is_first_compile());
385 383
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
386 bool optimization_disabled = info()->shared_info()->optimization_disabled(); 389 bool optimization_disabled = info()->shared_info()->optimization_disabled();
387 bool dont_crankshaft = info()->shared_info()->dont_crankshaft(); 390 bool dont_crankshaft = info()->shared_info()->dont_crankshaft();
388 391
389 // Check the enabling conditions for Turbofan. 392 // Check the enabling conditions for Turbofan.
390 // 1. "use asm" code. 393 // 1. "use asm" code.
391 bool is_turbofanable_asm = FLAG_turbo_asm && 394 bool is_turbofanable_asm = FLAG_turbo_asm &&
392 info()->shared_info()->asm_function() && 395 info()->shared_info()->asm_function() &&
393 !optimization_disabled; 396 !optimization_disabled;
394 397
395 // 2. Fallback for features unsupported by Crankshaft. 398 // 2. Fallback for features unsupported by Crankshaft.
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon( 808 MUST_USE_RESULT static MaybeHandle<Code> GetUnoptimizedCodeCommon(
806 CompilationInfo* info) { 809 CompilationInfo* info) {
807 VMState<COMPILER> state(info->isolate()); 810 VMState<COMPILER> state(info->isolate());
808 PostponeInterruptsScope postpone(info->isolate()); 811 PostponeInterruptsScope postpone(info->isolate());
809 812
810 // Parse and update CompilationInfo with the results. 813 // Parse and update CompilationInfo with the results.
811 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); 814 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>();
812 Handle<SharedFunctionInfo> shared = info->shared_info(); 815 Handle<SharedFunctionInfo> shared = info->shared_info();
813 FunctionLiteral* lit = info->literal(); 816 FunctionLiteral* lit = info->literal();
814 DCHECK_EQ(shared->language_mode(), lit->language_mode()); 817 DCHECK_EQ(shared->language_mode(), lit->language_mode());
818 shared->set_num_literals(lit->materialized_literal_count());
815 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); 819 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count());
816 MaybeDisableOptimization(shared, lit->dont_optimize_reason()); 820 MaybeDisableOptimization(shared, lit->dont_optimize_reason());
817 821
818 // Compile either unoptimized code or bytecode for the interpreter. 822 // Compile either unoptimized code or bytecode for the interpreter.
819 if (!CompileBaselineCode(info)) return MaybeHandle<Code>(); 823 if (!CompileBaselineCode(info)) return MaybeHandle<Code>();
820 if (info->code()->kind() == Code::FUNCTION) { // Only for full code. 824 if (info->code()->kind() == Code::FUNCTION) { // Only for full code.
821 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); 825 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
822 } 826 }
823 827
824 // Update the shared function info with the scope info. Allocating the 828 // Update the shared function info with the scope info. Allocating the
825 // ScopeInfo object may cause a GC. 829 // ScopeInfo object may cause a GC.
826 Handle<ScopeInfo> scope_info = 830 Handle<ScopeInfo> scope_info =
827 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); 831 ScopeInfo::Create(info->isolate(), info->zone(), info->scope());
828 shared->set_scope_info(*scope_info); 832 shared->set_scope_info(*scope_info);
829 833
830 // Update the code and feedback vector for the shared function info. 834 // Update the code and feedback vector for the shared function info.
831 shared->ReplaceCode(*info->code()); 835 shared->ReplaceCode(*info->code());
832 shared->set_feedback_vector(*info->feedback_vector()); 836 shared->set_feedback_metadata(*info->feedback_metadata());
833 if (info->has_bytecode_array()) { 837 if (info->has_bytecode_array()) {
834 DCHECK(shared->function_data()->IsUndefined()); 838 DCHECK(shared->function_data()->IsUndefined());
835 shared->set_function_data(*info->bytecode_array()); 839 shared->set_function_data(*info->bytecode_array());
836 } 840 }
837 841
838 return info->code(); 842 return info->code();
839 } 843 }
840 844
841 845
842 MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap( 846 MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 return Handle<Code>(function->shared()->code()); 1040 return Handle<Code>(function->shared()->code());
1037 } 1041 }
1038 1042
1039 CompilationInfoWithZone info(function); 1043 CompilationInfoWithZone info(function);
1040 Handle<Code> result; 1044 Handle<Code> result;
1041 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCodeCommon(&info), 1045 ASSIGN_RETURN_ON_EXCEPTION(isolate, result, GetUnoptimizedCodeCommon(&info),
1042 Code); 1046 Code);
1043 1047
1044 if (FLAG_always_opt) { 1048 if (FLAG_always_opt) {
1045 Handle<Code> opt_code; 1049 Handle<Code> opt_code;
1050 JSFunction::EnsureLiterals(function);
1046 if (Compiler::GetOptimizedCode(function, Compiler::NOT_CONCURRENT) 1051 if (Compiler::GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
1047 .ToHandle(&opt_code)) { 1052 .ToHandle(&opt_code)) {
1048 result = opt_code; 1053 result = opt_code;
1049 } 1054 }
1050 } 1055 }
1051 1056
1052 return result; 1057 return result;
1053 } 1058 }
1054 1059
1055 1060
1056 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { 1061 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) {
1057 if (function->is_compiled()) return true; 1062 if (function->is_compiled()) return true;
1058 MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function); 1063 MaybeHandle<Code> maybe_code = Compiler::GetLazyCode(function);
1059 Handle<Code> code; 1064 Handle<Code> code;
1065 Isolate* isolate = function->GetIsolate();
1060 if (!maybe_code.ToHandle(&code)) { 1066 if (!maybe_code.ToHandle(&code)) {
1061 if (flag == CLEAR_EXCEPTION) { 1067 if (flag == CLEAR_EXCEPTION) {
1062 function->GetIsolate()->clear_pending_exception(); 1068 isolate->clear_pending_exception();
1063 } 1069 }
1064 return false; 1070 return false;
1065 } 1071 }
1066 function->ReplaceCode(*code); 1072 function->ReplaceCode(*code);
1067 DCHECK(function->is_compiled()); 1073 DCHECK(function->is_compiled());
1074 JSFunction::EnsureLiterals(function);
1068 return true; 1075 return true;
1069 } 1076 }
1070 1077
1071 1078
1072 // TODO(turbofan): In the future, unoptimized code with deopt support could 1079 // TODO(turbofan): In the future, unoptimized code with deopt support could
1073 // be generated lazily once deopt is triggered. 1080 // be generated lazily once deopt is triggered.
1074 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { 1081 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
1075 DCHECK_NOT_NULL(info->literal()); 1082 DCHECK_NOT_NULL(info->literal());
1076 DCHECK(info->has_scope()); 1083 DCHECK(info->has_scope());
1077 Handle<SharedFunctionInfo> shared = info->shared_info(); 1084 Handle<SharedFunctionInfo> shared = info->shared_info();
(...skipping 10 matching lines...) Expand all
1088 // If the current code has reloc info for serialization, also include 1095 // If the current code has reloc info for serialization, also include
1089 // reloc info for serialization for the new code, so that deopt support 1096 // reloc info for serialization for the new code, so that deopt support
1090 // can be added without losing IC state. 1097 // can be added without losing IC state.
1091 if (shared->code()->kind() == Code::FUNCTION && 1098 if (shared->code()->kind() == Code::FUNCTION &&
1092 shared->code()->has_reloc_info_for_serialization()) { 1099 shared->code()->has_reloc_info_for_serialization()) {
1093 unoptimized.PrepareForSerializing(); 1100 unoptimized.PrepareForSerializing();
1094 } 1101 }
1095 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; 1102 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
1096 1103
1097 shared->EnableDeoptimizationSupport(*unoptimized.code()); 1104 shared->EnableDeoptimizationSupport(*unoptimized.code());
1098 shared->set_feedback_vector(*unoptimized.feedback_vector()); 1105 shared->set_feedback_metadata(*unoptimized.feedback_metadata());
1099 1106
1100 info->MarkAsCompiled(); 1107 info->MarkAsCompiled();
1101 1108
1102 // The scope info might not have been set if a lazily compiled 1109 // The scope info might not have been set if a lazily compiled
1103 // function is inlined before being called for the first time. 1110 // function is inlined before being called for the first time.
1104 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { 1111 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) {
1105 Handle<ScopeInfo> target_scope_info = 1112 Handle<ScopeInfo> target_scope_info =
1106 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); 1113 ScopeInfo::Create(info->isolate(), info->zone(), info->scope());
1107 shared->set_scope_info(*target_scope_info); 1114 shared->set_scope_info(*target_scope_info);
1108 } 1115 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 1171
1165 static inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) { 1172 static inline bool IsEvalToplevel(Handle<SharedFunctionInfo> shared) {
1166 return shared->is_toplevel() && shared->script()->IsScript() && 1173 return shared->is_toplevel() && shared->script()->IsScript() &&
1167 Script::cast(shared->script())->compilation_type() == 1174 Script::cast(shared->script())->compilation_type() ==
1168 Script::COMPILATION_TYPE_EVAL; 1175 Script::COMPILATION_TYPE_EVAL;
1169 } 1176 }
1170 1177
1171 1178
1172 bool Compiler::CompileDebugCode(Handle<JSFunction> function) { 1179 bool Compiler::CompileDebugCode(Handle<JSFunction> function) {
1173 Handle<SharedFunctionInfo> shared(function->shared()); 1180 Handle<SharedFunctionInfo> shared(function->shared());
1181 bool result;
1174 if (IsEvalToplevel(shared)) { 1182 if (IsEvalToplevel(shared)) {
1175 return CompileEvalForDebugging(function, shared); 1183 result = CompileEvalForDebugging(function, shared);
1176 } else { 1184 } else {
1177 CompilationInfoWithZone info(function); 1185 CompilationInfoWithZone info(function);
1178 return CompileForDebugging(&info); 1186 result = CompileForDebugging(&info);
1179 } 1187 }
1188 JSFunction::EnsureLiterals(function);
1189 return result;
1180 } 1190 }
1181 1191
1182 1192
1183 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { 1193 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) {
1184 DCHECK(shared->allows_lazy_compilation_without_context()); 1194 DCHECK(shared->allows_lazy_compilation_without_context());
1185 DCHECK(!IsEvalToplevel(shared)); 1195 DCHECK(!IsEvalToplevel(shared));
1186 Zone zone; 1196 Zone zone;
1187 ParseInfo parse_info(&zone, shared); 1197 ParseInfo parse_info(&zone, shared);
1188 CompilationInfo info(&parse_info); 1198 CompilationInfo info(&parse_info);
1189 return CompileForDebugging(&info); 1199 return CompileForDebugging(&info);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 if (!CompileBaselineCode(info)) { 1291 if (!CompileBaselineCode(info)) {
1282 return Handle<SharedFunctionInfo>::null(); 1292 return Handle<SharedFunctionInfo>::null();
1283 } 1293 }
1284 1294
1285 // Allocate function. 1295 // Allocate function.
1286 DCHECK(!info->code().is_null()); 1296 DCHECK(!info->code().is_null());
1287 result = isolate->factory()->NewSharedFunctionInfo( 1297 result = isolate->factory()->NewSharedFunctionInfo(
1288 lit->name(), lit->materialized_literal_count(), lit->kind(), 1298 lit->name(), lit->materialized_literal_count(), lit->kind(),
1289 info->code(), 1299 info->code(),
1290 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), 1300 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()),
1291 info->feedback_vector()); 1301 info->feedback_metadata());
1292 if (info->has_bytecode_array()) { 1302 if (info->has_bytecode_array()) {
1293 DCHECK(result->function_data()->IsUndefined()); 1303 DCHECK(result->function_data()->IsUndefined());
1294 result->set_function_data(*info->bytecode_array()); 1304 result->set_function_data(*info->bytecode_array());
1295 } 1305 }
1296 1306
1297 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); 1307 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position());
1298 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); 1308 SharedFunctionInfo::InitFromFunctionLiteral(result, lit);
1299 SharedFunctionInfo::SetScript(result, script); 1309 SharedFunctionInfo::SetScript(result, script);
1300 result->set_is_toplevel(true); 1310 result->set_is_toplevel(true);
1301 if (info->is_eval()) { 1311 if (info->is_eval()) {
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 !LiveEditFunctionTracker::IsActive(isolate) && 1618 !LiveEditFunctionTracker::IsActive(isolate) &&
1609 (!info.is_debug() || allow_lazy_without_ctx); 1619 (!info.is_debug() || allow_lazy_without_ctx);
1610 1620
1611 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile(); 1621 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile();
1612 1622
1613 // Generate code 1623 // Generate code
1614 Handle<ScopeInfo> scope_info; 1624 Handle<ScopeInfo> scope_info;
1615 if (lazy) { 1625 if (lazy) {
1616 Handle<Code> code = isolate->builtins()->CompileLazy(); 1626 Handle<Code> code = isolate->builtins()->CompileLazy();
1617 info.SetCode(code); 1627 info.SetCode(code);
1618 // There's no need in theory for a lazy-compiled function to have a type 1628 // There's no need in theory for a lazy-compiled function to have type
1619 // feedback vector, but some parts of the system expect all 1629 // feedback metadata, but some parts of the system expect all
1620 // SharedFunctionInfo instances to have one. The size of the vector depends 1630 // SharedFunctionInfo instances to have one.
1621 // on how many feedback-needing nodes are in the tree, and when lazily 1631 info.EnsureFeedbackMetadata();
1622 // parsing we might not know that, if this function was never parsed before.
1623 // In that case the vector will be replaced the next time MakeCode is
1624 // called.
1625 info.EnsureFeedbackVector();
1626 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate)); 1632 scope_info = Handle<ScopeInfo>(ScopeInfo::Empty(isolate));
1627 } else if (Renumber(info.parse_info()) && GenerateBaselineCode(&info)) { 1633 } else if (Renumber(info.parse_info()) && GenerateBaselineCode(&info)) {
1628 // Code generation will ensure that the feedback vector is present and 1634 // Code generation will ensure that the feedback vector is present and
1629 // appropriately sized. 1635 // appropriately sized.
1630 DCHECK(!info.code().is_null()); 1636 DCHECK(!info.code().is_null());
1631 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); 1637 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope());
1632 if (literal->should_eager_compile() && 1638 if (literal->should_eager_compile() &&
1633 literal->should_be_used_once_hint()) { 1639 literal->should_be_used_once_hint()) {
1634 info.code()->MarkToBeExecutedOnce(isolate); 1640 info.code()->MarkToBeExecutedOnce(isolate);
1635 } 1641 }
1636 } else { 1642 } else {
1637 return Handle<SharedFunctionInfo>::null(); 1643 return Handle<SharedFunctionInfo>::null();
1638 } 1644 }
1639 1645
1640 if (maybe_existing.is_null()) { 1646 if (maybe_existing.is_null()) {
1641 // Create a shared function info object. 1647 // Create a shared function info object.
1642 Handle<SharedFunctionInfo> result = 1648 Handle<SharedFunctionInfo> result =
1643 isolate->factory()->NewSharedFunctionInfo( 1649 isolate->factory()->NewSharedFunctionInfo(
1644 literal->name(), literal->materialized_literal_count(), 1650 literal->name(), literal->materialized_literal_count(),
1645 literal->kind(), info.code(), scope_info, info.feedback_vector()); 1651 literal->kind(), info.code(), scope_info, info.feedback_metadata());
1646 if (info.has_bytecode_array()) { 1652 if (info.has_bytecode_array()) {
1647 DCHECK(result->function_data()->IsUndefined()); 1653 DCHECK(result->function_data()->IsUndefined());
1648 result->set_function_data(*info.bytecode_array()); 1654 result->set_function_data(*info.bytecode_array());
1649 } 1655 }
1650 1656
1651 SharedFunctionInfo::InitFromFunctionLiteral(result, literal); 1657 SharedFunctionInfo::InitFromFunctionLiteral(result, literal);
1652 SharedFunctionInfo::SetScript(result, script); 1658 SharedFunctionInfo::SetScript(result, script);
1653 result->set_is_toplevel(false); 1659 result->set_is_toplevel(false);
1654 // If the outer function has been compiled before, we cannot be sure that 1660 // If the outer function has been compiled before, we cannot be sure that
1655 // shared function info for this function literal has been created for the 1661 // shared function info for this function literal has been created for the
1656 // first time. It may have already been compiled previously. 1662 // first time. It may have already been compiled previously.
1657 result->set_never_compiled(outer_info->is_first_compile() && lazy); 1663 result->set_never_compiled(outer_info->is_first_compile() && lazy);
1658 1664
1659 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); 1665 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result);
1660 result->set_allows_lazy_compilation(literal->AllowsLazyCompilation()); 1666 result->set_allows_lazy_compilation(literal->AllowsLazyCompilation());
1661 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); 1667 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx);
1662 1668
1663 // Set the expected number of properties for instances and return 1669 // Set the expected number of properties for instances and return
1664 // the resulting function. 1670 // the resulting function.
1665 SetExpectedNofPropertiesFromEstimate(result, 1671 SetExpectedNofPropertiesFromEstimate(result,
1666 literal->expected_property_count()); 1672 literal->expected_property_count());
1667 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); 1673 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone());
1668 return result; 1674 return result;
1669 } else if (!lazy) { 1675 } else if (!lazy) {
1670 // Assert that we are not overwriting (possibly patched) debug code. 1676 // Assert that we are not overwriting (possibly patched) debug code.
1671 DCHECK(!existing->HasDebugCode()); 1677 DCHECK(!existing->HasDebugCode());
1672 existing->ReplaceCode(*info.code()); 1678 existing->ReplaceCode(*info.code());
1673 existing->set_scope_info(*scope_info); 1679 existing->set_scope_info(*scope_info);
1674 existing->set_feedback_vector(*info.feedback_vector()); 1680 existing->set_feedback_metadata(*info.feedback_metadata());
1675 } 1681 }
1676 return existing; 1682 return existing;
1677 } 1683 }
1678 1684
1679 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( 1685 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative(
1680 v8::Extension* extension, Handle<String> name) { 1686 v8::Extension* extension, Handle<String> name) {
1681 Isolate* isolate = name->GetIsolate(); 1687 Isolate* isolate = name->GetIsolate();
1682 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 1688 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
1683 1689
1684 // Compute the function template for the native function. 1690 // Compute the function template for the native function.
1685 v8::Local<v8::FunctionTemplate> fun_template = 1691 v8::Local<v8::FunctionTemplate> fun_template =
1686 extension->GetNativeFunctionTemplate(v8_isolate, 1692 extension->GetNativeFunctionTemplate(v8_isolate,
1687 v8::Utils::ToLocal(name)); 1693 v8::Utils::ToLocal(name));
1688 DCHECK(!fun_template.IsEmpty()); 1694 DCHECK(!fun_template.IsEmpty());
1689 1695
1690 // Instantiate the function and create a shared function info from it. 1696 // Instantiate the function and create a shared function info from it.
1691 Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle( 1697 Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle(
1692 *fun_template->GetFunction(v8_isolate->GetCurrentContext()) 1698 *fun_template->GetFunction(v8_isolate->GetCurrentContext())
1693 .ToLocalChecked())); 1699 .ToLocalChecked()));
1694 const int literals = fun->NumberOfLiterals(); 1700 const int literals = fun->NumberOfLiterals();
1695 Handle<Code> code = Handle<Code>(fun->shared()->code()); 1701 Handle<Code> code = Handle<Code>(fun->shared()->code());
1696 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub()); 1702 Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
1697 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo( 1703 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
1698 name, literals, FunctionKind::kNormalFunction, code, 1704 name, literals, FunctionKind::kNormalFunction, code,
1699 Handle<ScopeInfo>(fun->shared()->scope_info()), 1705 Handle<ScopeInfo>(fun->shared()->scope_info()),
1700 Handle<TypeFeedbackVector>(fun->shared()->feedback_vector())); 1706 Handle<TypeFeedbackMetadata>(fun->shared()->feedback_metadata()));
1701 shared->set_construct_stub(*construct_stub); 1707 shared->set_construct_stub(*construct_stub);
1702 1708
1703 // Copy the function data to the shared function info. 1709 // Copy the function data to the shared function info.
1704 shared->set_function_data(fun->shared()->function_data()); 1710 shared->set_function_data(fun->shared()->function_data());
1705 int parameters = fun->shared()->internal_formal_parameter_count(); 1711 int parameters = fun->shared()->internal_formal_parameter_count();
1706 shared->set_internal_formal_parameter_count(parameters); 1712 shared->set_internal_formal_parameter_count(parameters);
1707 1713
1708 return shared; 1714 return shared;
1709 } 1715 }
1710 1716
(...skipping 27 matching lines...) Expand all
1738 // The function was never compiled. Compile it unoptimized first. 1744 // The function was never compiled. Compile it unoptimized first.
1739 // TODO(titzer): reuse the AST and scope info from this compile. 1745 // TODO(titzer): reuse the AST and scope info from this compile.
1740 CompilationInfoWithZone unoptimized(function); 1746 CompilationInfoWithZone unoptimized(function);
1741 unoptimized.EnableDeoptimizationSupport(); 1747 unoptimized.EnableDeoptimizationSupport();
1742 if (!GetUnoptimizedCodeCommon(&unoptimized).ToHandle(&current_code)) { 1748 if (!GetUnoptimizedCodeCommon(&unoptimized).ToHandle(&current_code)) {
1743 return MaybeHandle<Code>(); 1749 return MaybeHandle<Code>();
1744 } 1750 }
1745 shared->ReplaceCode(*current_code); 1751 shared->ReplaceCode(*current_code);
1746 } 1752 }
1747 1753
1754 // At this point we know we've compiled the function, so make sure the closure
1755 // points to valid literals and type-feedback-vector.
1756 JSFunction::EnsureLiterals(function);
1757
1748 current_code->set_profiler_ticks(0); 1758 current_code->set_profiler_ticks(0);
1749 1759
1750 // TODO(mstarzinger): We cannot properly deserialize a scope chain containing 1760 // TODO(mstarzinger): We cannot properly deserialize a scope chain containing
1751 // an eval scope and hence would fail at parsing the eval source again. 1761 // an eval scope and hence would fail at parsing the eval source again.
1752 if (shared->disable_optimization_reason() == kEval) { 1762 if (shared->disable_optimization_reason() == kEval) {
1753 return MaybeHandle<Code>(); 1763 return MaybeHandle<Code>();
1754 } 1764 }
1755 1765
1756 // TODO(mstarzinger): We cannot properly deserialize a scope chain for the 1766 // TODO(mstarzinger): We cannot properly deserialize a scope chain for the
1757 // builtin context, hence Genesis::InstallExperimentalNatives would fail. 1767 // builtin context, hence Genesis::InstallExperimentalNatives would fail.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 } 1872 }
1863 1873
1864 #if DEBUG 1874 #if DEBUG
1865 void CompilationInfo::PrintAstForTesting() { 1875 void CompilationInfo::PrintAstForTesting() {
1866 PrintF("--- Source from AST ---\n%s\n", 1876 PrintF("--- Source from AST ---\n%s\n",
1867 PrettyPrinter(isolate()).PrintProgram(literal())); 1877 PrettyPrinter(isolate()).PrintProgram(literal()));
1868 } 1878 }
1869 #endif 1879 #endif
1870 } // namespace internal 1880 } // namespace internal
1871 } // namespace v8 1881 } // 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