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 582 matching lines...) Loading... |
593 } else { | 593 } else { |
594 if (result->ic_age() != HEAP->global_ic_age()) { | 594 if (result->ic_age() != HEAP->global_ic_age()) { |
595 result->ResetForNewContext(HEAP->global_ic_age()); | 595 result->ResetForNewContext(HEAP->global_ic_age()); |
596 } | 596 } |
597 } | 597 } |
598 | 598 |
599 return result; | 599 return result; |
600 } | 600 } |
601 | 601 |
602 | 602 |
| 603 static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 604 Handle<Context> global_context, |
| 605 Handle<Code> code) { |
| 606 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
| 607 ASSERT(global_context->IsGlobalContext()); |
| 608 |
| 609 Object* value = shared->optimized_code_map(); |
| 610 Handle<FixedArray> new_map; |
| 611 if (value->IsSmi()) { |
| 612 // No optimized code map. |
| 613 ASSERT_EQ(0, Smi::cast(value)->value()); |
| 614 new_map = FACTORY->NewFixedArray(2); |
| 615 new_map->set(0, *global_context); |
| 616 new_map->set(1, *code); |
| 617 } else { |
| 618 Handle<FixedArray> old_map(FixedArray::cast(value)); |
| 619 ASSERT_EQ(NULL, shared->SearchOptimizedCodeMap(*global_context)); |
| 620 int old_length = old_map->length(); |
| 621 int new_length = old_length + 2; |
| 622 new_map = FACTORY->NewFixedArray(new_length); |
| 623 for (int i = 0; i < old_length; i += 2) { |
| 624 new_map->set(i, old_map->get(i)); |
| 625 new_map->set(i + 1, old_map->get(i + 1)); |
| 626 } |
| 627 new_map->set(old_length, *global_context); |
| 628 new_map->set(old_length + 1, *code); |
| 629 } |
| 630 #ifdef DEBUG |
| 631 for (int i = 0; i < new_map->length(); i += 2) { |
| 632 ASSERT(new_map->get(i)->IsGlobalContext()); |
| 633 ASSERT(new_map->get(i + 1)->IsCode()); |
| 634 ASSERT(Code::cast(new_map->get(i + 1))->kind() == Code::OPTIMIZED_FUNCTION); |
| 635 } |
| 636 #endif |
| 637 shared->set_optimized_code_map(*new_map); |
| 638 } |
| 639 |
| 640 |
603 bool Compiler::CompileLazy(CompilationInfo* info) { | 641 bool Compiler::CompileLazy(CompilationInfo* info) { |
604 Isolate* isolate = info->isolate(); | 642 Isolate* isolate = info->isolate(); |
605 | 643 |
606 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 644 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); |
607 | 645 |
608 // The VM is in the COMPILER state until exiting this function. | 646 // The VM is in the COMPILER state until exiting this function. |
609 VMState state(isolate, COMPILER); | 647 VMState state(isolate, COMPILER); |
610 | 648 |
611 PostponeInterruptsScope postpone(isolate); | 649 PostponeInterruptsScope postpone(isolate); |
612 | 650 |
613 Handle<SharedFunctionInfo> shared = info->shared_info(); | 651 Handle<SharedFunctionInfo> shared = info->shared_info(); |
614 int compiled_size = shared->end_position() - shared->start_position(); | 652 int compiled_size = shared->end_position() - shared->start_position(); |
615 isolate->counters()->total_compile_size()->Increment(compiled_size); | 653 isolate->counters()->total_compile_size()->Increment(compiled_size); |
616 | 654 |
| 655 if (FLAG_cache_optimized_code |
| 656 && info->IsOptimizing() /*&& info->osr_ast_id() == -1*/) { |
| 657 Handle<JSFunction> function = info->closure(); |
| 658 ASSERT(!function.is_null()); |
| 659 Handle<Context> global_context(function->context()->global_context()); |
| 660 Code* code = function->shared()->SearchOptimizedCodeMap(*global_context); |
| 661 if (code != NULL) { |
| 662 if (FLAG_trace_opt) { |
| 663 PrintF(" [Found optimized code for"); |
| 664 function->PrintName(); |
| 665 PrintF("\n"); |
| 666 } |
| 667 function->ReplaceCode(code); |
| 668 return true; |
| 669 } |
| 670 } |
| 671 |
617 // Generate the AST for the lazily compiled function. | 672 // Generate the AST for the lazily compiled function. |
618 if (ParserApi::Parse(info, kNoParsingFlags)) { | 673 if (ParserApi::Parse(info, kNoParsingFlags)) { |
619 // Measure how long it takes to do the lazy compilation; only take the | 674 // Measure how long it takes to do the lazy compilation; only take the |
620 // rest of the function into account to avoid overlap with the lazy | 675 // rest of the function into account to avoid overlap with the lazy |
621 // parsing statistics. | 676 // parsing statistics. |
622 HistogramTimerScope timer(isolate->counters()->compile_lazy()); | 677 HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
623 | 678 |
624 // After parsing we know the function's language mode. Remember it. | 679 // After parsing we know the function's language mode. Remember it. |
625 LanguageMode language_mode = info->function()->language_mode(); | 680 LanguageMode language_mode = info->function()->language_mode(); |
626 info->SetLanguageMode(language_mode); | 681 info->SetLanguageMode(language_mode); |
(...skipping 11 matching lines...) Loading... |
638 // function info, e.g., we might have flushed the code and must | 693 // function info, e.g., we might have flushed the code and must |
639 // reset this bit when lazy compiling the code again. | 694 // reset this bit when lazy compiling the code again. |
640 if (shared->optimization_disabled()) code->set_optimizable(false); | 695 if (shared->optimization_disabled()) code->set_optimizable(false); |
641 | 696 |
642 Handle<JSFunction> function = info->closure(); | 697 Handle<JSFunction> function = info->closure(); |
643 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 698 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
644 | 699 |
645 if (info->IsOptimizing()) { | 700 if (info->IsOptimizing()) { |
646 ASSERT(shared->scope_info() != ScopeInfo::Empty()); | 701 ASSERT(shared->scope_info() != ScopeInfo::Empty()); |
647 function->ReplaceCode(*code); | 702 function->ReplaceCode(*code); |
| 703 if (FLAG_cache_optimized_code && |
| 704 code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 705 Handle<SharedFunctionInfo> shared(function->shared()); |
| 706 Handle<Context> global_context(function->context()->global_context()); |
| 707 AddToOptimizedCodeMap(shared, global_context, code); |
| 708 } |
648 } else { | 709 } else { |
649 // Update the shared function info with the compiled code and the | 710 // Update the shared function info with the compiled code and the |
650 // scope info. Please note, that the order of the shared function | 711 // scope info. Please note, that the order of the shared function |
651 // info initialization is important since set_scope_info might | 712 // info initialization is important since set_scope_info might |
652 // trigger a GC, causing the ASSERT below to be invalid if the code | 713 // trigger a GC, causing the ASSERT below to be invalid if the code |
653 // was flushed. By setting the code object last we avoid this. | 714 // was flushed. By setting the code object last we avoid this. |
654 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope()); | 715 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope()); |
655 shared->set_scope_info(*scope_info); | 716 shared->set_scope_info(*scope_info); |
656 shared->set_code(*code); | 717 shared->set_code(*code); |
657 if (!function.is_null()) { | 718 if (!function.is_null()) { |
(...skipping 159 matching lines...) Loading... |
817 } | 878 } |
818 } | 879 } |
819 | 880 |
820 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 881 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
821 Handle<Script>(info->script()), | 882 Handle<Script>(info->script()), |
822 Handle<Code>(info->code()), | 883 Handle<Code>(info->code()), |
823 info)); | 884 info)); |
824 } | 885 } |
825 | 886 |
826 } } // namespace v8::internal | 887 } } // namespace v8::internal |
OLD | NEW |