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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 bool CompileBaselineCode(CompilationInfo* info) { | 551 bool CompileBaselineCode(CompilationInfo* info) { |
552 DCHECK(AllowCompilation::IsAllowed(info->isolate())); | 552 DCHECK(AllowCompilation::IsAllowed(info->isolate())); |
553 if (!Compiler::Analyze(info->parse_info()) || !GenerateBaselineCode(info)) { | 553 if (!Compiler::Analyze(info->parse_info()) || !GenerateBaselineCode(info)) { |
554 Isolate* isolate = info->isolate(); | 554 Isolate* isolate = info->isolate(); |
555 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 555 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
556 return false; | 556 return false; |
557 } | 557 } |
558 return true; | 558 return true; |
559 } | 559 } |
560 | 560 |
561 void InstallBaselineCompilationResult(CompilationInfo* info, | 561 void InstallSharedScopeInfo(CompilationInfo* info, |
562 Handle<SharedFunctionInfo> shared, | 562 Handle<SharedFunctionInfo> shared) { |
563 Handle<ScopeInfo> scope_info) { | 563 Handle<ScopeInfo> scope_info = |
| 564 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); |
| 565 shared->set_scope_info(*scope_info); |
| 566 } |
| 567 |
| 568 void InstallSharedCompilationResult(CompilationInfo* info, |
| 569 Handle<SharedFunctionInfo> shared) { |
564 // Assert that we are not overwriting (possibly patched) debug code. | 570 // Assert that we are not overwriting (possibly patched) debug code. |
565 DCHECK(!shared->HasDebugCode()); | 571 DCHECK(!shared->HasDebugCode()); |
566 DCHECK(!info->code().is_null()); | 572 DCHECK(!info->code().is_null()); |
567 shared->ReplaceCode(*info->code()); | 573 shared->ReplaceCode(*info->code()); |
568 shared->set_scope_info(*scope_info); | |
569 if (info->has_bytecode_array()) { | 574 if (info->has_bytecode_array()) { |
570 DCHECK(!shared->HasBytecodeArray()); // Only compiled once. | 575 DCHECK(!shared->HasBytecodeArray()); // Only compiled once. |
571 shared->set_bytecode_array(*info->bytecode_array()); | 576 shared->set_bytecode_array(*info->bytecode_array()); |
572 } | 577 } |
573 } | 578 } |
574 | 579 |
575 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { | 580 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { |
576 VMState<COMPILER> state(info->isolate()); | 581 VMState<COMPILER> state(info->isolate()); |
577 PostponeInterruptsScope postpone(info->isolate()); | 582 PostponeInterruptsScope postpone(info->isolate()); |
578 | 583 |
579 // Parse and update CompilationInfo with the results. | 584 // Parse and update CompilationInfo with the results. |
580 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); | 585 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); |
581 Handle<SharedFunctionInfo> shared = info->shared_info(); | 586 Handle<SharedFunctionInfo> shared = info->shared_info(); |
582 DCHECK_EQ(shared->language_mode(), info->literal()->language_mode()); | 587 DCHECK_EQ(shared->language_mode(), info->literal()->language_mode()); |
583 | 588 |
584 // Compile either unoptimized code or bytecode for the interpreter. | 589 // Compile either unoptimized code or bytecode for the interpreter. |
585 if (!CompileBaselineCode(info)) return MaybeHandle<Code>(); | 590 if (!CompileBaselineCode(info)) return MaybeHandle<Code>(); |
586 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); | 591 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
587 | 592 |
588 // Update the shared function info with the scope info. Allocating the | 593 // Update the shared function info with the scope info. |
589 // ScopeInfo object may cause a GC. | 594 InstallSharedScopeInfo(info, shared); |
590 Handle<ScopeInfo> scope_info = | |
591 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); | |
592 | 595 |
593 // Install compilation result on the shared function info | 596 // Install compilation result on the shared function info |
594 InstallBaselineCompilationResult(info, shared, scope_info); | 597 InstallSharedCompilationResult(info, shared); |
595 | 598 |
596 return info->code(); | 599 return info->code(); |
597 } | 600 } |
598 | 601 |
599 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 602 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
600 Handle<JSFunction> function, BailoutId osr_ast_id) { | 603 Handle<JSFunction> function, BailoutId osr_ast_id) { |
601 Handle<SharedFunctionInfo> shared(function->shared()); | 604 Handle<SharedFunctionInfo> shared(function->shared()); |
602 DisallowHeapAllocation no_gc; | 605 DisallowHeapAllocation no_gc; |
603 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 606 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( |
604 function->context()->native_context(), osr_ast_id); | 607 function->context()->native_context(), osr_ast_id); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 // Eval scripts cannot be (re-)compiled without context. | 1014 // Eval scripts cannot be (re-)compiled without context. |
1012 result->set_allows_lazy_compilation_without_context(false); | 1015 result->set_allows_lazy_compilation_without_context(false); |
1013 } | 1016 } |
1014 parse_info->set_shared_info(result); | 1017 parse_info->set_shared_info(result); |
1015 | 1018 |
1016 // Compile the code. | 1019 // Compile the code. |
1017 if (!CompileBaselineCode(info)) { | 1020 if (!CompileBaselineCode(info)) { |
1018 return Handle<SharedFunctionInfo>::null(); | 1021 return Handle<SharedFunctionInfo>::null(); |
1019 } | 1022 } |
1020 | 1023 |
| 1024 // Update the shared function info with the scope info. |
| 1025 InstallSharedScopeInfo(info, result); |
| 1026 |
1021 // Install compilation result on the shared function info | 1027 // Install compilation result on the shared function info |
1022 Handle<ScopeInfo> scope_info = | 1028 InstallSharedCompilationResult(info, result); |
1023 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); | |
1024 InstallBaselineCompilationResult(info, result, scope_info); | |
1025 | 1029 |
1026 Handle<String> script_name = | 1030 Handle<String> script_name = |
1027 script->name()->IsString() | 1031 script->name()->IsString() |
1028 ? Handle<String>(String::cast(script->name())) | 1032 ? Handle<String>(String::cast(script->name())) |
1029 : isolate->factory()->empty_string(); | 1033 : isolate->factory()->empty_string(); |
1030 Logger::LogEventsAndTags log_tag = info->is_eval() | 1034 Logger::LogEventsAndTags log_tag = info->is_eval() |
1031 ? Logger::EVAL_TAG | 1035 ? Logger::EVAL_TAG |
1032 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); | 1036 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); |
1033 | 1037 |
1034 PROFILE(isolate, CodeCreateEvent(log_tag, *info->abstract_code(), *result, | 1038 PROFILE(isolate, CodeCreateEvent(log_tag, *info->abstract_code(), *result, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 unoptimized.PrepareForSerializing(); | 1213 unoptimized.PrepareForSerializing(); |
1210 } | 1214 } |
1211 EnsureFeedbackVector(&unoptimized); | 1215 EnsureFeedbackVector(&unoptimized); |
1212 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; | 1216 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; |
1213 | 1217 |
1214 shared->EnableDeoptimizationSupport(*unoptimized.code()); | 1218 shared->EnableDeoptimizationSupport(*unoptimized.code()); |
1215 | 1219 |
1216 // The scope info might not have been set if a lazily compiled | 1220 // The scope info might not have been set if a lazily compiled |
1217 // function is inlined before being called for the first time. | 1221 // function is inlined before being called for the first time. |
1218 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { | 1222 if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { |
1219 Handle<ScopeInfo> target_scope_info = | 1223 InstallSharedScopeInfo(info, shared); |
1220 ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); | |
1221 shared->set_scope_info(*target_scope_info); | |
1222 } | 1224 } |
1223 | 1225 |
1224 // The existing unoptimized code was replaced with the new one. | 1226 // The existing unoptimized code was replaced with the new one. |
1225 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized, shared); | 1227 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized, shared); |
1226 } | 1228 } |
1227 return true; | 1229 return true; |
1228 } | 1230 } |
1229 | 1231 |
1230 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( | 1232 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( |
1231 Handle<String> source, Handle<SharedFunctionInfo> outer_info, | 1233 Handle<String> source, Handle<SharedFunctionInfo> outer_info, |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1531 | 1533 |
1532 // Generate code | 1534 // Generate code |
1533 TimerEventScope<TimerEventCompileCode> timer(isolate); | 1535 TimerEventScope<TimerEventCompileCode> timer(isolate); |
1534 TRACE_EVENT0("v8", "V8.CompileCode"); | 1536 TRACE_EVENT0("v8", "V8.CompileCode"); |
1535 if (lazy) { | 1537 if (lazy) { |
1536 info.SetCode(isolate->builtins()->CompileLazy()); | 1538 info.SetCode(isolate->builtins()->CompileLazy()); |
1537 } else if (Renumber(info.parse_info()) && GenerateBaselineCode(&info)) { | 1539 } else if (Renumber(info.parse_info()) && GenerateBaselineCode(&info)) { |
1538 // Code generation will ensure that the feedback vector is present and | 1540 // Code generation will ensure that the feedback vector is present and |
1539 // appropriately sized. | 1541 // appropriately sized. |
1540 DCHECK(!info.code().is_null()); | 1542 DCHECK(!info.code().is_null()); |
1541 Handle<ScopeInfo> scope_info = | |
1542 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | |
1543 if (literal->should_eager_compile() && | 1543 if (literal->should_eager_compile() && |
1544 literal->should_be_used_once_hint()) { | 1544 literal->should_be_used_once_hint()) { |
1545 info.code()->MarkToBeExecutedOnce(isolate); | 1545 info.code()->MarkToBeExecutedOnce(isolate); |
1546 } | 1546 } |
| 1547 // Update the shared function info with the scope info. |
| 1548 InstallSharedScopeInfo(&info, result); |
1547 // Install compilation result on the shared function info. | 1549 // Install compilation result on the shared function info. |
1548 InstallBaselineCompilationResult(&info, result, scope_info); | 1550 InstallSharedCompilationResult(&info, result); |
1549 } else { | 1551 } else { |
1550 return Handle<SharedFunctionInfo>::null(); | 1552 return Handle<SharedFunctionInfo>::null(); |
1551 } | 1553 } |
1552 | 1554 |
1553 if (maybe_existing.is_null()) { | 1555 if (maybe_existing.is_null()) { |
1554 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); | 1556 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, result); |
1555 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); | 1557 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); |
1556 } | 1558 } |
1557 | 1559 |
1558 return result; | 1560 return result; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 MaybeHandle<Code> code; | 1682 MaybeHandle<Code> code; |
1681 if (cached.code != nullptr) code = handle(cached.code); | 1683 if (cached.code != nullptr) code = handle(cached.code); |
1682 Handle<Context> native_context(function->context()->native_context()); | 1684 Handle<Context> native_context(function->context()->native_context()); |
1683 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1685 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1684 literals, BailoutId::None()); | 1686 literals, BailoutId::None()); |
1685 } | 1687 } |
1686 } | 1688 } |
1687 | 1689 |
1688 } // namespace internal | 1690 } // namespace internal |
1689 } // namespace v8 | 1691 } // namespace v8 |
OLD | NEW |