OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // optimized code. | 254 // optimized code. |
255 unoptimized.SetFunction(info->function()); | 255 unoptimized.SetFunction(info->function()); |
256 unoptimized.SetScope(info->scope()); | 256 unoptimized.SetScope(info->scope()); |
257 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); | 257 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
258 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); | 258 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); |
259 if (should_recompile) { | 259 if (should_recompile) { |
260 if (!succeeded) return false; | 260 if (!succeeded) return false; |
261 Handle<SharedFunctionInfo> shared = info->shared_info(); | 261 Handle<SharedFunctionInfo> shared = info->shared_info(); |
262 shared->EnableDeoptimizationSupport(*unoptimized.code()); | 262 shared->EnableDeoptimizationSupport(*unoptimized.code()); |
263 // The existing unoptimized code was replaced with the new one. | 263 // The existing unoptimized code was replaced with the new one. |
264 Compiler::RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, | 264 Compiler::RecordFunctionCompilation( |
265 Handle<String>(shared->DebugName()), | 265 Logger::LAZY_COMPILE_TAG, &unoptimized, shared); |
266 shared->start_position(), | |
267 &unoptimized); | |
268 } | 266 } |
269 } | 267 } |
270 | 268 |
271 // Check that the unoptimized, shared code is ready for | 269 // Check that the unoptimized, shared code is ready for |
272 // optimizations. When using the always_opt flag we disregard the | 270 // optimizations. When using the always_opt flag we disregard the |
273 // optimizable marker in the code object and optimize anyway. This | 271 // optimizable marker in the code object and optimize anyway. This |
274 // is safe as long as the unoptimized code has deoptimization | 272 // is safe as long as the unoptimized code has deoptimization |
275 // support. | 273 // support. |
276 ASSERT(FLAG_always_opt || code->optimizable()); | 274 ASSERT(FLAG_always_opt || code->optimizable()); |
277 ASSERT(info->shared_info()->has_deoptimization_support()); | 275 ASSERT(info->shared_info()->has_deoptimization_support()); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 HistogramTimerScope timer(rate); | 405 HistogramTimerScope timer(rate); |
408 | 406 |
409 // Compile the code. | 407 // Compile the code. |
410 FunctionLiteral* lit = info->function(); | 408 FunctionLiteral* lit = info->function(); |
411 LiveEditFunctionTracker live_edit_tracker(lit); | 409 LiveEditFunctionTracker live_edit_tracker(lit); |
412 if (!MakeCode(info)) { | 410 if (!MakeCode(info)) { |
413 Top::StackOverflow(); | 411 Top::StackOverflow(); |
414 return Handle<SharedFunctionInfo>::null(); | 412 return Handle<SharedFunctionInfo>::null(); |
415 } | 413 } |
416 | 414 |
| 415 // Allocate function. |
417 ASSERT(!info->code().is_null()); | 416 ASSERT(!info->code().is_null()); |
| 417 Handle<SharedFunctionInfo> result = |
| 418 Factory::NewSharedFunctionInfo( |
| 419 lit->name(), |
| 420 lit->materialized_literal_count(), |
| 421 info->code(), |
| 422 SerializedScopeInfo::Create(info->scope())); |
| 423 |
| 424 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); |
| 425 Compiler::SetFunctionInfo(result, lit, true, script); |
| 426 |
418 if (script->name()->IsString()) { | 427 if (script->name()->IsString()) { |
419 PROFILE(CodeCreateEvent( | 428 PROFILE(CodeCreateEvent( |
420 info->is_eval() | 429 info->is_eval() |
421 ? Logger::EVAL_TAG | 430 ? Logger::EVAL_TAG |
422 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), | 431 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
423 *info->code(), | 432 *info->code(), |
| 433 *result, |
424 String::cast(script->name()))); | 434 String::cast(script->name()))); |
425 GDBJIT(AddCode(Handle<String>(String::cast(script->name())), | 435 GDBJIT(AddCode(Handle<String>(String::cast(script->name())), |
426 script, | 436 script, |
427 info->code())); | 437 info->code())); |
428 } else { | 438 } else { |
429 PROFILE(CodeCreateEvent( | 439 PROFILE(CodeCreateEvent( |
430 info->is_eval() | 440 info->is_eval() |
431 ? Logger::EVAL_TAG | 441 ? Logger::EVAL_TAG |
432 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), | 442 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script), |
433 *info->code(), | 443 *info->code(), |
434 "")); | 444 *result, |
| 445 Heap::empty_string())); |
435 GDBJIT(AddCode(Handle<String>(), script, info->code())); | 446 GDBJIT(AddCode(Handle<String>(), script, info->code())); |
436 } | 447 } |
437 | 448 |
438 // Allocate function. | |
439 Handle<SharedFunctionInfo> result = | |
440 Factory::NewSharedFunctionInfo( | |
441 lit->name(), | |
442 lit->materialized_literal_count(), | |
443 info->code(), | |
444 SerializedScopeInfo::Create(info->scope())); | |
445 | |
446 ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position()); | |
447 Compiler::SetFunctionInfo(result, lit, true, script); | |
448 | |
449 // Hint to the runtime system used when allocating space for initial | 449 // Hint to the runtime system used when allocating space for initial |
450 // property space by setting the expected number of properties for | 450 // property space by setting the expected number of properties for |
451 // the instances of the function. | 451 // the instances of the function. |
452 SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count()); | 452 SetExpectedNofPropertiesFromEstimate(result, lit->expected_property_count()); |
453 | 453 |
454 #ifdef ENABLE_DEBUGGER_SUPPORT | 454 #ifdef ENABLE_DEBUGGER_SUPPORT |
455 // Notify debugger | 455 // Notify debugger |
456 Debugger::OnAfterCompile(script, Debugger::NO_AFTER_COMPILE_FLAGS); | 456 Debugger::OnAfterCompile(script, Debugger::NO_AFTER_COMPILE_FLAGS); |
457 #endif | 457 #endif |
458 | 458 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 | 605 |
606 // Compile the code. | 606 // Compile the code. |
607 if (!MakeCode(info)) { | 607 if (!MakeCode(info)) { |
608 if (!Top::has_pending_exception()) { | 608 if (!Top::has_pending_exception()) { |
609 Top::StackOverflow(); | 609 Top::StackOverflow(); |
610 } | 610 } |
611 } else { | 611 } else { |
612 ASSERT(!info->code().is_null()); | 612 ASSERT(!info->code().is_null()); |
613 Handle<Code> code = info->code(); | 613 Handle<Code> code = info->code(); |
614 Handle<JSFunction> function = info->closure(); | 614 Handle<JSFunction> function = info->closure(); |
615 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, | 615 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
616 Handle<String>(shared->DebugName()), | |
617 shared->start_position(), | |
618 info); | |
619 | 616 |
620 if (info->IsOptimizing()) { | 617 if (info->IsOptimizing()) { |
621 function->ReplaceCode(*code); | 618 function->ReplaceCode(*code); |
622 } else { | 619 } else { |
623 // Update the shared function info with the compiled code and the | 620 // Update the shared function info with the compiled code and the |
624 // scope info. Please note, that the order of the shared function | 621 // scope info. Please note, that the order of the shared function |
625 // info initialization is important since set_scope_info might | 622 // info initialization is important since set_scope_info might |
626 // trigger a GC, causing the ASSERT below to be invalid if the code | 623 // trigger a GC, causing the ASSERT below to be invalid if the code |
627 // was flushed. By settting the code object last we avoid this. | 624 // was flushed. By settting the code object last we avoid this. |
628 Handle<SerializedScopeInfo> scope_info = | 625 Handle<SerializedScopeInfo> scope_info = |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 // We fall back to the classic V8 code generator. | 713 // We fall back to the classic V8 code generator. |
717 if (!AssignedVariablesAnalyzer::Analyze(&info) || | 714 if (!AssignedVariablesAnalyzer::Analyze(&info) || |
718 !CodeGenerator::MakeCode(&info)) { | 715 !CodeGenerator::MakeCode(&info)) { |
719 return Handle<SharedFunctionInfo>::null(); | 716 return Handle<SharedFunctionInfo>::null(); |
720 } | 717 } |
721 } | 718 } |
722 } | 719 } |
723 ASSERT(!info.code().is_null()); | 720 ASSERT(!info.code().is_null()); |
724 | 721 |
725 // Function compilation complete. | 722 // Function compilation complete. |
726 RecordFunctionCompilation(Logger::FUNCTION_TAG, | |
727 literal->debug_name(), | |
728 literal->start_position(), | |
729 &info); | |
730 scope_info = SerializedScopeInfo::Create(info.scope()); | 723 scope_info = SerializedScopeInfo::Create(info.scope()); |
731 } | 724 } |
732 | 725 |
733 // Create a shared function info object. | 726 // Create a shared function info object. |
734 Handle<SharedFunctionInfo> result = | 727 Handle<SharedFunctionInfo> result = |
735 Factory::NewSharedFunctionInfo(literal->name(), | 728 Factory::NewSharedFunctionInfo(literal->name(), |
736 literal->materialized_literal_count(), | 729 literal->materialized_literal_count(), |
737 info.code(), | 730 info.code(), |
738 scope_info); | 731 scope_info); |
739 SetFunctionInfo(result, literal, false, script); | 732 SetFunctionInfo(result, literal, false, script); |
| 733 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
740 result->set_allows_lazy_compilation(allow_lazy); | 734 result->set_allows_lazy_compilation(allow_lazy); |
741 | 735 |
742 // Set the expected number of properties for instances and return | 736 // Set the expected number of properties for instances and return |
743 // the resulting function. | 737 // the resulting function. |
744 SetExpectedNofPropertiesFromEstimate(result, | 738 SetExpectedNofPropertiesFromEstimate(result, |
745 literal->expected_property_count()); | 739 literal->expected_property_count()); |
746 live_edit_tracker.RecordFunctionInfo(result, literal); | 740 live_edit_tracker.RecordFunctionInfo(result, literal); |
747 return result; | 741 return result; |
748 } | 742 } |
749 | 743 |
(...skipping 18 matching lines...) Expand all Loading... |
768 function_info->SetThisPropertyAssignmentsInfo( | 762 function_info->SetThisPropertyAssignmentsInfo( |
769 lit->has_only_simple_this_property_assignments(), | 763 lit->has_only_simple_this_property_assignments(), |
770 *lit->this_property_assignments()); | 764 *lit->this_property_assignments()); |
771 function_info->set_try_full_codegen(lit->try_full_codegen()); | 765 function_info->set_try_full_codegen(lit->try_full_codegen()); |
772 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); | 766 function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation()); |
773 function_info->set_strict_mode(lit->strict_mode()); | 767 function_info->set_strict_mode(lit->strict_mode()); |
774 } | 768 } |
775 | 769 |
776 | 770 |
777 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 771 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
778 Handle<String> name, | 772 CompilationInfo* info, |
779 int start_position, | 773 Handle<SharedFunctionInfo> shared) { |
780 CompilationInfo* info) { | |
781 // Log the code generation. If source information is available include | 774 // Log the code generation. If source information is available include |
782 // script name and line number. Check explicitly whether logging is | 775 // script name and line number. Check explicitly whether logging is |
783 // enabled as finding the line number is not free. | 776 // enabled as finding the line number is not free. |
784 if (Logger::is_logging() || | 777 if (Logger::is_logging() || |
785 CpuProfiler::is_profiling()) { | 778 CpuProfiler::is_profiling()) { |
786 Handle<Script> script = info->script(); | 779 Handle<Script> script = info->script(); |
787 Handle<Code> code = info->code(); | 780 Handle<Code> code = info->code(); |
788 if (script->name()->IsString()) { | 781 if (script->name()->IsString()) { |
789 int line_num = GetScriptLineNumber(script, start_position) + 1; | 782 int line_num = GetScriptLineNumber(script, shared->start_position()) + 1; |
790 USE(line_num); | 783 USE(line_num); |
791 PROFILE(CodeCreateEvent(Logger::ToNativeByScript(tag, *script), | 784 PROFILE(CodeCreateEvent(Logger::ToNativeByScript(tag, *script), |
792 *code, | 785 *code, |
793 *name, | 786 *shared, |
794 String::cast(script->name()), | 787 String::cast(script->name()), |
795 line_num)); | 788 line_num)); |
796 } else { | 789 } else { |
797 PROFILE(CodeCreateEvent(Logger::ToNativeByScript(tag, *script), | 790 PROFILE(CodeCreateEvent(Logger::ToNativeByScript(tag, *script), |
798 *code, | 791 *code, |
799 *name)); | 792 *shared, |
| 793 shared->DebugName())); |
800 } | 794 } |
801 } | 795 } |
802 | 796 |
803 GDBJIT(AddCode(name, | 797 GDBJIT(AddCode(name, |
804 Handle<Script>(info->script()), | 798 Handle<Script>(info->script()), |
805 Handle<Code>(info->code()))); | 799 Handle<Code>(info->code()))); |
806 } | 800 } |
807 | 801 |
808 } } // namespace v8::internal | 802 } } // namespace v8::internal |
OLD | NEW |