| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 CompilationJob::Status CompilationJob::ExecuteJob() { | 91 CompilationJob::Status CompilationJob::ExecuteJob() { |
| 92 std::unique_ptr<DisallowHeapAllocation> no_allocation; | 92 std::unique_ptr<DisallowHeapAllocation> no_allocation; |
| 93 std::unique_ptr<DisallowHandleAllocation> no_handles; | 93 std::unique_ptr<DisallowHandleAllocation> no_handles; |
| 94 std::unique_ptr<DisallowHandleDereference> no_deref; | 94 std::unique_ptr<DisallowHandleDereference> no_deref; |
| 95 std::unique_ptr<DisallowCodeDependencyChange> no_dependency_change; | 95 std::unique_ptr<DisallowCodeDependencyChange> no_dependency_change; |
| 96 if (can_execute_on_background_thread()) { | 96 if (can_execute_on_background_thread()) { |
| 97 no_allocation.reset(new DisallowHeapAllocation()); | 97 no_allocation.reset(new DisallowHeapAllocation()); |
| 98 no_handles.reset(new DisallowHandleAllocation()); | 98 no_handles.reset(new DisallowHandleAllocation()); |
| 99 no_deref.reset(new DisallowHandleDereference()); | 99 no_deref.reset(new DisallowHandleDereference()); |
| 100 no_dependency_change.reset(new DisallowCodeDependencyChange()); | 100 no_dependency_change.reset(new DisallowCodeDependencyChange()); |
| 101 executed_on_background_thread_ = |
| 102 !ThreadId::Current().Equals(info()->isolate()->thread_id()); |
| 101 } else { | 103 } else { |
| 102 DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id())); | 104 DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id())); |
| 103 } | 105 } |
| 104 | 106 |
| 105 // Delegate to the underlying implementation. | 107 // Delegate to the underlying implementation. |
| 106 DCHECK(state() == State::kReadyToExecute); | 108 DCHECK(state() == State::kReadyToExecute); |
| 107 ScopedTimer t(&time_taken_to_execute_); | 109 ScopedTimer t(&time_taken_to_execute_); |
| 108 return UpdateState(ExecuteJobImpl(), State::kReadyToFinalize); | 110 return UpdateState(ExecuteJobImpl(), State::kReadyToFinalize); |
| 109 } | 111 } |
| 110 | 112 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 if (!Compiler::Analyze(info->parse_info()) || | 456 if (!Compiler::Analyze(info->parse_info()) || |
| 455 !GenerateUnoptimizedCode(info)) { | 457 !GenerateUnoptimizedCode(info)) { |
| 456 Isolate* isolate = info->isolate(); | 458 Isolate* isolate = info->isolate(); |
| 457 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 459 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
| 458 return false; | 460 return false; |
| 459 } | 461 } |
| 460 return true; | 462 return true; |
| 461 } | 463 } |
| 462 | 464 |
| 463 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { | 465 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { |
| 466 RuntimeCallTimerScope runtimeTimer( |
| 467 info->isolate(), &RuntimeCallStats::CompileGetUnoptimizedCode); |
| 464 VMState<COMPILER> state(info->isolate()); | 468 VMState<COMPILER> state(info->isolate()); |
| 465 PostponeInterruptsScope postpone(info->isolate()); | 469 PostponeInterruptsScope postpone(info->isolate()); |
| 466 | 470 |
| 467 // Parse and update CompilationInfo with the results. | 471 // Parse and update CompilationInfo with the results. |
| 468 if (!parsing::ParseAny(info->parse_info())) return MaybeHandle<Code>(); | 472 if (!parsing::ParseAny(info->parse_info())) return MaybeHandle<Code>(); |
| 469 DCHECK_EQ(info->shared_info()->language_mode(), | 473 DCHECK_EQ(info->shared_info()->language_mode(), |
| 470 info->literal()->language_mode()); | 474 info->literal()->language_mode()); |
| 471 | 475 |
| 472 // Compile either unoptimized code or bytecode for the interpreter. | 476 // Compile either unoptimized code or bytecode for the interpreter. |
| 473 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 477 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
| 474 | 478 |
| 475 // Record the function compilation event. | 479 // Record the function compilation event. |
| 476 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 480 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
| 477 | 481 |
| 478 return info->code(); | 482 return info->code(); |
| 479 } | 483 } |
| 480 | 484 |
| 481 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 485 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
| 482 Handle<JSFunction> function, BailoutId osr_ast_id) { | 486 Handle<JSFunction> function, BailoutId osr_ast_id) { |
| 487 RuntimeCallTimerScope runtimeTimer( |
| 488 function->GetIsolate(), |
| 489 &RuntimeCallStats::CompileGetFromOptimizedCodeMap); |
| 483 Handle<SharedFunctionInfo> shared(function->shared()); | 490 Handle<SharedFunctionInfo> shared(function->shared()); |
| 484 DisallowHeapAllocation no_gc; | 491 DisallowHeapAllocation no_gc; |
| 485 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 492 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( |
| 486 function->context()->native_context(), osr_ast_id); | 493 function->context()->native_context(), osr_ast_id); |
| 487 if (cached.code != nullptr) { | 494 if (cached.code != nullptr) { |
| 488 // Caching of optimized code enabled and optimized code found. | 495 // Caching of optimized code enabled and optimized code found. |
| 489 if (cached.literals != nullptr) function->set_literals(cached.literals); | 496 if (cached.literals != nullptr) function->set_literals(cached.literals); |
| 490 DCHECK(!cached.code->marked_for_deoptimization()); | 497 DCHECK(!cached.code->marked_for_deoptimization()); |
| 491 DCHECK(function->shared()->is_compiled()); | 498 DCHECK(function->shared()->is_compiled()); |
| 492 return Handle<Code>(cached.code); | 499 return Handle<Code>(cached.code); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, &info); | 863 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, &info); |
| 857 | 864 |
| 858 return info.code(); | 865 return info.code(); |
| 859 } | 866 } |
| 860 | 867 |
| 861 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { | 868 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { |
| 862 Isolate* isolate = function->GetIsolate(); | 869 Isolate* isolate = function->GetIsolate(); |
| 863 DCHECK(!isolate->has_pending_exception()); | 870 DCHECK(!isolate->has_pending_exception()); |
| 864 DCHECK(!function->is_compiled()); | 871 DCHECK(!function->is_compiled()); |
| 865 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); | 872 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); |
| 866 RuntimeCallTimerScope runtimeTimer(isolate, | |
| 867 &RuntimeCallStats::CompileCodeLazy); | |
| 868 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); | 873 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); |
| 869 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 874 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 870 | 875 |
| 871 Handle<Code> cached_code; | 876 Handle<Code> cached_code; |
| 872 if (GetCodeFromOptimizedCodeMap(function, BailoutId::None()) | 877 if (GetCodeFromOptimizedCodeMap(function, BailoutId::None()) |
| 873 .ToHandle(&cached_code)) { | 878 .ToHandle(&cached_code)) { |
| 874 if (FLAG_trace_opt) { | 879 if (FLAG_trace_opt) { |
| 875 PrintF("[found optimized code for "); | 880 PrintF("[found optimized code for "); |
| 876 function->ShortPrint(); | 881 function->ShortPrint(); |
| 877 PrintF(" during unoptimized compile]\n"); | 882 PrintF(" during unoptimized compile]\n"); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 return result; | 1021 return result; |
| 1017 } | 1022 } |
| 1018 | 1023 |
| 1019 } // namespace | 1024 } // namespace |
| 1020 | 1025 |
| 1021 // ---------------------------------------------------------------------------- | 1026 // ---------------------------------------------------------------------------- |
| 1022 // Implementation of Compiler | 1027 // Implementation of Compiler |
| 1023 | 1028 |
| 1024 bool Compiler::Analyze(ParseInfo* info) { | 1029 bool Compiler::Analyze(ParseInfo* info) { |
| 1025 DCHECK_NOT_NULL(info->literal()); | 1030 DCHECK_NOT_NULL(info->literal()); |
| 1031 RuntimeCallTimerScope runtimeTimer(info->isolate(), |
| 1032 &RuntimeCallStats::CompileAnalyse); |
| 1026 if (!Rewriter::Rewrite(info)) return false; | 1033 if (!Rewriter::Rewrite(info)) return false; |
| 1027 DeclarationScope::Analyze(info, AnalyzeMode::kRegular); | 1034 DeclarationScope::Analyze(info, AnalyzeMode::kRegular); |
| 1028 if (!Renumber(info)) return false; | 1035 if (!Renumber(info)) return false; |
| 1029 DCHECK_NOT_NULL(info->scope()); | 1036 DCHECK_NOT_NULL(info->scope()); |
| 1030 return true; | 1037 return true; |
| 1031 } | 1038 } |
| 1032 | 1039 |
| 1033 bool Compiler::ParseAndAnalyze(ParseInfo* info) { | 1040 bool Compiler::ParseAndAnalyze(ParseInfo* info) { |
| 1034 if (!parsing::ParseAny(info)) return false; | 1041 if (!parsing::ParseAny(info)) return false; |
| 1035 if (!Compiler::Analyze(info)) return false; | 1042 if (!Compiler::Analyze(info)) return false; |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 DCHECK(shared->is_compiled()); | 1728 DCHECK(shared->is_compiled()); |
| 1722 function->set_literals(cached.literals); | 1729 function->set_literals(cached.literals); |
| 1723 } else if (shared->is_compiled()) { | 1730 } else if (shared->is_compiled()) { |
| 1724 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1731 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1725 JSFunction::EnsureLiterals(function); | 1732 JSFunction::EnsureLiterals(function); |
| 1726 } | 1733 } |
| 1727 } | 1734 } |
| 1728 | 1735 |
| 1729 } // namespace internal | 1736 } // namespace internal |
| 1730 } // namespace v8 | 1737 } // namespace v8 |
| OLD | NEW |