| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler.h" | 5 #include "src/compiler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "src/ast/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
| 10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 passes_osr_test; | 699 passes_osr_test; |
| 700 } | 700 } |
| 701 | 701 |
| 702 bool GetOptimizedCodeNow(CompilationInfo* info) { | 702 bool GetOptimizedCodeNow(CompilationInfo* info) { |
| 703 Isolate* isolate = info->isolate(); | 703 Isolate* isolate = info->isolate(); |
| 704 CanonicalHandleScope canonical(isolate); | 704 CanonicalHandleScope canonical(isolate); |
| 705 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); | 705 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); |
| 706 TRACE_EVENT0("v8", "V8.OptimizeCode"); | 706 TRACE_EVENT0("v8", "V8.OptimizeCode"); |
| 707 | 707 |
| 708 bool use_turbofan = UseTurboFan(info); | 708 bool use_turbofan = UseTurboFan(info); |
| 709 OptimizedCompileJob* job = use_turbofan | 709 base::SmartPointer<OptimizedCompileJob> job( |
| 710 ? compiler::Pipeline::NewCompilationJob(info) | 710 use_turbofan ? compiler::Pipeline::NewCompilationJob(info) |
| 711 : new (info->zone()) HCompilationJob(info); | 711 : new HCompilationJob(info)); |
| 712 | 712 |
| 713 // Parsing is not required when optimizing from existing bytecode. | 713 // Parsing is not required when optimizing from existing bytecode. |
| 714 if (!use_turbofan || !info->shared_info()->HasBytecodeArray()) { | 714 if (!use_turbofan || !info->shared_info()->HasBytecodeArray()) { |
| 715 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; | 715 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; |
| 716 } else { | 716 } else { |
| 717 info->MarkAsOptimizeFromBytecode(); | 717 info->MarkAsOptimizeFromBytecode(); |
| 718 } | 718 } |
| 719 | 719 |
| 720 TimerEventScope<TimerEventRecompileSynchronous> timer(isolate); | 720 TimerEventScope<TimerEventRecompileSynchronous> timer(isolate); |
| 721 TRACE_EVENT0("v8", "V8.RecompileSynchronous"); | 721 TRACE_EVENT0("v8", "V8.RecompileSynchronous"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 748 if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) { | 748 if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) { |
| 749 if (FLAG_trace_concurrent_recompilation) { | 749 if (FLAG_trace_concurrent_recompilation) { |
| 750 PrintF(" ** Compilation queue full, will retry optimizing "); | 750 PrintF(" ** Compilation queue full, will retry optimizing "); |
| 751 info->closure()->ShortPrint(); | 751 info->closure()->ShortPrint(); |
| 752 PrintF(" later.\n"); | 752 PrintF(" later.\n"); |
| 753 } | 753 } |
| 754 return false; | 754 return false; |
| 755 } | 755 } |
| 756 | 756 |
| 757 bool use_turbofan = UseTurboFan(info); | 757 bool use_turbofan = UseTurboFan(info); |
| 758 OptimizedCompileJob* job = use_turbofan | 758 base::SmartPointer<OptimizedCompileJob> job( |
| 759 ? compiler::Pipeline::NewCompilationJob(info) | 759 use_turbofan ? compiler::Pipeline::NewCompilationJob(info) |
| 760 : new (info->zone()) HCompilationJob(info); | 760 : new HCompilationJob(info)); |
| 761 | 761 |
| 762 // All handles below this point will be allocated in a deferred handle scope | 762 // All handles below this point will be allocated in a deferred handle scope |
| 763 // that is detached and handed off to the background thread when we return. | 763 // that is detached and handed off to the background thread when we return. |
| 764 CompilationHandleScope handle_scope(info); | 764 CompilationHandleScope handle_scope(info); |
| 765 | 765 |
| 766 // Parsing is not required when optimizing from existing bytecode. | 766 // Parsing is not required when optimizing from existing bytecode. |
| 767 if (!use_turbofan || !info->shared_info()->HasBytecodeArray()) { | 767 if (!use_turbofan || !info->shared_info()->HasBytecodeArray()) { |
| 768 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; | 768 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; |
| 769 } else { | 769 } else { |
| 770 info->MarkAsOptimizeFromBytecode(); | 770 info->MarkAsOptimizeFromBytecode(); |
| 771 } | 771 } |
| 772 | 772 |
| 773 // Reopen handles in the new CompilationHandleScope. | 773 // Reopen handles in the new CompilationHandleScope. |
| 774 info->ReopenHandlesInNewHandleScope(); | 774 info->ReopenHandlesInNewHandleScope(); |
| 775 info->parse_info()->ReopenHandlesInNewHandleScope(); | 775 info->parse_info()->ReopenHandlesInNewHandleScope(); |
| 776 | 776 |
| 777 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 777 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
| 778 TRACE_EVENT0("v8", "V8.RecompileSynchronous"); | 778 TRACE_EVENT0("v8", "V8.RecompileSynchronous"); |
| 779 | 779 |
| 780 if (job->CreateGraph() != OptimizedCompileJob::SUCCEEDED) return false; | 780 if (job->CreateGraph() != OptimizedCompileJob::SUCCEEDED) return false; |
| 781 isolate->optimizing_compile_dispatcher()->QueueForOptimization(job); | 781 isolate->optimizing_compile_dispatcher()->QueueForOptimization(job.get()); |
| 782 job.Detach(); // The background recompile job owns this now. |
| 782 | 783 |
| 783 if (FLAG_trace_concurrent_recompilation) { | 784 if (FLAG_trace_concurrent_recompilation) { |
| 784 PrintF(" ** Queued "); | 785 PrintF(" ** Queued "); |
| 785 info->closure()->ShortPrint(); | 786 info->closure()->ShortPrint(); |
| 786 PrintF(" for concurrent optimization.\n"); | 787 PrintF(" for concurrent optimization.\n"); |
| 787 } | 788 } |
| 788 return true; | 789 return true; |
| 789 } | 790 } |
| 790 | 791 |
| 791 MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function, | 792 MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function, |
| (...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, | 1719 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, |
| 1719 BailoutId osr_ast_id, | 1720 BailoutId osr_ast_id, |
| 1720 JavaScriptFrame* osr_frame) { | 1721 JavaScriptFrame* osr_frame) { |
| 1721 DCHECK(!osr_ast_id.IsNone()); | 1722 DCHECK(!osr_ast_id.IsNone()); |
| 1722 DCHECK_NOT_NULL(osr_frame); | 1723 DCHECK_NOT_NULL(osr_frame); |
| 1723 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); | 1724 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); |
| 1724 } | 1725 } |
| 1725 | 1726 |
| 1726 void Compiler::FinalizeOptimizedCompileJob(OptimizedCompileJob* job) { | 1727 void Compiler::FinalizeOptimizedCompileJob(OptimizedCompileJob* job) { |
| 1727 // Take ownership of compilation info. Deleting compilation info | 1728 // Take ownership of compilation info. Deleting compilation info |
| 1728 // also tears down the zone and the recompile job. | 1729 // also tears down the zone. |
| 1729 base::SmartPointer<CompilationInfo> info(job->info()); | 1730 base::SmartPointer<CompilationInfo> info(job->info()); |
| 1730 Isolate* isolate = info->isolate(); | 1731 Isolate* isolate = info->isolate(); |
| 1731 | 1732 |
| 1732 VMState<COMPILER> state(isolate); | 1733 VMState<COMPILER> state(isolate); |
| 1733 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 1734 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
| 1734 TRACE_EVENT0("v8", "V8.RecompileSynchronous"); | 1735 TRACE_EVENT0("v8", "V8.RecompileSynchronous"); |
| 1735 | 1736 |
| 1736 Handle<SharedFunctionInfo> shared = info->shared_info(); | 1737 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 1737 shared->code()->set_profiler_ticks(0); | 1738 shared->code()->set_profiler_ticks(0); |
| 1738 | 1739 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1754 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), | 1755 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), |
| 1755 info->osr_ast_id()).code == nullptr) { | 1756 info->osr_ast_id()).code == nullptr) { |
| 1756 InsertCodeIntoOptimizedCodeMap(info.get()); | 1757 InsertCodeIntoOptimizedCodeMap(info.get()); |
| 1757 } | 1758 } |
| 1758 if (FLAG_trace_opt) { | 1759 if (FLAG_trace_opt) { |
| 1759 PrintF("[completed optimizing "); | 1760 PrintF("[completed optimizing "); |
| 1760 info->closure()->ShortPrint(); | 1761 info->closure()->ShortPrint(); |
| 1761 PrintF("]\n"); | 1762 PrintF("]\n"); |
| 1762 } | 1763 } |
| 1763 info->closure()->ReplaceCode(*info->code()); | 1764 info->closure()->ReplaceCode(*info->code()); |
| 1765 delete job; |
| 1764 return; | 1766 return; |
| 1765 } | 1767 } |
| 1766 } | 1768 } |
| 1767 | 1769 |
| 1768 DCHECK(job->last_status() != OptimizedCompileJob::SUCCEEDED); | 1770 DCHECK(job->last_status() != OptimizedCompileJob::SUCCEEDED); |
| 1769 if (FLAG_trace_opt) { | 1771 if (FLAG_trace_opt) { |
| 1770 PrintF("[aborted optimizing "); | 1772 PrintF("[aborted optimizing "); |
| 1771 info->closure()->ShortPrint(); | 1773 info->closure()->ShortPrint(); |
| 1772 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); | 1774 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); |
| 1773 } | 1775 } |
| 1774 info->closure()->ReplaceCode(shared->code()); | 1776 info->closure()->ReplaceCode(shared->code()); |
| 1777 delete job; |
| 1775 } | 1778 } |
| 1776 | 1779 |
| 1777 void Compiler::PostInstantiation(Handle<JSFunction> function, | 1780 void Compiler::PostInstantiation(Handle<JSFunction> function, |
| 1778 PretenureFlag pretenure) { | 1781 PretenureFlag pretenure) { |
| 1779 Handle<SharedFunctionInfo> shared(function->shared()); | 1782 Handle<SharedFunctionInfo> shared(function->shared()); |
| 1780 | 1783 |
| 1781 if (FLAG_always_opt && shared->allows_lazy_compilation()) { | 1784 if (FLAG_always_opt && shared->allows_lazy_compilation()) { |
| 1782 function->MarkForOptimization(); | 1785 function->MarkForOptimization(); |
| 1783 } | 1786 } |
| 1784 | 1787 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1805 MaybeHandle<Code> code; | 1808 MaybeHandle<Code> code; |
| 1806 if (cached.code != nullptr) code = handle(cached.code); | 1809 if (cached.code != nullptr) code = handle(cached.code); |
| 1807 Handle<Context> native_context(function->context()->native_context()); | 1810 Handle<Context> native_context(function->context()->native_context()); |
| 1808 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1811 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 1809 literals, BailoutId::None()); | 1812 literals, BailoutId::None()); |
| 1810 } | 1813 } |
| 1811 } | 1814 } |
| 1812 | 1815 |
| 1813 } // namespace internal | 1816 } // namespace internal |
| 1814 } // namespace v8 | 1817 } // namespace v8 |
| OLD | NEW |