OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 info->closure()->PrintName(); | 158 info->closure()->PrintName(); |
159 PrintF(" / %" V8PRIxPTR "]\n", | 159 PrintF(" / %" V8PRIxPTR "]\n", |
160 reinterpret_cast<intptr_t>(*info->closure())); | 160 reinterpret_cast<intptr_t>(*info->closure())); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 static bool MakeCrankshaftCode(CompilationInfo* info) { | 165 static bool MakeCrankshaftCode(CompilationInfo* info) { |
166 // Test if we can optimize this function when asked to. We can only | 166 // Test if we can optimize this function when asked to. We can only |
167 // do this after the scopes are computed. | 167 // do this after the scopes are computed. |
168 if (!info->AllowOptimize()) info->DisableOptimization(); | 168 if (!info->AllowOptimize()) info->DisableOptimization(); |
fschneider
2010/12/13 19:00:18
This checks if the function literal's scope has an
antonm
2010/12/13 22:41:04
I am not sure: CompilationInfo::AllowOptimize chec
antonm
2010/12/13 22:52:47
BTW, if I understand meaning of Scope::num_heap_sl
| |
169 | 169 |
170 // In case we are not optimizing simply return the code from | 170 // In case we are not optimizing simply return the code from |
171 // the full code generator. | 171 // the full code generator. |
172 if (!info->IsOptimizing()) { | 172 if (!info->IsOptimizing()) { |
173 return FullCodeGenerator::MakeCode(info); | 173 return FullCodeGenerator::MakeCode(info); |
174 } | 174 } |
175 | 175 |
176 // We should never arrive here if there is not code object on the | 176 // We should never arrive here if there is not code object on the |
177 // shared function object. | 177 // shared function object. |
178 Handle<Code> code(info->shared_info()->code()); | 178 Handle<Code> code(info->shared_info()->code()); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 result = MakeFunctionInfo(&info); | 544 result = MakeFunctionInfo(&info); |
545 if (!result.is_null()) { | 545 if (!result.is_null()) { |
546 CompilationCache::PutEval(source, context, is_global, result); | 546 CompilationCache::PutEval(source, context, is_global, result); |
547 } | 547 } |
548 } | 548 } |
549 | 549 |
550 return result; | 550 return result; |
551 } | 551 } |
552 | 552 |
553 | 553 |
554 class PrecompiledScope: public Scope { | |
555 public: | |
556 PrecompiledScope(Scope* inner_scope, SerializedScopeInfo* scope_info) | |
557 : Scope(inner_scope->outer_scope(), Scope::FUNCTION_SCOPE), | |
558 scope_info_(scope_info) { | |
559 InsertAfterScope(inner_scope); | |
560 if (scope_info->HasHeapAllocatedLocals()) { | |
561 num_heap_slots_ = scope_info->NumberOfContextSlots(); | |
562 } | |
563 MarkAsResolved(); | |
564 } | |
565 | |
566 virtual void Initialize(bool inside_with) { | |
567 UNREACHABLE(); | |
568 } | |
569 | |
570 virtual Variable* LocalLookup(Handle<String> name) { | |
571 // Check arguments object lookup. | |
572 if (*name == *Factory::arguments_symbol()) { | |
573 return new Variable(this, name, Variable::VAR, true, Variable::ARGUMENTS); | |
574 } | |
575 | |
576 // Check context slot lookup. | |
577 Variable::Mode mode; | |
578 int index = scope_info_->ContextSlotIndex(*name, &mode); | |
579 if (index < 0) { | |
580 return NULL; | |
581 } | |
582 | |
583 Variable* var = new Variable(this, name, mode, true, Variable::NORMAL); | |
584 var->set_rewrite(new Slot(var, Slot::CONTEXT, index)); | |
585 return var; | |
586 } | |
587 | |
588 virtual Variable* DeclareLocal(Handle<String> name, Variable::Mode mode) { | |
589 UNREACHABLE(); | |
590 return NULL; | |
591 } | |
592 | |
593 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { | |
594 UNREACHABLE(); | |
595 return NULL; | |
596 } | |
597 | |
598 virtual Variable* NewTemporary(Handle<String> name) { | |
599 UNREACHABLE(); | |
600 return NULL; | |
601 } | |
602 | |
603 private: | |
604 SerializedScopeInfo* scope_info_; | |
605 }; | |
606 | |
607 | |
554 bool Compiler::CompileLazy(CompilationInfo* info) { | 608 bool Compiler::CompileLazy(CompilationInfo* info) { |
555 CompilationZoneScope zone_scope(DELETE_ON_EXIT); | 609 CompilationZoneScope zone_scope(DELETE_ON_EXIT); |
556 | 610 |
557 // The VM is in the COMPILER state until exiting this function. | 611 // The VM is in the COMPILER state until exiting this function. |
558 VMState state(COMPILER); | 612 VMState state(COMPILER); |
559 | 613 |
560 PostponeInterruptsScope postpone; | 614 PostponeInterruptsScope postpone; |
561 | 615 |
562 Handle<SharedFunctionInfo> shared = info->shared_info(); | 616 Handle<SharedFunctionInfo> shared = info->shared_info(); |
563 int compiled_size = shared->end_position() - shared->start_position(); | 617 int compiled_size = shared->end_position() - shared->start_position(); |
564 Counters::total_compile_size.Increment(compiled_size); | 618 Counters::total_compile_size.Increment(compiled_size); |
565 | 619 |
566 // Generate the AST for the lazily compiled function. | 620 // Generate the AST for the lazily compiled function. |
567 if (ParserApi::Parse(info)) { | 621 if (ParserApi::Parse(info)) { |
568 // Measure how long it takes to do the lazy compilation; only take the | 622 // Measure how long it takes to do the lazy compilation; only take the |
569 // rest of the function into account to avoid overlap with the lazy | 623 // rest of the function into account to avoid overlap with the lazy |
570 // parsing statistics. | 624 // parsing statistics. |
571 HistogramTimerScope timer(&Counters::compile_lazy); | 625 HistogramTimerScope timer(&Counters::compile_lazy); |
572 | 626 |
627 // If we have scope info, reuse it to build scope for function literal | |
628 // being compiled. | |
629 if (!info->closure().is_null()) { | |
630 SerializedScopeInfo* scope_info = info->closure()->shared()->scope_info(); | |
631 if (scope_info != SerializedScopeInfo::Empty()) { | |
632 Scope* scope = info->function()->scope(); | |
633 JSFunction* current = *info->closure(); | |
634 do { | |
635 current = current->context()->closure(); | |
636 SerializedScopeInfo* scope_info = current->shared()->scope_info(); | |
637 if (scope_info != SerializedScopeInfo::Empty()) { | |
638 scope = new PrecompiledScope(scope, scope_info); | |
639 } else { | |
640 ASSERT(current->context()->IsGlobalContext()); | |
641 } | |
642 } while (!current->context()->IsGlobalContext()); | |
643 } | |
644 } | |
645 | |
573 // Compile the code. | 646 // Compile the code. |
574 if (!MakeCode(info)) { | 647 if (!MakeCode(info)) { |
575 Top::StackOverflow(); | 648 Top::StackOverflow(); |
576 } else { | 649 } else { |
577 ASSERT(!info->code().is_null()); | 650 ASSERT(!info->code().is_null()); |
578 Handle<Code> code = info->code(); | 651 Handle<Code> code = info->code(); |
579 Handle<JSFunction> function = info->closure(); | 652 Handle<JSFunction> function = info->closure(); |
580 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, | 653 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, |
581 Handle<String>(shared->DebugName()), | 654 Handle<String>(shared->DebugName()), |
582 shared->start_position(), | 655 shared->start_position(), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 | 731 |
659 // Generate code | 732 // Generate code |
660 if (FLAG_lazy && allow_lazy) { | 733 if (FLAG_lazy && allow_lazy) { |
661 Handle<Code> code(Builtins::builtin(Builtins::LazyCompile)); | 734 Handle<Code> code(Builtins::builtin(Builtins::LazyCompile)); |
662 info.SetCode(code); | 735 info.SetCode(code); |
663 } else { | 736 } else { |
664 if (V8::UseCrankshaft()) { | 737 if (V8::UseCrankshaft()) { |
665 if (!MakeCrankshaftCode(&info)) { | 738 if (!MakeCrankshaftCode(&info)) { |
666 return Handle<SharedFunctionInfo>::null(); | 739 return Handle<SharedFunctionInfo>::null(); |
667 } | 740 } |
741 if (!AlwaysFullCompiler() | |
742 && !info.scope()->outer_scope_calls_eval() | |
743 && !info.scope()->inside_with()) { | |
744 ASSERT(info.code()->kind() == Code::FUNCTION); | |
745 info.code()->set_optimizable(true); | |
746 } | |
668 } else { | 747 } else { |
669 // The bodies of function literals have not yet been visited by the | 748 // The bodies of function literals have not yet been visited by the |
670 // AST optimizer/analyzer. | 749 // AST optimizer/analyzer. |
671 if (!Rewriter::Analyze(&info)) return Handle<SharedFunctionInfo>::null(); | 750 if (!Rewriter::Analyze(&info)) return Handle<SharedFunctionInfo>::null(); |
672 | 751 |
673 bool is_run_once = literal->try_full_codegen(); | 752 bool is_run_once = literal->try_full_codegen(); |
674 bool can_use_full = FLAG_full_compiler && !literal->contains_loops(); | 753 bool can_use_full = FLAG_full_compiler && !literal->contains_loops(); |
675 | 754 |
676 if (AlwaysFullCompiler() || (is_run_once && can_use_full)) { | 755 if (AlwaysFullCompiler() || (is_run_once && can_use_full)) { |
677 if (!FullCodeGenerator::MakeCode(&info)) { | 756 if (!FullCodeGenerator::MakeCode(&info)) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 *code, | 847 *code, |
769 *name)); | 848 *name)); |
770 OPROFILE(CreateNativeCodeRegion(*name, | 849 OPROFILE(CreateNativeCodeRegion(*name, |
771 code->instruction_start(), | 850 code->instruction_start(), |
772 code->instruction_size())); | 851 code->instruction_size())); |
773 } | 852 } |
774 } | 853 } |
775 } | 854 } |
776 | 855 |
777 } } // namespace v8::internal | 856 } } // namespace v8::internal |
OLD | NEW |