| 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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 time_taken_to_codegen_); | 440 time_taken_to_codegen_); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 // ---------------------------------------------------------------------------- | 444 // ---------------------------------------------------------------------------- |
| 445 // Local helper methods that make up the compilation pipeline. | 445 // Local helper methods that make up the compilation pipeline. |
| 446 | 446 |
| 447 namespace { | 447 namespace { |
| 448 | 448 |
| 449 void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 449 void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 450 CompilationInfo* info, | 450 CompilationInfo* info) { |
| 451 Handle<SharedFunctionInfo> shared) { | |
| 452 // SharedFunctionInfo is passed separately, because if CompilationInfo | |
| 453 // was created using Script object, it will not have it. | |
| 454 | |
| 455 // Log the code generation. If source information is available include | 451 // Log the code generation. If source information is available include |
| 456 // script name and line number. Check explicitly whether logging is | 452 // script name and line number. Check explicitly whether logging is |
| 457 // enabled as finding the line number is not free. | 453 // enabled as finding the line number is not free. |
| 458 if (info->isolate()->logger()->is_logging_code_events() || | 454 if (info->isolate()->logger()->is_logging_code_events() || |
| 459 info->isolate()->cpu_profiler()->is_profiling()) { | 455 info->isolate()->cpu_profiler()->is_profiling()) { |
| 456 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 460 Handle<Script> script = info->parse_info()->script(); | 457 Handle<Script> script = info->parse_info()->script(); |
| 461 Handle<AbstractCode> abstract_code = info->abstract_code(); | 458 Handle<AbstractCode> abstract_code = |
| 459 info->has_bytecode_array() |
| 460 ? Handle<AbstractCode>::cast(info->bytecode_array()) |
| 461 : Handle<AbstractCode>::cast(info->code()); |
| 462 if (abstract_code.is_identical_to( | 462 if (abstract_code.is_identical_to( |
| 463 info->isolate()->builtins()->CompileLazy())) { | 463 info->isolate()->builtins()->CompileLazy())) { |
| 464 return; | 464 return; |
| 465 } | 465 } |
| 466 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; | 466 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; |
| 467 int column_num = | 467 int column_num = |
| 468 Script::GetColumnNumber(script, shared->start_position()) + 1; | 468 Script::GetColumnNumber(script, shared->start_position()) + 1; |
| 469 String* script_name = script->name()->IsString() | 469 String* script_name = script->name()->IsString() |
| 470 ? String::cast(script->name()) | 470 ? String::cast(script->name()) |
| 471 : info->isolate()->heap()->empty_string(); | 471 : info->isolate()->heap()->empty_string(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 VMState<COMPILER> state(info->isolate()); | 576 VMState<COMPILER> state(info->isolate()); |
| 577 PostponeInterruptsScope postpone(info->isolate()); | 577 PostponeInterruptsScope postpone(info->isolate()); |
| 578 | 578 |
| 579 // Parse and update CompilationInfo with the results. | 579 // Parse and update CompilationInfo with the results. |
| 580 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); | 580 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); |
| 581 Handle<SharedFunctionInfo> shared = info->shared_info(); | 581 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 582 DCHECK_EQ(shared->language_mode(), info->literal()->language_mode()); | 582 DCHECK_EQ(shared->language_mode(), info->literal()->language_mode()); |
| 583 | 583 |
| 584 // Compile either unoptimized code or bytecode for the interpreter. | 584 // Compile either unoptimized code or bytecode for the interpreter. |
| 585 if (!CompileBaselineCode(info)) return MaybeHandle<Code>(); | 585 if (!CompileBaselineCode(info)) return MaybeHandle<Code>(); |
| 586 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 586 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info); |
| 587 | 587 |
| 588 // Update the shared function info with the scope info. Allocating the | 588 // Update the shared function info with the scope info. Allocating the |
| 589 // ScopeInfo object may cause a GC. | 589 // ScopeInfo object may cause a GC. |
| 590 Handle<ScopeInfo> scope_info = | 590 Handle<ScopeInfo> scope_info = |
| 591 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); | 591 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); |
| 592 | 592 |
| 593 // Install compilation result on the shared function info | 593 // Install compilation result on the shared function info |
| 594 InstallBaselineCompilationResult(info, shared, scope_info); | 594 InstallBaselineCompilationResult(info, shared, scope_info); |
| 595 | 595 |
| 596 return info->code(); | 596 return info->code(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 info->closure()->ShortPrint(); | 719 info->closure()->ShortPrint(); |
| 720 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); | 720 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); |
| 721 } | 721 } |
| 722 return false; | 722 return false; |
| 723 } | 723 } |
| 724 | 724 |
| 725 // Success! | 725 // Success! |
| 726 job->RecordOptimizationStats(); | 726 job->RecordOptimizationStats(); |
| 727 DCHECK(!isolate->has_pending_exception()); | 727 DCHECK(!isolate->has_pending_exception()); |
| 728 InsertCodeIntoOptimizedCodeMap(info); | 728 InsertCodeIntoOptimizedCodeMap(info); |
| 729 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, | 729 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info); |
| 730 info->shared_info()); | |
| 731 return true; | 730 return true; |
| 732 } | 731 } |
| 733 | 732 |
| 734 bool GetOptimizedCodeLater(CompilationInfo* info) { | 733 bool GetOptimizedCodeLater(CompilationInfo* info) { |
| 735 Isolate* isolate = info->isolate(); | 734 Isolate* isolate = info->isolate(); |
| 736 CanonicalHandleScope canonical(isolate); | 735 CanonicalHandleScope canonical(isolate); |
| 737 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); | 736 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); |
| 738 TRACE_EVENT0("v8", "V8.OptimizeCode"); | 737 TRACE_EVENT0("v8", "V8.OptimizeCode"); |
| 739 | 738 |
| 740 if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) { | 739 if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 InstallBaselineCompilationResult(info, result, scope_info); | 1019 InstallBaselineCompilationResult(info, result, scope_info); |
| 1021 | 1020 |
| 1022 Handle<String> script_name = | 1021 Handle<String> script_name = |
| 1023 script->name()->IsString() | 1022 script->name()->IsString() |
| 1024 ? Handle<String>(String::cast(script->name())) | 1023 ? Handle<String>(String::cast(script->name())) |
| 1025 : isolate->factory()->empty_string(); | 1024 : isolate->factory()->empty_string(); |
| 1026 Logger::LogEventsAndTags log_tag = info->is_eval() | 1025 Logger::LogEventsAndTags log_tag = info->is_eval() |
| 1027 ? Logger::EVAL_TAG | 1026 ? Logger::EVAL_TAG |
| 1028 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); | 1027 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); |
| 1029 | 1028 |
| 1030 PROFILE(isolate, CodeCreateEvent(log_tag, *info->abstract_code(), *result, | 1029 PROFILE(isolate, CodeCreateEvent(log_tag, result->abstract_code(), *result, |
| 1031 info, *script_name)); | 1030 info, *script_name)); |
| 1032 | 1031 |
| 1033 if (!script.is_null()) | 1032 if (!script.is_null()) |
| 1034 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); | 1033 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); |
| 1035 | 1034 |
| 1036 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); | 1035 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); |
| 1037 } | 1036 } |
| 1038 | 1037 |
| 1039 return result; | 1038 return result; |
| 1040 } | 1039 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 | 1210 |
| 1212 // The scope info might not have been set if a lazily compiled | 1211 // The scope info might not have been set if a lazily compiled |
| 1213 // function is inlined before being called for the first time. | 1212 // function is inlined before being called for the first time. |
| 1214 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { | 1213 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { |
| 1215 Handle<ScopeInfo> target_scope_info = | 1214 Handle<ScopeInfo> target_scope_info = |
| 1216 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); | 1215 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); |
| 1217 shared->set_scope_info(*target_scope_info); | 1216 shared->set_scope_info(*target_scope_info); |
| 1218 } | 1217 } |
| 1219 | 1218 |
| 1220 // The existing unoptimized code was replaced with the new one. | 1219 // The existing unoptimized code was replaced with the new one. |
| 1221 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized, shared); | 1220 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized); |
| 1222 } | 1221 } |
| 1223 return true; | 1222 return true; |
| 1224 } | 1223 } |
| 1225 | 1224 |
| 1226 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( | 1225 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
| 1227 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 1226 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
| 1228 Handle<Context> context, LanguageMode language_mode, | 1227 Handle<Context> context, LanguageMode language_mode, |
| 1229 ParseRestriction restriction, int eval_scope_position, int eval_position, | 1228 ParseRestriction restriction, int eval_scope_position, int eval_position, |
| 1230 int line_offset, int column_offset, Handle<Object> script_name, | 1229 int line_offset, int column_offset, Handle<Object> script_name, |
| 1231 ScriptOriginOptions options) { | 1230 ScriptOriginOptions options) { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 literal->should_be_used_once_hint()) { | 1538 literal->should_be_used_once_hint()) { |
| 1540 info.code()->MarkToBeExecutedOnce(isolate); | 1539 info.code()->MarkToBeExecutedOnce(isolate); |
| 1541 } | 1540 } |
| 1542 // Install compilation result on the shared function info. | 1541 // Install compilation result on the shared function info. |
| 1543 InstallBaselineCompilationResult(&info, result, scope_info); | 1542 InstallBaselineCompilationResult(&info, result, scope_info); |
| 1544 } else { | 1543 } else { |
| 1545 return Handle<SharedFunctionInfo>::null(); | 1544 return Handle<SharedFunctionInfo>::null(); |
| 1546 } | 1545 } |
| 1547 | 1546 |
| 1548 if (maybe_existing.is_null()) { | 1547 if (maybe_existing.is_null()) { |
| 1549 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 1548 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info); |
| 1550 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); | 1549 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); |
| 1551 } | 1550 } |
| 1552 | 1551 |
| 1553 return result; | 1552 return result; |
| 1554 } | 1553 } |
| 1555 | 1554 |
| 1556 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( | 1555 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( |
| 1557 v8::Extension* extension, Handle<String> name) { | 1556 v8::Extension* extension, Handle<String> name) { |
| 1558 Isolate* isolate = name->GetIsolate(); | 1557 Isolate* isolate = name->GetIsolate(); |
| 1559 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 1558 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1613 // Except when OSR already disabled optimization for some reason. | 1612 // Except when OSR already disabled optimization for some reason. |
| 1614 // 3) The code may have already been invalidated due to dependency change. | 1613 // 3) The code may have already been invalidated due to dependency change. |
| 1615 // 4) Code generation may have failed. | 1614 // 4) Code generation may have failed. |
| 1616 if (job->last_status() == OptimizedCompileJob::SUCCEEDED) { | 1615 if (job->last_status() == OptimizedCompileJob::SUCCEEDED) { |
| 1617 if (shared->optimization_disabled()) { | 1616 if (shared->optimization_disabled()) { |
| 1618 job->RetryOptimization(kOptimizationDisabled); | 1617 job->RetryOptimization(kOptimizationDisabled); |
| 1619 } else if (info->dependencies()->HasAborted()) { | 1618 } else if (info->dependencies()->HasAborted()) { |
| 1620 job->RetryOptimization(kBailedOutDueToDependencyChange); | 1619 job->RetryOptimization(kBailedOutDueToDependencyChange); |
| 1621 } else if (job->GenerateCode() == OptimizedCompileJob::SUCCEEDED) { | 1620 } else if (job->GenerateCode() == OptimizedCompileJob::SUCCEEDED) { |
| 1622 job->RecordOptimizationStats(); | 1621 job->RecordOptimizationStats(); |
| 1623 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info.get(), shared); | 1622 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info.get()); |
| 1624 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), | 1623 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), |
| 1625 info->osr_ast_id()).code == nullptr) { | 1624 info->osr_ast_id()).code == nullptr) { |
| 1626 InsertCodeIntoOptimizedCodeMap(info.get()); | 1625 InsertCodeIntoOptimizedCodeMap(info.get()); |
| 1627 } | 1626 } |
| 1628 if (FLAG_trace_opt) { | 1627 if (FLAG_trace_opt) { |
| 1629 PrintF("[completed optimizing "); | 1628 PrintF("[completed optimizing "); |
| 1630 info->closure()->ShortPrint(); | 1629 info->closure()->ShortPrint(); |
| 1631 PrintF("]\n"); | 1630 PrintF("]\n"); |
| 1632 } | 1631 } |
| 1633 info->closure()->ReplaceCode(*info->code()); | 1632 info->closure()->ReplaceCode(*info->code()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 MaybeHandle<Code> code; | 1674 MaybeHandle<Code> code; |
| 1676 if (cached.code != nullptr) code = handle(cached.code); | 1675 if (cached.code != nullptr) code = handle(cached.code); |
| 1677 Handle<Context> native_context(function->context()->native_context()); | 1676 Handle<Context> native_context(function->context()->native_context()); |
| 1678 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1677 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 1679 literals, BailoutId::None()); | 1678 literals, BailoutId::None()); |
| 1680 } | 1679 } |
| 1681 } | 1680 } |
| 1682 | 1681 |
| 1683 } // namespace internal | 1682 } // namespace internal |
| 1684 } // namespace v8 | 1683 } // namespace v8 |
| OLD | NEW |