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

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