| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 // Mark the shared code as unoptimizable unless it was an inlined | 304 // Mark the shared code as unoptimizable unless it was an inlined |
| 305 // function that bailed out. | 305 // function that bailed out. |
| 306 Handle<JSFunction> closure = info->closure(); | 306 Handle<JSFunction> closure = info->closure(); |
| 307 info->shared_info()->DisableOptimization(*closure); | 307 info->shared_info()->DisableOptimization(*closure); |
| 308 } | 308 } |
| 309 // True indicates the compilation pipeline is still going, not necessarily | 309 // True indicates the compilation pipeline is still going, not necessarily |
| 310 // that we optimized the code. | 310 // that we optimized the code. |
| 311 return true; | 311 return true; |
| 312 } | 312 } |
| 313 | 313 |
| 314 | |
| 315 static bool GenerateCode(CompilationInfo* info) { | 314 static bool GenerateCode(CompilationInfo* info) { |
| 316 return info->IsCompilingForDebugging() || !V8::UseCrankshaft() ? | 315 return info->IsCompilingForDebugging() || !V8::UseCrankshaft() ? |
| 317 FullCodeGenerator::MakeCode(info) : | 316 FullCodeGenerator::MakeCode(info) : |
| 318 MakeCrankshaftCode(info); | 317 MakeCrankshaftCode(info); |
| 319 } | 318 } |
| 320 | 319 |
| 321 | 320 |
| 322 static bool MakeCode(CompilationInfo* info) { | 321 static bool MakeCode(CompilationInfo* info) { |
| 323 // Precondition: code has been parsed. Postcondition: the code field in | 322 // Precondition: code has been parsed. Postcondition: the code field in |
| 324 // the compilation info is set if compilation succeeded. | 323 // the compilation info is set if compilation succeeded. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // Allocate function. | 396 // Allocate function. |
| 398 ASSERT(!info->code().is_null()); | 397 ASSERT(!info->code().is_null()); |
| 399 Handle<SharedFunctionInfo> result = | 398 Handle<SharedFunctionInfo> result = |
| 400 isolate->factory()->NewSharedFunctionInfo( | 399 isolate->factory()->NewSharedFunctionInfo( |
| 401 lit->name(), | 400 lit->name(), |
| 402 lit->materialized_literal_count(), | 401 lit->materialized_literal_count(), |
| 403 info->code(), | 402 info->code(), |
| 404 ScopeInfo::Create(info->scope())); | 403 ScopeInfo::Create(info->scope())); |
| 405 | 404 |
| 406 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | 405 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
| 407 Compiler::SetFunctionInfo(result, lit, true, script); | 406 Compiler::SetFunctionInfo(result, lit, info, true, script); |
| 408 | 407 |
| 409 if (script->name()->IsString()) { | 408 if (script->name()->IsString()) { |
| 410 PROFILE(isolate, CodeCreateEvent( | 409 PROFILE(isolate, CodeCreateEvent( |
| 411 info->is_eval() | 410 info->is_eval() |
| 412 ? Logger::EVAL_TAG | 411 ? Logger::EVAL_TAG |
| 413 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), | 412 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
| 414 *info->code(), | 413 *info->code(), |
| 415 *result, | 414 *result, |
| 416 String::cast(script->name()))); | 415 String::cast(script->name()))); |
| 417 GDBJIT(AddCode(Handle<String>(String::cast(script->name())), | 416 GDBJIT(AddCode(Handle<String>(String::cast(script->name())), |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 // TODO(keuchel): adapt this for extended mode. | 575 // TODO(keuchel): adapt this for extended mode. |
| 577 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); | 576 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); |
| 578 compilation_cache->PutEval( | 577 compilation_cache->PutEval( |
| 579 source, context, is_global, result, scope_position); | 578 source, context, is_global, result, scope_position); |
| 580 } | 579 } |
| 581 } | 580 } |
| 582 | 581 |
| 583 return result; | 582 return result; |
| 584 } | 583 } |
| 585 | 584 |
| 586 | |
| 587 bool Compiler::CompileLazy(CompilationInfo* info) { | 585 bool Compiler::CompileLazy(CompilationInfo* info) { |
| 588 Isolate* isolate = info->isolate(); | 586 Isolate* isolate = info->isolate(); |
| 589 | 587 |
| 590 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 588 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); |
| 591 | 589 |
| 592 // The VM is in the COMPILER state until exiting this function. | 590 // The VM is in the COMPILER state until exiting this function. |
| 593 VMState state(isolate, COMPILER); | 591 VMState state(isolate, COMPILER); |
| 594 | 592 |
| 595 PostponeInterruptsScope postpone(isolate); | 593 PostponeInterruptsScope postpone(isolate); |
| 596 | 594 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 // Set the optimization hints after performing lazy compilation, as | 653 // Set the optimization hints after performing lazy compilation, as |
| 656 // these are not set when the function is set up as a lazily | 654 // these are not set when the function is set up as a lazily |
| 657 // compiled function. | 655 // compiled function. |
| 658 shared->SetThisPropertyAssignmentsInfo( | 656 shared->SetThisPropertyAssignmentsInfo( |
| 659 lit->has_only_simple_this_property_assignments(), | 657 lit->has_only_simple_this_property_assignments(), |
| 660 *lit->this_property_assignments()); | 658 *lit->this_property_assignments()); |
| 661 | 659 |
| 662 // Check the function has compiled code. | 660 // Check the function has compiled code. |
| 663 ASSERT(shared->is_compiled()); | 661 ASSERT(shared->is_compiled()); |
| 664 shared->set_code_age(0); | 662 shared->set_code_age(0); |
| 663 shared->set_is_inlineable(lit->is_function_inlineable()); |
| 664 shared->set_is_primitive(lit->is_function_primitive()); |
| 665 shared->set_ast_node_count(lit->ast_node_count()); |
| 665 | 666 |
| 666 if (info->AllowOptimize() && !shared->optimization_disabled()) { | 667 if (info->AllowOptimize() && !shared->optimization_disabled()) { |
| 667 // If we're asked to always optimize, we compile the optimized | 668 // If we're asked to always optimize, we compile the optimized |
| 668 // version of the function right away - unless the debugger is | 669 // version of the function right away - unless the debugger is |
| 669 // active as it makes no sense to compile optimized code then. | 670 // active as it makes no sense to compile optimized code then. |
| 670 if (FLAG_always_opt && | 671 if (FLAG_always_opt && |
| 671 !Isolate::Current()->DebuggerHasBreakPoints()) { | 672 !Isolate::Current()->DebuggerHasBreakPoints()) { |
| 672 CompilationInfo optimized(function); | 673 CompilationInfo optimized(function); |
| 673 optimized.SetOptimizing(AstNode::kNoNumber); | 674 optimized.SetOptimizing(AstNode::kNoNumber); |
| 674 return CompileLazy(&optimized); | 675 return CompileLazy(&optimized); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 696 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); | 697 LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal); |
| 697 // Determine if the function can be lazily compiled. This is necessary to | 698 // Determine if the function can be lazily compiled. This is necessary to |
| 698 // allow some of our builtin JS files to be lazily compiled. These | 699 // allow some of our builtin JS files to be lazily compiled. These |
| 699 // builtins cannot be handled lazily by the parser, since we have to know | 700 // builtins cannot be handled lazily by the parser, since we have to know |
| 700 // if a function uses the special natives syntax, which is something the | 701 // if a function uses the special natives syntax, which is something the |
| 701 // parser records. | 702 // parser records. |
| 702 bool allow_lazy = literal->AllowsLazyCompilation() && | 703 bool allow_lazy = literal->AllowsLazyCompilation() && |
| 703 !LiveEditFunctionTracker::IsActive(info.isolate()); | 704 !LiveEditFunctionTracker::IsActive(info.isolate()); |
| 704 | 705 |
| 705 Handle<ScopeInfo> scope_info(ScopeInfo::Empty()); | 706 Handle<ScopeInfo> scope_info(ScopeInfo::Empty()); |
| 706 | |
| 707 // Generate code | 707 // Generate code |
| 708 if (FLAG_lazy && allow_lazy) { | 708 if (FLAG_lazy && allow_lazy) { |
| 709 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); | 709 Handle<Code> code = info.isolate()->builtins()->LazyCompile(); |
| 710 info.SetCode(code); | 710 info.SetCode(code); |
| 711 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || | 711 } else if ((V8::UseCrankshaft() && MakeCrankshaftCode(&info)) || |
| 712 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { | 712 (!V8::UseCrankshaft() && FullCodeGenerator::MakeCode(&info))) { |
| 713 ASSERT(!info.code().is_null()); | 713 ASSERT(!info.code().is_null()); |
| 714 scope_info = ScopeInfo::Create(info.scope()); | 714 scope_info = ScopeInfo::Create(info.scope()); |
| 715 } else { | 715 } else { |
| 716 return Handle<SharedFunctionInfo>::null(); | 716 return Handle<SharedFunctionInfo>::null(); |
| 717 } | 717 } |
| 718 | 718 |
| 719 // Create a shared function info object. | 719 // Create a shared function info object. |
| 720 Handle<SharedFunctionInfo> result = | 720 Handle<SharedFunctionInfo> result = |
| 721 FACTORY->NewSharedFunctionInfo(literal->name(), | 721 FACTORY->NewSharedFunctionInfo(literal->name(), |
| 722 literal->materialized_literal_count(), | 722 literal->materialized_literal_count(), |
| 723 info.code(), | 723 info.code(), |
| 724 scope_info); | 724 scope_info); |
| 725 SetFunctionInfo(result, literal, false, script); | 725 SetFunctionInfo(result, literal, &info, false, script); |
| 726 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 726 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
| 727 result->set_allows_lazy_compilation(allow_lazy); | 727 result->set_allows_lazy_compilation(allow_lazy); |
| 728 | 728 |
| 729 // Set the expected number of properties for instances and return | 729 // Set the expected number of properties for instances and return |
| 730 // the resulting function. | 730 // the resulting function. |
| 731 SetExpectedNofPropertiesFromEstimate(result, | 731 SetExpectedNofPropertiesFromEstimate(result, |
| 732 literal->expected_property_count()); | 732 literal->expected_property_count()); |
| 733 live_edit_tracker.RecordFunctionInfo(result, literal); | 733 live_edit_tracker.RecordFunctionInfo(result, literal); |
| 734 return result; | 734 return result; |
| 735 } | 735 } |
| 736 | 736 |
| 737 | 737 |
| 738 // Sets the function info on a function. | 738 // Sets the function info on a function. |
| 739 // The start_position points to the first '(' character after the function name | 739 // The start_position points to the first '(' character after the function name |
| 740 // in the full script source. When counting characters in the script source the | 740 // in the full script source. When counting characters in the script source the |
| 741 // the first character is number 0 (not 1). | 741 // the first character is number 0 (not 1). |
| 742 void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, | 742 void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info, |
| 743 FunctionLiteral* lit, | 743 FunctionLiteral* lit, |
| 744 CompilationInfo* info, |
| 744 bool is_toplevel, | 745 bool is_toplevel, |
| 745 Handle<Script> script) { | 746 Handle<Script> script) { |
| 746 function_info->set_length(lit->parameter_count()); | 747 function_info->set_length(lit->parameter_count()); |
| 747 function_info->set_formal_parameter_count(lit->parameter_count()); | 748 function_info->set_formal_parameter_count(lit->parameter_count()); |
| 748 function_info->set_script(*script); | 749 function_info->set_script(*script); |
| 749 function_info->set_function_token_position(lit->function_token_position()); | 750 function_info->set_function_token_position(lit->function_token_position()); |
| 750 function_info->set_start_position(lit->start_position()); | 751 function_info->set_start_position(lit->start_position()); |
| 751 function_info->set_end_position(lit->end_position()); | 752 function_info->set_end_position(lit->end_position()); |
| 752 function_info->set_is_expression(lit->is_expression()); | 753 function_info->set_is_expression(lit->is_expression()); |
| 753 function_info->set_is_anonymous(lit->is_anonymous()); | 754 function_info->set_is_anonymous(lit->is_anonymous()); |
| 754 function_info->set_is_toplevel(is_toplevel); | 755 function_info->set_is_toplevel(is_toplevel); |
| 755 function_info->set_inferred_name(*lit->inferred_name()); | 756 function_info->set_inferred_name(*lit->inferred_name()); |
| 756 function_info->SetThisPropertyAssignmentsInfo( | 757 function_info->SetThisPropertyAssignmentsInfo( |
| 757 lit->has_only_simple_this_property_assignments(), | 758 lit->has_only_simple_this_property_assignments(), |
| 758 *lit->this_property_assignments()); | 759 *lit->this_property_assignments()); |
| 759 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 760 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
| 760 function_info->set_strict_mode_flag(lit->strict_mode_flag()); | 761 function_info->set_strict_mode_flag(lit->strict_mode_flag()); |
| 761 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 762 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
| 762 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 763 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
| 764 function_info->set_is_inlineable(lit->is_function_inlineable()); |
| 765 function_info->set_is_primitive(lit->is_function_primitive()); |
| 766 function_info->set_ast_node_count(lit->ast_node_count()); |
| 763 } | 767 } |
| 764 | 768 |
| 765 | 769 |
| 766 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 770 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 767 CompilationInfo* info, | 771 CompilationInfo* info, |
| 768 Handle<SharedFunctionInfo> shared) { | 772 Handle<SharedFunctionInfo> shared) { |
| 769 // SharedFunctionInfo is passed separately, because if CompilationInfo | 773 // SharedFunctionInfo is passed separately, because if CompilationInfo |
| 770 // was created using Script object, it will not have it. | 774 // was created using Script object, it will not have it. |
| 771 | 775 |
| 772 // Log the code generation. If source information is available include | 776 // Log the code generation. If source information is available include |
| (...skipping 23 matching lines...) Expand all Loading... |
| 796 } | 800 } |
| 797 } | 801 } |
| 798 | 802 |
| 799 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 803 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
| 800 Handle<Script>(info->script()), | 804 Handle<Script>(info->script()), |
| 801 Handle<Code>(info->code()), | 805 Handle<Code>(info->code()), |
| 802 info)); | 806 info)); |
| 803 } | 807 } |
| 804 | 808 |
| 805 } } // namespace v8::internal | 809 } } // namespace v8::internal |
| OLD | NEW |