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

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: Created 8 years, 6 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
« no previous file with comments | « src/arm/lithium-codegen-arm.cc ('k') | src/deoptimizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 609
610 // The VM is in the COMPILER state until exiting this function. 610 // The VM is in the COMPILER state until exiting this function.
611 VMState state(isolate, COMPILER); 611 VMState state(isolate, COMPILER);
612 612
613 PostponeInterruptsScope postpone(isolate); 613 PostponeInterruptsScope postpone(isolate);
614 614
615 Handle<SharedFunctionInfo> shared = info->shared_info(); 615 Handle<SharedFunctionInfo> shared = info->shared_info();
616 int compiled_size = shared->end_position() - shared->start_position(); 616 int compiled_size = shared->end_position() - shared->start_position();
617 isolate->counters()->total_compile_size()->Increment(compiled_size); 617 isolate->counters()->total_compile_size()->Increment(compiled_size);
618 618
619 if (FLAG_cache_optimized_code && info->IsOptimizing()) {
620 Handle<JSFunction> function = info->closure();
621 ASSERT(!function.is_null());
622 Handle<Context> global_context(function->context()->global_context());
623 int index = function->shared()->SearchOptimizedCodeMap(*global_context);
624 if (index > 0) {
625 if (FLAG_trace_opt) {
626 PrintF(" [Found optimized code for");
627 function->PrintName();
628 PrintF("\n");
629 }
630 Code* code = Code::cast(
631 FixedArray::cast(shared->optimized_code_map())->get(index));
632 ASSERT(code != NULL);
633 function->ReplaceCode(code);
634 return true;
635 }
636 }
637
619 // Generate the AST for the lazily compiled function. 638 // Generate the AST for the lazily compiled function.
620 if (ParserApi::Parse(info, kNoParsingFlags)) { 639 if (ParserApi::Parse(info, kNoParsingFlags)) {
621 // Measure how long it takes to do the lazy compilation; only take the 640 // Measure how long it takes to do the lazy compilation; only take the
622 // rest of the function into account to avoid overlap with the lazy 641 // rest of the function into account to avoid overlap with the lazy
623 // parsing statistics. 642 // parsing statistics.
624 HistogramTimerScope timer(isolate->counters()->compile_lazy()); 643 HistogramTimerScope timer(isolate->counters()->compile_lazy());
625 644
626 // After parsing we know the function's language mode. Remember it. 645 // After parsing we know the function's language mode. Remember it.
627 LanguageMode language_mode = info->function()->language_mode(); 646 LanguageMode language_mode = info->function()->language_mode();
628 info->SetLanguageMode(language_mode); 647 info->SetLanguageMode(language_mode);
(...skipping 11 matching lines...) Expand all
640 // function info, e.g., we might have flushed the code and must 659 // function info, e.g., we might have flushed the code and must
641 // reset this bit when lazy compiling the code again. 660 // reset this bit when lazy compiling the code again.
642 if (shared->optimization_disabled()) code->set_optimizable(false); 661 if (shared->optimization_disabled()) code->set_optimizable(false);
643 662
644 Handle<JSFunction> function = info->closure(); 663 Handle<JSFunction> function = info->closure();
645 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); 664 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared);
646 665
647 if (info->IsOptimizing()) { 666 if (info->IsOptimizing()) {
648 ASSERT(shared->scope_info() != ScopeInfo::Empty()); 667 ASSERT(shared->scope_info() != ScopeInfo::Empty());
649 function->ReplaceCode(*code); 668 function->ReplaceCode(*code);
669 if (FLAG_cache_optimized_code &&
670 code->kind() == Code::OPTIMIZED_FUNCTION) {
671 Handle<SharedFunctionInfo> shared(function->shared());
672 Handle<Context> global_context(function->context()->global_context());
673
674 // Create literals array that will be shared for this global context.
675 int number_of_literals = shared->num_literals();
676 Handle<FixedArray> literals =
677 isolate->factory()->NewFixedArray(number_of_literals);
678 if (number_of_literals > 0) {
679 // Store the object, regexp and array functions in the literals
680 // array prefix. These functions will be used when creating
681 // object, regexp and array literals in this function.
682 literals->set(JSFunction::kLiteralGlobalContextIndex,
683 function->context()->global_context());
684 }
685
686 SharedFunctionInfo::AddToOptimizedCodeMap(
687 shared, global_context, code, literals);
688 }
650 } else { 689 } else {
651 // Update the shared function info with the compiled code and the 690 // Update the shared function info with the compiled code and the
652 // scope info. Please note, that the order of the shared function 691 // scope info. Please note, that the order of the shared function
653 // info initialization is important since set_scope_info might 692 // info initialization is important since set_scope_info might
654 // trigger a GC, causing the ASSERT below to be invalid if the code 693 // trigger a GC, causing the ASSERT below to be invalid if the code
655 // was flushed. By setting the code object last we avoid this. 694 // was flushed. By setting the code object last we avoid this.
656 Handle<ScopeInfo> scope_info = 695 Handle<ScopeInfo> scope_info =
657 ScopeInfo::Create(info->scope(), info->isolate()->zone()); 696 ScopeInfo::Create(info->scope(), info->isolate()->zone());
658 shared->set_scope_info(*scope_info); 697 shared->set_scope_info(*scope_info);
659 shared->set_code(*code); 698 shared->set_code(*code);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 859 }
821 } 860 }
822 861
823 GDBJIT(AddCode(Handle<String>(shared->DebugName()), 862 GDBJIT(AddCode(Handle<String>(shared->DebugName()),
824 Handle<Script>(info->script()), 863 Handle<Script>(info->script()),
825 Handle<Code>(info->code()), 864 Handle<Code>(info->code()),
826 info)); 865 info));
827 } 866 }
828 867
829 } } // namespace v8::internal 868 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-codegen-arm.cc ('k') | src/deoptimizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698