Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: src/compiler.cc

Issue 2399833002: Teach Scopes whether they will end up being lazily compiled or not (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compilation-info.cc ('k') | src/parsing/parse-info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 // only needs to be done when the given function has bytecode, otherwise we 1387 // only needs to be done when the given function has bytecode, otherwise we
1388 // can be sure there are no activations. Note that this only applies in case 1388 // can be sure there are no activations. Note that this only applies in case
1389 // the --ignition-preserve-bytecode flag is not passed. 1389 // the --ignition-preserve-bytecode flag is not passed.
1390 if (!FLAG_ignition_preserve_bytecode && shared->HasBytecodeArray()) { 1390 if (!FLAG_ignition_preserve_bytecode && shared->HasBytecodeArray()) {
1391 InterpreterActivationsFinder activations_finder(*shared); 1391 InterpreterActivationsFinder activations_finder(*shared);
1392 if (HasInterpreterActivations(info->isolate(), &activations_finder)) { 1392 if (HasInterpreterActivations(info->isolate(), &activations_finder)) {
1393 return false; 1393 return false;
1394 } 1394 }
1395 } 1395 }
1396 1396
1397 // When we call PrepareForSerializing below, we will change the shared
1398 // ParseInfo. Make sure to reset it.
1399 bool old_will_serialize_value = info->parse_info()->will_serialize();
1400
1397 // If the current code has reloc info for serialization, also include 1401 // If the current code has reloc info for serialization, also include
1398 // reloc info for serialization for the new code, so that deopt support 1402 // reloc info for serialization for the new code, so that deopt support
1399 // can be added without losing IC state. 1403 // can be added without losing IC state.
1400 if (shared->code()->kind() == Code::FUNCTION && 1404 if (shared->code()->kind() == Code::FUNCTION &&
1401 shared->code()->has_reloc_info_for_serialization()) { 1405 shared->code()->has_reloc_info_for_serialization()) {
1402 unoptimized.PrepareForSerializing(); 1406 unoptimized.PrepareForSerializing();
1403 } 1407 }
1404 EnsureFeedbackMetadata(&unoptimized); 1408 EnsureFeedbackMetadata(&unoptimized);
1405 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false; 1409 if (!FullCodeGenerator::MakeCode(&unoptimized)) return false;
1406 1410
1411 info->parse_info()->set_will_serialize(old_will_serialize_value);
1412
1407 // TODO(4280): For now we play it safe and remove the bytecode array when we 1413 // TODO(4280): For now we play it safe and remove the bytecode array when we
1408 // switch to baseline code. We might consider keeping around the bytecode so 1414 // switch to baseline code. We might consider keeping around the bytecode so
1409 // that it can be used as the "source of truth" eventually. Note that this 1415 // that it can be used as the "source of truth" eventually. Note that this
1410 // only applies in case the --ignition-preserve-bytecode flag is not passed. 1416 // only applies in case the --ignition-preserve-bytecode flag is not passed.
1411 if (!FLAG_ignition_preserve_bytecode && shared->HasBytecodeArray()) { 1417 if (!FLAG_ignition_preserve_bytecode && shared->HasBytecodeArray()) {
1412 shared->ClearBytecodeArray(); 1418 shared->ClearBytecodeArray();
1413 } 1419 }
1414 1420
1415 // The scope info might not have been set if a lazily compiled 1421 // The scope info might not have been set if a lazily compiled
1416 // function is inlined before being called for the first time. 1422 // function is inlined before being called for the first time.
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 1763
1758 Zone zone(isolate->allocator()); 1764 Zone zone(isolate->allocator());
1759 ParseInfo parse_info(&zone, script); 1765 ParseInfo parse_info(&zone, script);
1760 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 1766 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
1761 parse_info.set_literal(literal); 1767 parse_info.set_literal(literal);
1762 parse_info.set_shared_info(result); 1768 parse_info.set_shared_info(result);
1763 parse_info.set_language_mode(literal->scope()->language_mode()); 1769 parse_info.set_language_mode(literal->scope()->language_mode());
1764 if (outer_info->will_serialize()) info.PrepareForSerializing(); 1770 if (outer_info->will_serialize()) info.PrepareForSerializing();
1765 if (outer_info->is_debug()) info.MarkAsDebug(); 1771 if (outer_info->is_debug()) info.MarkAsDebug();
1766 1772
1767 // Determine if the function can be lazily compiled. This is necessary to
1768 // allow some of our builtin JS files to be lazily compiled. These
1769 // builtins cannot be handled lazily by the parser, since we have to know
1770 // if a function uses the special natives syntax, which is something the
1771 // parser records.
1772 // If the debugger requests compilation for break points, we cannot be
1773 // aggressive about lazy compilation, because it might trigger compilation
1774 // of functions without an outer context when setting a breakpoint through
1775 // Debug::FindSharedFunctionInfoInScript.
1776 bool allow_lazy = literal->AllowsLazyCompilation() && !info.is_debug();
1777 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile();
1778
1779 // Consider compiling eagerly when targeting the code cache.
1780 lazy &= !(FLAG_serialize_eager && info.will_serialize());
1781
1782 // Consider compiling eagerly when compiling bytecode for Ignition.
1783 lazy &=
1784 !(FLAG_ignition && FLAG_ignition_eager && !isolate->serializer_enabled());
1785
1786 // Generate code 1773 // Generate code
1787 TimerEventScope<TimerEventCompileCode> timer(isolate); 1774 TimerEventScope<TimerEventCompileCode> timer(isolate);
1788 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::CompileCode); 1775 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::CompileCode);
1789 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); 1776 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode");
1790 1777
1791 if (lazy) { 1778 if (!literal->ShouldEagerCompile()) {
1792 info.SetCode(isolate->builtins()->CompileLazy()); 1779 info.SetCode(isolate->builtins()->CompileLazy());
1793 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext(); 1780 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext();
1794 if (outer_scope) { 1781 if (outer_scope) {
1795 result->set_outer_scope_info(*outer_scope->scope_info()); 1782 result->set_outer_scope_info(*outer_scope->scope_info());
1796 } 1783 }
1797 } else if (Renumber(info.parse_info()) && GenerateUnoptimizedCode(&info)) { 1784 } else if (Renumber(info.parse_info()) && GenerateUnoptimizedCode(&info)) {
1798 // Code generation will ensure that the feedback vector is present and 1785 // Code generation will ensure that the feedback vector is present and
1799 // appropriately sized. 1786 // appropriately sized.
1800 DCHECK(!info.code().is_null()); 1787 DCHECK(!info.code().is_null());
1801 if (literal->should_eager_compile() && 1788 if (literal->should_be_used_once_hint()) {
1802 literal->should_be_used_once_hint()) {
1803 info.code()->MarkToBeExecutedOnce(isolate); 1789 info.code()->MarkToBeExecutedOnce(isolate);
1804 } 1790 }
1805 // Update the shared function info with the scope info. 1791 // Update the shared function info with the scope info.
1806 InstallSharedScopeInfo(&info, result); 1792 InstallSharedScopeInfo(&info, result);
1807 // Install compilation result on the shared function info. 1793 // Install compilation result on the shared function info.
1808 InstallSharedCompilationResult(&info, result); 1794 InstallSharedCompilationResult(&info, result);
1809 } else { 1795 } else {
1810 return Handle<SharedFunctionInfo>::null(); 1796 return Handle<SharedFunctionInfo>::null();
1811 } 1797 }
1812 1798
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 DCHECK(shared->is_compiled()); 1888 DCHECK(shared->is_compiled());
1903 function->set_literals(cached.literals); 1889 function->set_literals(cached.literals);
1904 } else if (shared->is_compiled()) { 1890 } else if (shared->is_compiled()) {
1905 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. 1891 // TODO(mvstanton): pass pretenure flag to EnsureLiterals.
1906 JSFunction::EnsureLiterals(function); 1892 JSFunction::EnsureLiterals(function);
1907 } 1893 }
1908 } 1894 }
1909 1895
1910 } // namespace internal 1896 } // namespace internal
1911 } // namespace v8 1897 } // namespace v8
OLDNEW
« no previous file with comments | « src/compilation-info.cc ('k') | src/parsing/parse-info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698