OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 PostponeInterruptsScope postpone(isolate); | 616 PostponeInterruptsScope postpone(isolate); |
617 | 617 |
618 Handle<SharedFunctionInfo> shared = info->shared_info(); | 618 Handle<SharedFunctionInfo> shared = info->shared_info(); |
619 int compiled_size = shared->end_position() - shared->start_position(); | 619 int compiled_size = shared->end_position() - shared->start_position(); |
620 isolate->counters()->total_compile_size()->Increment(compiled_size); | 620 isolate->counters()->total_compile_size()->Increment(compiled_size); |
621 | 621 |
622 if (FLAG_cache_optimized_code && info->IsOptimizing()) { | 622 if (FLAG_cache_optimized_code && info->IsOptimizing()) { |
623 Handle<JSFunction> function = info->closure(); | 623 Handle<JSFunction> function = info->closure(); |
624 ASSERT(!function.is_null()); | 624 ASSERT(!function.is_null()); |
625 Handle<Context> global_context(function->context()->global_context()); | 625 Handle<Context> global_context(function->context()->global_context()); |
626 int index = function->shared()->SearchOptimizedCodeMap(*global_context); | 626 int index = shared->SearchOptimizedCodeMap(*global_context); |
627 if (index > 0) { | 627 if (index > 0) { |
628 if (FLAG_trace_opt) { | 628 if (FLAG_trace_opt) { |
629 PrintF(" [Found optimized code for"); | 629 PrintF("[found optimized code for: "); |
630 function->PrintName(); | 630 function->PrintName(); |
631 PrintF("\n"); | 631 PrintF(" / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(*function)); |
632 } | 632 } |
633 Code* code = Code::cast( | 633 // Caching of optimized code enabled and optimized code found. |
634 FixedArray::cast(shared->optimized_code_map())->get(index)); | 634 shared->InstallFromOptimizedCodeMap(*function, index); |
635 ASSERT(code != NULL); | |
636 function->ReplaceCode(code); | |
637 return true; | 635 return true; |
638 } | 636 } |
639 } | 637 } |
640 | 638 |
641 // Generate the AST for the lazily compiled function. | 639 // Generate the AST for the lazily compiled function. |
642 if (ParserApi::Parse(info, kNoParsingFlags)) { | 640 if (ParserApi::Parse(info, kNoParsingFlags)) { |
643 // Measure how long it takes to do the lazy compilation; only take the | 641 // Measure how long it takes to do the lazy compilation; only take the |
644 // rest of the function into account to avoid overlap with the lazy | 642 // rest of the function into account to avoid overlap with the lazy |
645 // parsing statistics. | 643 // parsing statistics. |
646 HistogramTimerScope timer(isolate->counters()->compile_lazy()); | 644 HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
(...skipping 18 matching lines...) Expand all Loading... |
665 | 663 |
666 Handle<JSFunction> function = info->closure(); | 664 Handle<JSFunction> function = info->closure(); |
667 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 665 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
668 | 666 |
669 if (info->IsOptimizing()) { | 667 if (info->IsOptimizing()) { |
670 ASSERT(shared->scope_info() != ScopeInfo::Empty()); | 668 ASSERT(shared->scope_info() != ScopeInfo::Empty()); |
671 function->ReplaceCode(*code); | 669 function->ReplaceCode(*code); |
672 if (FLAG_cache_optimized_code && | 670 if (FLAG_cache_optimized_code && |
673 code->kind() == Code::OPTIMIZED_FUNCTION) { | 671 code->kind() == Code::OPTIMIZED_FUNCTION) { |
674 Handle<SharedFunctionInfo> shared(function->shared()); | 672 Handle<SharedFunctionInfo> shared(function->shared()); |
| 673 Handle<FixedArray> literals(function->literals()); |
675 Handle<Context> global_context(function->context()->global_context()); | 674 Handle<Context> global_context(function->context()->global_context()); |
676 | |
677 // Create literals array that will be shared for this global context. | |
678 int number_of_literals = shared->num_literals(); | |
679 Handle<FixedArray> literals = | |
680 isolate->factory()->NewFixedArray(number_of_literals); | |
681 if (number_of_literals > 0) { | |
682 // Store the object, regexp and array functions in the literals | |
683 // array prefix. These functions will be used when creating | |
684 // object, regexp and array literals in this function. | |
685 literals->set(JSFunction::kLiteralGlobalContextIndex, | |
686 function->context()->global_context()); | |
687 } | |
688 | |
689 SharedFunctionInfo::AddToOptimizedCodeMap( | 675 SharedFunctionInfo::AddToOptimizedCodeMap( |
690 shared, global_context, code, literals); | 676 shared, global_context, code, literals); |
691 } | 677 } |
692 } else { | 678 } else { |
693 // Update the shared function info with the compiled code and the | 679 // Update the shared function info with the compiled code and the |
694 // scope info. Please note, that the order of the shared function | 680 // scope info. Please note, that the order of the shared function |
695 // info initialization is important since set_scope_info might | 681 // info initialization is important since set_scope_info might |
696 // trigger a GC, causing the ASSERT below to be invalid if the code | 682 // trigger a GC, causing the ASSERT below to be invalid if the code |
697 // was flushed. By setting the code object last we avoid this. | 683 // was flushed. By setting the code object last we avoid this. |
698 Handle<ScopeInfo> scope_info = | 684 Handle<ScopeInfo> scope_info = |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 } | 857 } |
872 } | 858 } |
873 | 859 |
874 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 860 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
875 Handle<Script>(info->script()), | 861 Handle<Script>(info->script()), |
876 Handle<Code>(info->code()), | 862 Handle<Code>(info->code()), |
877 info)); | 863 info)); |
878 } | 864 } |
879 | 865 |
880 } } // namespace v8::internal | 866 } } // namespace v8::internal |
OLD | NEW |