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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 // Checks whether top level functions should be passed by the filter. | 359 // Checks whether top level functions should be passed by the filter. |
360 if (shared->is_toplevel()) { | 360 if (shared->is_toplevel()) { |
361 Vector<const char> filter = CStrVector(FLAG_ignition_filter); | 361 Vector<const char> filter = CStrVector(FLAG_ignition_filter); |
362 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); | 362 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); |
363 } | 363 } |
364 | 364 |
365 // Finally respect the filter. | 365 // Finally respect the filter. |
366 return shared->PassesFilter(FLAG_ignition_filter); | 366 return shared->PassesFilter(FLAG_ignition_filter); |
367 } | 367 } |
368 | 368 |
369 CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info) { | 369 CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info, |
| 370 LazyCompilationMode mode) { |
370 // Function should have been parsed and analyzed before creating a compilation | 371 // Function should have been parsed and analyzed before creating a compilation |
371 // job. | 372 // job. |
372 DCHECK_NOT_NULL(info->literal()); | 373 DCHECK_NOT_NULL(info->literal()); |
373 DCHECK_NOT_NULL(info->scope()); | 374 DCHECK_NOT_NULL(info->scope()); |
374 | 375 |
375 EnsureFeedbackMetadata(info); | 376 EnsureFeedbackMetadata(info); |
376 if (ShouldUseIgnition(info)) { | 377 if (ShouldUseIgnition(info)) { |
377 return interpreter::Interpreter::NewCompilationJob(info); | 378 return interpreter::Interpreter::NewCompilationJob(info, mode); |
378 } else { | 379 } else { |
379 return FullCodeGenerator::NewCompilationJob(info); | 380 return FullCodeGenerator::NewCompilationJob(info, mode); |
380 } | 381 } |
381 } | 382 } |
382 | 383 |
383 void InstallSharedScopeInfo(CompilationInfo* info, | 384 void InstallSharedScopeInfo(CompilationInfo* info, |
384 Handle<SharedFunctionInfo> shared) { | 385 Handle<SharedFunctionInfo> shared) { |
385 Handle<ScopeInfo> scope_info = info->scope()->scope_info(); | 386 Handle<ScopeInfo> scope_info = info->scope()->scope_info(); |
386 shared->set_scope_info(*scope_info); | 387 shared->set_scope_info(*scope_info); |
387 Scope* outer_scope = info->scope()->GetOuterScopeWithContext(); | 388 Scope* outer_scope = info->scope()->GetOuterScopeWithContext(); |
388 if (outer_scope) { | 389 if (outer_scope) { |
389 shared->set_outer_scope_info(*outer_scope->scope_info()); | 390 shared->set_outer_scope_info(*outer_scope->scope_info()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 MaybeHandle<FixedArray> wasm_data; | 433 MaybeHandle<FixedArray> wasm_data; |
433 wasm_data = AsmJs::CompileAsmViaWasm(info->parse_info()); | 434 wasm_data = AsmJs::CompileAsmViaWasm(info->parse_info()); |
434 if (!wasm_data.is_null()) { | 435 if (!wasm_data.is_null()) { |
435 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); | 436 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); |
436 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); | 437 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); |
437 InstallUnoptimizedCode(info); | 438 InstallUnoptimizedCode(info); |
438 return true; | 439 return true; |
439 } | 440 } |
440 } | 441 } |
441 | 442 |
442 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info)); | 443 std::unique_ptr<CompilationJob> job( |
| 444 GetUnoptimizedCompilationJob(info, LazyCompilationMode::kIfRequested)); |
443 if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false; | 445 if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false; |
444 if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false; | 446 if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false; |
445 if (FinalizeUnoptimizedCompilationJob(job.get()) != | 447 if (FinalizeUnoptimizedCompilationJob(job.get()) != |
446 CompilationJob::SUCCEEDED) { | 448 CompilationJob::SUCCEEDED) { |
447 return false; | 449 return false; |
448 } | 450 } |
449 return true; | 451 return true; |
450 } | 452 } |
451 | 453 |
452 bool CompileUnoptimizedCode(CompilationInfo* info) { | 454 bool CompileUnoptimizedCode(CompilationInfo* info) { |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 CompilationInfo compile_info(parse_info, Handle<JSFunction>::null()); | 1559 CompilationInfo compile_info(parse_info, Handle<JSFunction>::null()); |
1558 | 1560 |
1559 // The source was parsed lazily, so compiling for debugging is not possible. | 1561 // The source was parsed lazily, so compiling for debugging is not possible. |
1560 DCHECK(!compile_info.is_debug()); | 1562 DCHECK(!compile_info.is_debug()); |
1561 | 1563 |
1562 Handle<SharedFunctionInfo> result = CompileToplevel(&compile_info); | 1564 Handle<SharedFunctionInfo> result = CompileToplevel(&compile_info); |
1563 if (!result.is_null()) isolate->debug()->OnAfterCompile(script); | 1565 if (!result.is_null()) isolate->debug()->OnAfterCompile(script); |
1564 return result; | 1566 return result; |
1565 } | 1567 } |
1566 | 1568 |
1567 | |
1568 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( | 1569 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( |
1569 FunctionLiteral* literal, Handle<Script> script, | 1570 FunctionLiteral* literal, Handle<Script> script, |
1570 CompilationInfo* outer_info) { | 1571 CompilationInfo* outer_info, LazyCompilationMode mode) { |
1571 // Precondition: code has been parsed and scopes have been analyzed. | 1572 // Precondition: code has been parsed and scopes have been analyzed. |
1572 Isolate* isolate = outer_info->isolate(); | 1573 Isolate* isolate = outer_info->isolate(); |
1573 MaybeHandle<SharedFunctionInfo> maybe_existing; | 1574 MaybeHandle<SharedFunctionInfo> maybe_existing; |
1574 | 1575 |
1575 // Find any previously allocated shared function info for the given literal. | 1576 // Find any previously allocated shared function info for the given literal. |
1576 maybe_existing = script->FindSharedFunctionInfo(isolate, literal); | 1577 maybe_existing = script->FindSharedFunctionInfo(isolate, literal); |
1577 | 1578 |
1578 // We found an existing shared function info. If it has any sort of code | 1579 // We found an existing shared function info. If it has any sort of code |
1579 // attached, don't worry about compiling and simply return it. Otherwise, | 1580 // attached, don't worry about compiling and simply return it. Otherwise, |
1580 // continue to decide whether to eagerly compile. | 1581 // continue to decide whether to eagerly compile. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1613 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
1613 if (outer_info->is_debug()) info.MarkAsDebug(); | 1614 if (outer_info->is_debug()) info.MarkAsDebug(); |
1614 | 1615 |
1615 // If this inner function is already compiled, we don't need to compile | 1616 // If this inner function is already compiled, we don't need to compile |
1616 // again. When compiling for debug, we are not interested in having debug | 1617 // again. When compiling for debug, we are not interested in having debug |
1617 // break slots in inner functions, neither for setting break points nor | 1618 // break slots in inner functions, neither for setting break points nor |
1618 // for revealing inner functions. | 1619 // for revealing inner functions. |
1619 // This is especially important for generators. We must not replace the | 1620 // This is especially important for generators. We must not replace the |
1620 // code for generators, as there may be suspended generator objects. | 1621 // code for generators, as there may be suspended generator objects. |
1621 if (!result->is_compiled()) { | 1622 if (!result->is_compiled()) { |
1622 if (!literal->ShouldEagerCompile()) { | 1623 if (mode == LazyCompilationMode::kAlways || |
| 1624 !literal->ShouldEagerCompile()) { |
1623 info.SetCode(isolate->builtins()->CompileLazy()); | 1625 info.SetCode(isolate->builtins()->CompileLazy()); |
1624 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext(); | 1626 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext(); |
1625 if (outer_scope) { | 1627 if (outer_scope) { |
1626 result->set_outer_scope_info(*outer_scope->scope_info()); | 1628 result->set_outer_scope_info(*outer_scope->scope_info()); |
1627 } | 1629 } |
1628 } else { | 1630 } else { |
1629 // Generate code | 1631 // Generate code |
1630 TimerEventScope<TimerEventCompileCode> timer(isolate); | 1632 TimerEventScope<TimerEventCompileCode> timer(isolate); |
1631 RuntimeCallTimerScope runtimeTimer(isolate, | 1633 RuntimeCallTimerScope runtimeTimer(isolate, |
1632 &RuntimeCallStats::CompileCode); | 1634 &RuntimeCallStats::CompileCode); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1685 | 1687 |
1686 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, | 1688 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, |
1687 BailoutId osr_ast_id, | 1689 BailoutId osr_ast_id, |
1688 JavaScriptFrame* osr_frame) { | 1690 JavaScriptFrame* osr_frame) { |
1689 DCHECK(!osr_ast_id.IsNone()); | 1691 DCHECK(!osr_ast_id.IsNone()); |
1690 DCHECK_NOT_NULL(osr_frame); | 1692 DCHECK_NOT_NULL(osr_frame); |
1691 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); | 1693 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); |
1692 } | 1694 } |
1693 | 1695 |
1694 CompilationJob* Compiler::PrepareUnoptimizedCompilationJob( | 1696 CompilationJob* Compiler::PrepareUnoptimizedCompilationJob( |
1695 CompilationInfo* info) { | 1697 CompilationInfo* info, LazyCompilationMode mode) { |
1696 VMState<COMPILER> state(info->isolate()); | 1698 VMState<COMPILER> state(info->isolate()); |
1697 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info)); | 1699 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info, mode)); |
1698 if (job->PrepareJob() != CompilationJob::SUCCEEDED) { | 1700 if (job->PrepareJob() != CompilationJob::SUCCEEDED) { |
1699 return nullptr; | 1701 return nullptr; |
1700 } | 1702 } |
1701 return job.release(); | 1703 return job.release(); |
1702 } | 1704 } |
1703 | 1705 |
1704 bool Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { | 1706 bool Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { |
1705 // Take ownership of compilation job. Deleting job also tears down the zone. | 1707 // Take ownership of compilation job. Deleting job also tears down the zone. |
1706 std::unique_ptr<CompilationJob> job(raw_job); | 1708 std::unique_ptr<CompilationJob> job(raw_job); |
1707 | 1709 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 DCHECK(shared->is_compiled()); | 1745 DCHECK(shared->is_compiled()); |
1744 function->set_literals(cached.literals); | 1746 function->set_literals(cached.literals); |
1745 } else if (shared->is_compiled()) { | 1747 } else if (shared->is_compiled()) { |
1746 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1748 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
1747 JSFunction::EnsureLiterals(function); | 1749 JSFunction::EnsureLiterals(function); |
1748 } | 1750 } |
1749 } | 1751 } |
1750 | 1752 |
1751 } // namespace internal | 1753 } // namespace internal |
1752 } // namespace v8 | 1754 } // namespace v8 |
OLD | NEW |