| 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()); | |
| 103 } else { | 101 } else { |
| 104 DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id())); | 102 DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id())); |
| 105 } | 103 } |
| 106 | 104 |
| 107 // Delegate to the underlying implementation. | 105 // Delegate to the underlying implementation. |
| 108 DCHECK(state() == State::kReadyToExecute); | 106 DCHECK(state() == State::kReadyToExecute); |
| 109 ScopedTimer t(&time_taken_to_execute_); | 107 ScopedTimer t(&time_taken_to_execute_); |
| 110 return UpdateState(ExecuteJobImpl(), State::kReadyToFinalize); | 108 return UpdateState(ExecuteJobImpl(), State::kReadyToFinalize); |
| 111 } | 109 } |
| 112 | 110 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 info->max_function_literal_id() + 1); | 470 info->max_function_literal_id() + 1); |
| 473 return; | 471 return; |
| 474 } | 472 } |
| 475 Isolate* isolate = info->isolate(); | 473 Isolate* isolate = info->isolate(); |
| 476 Handle<FixedArray> infos( | 474 Handle<FixedArray> infos( |
| 477 isolate->factory()->NewFixedArray(info->max_function_literal_id() + 1)); | 475 isolate->factory()->NewFixedArray(info->max_function_literal_id() + 1)); |
| 478 info->script()->set_shared_function_infos(*infos); | 476 info->script()->set_shared_function_infos(*infos); |
| 479 } | 477 } |
| 480 | 478 |
| 481 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { | 479 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { |
| 482 RuntimeCallTimerScope runtimeTimer( | |
| 483 info->isolate(), &RuntimeCallStats::CompileGetUnoptimizedCode); | |
| 484 VMState<COMPILER> state(info->isolate()); | 480 VMState<COMPILER> state(info->isolate()); |
| 485 PostponeInterruptsScope postpone(info->isolate()); | 481 PostponeInterruptsScope postpone(info->isolate()); |
| 486 | 482 |
| 487 // Parse and update CompilationInfo with the results. | 483 // Parse and update CompilationInfo with the results. |
| 488 if (!parsing::ParseAny(info->parse_info())) return MaybeHandle<Code>(); | 484 if (!parsing::ParseAny(info->parse_info())) return MaybeHandle<Code>(); |
| 489 if (info->parse_info()->is_toplevel()) { | 485 if (info->parse_info()->is_toplevel()) { |
| 490 EnsureSharedFunctionInfosArrayOnScript(info->parse_info()); | 486 EnsureSharedFunctionInfosArrayOnScript(info->parse_info()); |
| 491 } | 487 } |
| 492 DCHECK_EQ(info->shared_info()->language_mode(), | 488 DCHECK_EQ(info->shared_info()->language_mode(), |
| 493 info->literal()->language_mode()); | 489 info->literal()->language_mode()); |
| 494 | 490 |
| 495 // Compile either unoptimized code or bytecode for the interpreter. | 491 // Compile either unoptimized code or bytecode for the interpreter. |
| 496 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 492 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
| 497 | 493 |
| 498 // Record the function compilation event. | 494 // Record the function compilation event. |
| 499 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 495 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
| 500 | 496 |
| 501 return info->code(); | 497 return info->code(); |
| 502 } | 498 } |
| 503 | 499 |
| 504 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 500 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
| 505 Handle<JSFunction> function, BailoutId osr_ast_id) { | 501 Handle<JSFunction> function, BailoutId osr_ast_id) { |
| 506 RuntimeCallTimerScope runtimeTimer( | |
| 507 function->GetIsolate(), | |
| 508 &RuntimeCallStats::CompileGetFromOptimizedCodeMap); | |
| 509 Handle<SharedFunctionInfo> shared(function->shared()); | 502 Handle<SharedFunctionInfo> shared(function->shared()); |
| 510 DisallowHeapAllocation no_gc; | 503 DisallowHeapAllocation no_gc; |
| 511 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 504 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( |
| 512 function->context()->native_context(), osr_ast_id); | 505 function->context()->native_context(), osr_ast_id); |
| 513 if (cached.code != nullptr) { | 506 if (cached.code != nullptr) { |
| 514 // Caching of optimized code enabled and optimized code found. | 507 // Caching of optimized code enabled and optimized code found. |
| 515 if (cached.literals != nullptr) function->set_literals(cached.literals); | 508 if (cached.literals != nullptr) function->set_literals(cached.literals); |
| 516 DCHECK(!cached.code->marked_for_deoptimization()); | 509 DCHECK(!cached.code->marked_for_deoptimization()); |
| 517 DCHECK(function->shared()->is_compiled()); | 510 DCHECK(function->shared()->is_compiled()); |
| 518 return Handle<Code>(cached.code); | 511 return Handle<Code>(cached.code); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, &info); | 875 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, &info); |
| 883 | 876 |
| 884 return info.code(); | 877 return info.code(); |
| 885 } | 878 } |
| 886 | 879 |
| 887 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { | 880 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { |
| 888 Isolate* isolate = function->GetIsolate(); | 881 Isolate* isolate = function->GetIsolate(); |
| 889 DCHECK(!isolate->has_pending_exception()); | 882 DCHECK(!isolate->has_pending_exception()); |
| 890 DCHECK(!function->is_compiled()); | 883 DCHECK(!function->is_compiled()); |
| 891 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); | 884 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); |
| 885 RuntimeCallTimerScope runtimeTimer(isolate, |
| 886 &RuntimeCallStats::CompileCodeLazy); |
| 892 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); | 887 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); |
| 893 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 888 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 894 | 889 |
| 895 Handle<Code> cached_code; | 890 Handle<Code> cached_code; |
| 896 if (GetCodeFromOptimizedCodeMap(function, BailoutId::None()) | 891 if (GetCodeFromOptimizedCodeMap(function, BailoutId::None()) |
| 897 .ToHandle(&cached_code)) { | 892 .ToHandle(&cached_code)) { |
| 898 if (FLAG_trace_opt) { | 893 if (FLAG_trace_opt) { |
| 899 PrintF("[found optimized code for "); | 894 PrintF("[found optimized code for "); |
| 900 function->ShortPrint(); | 895 function->ShortPrint(); |
| 901 PrintF(" during unoptimized compile]\n"); | 896 PrintF(" during unoptimized compile]\n"); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 return result; | 1038 return result; |
| 1044 } | 1039 } |
| 1045 | 1040 |
| 1046 } // namespace | 1041 } // namespace |
| 1047 | 1042 |
| 1048 // ---------------------------------------------------------------------------- | 1043 // ---------------------------------------------------------------------------- |
| 1049 // Implementation of Compiler | 1044 // Implementation of Compiler |
| 1050 | 1045 |
| 1051 bool Compiler::Analyze(ParseInfo* info) { | 1046 bool Compiler::Analyze(ParseInfo* info) { |
| 1052 DCHECK_NOT_NULL(info->literal()); | 1047 DCHECK_NOT_NULL(info->literal()); |
| 1053 RuntimeCallTimerScope runtimeTimer(info->isolate(), | |
| 1054 &RuntimeCallStats::CompileAnalyse); | |
| 1055 if (!Rewriter::Rewrite(info)) return false; | 1048 if (!Rewriter::Rewrite(info)) return false; |
| 1056 DeclarationScope::Analyze(info, AnalyzeMode::kRegular); | 1049 DeclarationScope::Analyze(info, AnalyzeMode::kRegular); |
| 1057 if (!Renumber(info)) return false; | 1050 if (!Renumber(info)) return false; |
| 1058 DCHECK_NOT_NULL(info->scope()); | 1051 DCHECK_NOT_NULL(info->scope()); |
| 1059 return true; | 1052 return true; |
| 1060 } | 1053 } |
| 1061 | 1054 |
| 1062 bool Compiler::ParseAndAnalyze(ParseInfo* info) { | 1055 bool Compiler::ParseAndAnalyze(ParseInfo* info) { |
| 1063 if (!parsing::ParseAny(info)) return false; | 1056 if (!parsing::ParseAny(info)) return false; |
| 1064 if (info->is_toplevel()) EnsureSharedFunctionInfosArrayOnScript(info); | 1057 if (info->is_toplevel()) EnsureSharedFunctionInfosArrayOnScript(info); |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 DCHECK(shared->is_compiled()); | 1746 DCHECK(shared->is_compiled()); |
| 1754 function->set_literals(cached.literals); | 1747 function->set_literals(cached.literals); |
| 1755 } else if (shared->is_compiled()) { | 1748 } else if (shared->is_compiled()) { |
| 1756 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1749 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1757 JSFunction::EnsureLiterals(function); | 1750 JSFunction::EnsureLiterals(function); |
| 1758 } | 1751 } |
| 1759 } | 1752 } |
| 1760 | 1753 |
| 1761 } // namespace internal | 1754 } // namespace internal |
| 1762 } // namespace v8 | 1755 } // namespace v8 |
| OLD | NEW |