OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 // eval("'use strict'; ..."); | 577 // eval("'use strict'; ..."); |
578 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); | 578 ASSERT(strict_mode == kNonStrictMode || result->strict_mode()); |
579 compilation_cache->PutEval(source, context, is_global, result); | 579 compilation_cache->PutEval(source, context, is_global, result); |
580 } | 580 } |
581 } | 581 } |
582 | 582 |
583 return result; | 583 return result; |
584 } | 584 } |
585 | 585 |
586 | 586 |
| 587 static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 588 Handle<Context> global_context, |
| 589 Handle<Code> code) { |
| 590 ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
| 591 ASSERT(global_context->IsGlobalContext()); |
| 592 |
| 593 Object* value = shared->optimized_code_map(); |
| 594 Handle<FixedArray> new_map; |
| 595 if (value->IsSmi()) { |
| 596 // No optimized code map. |
| 597 ASSERT_EQ(0, Smi::cast(value)->value()); |
| 598 new_map = FACTORY->NewFixedArray(2); |
| 599 new_map->set(0, *global_context); |
| 600 new_map->set(1, *code); |
| 601 } else { |
| 602 Handle<FixedArray> old_map(FixedArray::cast(value)); |
| 603 ASSERT_EQ(NULL, shared->SearchOptimizedCodeMap(*global_context)); |
| 604 int old_length = old_map->length(); |
| 605 int new_length = old_length + 2; |
| 606 new_map = FACTORY->NewFixedArray(new_length); |
| 607 for (int i = 0; i < old_length; i += 2) { |
| 608 new_map->set(i, old_map->get(i)); |
| 609 new_map->set(i + 1, old_map->get(i + 1)); |
| 610 } |
| 611 new_map->set(old_length, *global_context); |
| 612 new_map->set(old_length + 1, *code); |
| 613 } |
| 614 #ifdef DEBUG |
| 615 for (int i = 0; i < new_map->length(); i += 2) { |
| 616 ASSERT(new_map->get(i)->IsGlobalContext()); |
| 617 ASSERT(new_map->get(i + 1)->IsCode()); |
| 618 ASSERT(Code::cast(new_map->get(i + 1))->kind() == Code::OPTIMIZED_FUNCTION); |
| 619 } |
| 620 #endif |
| 621 shared->set_optimized_code_map(*new_map); |
| 622 } |
| 623 |
| 624 |
587 bool Compiler::CompileLazy(CompilationInfo* info) { | 625 bool Compiler::CompileLazy(CompilationInfo* info) { |
588 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 626 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
589 | 627 |
590 // The VM is in the COMPILER state until exiting this function. | 628 // The VM is in the COMPILER state until exiting this function. |
591 VMState state(info->isolate(), COMPILER); | 629 VMState state(info->isolate(), COMPILER); |
592 | 630 |
593 Isolate* isolate = info->isolate(); | 631 Isolate* isolate = info->isolate(); |
594 PostponeInterruptsScope postpone(isolate); | 632 PostponeInterruptsScope postpone(isolate); |
595 | 633 |
596 Handle<SharedFunctionInfo> shared = info->shared_info(); | 634 Handle<SharedFunctionInfo> shared = info->shared_info(); |
597 int compiled_size = shared->end_position() - shared->start_position(); | 635 int compiled_size = shared->end_position() - shared->start_position(); |
598 isolate->counters()->total_compile_size()->Increment(compiled_size); | 636 isolate->counters()->total_compile_size()->Increment(compiled_size); |
599 | 637 |
| 638 if (FLAG_cache_optimized_code |
| 639 && info->IsOptimizing() && info->osr_ast_id() == -1) { |
| 640 Handle<JSFunction> function = info->closure(); |
| 641 ASSERT(!function.is_null()); |
| 642 Handle<Context> global_context(function->context()->global_context()); |
| 643 Code* code = function->shared()->SearchOptimizedCodeMap(*global_context); |
| 644 if (code != NULL) { |
| 645 function->ReplaceCode(code); |
| 646 return true; |
| 647 } |
| 648 } |
| 649 |
600 // Generate the AST for the lazily compiled function. | 650 // Generate the AST for the lazily compiled function. |
601 if (ParserApi::Parse(info)) { | 651 if (ParserApi::Parse(info)) { |
602 // Measure how long it takes to do the lazy compilation; only take the | 652 // Measure how long it takes to do the lazy compilation; only take the |
603 // rest of the function into account to avoid overlap with the lazy | 653 // rest of the function into account to avoid overlap with the lazy |
604 // parsing statistics. | 654 // parsing statistics. |
605 HistogramTimerScope timer(isolate->counters()->compile_lazy()); | 655 HistogramTimerScope timer(isolate->counters()->compile_lazy()); |
606 | 656 |
607 // Compile the code. | 657 // Compile the code. |
608 if (!MakeCode(info)) { | 658 if (!MakeCode(info)) { |
609 if (!isolate->has_pending_exception()) { | 659 if (!isolate->has_pending_exception()) { |
610 isolate->StackOverflow(); | 660 isolate->StackOverflow(); |
611 } | 661 } |
612 } else { | 662 } else { |
613 ASSERT(!info->code().is_null()); | 663 ASSERT(!info->code().is_null()); |
614 Handle<Code> code = info->code(); | 664 Handle<Code> code = info->code(); |
615 // Set optimizable to false if this is disallowed by the shared | 665 // Set optimizable to false if this is disallowed by the shared |
616 // function info, e.g., we might have flushed the code and must | 666 // function info, e.g., we might have flushed the code and must |
617 // reset this bit when lazy compiling the code again. | 667 // reset this bit when lazy compiling the code again. |
618 if (shared->optimization_disabled()) code->set_optimizable(false); | 668 if (shared->optimization_disabled()) code->set_optimizable(false); |
619 | 669 |
620 Handle<JSFunction> function = info->closure(); | 670 Handle<JSFunction> function = info->closure(); |
621 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 671 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
622 | 672 |
623 if (info->IsOptimizing()) { | 673 if (info->IsOptimizing()) { |
624 function->ReplaceCode(*code); | 674 function->ReplaceCode(*code); |
| 675 if (FLAG_cache_optimized_code |
| 676 && code->kind() == Code::OPTIMIZED_FUNCTION |
| 677 && info->osr_ast_id() == -1) { |
| 678 Handle<SharedFunctionInfo> shared(function->shared()); |
| 679 Handle<Context> global_context(function->context()->global_context()); |
| 680 AddToOptimizedCodeMap(shared, global_context, code); |
| 681 } |
625 } else { | 682 } else { |
626 // Update the shared function info with the compiled code and the | 683 // Update the shared function info with the compiled code and the |
627 // scope info. Please note, that the order of the shared function | 684 // scope info. Please note, that the order of the shared function |
628 // info initialization is important since set_scope_info might | 685 // info initialization is important since set_scope_info might |
629 // trigger a GC, causing the ASSERT below to be invalid if the code | 686 // trigger a GC, causing the ASSERT below to be invalid if the code |
630 // was flushed. By settting the code object last we avoid this. | 687 // was flushed. By settting the code object last we avoid this. |
631 Handle<SerializedScopeInfo> scope_info = | 688 Handle<SerializedScopeInfo> scope_info = |
632 SerializedScopeInfo::Create(info->scope()); | 689 SerializedScopeInfo::Create(info->scope()); |
633 shared->set_scope_info(*scope_info); | 690 shared->set_scope_info(*scope_info); |
634 shared->set_code(*code); | 691 shared->set_code(*code); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 shared->DebugName())); | 840 shared->DebugName())); |
784 } | 841 } |
785 } | 842 } |
786 | 843 |
787 GDBJIT(AddCode(name, | 844 GDBJIT(AddCode(name, |
788 Handle<Script>(info->script()), | 845 Handle<Script>(info->script()), |
789 Handle<Code>(info->code()))); | 846 Handle<Code>(info->code()))); |
790 } | 847 } |
791 | 848 |
792 } } // namespace v8::internal | 849 } } // namespace v8::internal |
OLD | NEW |