Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: src/compiler.cc

Issue 10103035: Share optimized code for closures. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: added x64 and ARM ports Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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...) Expand 10 before | Expand all | Expand 10 after
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,
Michael Starzinger 2012/05/23 11:16:29 Can we move this into the the SharedFunctionInfo c
fschneider 2012/06/14 11:08:23 Done.
604 Handle<Context> global_context,
605 Handle<Code> code,
606 Handle<FixedArray> literals) {
607 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
608 ASSERT(global_context->IsGlobalContext());
609 const int kEntryLength = 3;
Michael Starzinger 2012/05/23 11:16:29 Moving these constants into SharedFunctionInfo and
fschneider 2012/06/14 11:08:23 Done.
610 Object* value = shared->optimized_code_map();
611 Handle<FixedArray> new_map;
612 if (value->IsSmi()) {
613 // No optimized code map.
614 ASSERT_EQ(0, Smi::cast(value)->value());
615 // Crate 3 entries per context {context, code, literals}.
616 new_map = FACTORY->NewFixedArray(kEntryLength);
617 new_map->set(0, *global_context);
618 new_map->set(1, *code);
619 new_map->set(2, *literals);
620 } else {
621 Handle<FixedArray> old_map(FixedArray::cast(value));
622 ASSERT_EQ(-1, shared->SearchOptimizedCodeMap(*global_context));
623 int old_length = old_map->length();
624 int new_length = old_length + kEntryLength;
625 new_map = FACTORY->NewFixedArray(new_length);
626 for (int i = 0; i < old_length; i += kEntryLength) {
Michael Starzinger 2012/05/23 11:16:29 Can we use FixedArray::CopyTo or even a handlified
fschneider 2012/06/14 11:08:23 Done.
627 new_map->set(i, old_map->get(i));
628 new_map->set(i + 1, old_map->get(i + 1));
629 new_map->set(i + 2, old_map->get(i + 2));
630 }
631 new_map->set(old_length, *global_context);
632 new_map->set(old_length + 1, *code);
633 new_map->set(old_length + 2, *literals);
634 }
635 #ifdef DEBUG
636 for (int i = 0; i < new_map->length(); i += kEntryLength) {
637 ASSERT(new_map->get(i)->IsGlobalContext());
638 ASSERT(new_map->get(i + 1)->IsCode());
639 ASSERT(Code::cast(new_map->get(i + 1))->kind() == Code::OPTIMIZED_FUNCTION);
640 ASSERT(new_map->get(i + 2)->IsFixedArray());
641 }
642 #endif
643 shared->set_optimized_code_map(*new_map);
644 }
645
646
603 bool Compiler::CompileLazy(CompilationInfo* info) { 647 bool Compiler::CompileLazy(CompilationInfo* info) {
604 Isolate* isolate = info->isolate(); 648 Isolate* isolate = info->isolate();
605 649
606 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); 650 ZoneScope zone_scope(isolate, DELETE_ON_EXIT);
607 651
608 // The VM is in the COMPILER state until exiting this function. 652 // The VM is in the COMPILER state until exiting this function.
609 VMState state(isolate, COMPILER); 653 VMState state(isolate, COMPILER);
610 654
611 PostponeInterruptsScope postpone(isolate); 655 PostponeInterruptsScope postpone(isolate);
612 656
613 Handle<SharedFunctionInfo> shared = info->shared_info(); 657 Handle<SharedFunctionInfo> shared = info->shared_info();
614 int compiled_size = shared->end_position() - shared->start_position(); 658 int compiled_size = shared->end_position() - shared->start_position();
615 isolate->counters()->total_compile_size()->Increment(compiled_size); 659 isolate->counters()->total_compile_size()->Increment(compiled_size);
616 660
661 if (FLAG_cache_optimized_code && info->IsOptimizing()) {
662 Handle<JSFunction> function = info->closure();
663 ASSERT(!function.is_null());
664 Handle<Context> global_context(function->context()->global_context());
665 int index = function->shared()->SearchOptimizedCodeMap(*global_context);
666 if (index > 0) {
667 if (FLAG_trace_opt) {
668 PrintF(" [Found optimized code for");
669 function->PrintName();
670 PrintF("\n");
671 }
672 Code* code = Code::cast(
673 FixedArray::cast(shared->optimized_code_map())->get(index));
674 ASSERT(code != NULL);
675 function->ReplaceCode(code);
676 return true;
677 }
678 }
679
617 // Generate the AST for the lazily compiled function. 680 // Generate the AST for the lazily compiled function.
618 if (ParserApi::Parse(info, kNoParsingFlags)) { 681 if (ParserApi::Parse(info, kNoParsingFlags)) {
619 // Measure how long it takes to do the lazy compilation; only take the 682 // 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 683 // rest of the function into account to avoid overlap with the lazy
621 // parsing statistics. 684 // parsing statistics.
622 HistogramTimerScope timer(isolate->counters()->compile_lazy()); 685 HistogramTimerScope timer(isolate->counters()->compile_lazy());
623 686
624 // After parsing we know the function's language mode. Remember it. 687 // After parsing we know the function's language mode. Remember it.
625 LanguageMode language_mode = info->function()->language_mode(); 688 LanguageMode language_mode = info->function()->language_mode();
626 info->SetLanguageMode(language_mode); 689 info->SetLanguageMode(language_mode);
(...skipping 11 matching lines...) Expand all
638 // function info, e.g., we might have flushed the code and must 701 // function info, e.g., we might have flushed the code and must
639 // reset this bit when lazy compiling the code again. 702 // reset this bit when lazy compiling the code again.
640 if (shared->optimization_disabled()) code->set_optimizable(false); 703 if (shared->optimization_disabled()) code->set_optimizable(false);
641 704
642 Handle<JSFunction> function = info->closure(); 705 Handle<JSFunction> function = info->closure();
643 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); 706 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
644 707
645 if (info->IsOptimizing()) { 708 if (info->IsOptimizing()) {
646 ASSERT(shared->scope_info() != ScopeInfo::Empty()); 709 ASSERT(shared->scope_info() != ScopeInfo::Empty());
647 function->ReplaceCode(*code); 710 function->ReplaceCode(*code);
711 if (FLAG_cache_optimized_code &&
712 code->kind() == Code::OPTIMIZED_FUNCTION) {
713 Handle<SharedFunctionInfo> shared(function->shared());
714 Handle<Context> global_context(function->context()->global_context());
715
716 // Create literals array that will be shared for this global context.
717 int number_of_literals = shared->num_literals();
718 Handle<FixedArray> literals =
719 isolate->factory()->NewFixedArray(number_of_literals);
720 if (number_of_literals > 0) {
721 // Store the object, regexp and array functions in the literals
722 // array prefix. These functions will be used when creating
723 // object, regexp and array literals in this function.
724 literals->set(JSFunction::kLiteralGlobalContextIndex,
725 function->context()->global_context());
726 }
727
728 AddToOptimizedCodeMap(shared, global_context, code, literals);
729 }
648 } else { 730 } else {
649 // Update the shared function info with the compiled code and the 731 // Update the shared function info with the compiled code and the
650 // scope info. Please note, that the order of the shared function 732 // scope info. Please note, that the order of the shared function
651 // info initialization is important since set_scope_info might 733 // info initialization is important since set_scope_info might
652 // trigger a GC, causing the ASSERT below to be invalid if the code 734 // 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. 735 // was flushed. By setting the code object last we avoid this.
654 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope()); 736 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope());
655 shared->set_scope_info(*scope_info); 737 shared->set_scope_info(*scope_info);
656 shared->set_code(*code); 738 shared->set_code(*code);
657 if (!function.is_null()) { 739 if (!function.is_null()) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 899 }
818 } 900 }
819 901
820 GDBJIT(AddCode(Handle<String>(shared->DebugName()), 902 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
821 Handle<Script>(info->script()), 903 Handle<Script>(info->script()),
822 Handle<Code>(info->code()), 904 Handle<Code>(info->code()),
823 info)); 905 info));
824 } 906 }
825 907
826 } } // namespace v8::internal 908 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-codegen-arm.cc ('k') | src/deoptimizer.h » ('j') | src/factory.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698