| 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 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/asmjs/asm-js.h" | 10 #include "src/asmjs/asm-js.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 // Checks whether top level functions should be passed by the filter. | 339 // Checks whether top level functions should be passed by the filter. |
| 340 if (info->shared_info()->is_toplevel()) { | 340 if (info->shared_info()->is_toplevel()) { |
| 341 Vector<const char> filter = CStrVector(FLAG_ignition_filter); | 341 Vector<const char> filter = CStrVector(FLAG_ignition_filter); |
| 342 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); | 342 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Finally respect the filter. | 345 // Finally respect the filter. |
| 346 return info->shared_info()->PassesFilter(FLAG_ignition_filter); | 346 return info->shared_info()->PassesFilter(FLAG_ignition_filter); |
| 347 } | 347 } |
| 348 | 348 |
| 349 CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info) { | 349 std::vector<std::unique_ptr<CompilationJob>> GetUnoptimizedCompilationJob( |
| 350 CompilationInfo* info) { |
| 350 // Function should have been parsed and analyzed before creating a compilation | 351 // Function should have been parsed and analyzed before creating a compilation |
| 351 // job. | 352 // job. |
| 352 DCHECK_NOT_NULL(info->literal()); | 353 DCHECK_NOT_NULL(info->literal()); |
| 353 DCHECK_NOT_NULL(info->scope()); | 354 DCHECK_NOT_NULL(info->scope()); |
| 354 | 355 |
| 355 EnsureFeedbackMetadata(info); | 356 EnsureFeedbackMetadata(info); |
| 356 if (ShouldUseIgnition(info)) { | 357 if (ShouldUseIgnition(info)) { |
| 357 return interpreter::Interpreter::NewCompilationJob(info); | 358 return interpreter::Interpreter::NewCompilationJob(info); |
| 358 } else { | 359 } else { |
| 359 return FullCodeGenerator::NewCompilationJob(info); | 360 std::unique_ptr<CompilationJob> job( |
| 361 FullCodeGenerator::NewCompilationJob(info)); |
| 362 std::vector<std::unique_ptr<CompilationJob>> result; |
| 363 result.push_back(std::move(job)); |
| 364 return result; |
| 360 } | 365 } |
| 361 } | 366 } |
| 362 | 367 |
| 363 bool GenerateUnoptimizedCode(CompilationInfo* info) { | 368 bool GenerateUnoptimizedCode(CompilationInfo* info) { |
| 364 if (FLAG_validate_asm && info->scope()->asm_module() && | 369 if (FLAG_validate_asm && info->scope()->asm_module() && |
| 365 !info->shared_info()->is_asm_wasm_broken()) { | 370 !info->shared_info()->is_asm_wasm_broken()) { |
| 366 EnsureFeedbackMetadata(info); | 371 EnsureFeedbackMetadata(info); |
| 367 MaybeHandle<FixedArray> wasm_data; | 372 MaybeHandle<FixedArray> wasm_data; |
| 368 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info()); | 373 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info()); |
| 369 if (!wasm_data.is_null()) { | 374 if (!wasm_data.is_null()) { |
| 370 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); | 375 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); |
| 371 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); | 376 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); |
| 372 return true; | 377 return true; |
| 373 } | 378 } |
| 374 } | 379 } |
| 375 | 380 |
| 376 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info)); | 381 std::vector<std::unique_ptr<CompilationJob>> jobs( |
| 377 if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false; | 382 GetUnoptimizedCompilationJob(info)); |
| 378 if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false; | 383 for (auto& job : jobs) { |
| 379 if (job->FinalizeJob() != CompilationJob::SUCCEEDED) return false; | 384 if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false; |
| 380 job->RecordUnoptimizedCompilationStats(); | 385 if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false; |
| 386 if (job->FinalizeJob() != CompilationJob::SUCCEEDED) return false; |
| 387 job->RecordUnoptimizedCompilationStats(); |
| 388 job.reset(); |
| 389 } |
| 381 return true; | 390 return true; |
| 382 } | 391 } |
| 383 | 392 |
| 384 bool CompileUnoptimizedCode(CompilationInfo* info) { | 393 bool CompileUnoptimizedCode(CompilationInfo* info) { |
| 385 DCHECK(AllowCompilation::IsAllowed(info->isolate())); | 394 DCHECK(AllowCompilation::IsAllowed(info->isolate())); |
| 386 if (!Compiler::Analyze(info->parse_info()) || | 395 if (!Compiler::Analyze(info->parse_info()) || |
| 387 !GenerateUnoptimizedCode(info)) { | 396 !GenerateUnoptimizedCode(info)) { |
| 388 Isolate* isolate = info->isolate(); | 397 Isolate* isolate = info->isolate(); |
| 389 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 398 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
| 390 return false; | 399 return false; |
| (...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 CompilationInfo compile_info(parse_info, Handle<JSFunction>::null()); | 1717 CompilationInfo compile_info(parse_info, Handle<JSFunction>::null()); |
| 1709 | 1718 |
| 1710 // The source was parsed lazily, so compiling for debugging is not possible. | 1719 // The source was parsed lazily, so compiling for debugging is not possible. |
| 1711 DCHECK(!compile_info.is_debug()); | 1720 DCHECK(!compile_info.is_debug()); |
| 1712 | 1721 |
| 1713 Handle<SharedFunctionInfo> result = CompileToplevel(&compile_info); | 1722 Handle<SharedFunctionInfo> result = CompileToplevel(&compile_info); |
| 1714 if (!result.is_null()) isolate->debug()->OnAfterCompile(script); | 1723 if (!result.is_null()) isolate->debug()->OnAfterCompile(script); |
| 1715 return result; | 1724 return result; |
| 1716 } | 1725 } |
| 1717 | 1726 |
| 1718 | |
| 1719 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( | 1727 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( |
| 1720 FunctionLiteral* literal, Handle<Script> script, | 1728 FunctionLiteral* literal, Handle<Script> script, |
| 1721 CompilationInfo* outer_info) { | 1729 CompilationInfo* outer_info, ShouldCompile should_compile) { |
| 1722 // Precondition: code has been parsed and scopes have been analyzed. | 1730 // Precondition: code has been parsed and scopes have been analyzed. |
| 1723 Isolate* isolate = outer_info->isolate(); | 1731 Isolate* isolate = outer_info->isolate(); |
| 1724 MaybeHandle<SharedFunctionInfo> maybe_existing; | 1732 MaybeHandle<SharedFunctionInfo> maybe_existing; |
| 1725 | 1733 |
| 1726 // Find any previously allocated shared function info for the given literal. | 1734 // Find any previously allocated shared function info for the given literal. |
| 1727 if (outer_info->shared_info()->never_compiled()) { | 1735 if (outer_info->shared_info()->never_compiled()) { |
| 1728 // On the first compile, there are no existing shared function info for | 1736 // On the first compile, there are no existing shared function info for |
| 1729 // inner functions yet, so do not try to find them. All bets are off for | 1737 // inner functions yet, so do not try to find them. All bets are off for |
| 1730 // live edit though. | 1738 // live edit though. |
| 1731 SLOW_DCHECK(script->FindSharedFunctionInfo(literal).is_null() || | 1739 SLOW_DCHECK(script->FindSharedFunctionInfo(literal).is_null() || |
| 1732 isolate->debug()->live_edit_enabled()); | 1740 isolate->debug()->live_edit_enabled()); |
| 1733 } else { | 1741 } else { |
| 1734 maybe_existing = script->FindSharedFunctionInfo(literal); | 1742 maybe_existing = script->FindSharedFunctionInfo(literal); |
| 1735 } | 1743 } |
| 1736 | 1744 |
| 1737 // We found an existing shared function info. If it has any sort of code | 1745 // We found an existing shared function info. If it has any sort of code |
| 1738 // attached, don't worry about compiling and simply return it. Otherwise, | 1746 // attached, don't worry about compiling and simply return it. Otherwise, |
| 1739 // continue to decide whether to eagerly compile. | 1747 // continue to decide whether to eagerly compile. |
| 1740 // Note that we also carry on if we are compiling eager to obtain code for | 1748 // Note that we also carry on if we are compiling eager to obtain code for |
| 1741 // debugging, unless we already have code with debug break slots. | 1749 // debugging, unless we already have code with debug break slots. |
| 1742 Handle<SharedFunctionInfo> existing; | 1750 Handle<SharedFunctionInfo> existing; |
| 1743 if (maybe_existing.ToHandle(&existing)) { | 1751 if (maybe_existing.ToHandle(&existing)) { |
| 1744 DCHECK(!existing->is_toplevel()); | 1752 DCHECK(!existing->is_toplevel()); |
| 1745 if (existing->HasBaselineCode() || existing->HasBytecodeArray()) { | 1753 if (existing->HasBaselineCode() || existing->HasBytecodeArray()) { |
| 1746 if (!outer_info->is_debug() || existing->HasDebugCode()) { | 1754 if (!outer_info->is_debug() || existing->HasDebugCode()) { |
| 1747 return existing; | 1755 return existing; |
| 1748 } | 1756 } |
| 1757 } else if (should_compile == ShouldCompile::kNever) { |
| 1758 return existing; |
| 1749 } | 1759 } |
| 1750 } | 1760 } |
| 1751 | 1761 |
| 1752 // Allocate a shared function info object. | 1762 // Allocate a shared function info object. |
| 1753 Handle<SharedFunctionInfo> result; | 1763 Handle<SharedFunctionInfo> result; |
| 1754 if (!maybe_existing.ToHandle(&result)) { | 1764 if (!maybe_existing.ToHandle(&result)) { |
| 1755 result = NewSharedFunctionInfoForLiteral(isolate, literal, script); | 1765 result = NewSharedFunctionInfoForLiteral(isolate, literal, script); |
| 1756 result->set_is_toplevel(false); | 1766 result->set_is_toplevel(false); |
| 1757 | 1767 |
| 1758 // If the outer function has been compiled before, we cannot be sure that | 1768 // If the outer function has been compiled before, we cannot be sure that |
| 1759 // shared function info for this function literal has been created for the | 1769 // shared function info for this function literal has been created for the |
| 1760 // first time. It may have already been compiled previously. | 1770 // first time. It may have already been compiled previously. |
| 1761 result->set_never_compiled(outer_info->shared_info()->never_compiled()); | 1771 result->set_never_compiled(outer_info->shared_info()->never_compiled()); |
| 1762 } | 1772 } |
| 1763 | 1773 |
| 1764 Zone zone(isolate->allocator()); | 1774 Zone zone(isolate->allocator()); |
| 1765 ParseInfo parse_info(&zone, script); | 1775 ParseInfo parse_info(&zone, script); |
| 1766 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1776 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1767 parse_info.set_literal(literal); | 1777 parse_info.set_literal(literal); |
| 1768 parse_info.set_shared_info(result); | 1778 parse_info.set_shared_info(result); |
| 1769 parse_info.set_language_mode(literal->scope()->language_mode()); | 1779 parse_info.set_language_mode(literal->scope()->language_mode()); |
| 1770 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1780 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
| 1771 if (outer_info->is_debug()) info.MarkAsDebug(); | 1781 if (outer_info->is_debug()) info.MarkAsDebug(); |
| 1772 | 1782 |
| 1773 // Generate code | 1783 // Generate code |
| 1774 TimerEventScope<TimerEventCompileCode> timer(isolate); | 1784 TimerEventScope<TimerEventCompileCode> timer(isolate); |
| 1775 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::CompileCode); | 1785 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::CompileCode); |
| 1776 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); | 1786 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); |
| 1777 | 1787 |
| 1778 if (!literal->ShouldEagerCompile()) { | 1788 if (!literal->ShouldEagerCompile() || |
| 1789 should_compile == ShouldCompile::kNever) { |
| 1779 info.SetCode(isolate->builtins()->CompileLazy()); | 1790 info.SetCode(isolate->builtins()->CompileLazy()); |
| 1780 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext(); | 1791 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext(); |
| 1781 if (outer_scope) { | 1792 if (outer_scope) { |
| 1782 result->set_outer_scope_info(*outer_scope->scope_info()); | 1793 result->set_outer_scope_info(*outer_scope->scope_info()); |
| 1783 } | 1794 } |
| 1784 } else if (Renumber(info.parse_info()) && GenerateUnoptimizedCode(&info)) { | 1795 } else if (Renumber(info.parse_info()) && GenerateUnoptimizedCode(&info)) { |
| 1785 // Code generation will ensure that the feedback vector is present and | 1796 // Code generation will ensure that the feedback vector is present and |
| 1786 // appropriately sized. | 1797 // appropriately sized. |
| 1787 DCHECK(!info.code().is_null()); | 1798 DCHECK(!info.code().is_null()); |
| 1788 if (literal->should_be_used_once_hint()) { | 1799 if (literal->should_be_used_once_hint()) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 } | 1847 } |
| 1837 | 1848 |
| 1838 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, | 1849 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, |
| 1839 BailoutId osr_ast_id, | 1850 BailoutId osr_ast_id, |
| 1840 JavaScriptFrame* osr_frame) { | 1851 JavaScriptFrame* osr_frame) { |
| 1841 DCHECK(!osr_ast_id.IsNone()); | 1852 DCHECK(!osr_ast_id.IsNone()); |
| 1842 DCHECK_NOT_NULL(osr_frame); | 1853 DCHECK_NOT_NULL(osr_frame); |
| 1843 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); | 1854 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); |
| 1844 } | 1855 } |
| 1845 | 1856 |
| 1846 CompilationJob* Compiler::PrepareUnoptimizedCompilationJob( | 1857 std::vector<std::unique_ptr<CompilationJob>> |
| 1847 CompilationInfo* info) { | 1858 Compiler::PrepareUnoptimizedCompilationJob(CompilationInfo* info) { |
| 1848 VMState<COMPILER> state(info->isolate()); | 1859 VMState<COMPILER> state(info->isolate()); |
| 1849 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info)); | 1860 std::vector<std::unique_ptr<CompilationJob>> jobs( |
| 1850 if (job->PrepareJob() != CompilationJob::SUCCEEDED) { | 1861 GetUnoptimizedCompilationJob(info)); |
| 1851 return nullptr; | 1862 for (auto& job : jobs) { |
| 1863 if (job->PrepareJob() != CompilationJob::SUCCEEDED) { |
| 1864 std::vector<std::unique_ptr<CompilationJob>> result; |
| 1865 return result; |
| 1866 } |
| 1852 } | 1867 } |
| 1853 return job.release(); | 1868 return jobs; |
| 1854 } | 1869 } |
| 1855 | 1870 |
| 1856 bool Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { | 1871 bool Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { |
| 1857 // Take ownership of compilation job. Deleting job also tears down the zone. | 1872 // Take ownership of compilation job. Deleting job also tears down the zone. |
| 1858 std::unique_ptr<CompilationJob> job(raw_job); | 1873 std::unique_ptr<CompilationJob> job(raw_job); |
| 1859 | 1874 |
| 1860 VMState<COMPILER> state(job->info()->isolate()); | 1875 VMState<COMPILER> state(job->info()->isolate()); |
| 1861 if (job->info()->IsOptimizing()) { | 1876 if (job->info()->IsOptimizing()) { |
| 1862 return FinalizeOptimizedCompilationJob(job.get()) == | 1877 return FinalizeOptimizedCompilationJob(job.get()) == |
| 1863 CompilationJob::SUCCEEDED; | 1878 CompilationJob::SUCCEEDED; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1888 DCHECK(shared->is_compiled()); | 1903 DCHECK(shared->is_compiled()); |
| 1889 function->set_literals(cached.literals); | 1904 function->set_literals(cached.literals); |
| 1890 } else if (shared->is_compiled()) { | 1905 } else if (shared->is_compiled()) { |
| 1891 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1906 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1892 JSFunction::EnsureLiterals(function); | 1907 JSFunction::EnsureLiterals(function); |
| 1893 } | 1908 } |
| 1894 } | 1909 } |
| 1895 | 1910 |
| 1896 } // namespace internal | 1911 } // namespace internal |
| 1897 } // namespace v8 | 1912 } // namespace v8 |
| OLD | NEW |