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/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
10 #include "src/ast-this-access-visitor.h" | 10 #include "src/ast-this-access-visitor.h" |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 602 |
603 | 603 |
604 static void MaybeDisableOptimization(Handle<SharedFunctionInfo> shared_info, | 604 static void MaybeDisableOptimization(Handle<SharedFunctionInfo> shared_info, |
605 BailoutReason bailout_reason) { | 605 BailoutReason bailout_reason) { |
606 if (bailout_reason != kNoReason) { | 606 if (bailout_reason != kNoReason) { |
607 shared_info->DisableOptimization(bailout_reason); | 607 shared_info->DisableOptimization(bailout_reason); |
608 } | 608 } |
609 } | 609 } |
610 | 610 |
611 | 611 |
612 // Sets the function info on a function. | |
613 // The start_position points to the first '(' character after the function name | |
614 // in the full script source. When counting characters in the script source the | |
615 // the first character is number 0 (not 1). | |
616 static void SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | |
617 FunctionLiteral* lit, | |
618 bool is_toplevel, | |
619 Handle<Script> script) { | |
620 function_info->set_length(lit->parameter_count()); | |
621 if (FLAG_experimental_classes && IsSubclassConstructor(lit->kind())) { | |
622 function_info->set_internal_formal_parameter_count(lit->parameter_count() + | |
623 1); | |
624 } else { | |
625 function_info->set_internal_formal_parameter_count(lit->parameter_count()); | |
626 } | |
627 function_info->set_script(*script); | |
628 function_info->set_function_token_position(lit->function_token_position()); | |
629 function_info->set_start_position(lit->start_position()); | |
630 function_info->set_end_position(lit->end_position()); | |
631 function_info->set_is_expression(lit->is_expression()); | |
632 function_info->set_is_anonymous(lit->is_anonymous()); | |
633 function_info->set_is_toplevel(is_toplevel); | |
634 function_info->set_inferred_name(*lit->inferred_name()); | |
635 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | |
636 function_info->set_allows_lazy_compilation_without_context( | |
637 lit->AllowsLazyCompilationWithoutContext()); | |
638 function_info->set_language_mode(lit->language_mode()); | |
639 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | |
640 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | |
641 function_info->set_ast_node_count(lit->ast_node_count()); | |
642 function_info->set_is_function(lit->is_function()); | |
643 MaybeDisableOptimization(function_info, lit->dont_optimize_reason()); | |
644 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); | |
645 function_info->set_kind(lit->kind()); | |
646 function_info->set_uses_super_property(lit->uses_super_property()); | |
647 function_info->set_uses_super_constructor_call( | |
648 lit->uses_super_constructor_call()); | |
649 function_info->set_asm_function(lit->scope()->asm_function()); | |
650 } | |
651 | |
652 | |
653 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 612 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
654 CompilationInfo* info, | 613 CompilationInfo* info, |
655 Handle<SharedFunctionInfo> shared) { | 614 Handle<SharedFunctionInfo> shared) { |
656 // SharedFunctionInfo is passed separately, because if CompilationInfo | 615 // SharedFunctionInfo is passed separately, because if CompilationInfo |
657 // was created using Script object, it will not have it. | 616 // was created using Script object, it will not have it. |
658 | 617 |
659 // Log the code generation. If source information is available include | 618 // Log the code generation. If source information is available include |
660 // script name and line number. Check explicitly whether logging is | 619 // script name and line number. Check explicitly whether logging is |
661 // enabled as finding the line number is not free. | 620 // enabled as finding the line number is not free. |
662 if (info->isolate()->logger()->is_logging_code_events() || | 621 if (info->isolate()->logger()->is_logging_code_events() || |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 | 1146 |
1188 // Allocate function. | 1147 // Allocate function. |
1189 DCHECK(!info->code().is_null()); | 1148 DCHECK(!info->code().is_null()); |
1190 result = isolate->factory()->NewSharedFunctionInfo( | 1149 result = isolate->factory()->NewSharedFunctionInfo( |
1191 lit->name(), lit->materialized_literal_count(), lit->kind(), | 1150 lit->name(), lit->materialized_literal_count(), lit->kind(), |
1192 info->code(), | 1151 info->code(), |
1193 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), | 1152 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()), |
1194 info->feedback_vector()); | 1153 info->feedback_vector()); |
1195 | 1154 |
1196 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 1155 DCHECK_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
1197 SetFunctionInfo(result, lit, true, script); | 1156 SharedFunctionInfo::InitFromFunctionLiteral(result, lit); |
| 1157 result->set_script(*script); |
| 1158 result->set_is_toplevel(true); |
1198 | 1159 |
1199 Handle<String> script_name = script->name()->IsString() | 1160 Handle<String> script_name = script->name()->IsString() |
1200 ? Handle<String>(String::cast(script->name())) | 1161 ? Handle<String>(String::cast(script->name())) |
1201 : isolate->factory()->empty_string(); | 1162 : isolate->factory()->empty_string(); |
1202 Logger::LogEventsAndTags log_tag = info->is_eval() | 1163 Logger::LogEventsAndTags log_tag = info->is_eval() |
1203 ? Logger::EVAL_TAG | 1164 ? Logger::EVAL_TAG |
1204 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); | 1165 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); |
1205 | 1166 |
1206 PROFILE(isolate, CodeCreateEvent( | 1167 PROFILE(isolate, CodeCreateEvent( |
1207 log_tag, *info->code(), *result, info, *script_name)); | 1168 log_tag, *info->code(), *result, info, *script_name)); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 DCHECK(!info.code().is_null()); | 1422 DCHECK(!info.code().is_null()); |
1462 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | 1423 scope_info = ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); |
1463 } else { | 1424 } else { |
1464 return Handle<SharedFunctionInfo>::null(); | 1425 return Handle<SharedFunctionInfo>::null(); |
1465 } | 1426 } |
1466 | 1427 |
1467 // Create a shared function info object. | 1428 // Create a shared function info object. |
1468 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( | 1429 Handle<SharedFunctionInfo> result = factory->NewSharedFunctionInfo( |
1469 literal->name(), literal->materialized_literal_count(), literal->kind(), | 1430 literal->name(), literal->materialized_literal_count(), literal->kind(), |
1470 info.code(), scope_info, info.feedback_vector()); | 1431 info.code(), scope_info, info.feedback_vector()); |
1471 SetFunctionInfo(result, literal, false, script); | 1432 |
| 1433 SharedFunctionInfo::InitFromFunctionLiteral(result, literal); |
| 1434 result->set_script(*script); |
| 1435 result->set_is_toplevel(false); |
| 1436 |
1472 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 1437 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
1473 result->set_allows_lazy_compilation(allow_lazy); | 1438 result->set_allows_lazy_compilation(allow_lazy); |
1474 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); | 1439 result->set_allows_lazy_compilation_without_context(allow_lazy_without_ctx); |
1475 | 1440 |
1476 // Set the expected number of properties for instances and return | 1441 // Set the expected number of properties for instances and return |
1477 // the resulting function. | 1442 // the resulting function. |
1478 SetExpectedNofPropertiesFromEstimate(result, | 1443 SetExpectedNofPropertiesFromEstimate(result, |
1479 literal->expected_property_count()); | 1444 literal->expected_property_count()); |
1480 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); | 1445 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); |
1481 return result; | 1446 return result; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 } | 1585 } |
1621 | 1586 |
1622 | 1587 |
1623 #if DEBUG | 1588 #if DEBUG |
1624 void CompilationInfo::PrintAstForTesting() { | 1589 void CompilationInfo::PrintAstForTesting() { |
1625 PrintF("--- Source from AST ---\n%s\n", | 1590 PrintF("--- Source from AST ---\n%s\n", |
1626 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1591 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1627 } | 1592 } |
1628 #endif | 1593 #endif |
1629 } } // namespace v8::internal | 1594 } } // namespace v8::internal |
OLD | NEW |