Chromium Code Reviews

Side by Side Diff: src/compiler.cc

Issue 2399463008: Create multiple compilation jobs for ignition if compiling multiple literals (Closed)
Patch Set: updates Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 328 matching lines...)
339 // Checks whether top level functions should be passed by the filter. 339 // Checks whether top level functions should be passed by the filter.
340 if (info->shared_info()->is_toplevel()) { 340 if (info->shared_info()->is_toplevel()) {
341 Vector<const char> filter = CStrVector(FLAG_ignition_filter); 341 Vector<const char> filter = CStrVector(FLAG_ignition_filter);
342 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); 342 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*');
343 } 343 }
344 344
345 // Finally respect the filter. 345 // Finally respect the filter.
346 return info->shared_info()->PassesFilter(FLAG_ignition_filter); 346 return info->shared_info()->PassesFilter(FLAG_ignition_filter);
347 } 347 }
348 348
349 CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info) { 349 std::vector<std::unique_ptr<CompilationJob>> GetUnoptimizedCompilationJob(
350 CompilationInfo* info) {
350 // Function should have been parsed and analyzed before creating a compilation 351 // Function should have been parsed and analyzed before creating a compilation
351 // job. 352 // job.
352 DCHECK_NOT_NULL(info->literal()); 353 DCHECK_NOT_NULL(info->literal());
353 DCHECK_NOT_NULL(info->scope()); 354 DCHECK_NOT_NULL(info->scope());
354 355
355 EnsureFeedbackMetadata(info); 356 EnsureFeedbackMetadata(info);
356 if (ShouldUseIgnition(info)) { 357 if (ShouldUseIgnition(info)) {
357 return interpreter::Interpreter::NewCompilationJob(info); 358 return interpreter::Interpreter::NewCompilationJob(info);
358 } else { 359 } else {
359 return FullCodeGenerator::NewCompilationJob(info); 360 std::unique_ptr<CompilationJob> job(
361 FullCodeGenerator::NewCompilationJob(info));
362 std::vector<std::unique_ptr<CompilationJob>> result;
363 result.push_back(std::move(job));
364 return result;
360 } 365 }
361 } 366 }
362 367
363 bool GenerateUnoptimizedCode(CompilationInfo* info) {
364 if (FLAG_validate_asm && info->scope()->asm_module() &&
365 !info->shared_info()->is_asm_wasm_broken()) {
366 EnsureFeedbackMetadata(info);
367 MaybeHandle<FixedArray> wasm_data;
368 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info());
369 if (!wasm_data.is_null()) {
370 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked());
371 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs());
372 return true;
373 }
374 }
375
376 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info));
377 if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false;
378 if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false;
379 if (job->FinalizeJob() != CompilationJob::SUCCEEDED) return false;
380 job->RecordUnoptimizedCompilationStats();
381 return true;
382 }
383
384 bool CompileUnoptimizedCode(CompilationInfo* info) {
385 DCHECK(AllowCompilation::IsAllowed(info->isolate()));
386 if (!Compiler::Analyze(info->parse_info()) ||
387 !GenerateUnoptimizedCode(info)) {
388 Isolate* isolate = info->isolate();
389 if (!isolate->has_pending_exception()) isolate->StackOverflow();
390 return false;
391 }
392 return true;
393 }
394
395 void InstallSharedScopeInfo(CompilationInfo* info, 368 void InstallSharedScopeInfo(CompilationInfo* info,
396 Handle<SharedFunctionInfo> shared) { 369 Handle<SharedFunctionInfo> shared) {
397 Handle<ScopeInfo> scope_info = info->scope()->scope_info(); 370 Handle<ScopeInfo> scope_info = info->scope()->scope_info();
398 shared->set_scope_info(*scope_info); 371 shared->set_scope_info(*scope_info);
399 Scope* outer_scope = info->scope()->GetOuterScopeWithContext(); 372 Scope* outer_scope = info->scope()->GetOuterScopeWithContext();
400 if (outer_scope) { 373 if (outer_scope) {
401 shared->set_outer_scope_info(*outer_scope->scope_info()); 374 shared->set_outer_scope_info(*outer_scope->scope_info());
402 } 375 }
403 } 376 }
404 377
(...skipping 19 matching lines...)
424 // Update the shared function info with the scope info. 397 // Update the shared function info with the scope info.
425 InstallSharedScopeInfo(info, shared); 398 InstallSharedScopeInfo(info, shared);
426 399
427 // Install compilation result on the shared function info 400 // Install compilation result on the shared function info
428 InstallSharedCompilationResult(info, shared); 401 InstallSharedCompilationResult(info, shared);
429 402
430 // Record the function compilation event. 403 // Record the function compilation event.
431 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); 404 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info);
432 } 405 }
433 406
407 CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) {
408 CompilationJob::Status status = job->FinalizeJob();
409 if (status == CompilationJob::SUCCEEDED) {
410 DCHECK(!job->info()->shared_info()->is_compiled());
411 InstallUnoptimizedCode(job->info());
412 job->RecordUnoptimizedCompilationStats();
413 }
414 return status;
415 }
416
417 bool GenerateUnoptimizedCode(CompilationInfo* info) {
418 if (FLAG_validate_asm && info->scope()->asm_module() &&
419 !info->shared_info()->is_asm_wasm_broken()) {
420 EnsureFeedbackMetadata(info);
421 MaybeHandle<FixedArray> wasm_data;
422 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info());
423 if (!wasm_data.is_null()) {
424 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked());
425 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs());
426 return true;
427 }
428 }
429
430 std::vector<std::unique_ptr<CompilationJob>> jobs(
431 GetUnoptimizedCompilationJob(info));
432 for (auto& job : jobs) {
433 if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false;
434 if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false;
435 if (FinalizeUnoptimizedCompilationJob(job.get()) !=
436 CompilationJob::SUCCEEDED) {
437 return false;
438 }
439 job.reset();
440 }
441 return true;
442 }
443
444 bool CompileUnoptimizedCode(CompilationInfo* info) {
445 DCHECK(AllowCompilation::IsAllowed(info->isolate()));
446 if (!Compiler::Analyze(info->parse_info()) ||
447 !GenerateUnoptimizedCode(info)) {
448 Isolate* isolate = info->isolate();
449 if (!isolate->has_pending_exception()) isolate->StackOverflow();
450 return false;
451 }
452 return true;
453 }
454
434 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { 455 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) {
435 VMState<COMPILER> state(info->isolate()); 456 VMState<COMPILER> state(info->isolate());
436 PostponeInterruptsScope postpone(info->isolate()); 457 PostponeInterruptsScope postpone(info->isolate());
437 458
438 // Parse and update CompilationInfo with the results. 459 // Parse and update CompilationInfo with the results.
439 if (!Parse(info->parse_info())) return MaybeHandle<Code>(); 460 if (!Parse(info->parse_info())) return MaybeHandle<Code>();
440 DCHECK_EQ(info->shared_info()->language_mode(), 461 DCHECK_EQ(info->shared_info()->language_mode(),
441 info->literal()->language_mode()); 462 info->literal()->language_mode());
442 463
443 // Compile either unoptimized code or bytecode for the interpreter. 464 // Compile either unoptimized code or bytecode for the interpreter.
444 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); 465 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>();
445 466
446 InstallUnoptimizedCode(info);
447
448 return info->code(); 467 return info->code();
449 } 468 }
450 469
451 CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) {
452 CompilationJob::Status status = job->FinalizeJob();
453 if (status == CompilationJob::SUCCEEDED) {
454 DCHECK(!job->info()->shared_info()->is_compiled());
455 InstallUnoptimizedCode(job->info());
456 job->RecordUnoptimizedCompilationStats();
457 }
458 return status;
459 }
460
461 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( 470 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap(
462 Handle<JSFunction> function, BailoutId osr_ast_id) { 471 Handle<JSFunction> function, BailoutId osr_ast_id) {
463 Handle<SharedFunctionInfo> shared(function->shared()); 472 Handle<SharedFunctionInfo> shared(function->shared());
464 DisallowHeapAllocation no_gc; 473 DisallowHeapAllocation no_gc;
465 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( 474 CodeAndLiterals cached = shared->SearchOptimizedCodeMap(
466 function->context()->native_context(), osr_ast_id); 475 function->context()->native_context(), osr_ast_id);
467 if (cached.code != nullptr) { 476 if (cached.code != nullptr) {
468 // Caching of optimized code enabled and optimized code found. 477 // Caching of optimized code enabled and optimized code found.
469 if (cached.literals != nullptr) function->set_literals(cached.literals); 478 if (cached.literals != nullptr) function->set_literals(cached.literals);
470 DCHECK(!cached.code->marked_for_deoptimization()); 479 DCHECK(!cached.code->marked_for_deoptimization());
(...skipping 19 matching lines...)
490 499
491 // Cache optimized context-specific code. 500 // Cache optimized context-specific code.
492 Handle<JSFunction> function = info->closure(); 501 Handle<JSFunction> function = info->closure();
493 Handle<SharedFunctionInfo> shared(function->shared()); 502 Handle<SharedFunctionInfo> shared(function->shared());
494 Handle<LiteralsArray> literals(function->literals()); 503 Handle<LiteralsArray> literals(function->literals());
495 Handle<Context> native_context(function->context()->native_context()); 504 Handle<Context> native_context(function->context()->native_context());
496 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, 505 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code,
497 literals, info->osr_ast_id()); 506 literals, info->osr_ast_id());
498 } 507 }
499 508
500 bool Renumber(ParseInfo* parse_info) {
501 // Create a canonical handle scope if compiling ignition bytecode. This is
502 // required by the constant array builder to de-duplicate objects without
503 // dereferencing handles.
504 std::unique_ptr<CanonicalHandleScope> canonical;
505 if (FLAG_ignition) {
506 canonical.reset(new CanonicalHandleScope(parse_info->isolate()));
507 }
508
509 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(),
510 parse_info->literal())) {
511 return false;
512 }
513 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info();
514 if (!shared_info.is_null()) {
515 FunctionLiteral* lit = parse_info->literal();
516 shared_info->set_ast_node_count(lit->ast_node_count());
517 if (lit->dont_optimize_reason() != kNoReason) {
518 shared_info->DisableOptimization(lit->dont_optimize_reason());
519 }
520 if (lit->flags() & AstProperties::kDontCrankshaft) {
521 shared_info->set_dont_crankshaft(true);
522 }
523 }
524 return true;
525 }
526
527 bool UseTurboFan(Handle<SharedFunctionInfo> shared) { 509 bool UseTurboFan(Handle<SharedFunctionInfo> shared) {
528 bool optimization_disabled = shared->optimization_disabled(); 510 bool optimization_disabled = shared->optimization_disabled();
529 bool dont_crankshaft = shared->dont_crankshaft(); 511 bool dont_crankshaft = shared->dont_crankshaft();
530 512
531 // Check the enabling conditions for Turbofan. 513 // Check the enabling conditions for Turbofan.
532 // 1. "use asm" code. 514 // 1. "use asm" code.
533 bool is_turbofanable_asm = 515 bool is_turbofanable_asm =
534 FLAG_turbo_asm && shared->asm_function() && !optimization_disabled; 516 FLAG_turbo_asm && shared->asm_function() && !optimization_disabled;
535 517
536 // 2. Fallback for features unsupported by Crankshaft. 518 // 2. Fallback for features unsupported by Crankshaft.
(...skipping 569 matching lines...)
1106 DCHECK_EQ(kNoSourcePosition, lit->function_token_position()); 1088 DCHECK_EQ(kNoSourcePosition, lit->function_token_position());
1107 result = NewSharedFunctionInfoForLiteral(isolate, lit, script); 1089 result = NewSharedFunctionInfoForLiteral(isolate, lit, script);
1108 result->set_is_toplevel(true); 1090 result->set_is_toplevel(true);
1109 parse_info->set_shared_info(result); 1091 parse_info->set_shared_info(result);
1110 1092
1111 // Compile the code. 1093 // Compile the code.
1112 if (!CompileUnoptimizedCode(info)) { 1094 if (!CompileUnoptimizedCode(info)) {
1113 return Handle<SharedFunctionInfo>::null(); 1095 return Handle<SharedFunctionInfo>::null();
1114 } 1096 }
1115 1097
1116 // Update the shared function info with the scope info.
1117 InstallSharedScopeInfo(info, result);
1118
1119 // Install compilation result on the shared function info
1120 InstallSharedCompilationResult(info, result);
1121
1122 Handle<String> script_name = 1098 Handle<String> script_name =
1123 script->name()->IsString() 1099 script->name()->IsString()
1124 ? Handle<String>(String::cast(script->name())) 1100 ? Handle<String>(String::cast(script->name()))
1125 : isolate->factory()->empty_string(); 1101 : isolate->factory()->empty_string();
1126 CodeEventListener::LogEventsAndTags log_tag = 1102 CodeEventListener::LogEventsAndTags log_tag =
1127 parse_info->is_eval() 1103 parse_info->is_eval()
1128 ? CodeEventListener::EVAL_TAG 1104 ? CodeEventListener::EVAL_TAG
1129 : Logger::ToNativeByScript(CodeEventListener::SCRIPT_TAG, *script); 1105 : Logger::ToNativeByScript(CodeEventListener::SCRIPT_TAG, *script);
1130 1106
1131 PROFILE(isolate, CodeCreateEvent(log_tag, result->abstract_code(), *result, 1107 PROFILE(isolate, CodeCreateEvent(log_tag, result->abstract_code(), *result,
(...skipping 21 matching lines...)
1153 } 1129 }
1154 1130
1155 bool Compiler::ParseAndAnalyze(ParseInfo* info) { 1131 bool Compiler::ParseAndAnalyze(ParseInfo* info) {
1156 if (!Parse(info)) return false; 1132 if (!Parse(info)) return false;
1157 if (!Compiler::Analyze(info)) return false; 1133 if (!Compiler::Analyze(info)) return false;
1158 DCHECK_NOT_NULL(info->literal()); 1134 DCHECK_NOT_NULL(info->literal());
1159 DCHECK_NOT_NULL(info->scope()); 1135 DCHECK_NOT_NULL(info->scope());
1160 return true; 1136 return true;
1161 } 1137 }
1162 1138
1139 bool Compiler::Renumber(ParseInfo* parse_info) {
1140 // Create a canonical handle scope if compiling ignition bytecode. This is
1141 // required by the constant array builder to de-duplicate objects without
1142 // dereferencing handles.
1143 std::unique_ptr<CanonicalHandleScope> canonical;
1144 if (FLAG_ignition) {
1145 canonical.reset(new CanonicalHandleScope(parse_info->isolate()));
1146 }
1147
1148 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(),
1149 parse_info->literal())) {
1150 return false;
1151 }
1152 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info();
1153 if (!shared_info.is_null()) {
1154 FunctionLiteral* lit = parse_info->literal();
1155 shared_info->set_ast_node_count(lit->ast_node_count());
1156 if (lit->dont_optimize_reason() != kNoReason) {
1157 shared_info->DisableOptimization(lit->dont_optimize_reason());
1158 }
1159 if (lit->flags() & AstProperties::kDontCrankshaft) {
1160 shared_info->set_dont_crankshaft(true);
1161 }
1162 }
1163 return true;
1164 }
1165
1163 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { 1166 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) {
1164 if (function->is_compiled()) return true; 1167 if (function->is_compiled()) return true;
1165 Isolate* isolate = function->GetIsolate(); 1168 Isolate* isolate = function->GetIsolate();
1166 DCHECK(AllowCompilation::IsAllowed(isolate)); 1169 DCHECK(AllowCompilation::IsAllowed(isolate));
1167 1170
1168 // Start a compilation. 1171 // Start a compilation.
1169 Handle<Code> code; 1172 Handle<Code> code;
1170 if (!GetLazyCode(function).ToHandle(&code)) { 1173 if (!GetLazyCode(function).ToHandle(&code)) {
1171 if (flag == CLEAR_EXCEPTION) { 1174 if (flag == CLEAR_EXCEPTION) {
1172 isolate->clear_pending_exception(); 1175 isolate->clear_pending_exception();
(...skipping 523 matching lines...)
1696 CompilationInfo compile_info(parse_info, Handle<JSFunction>::null()); 1699 CompilationInfo compile_info(parse_info, Handle<JSFunction>::null());
1697 1700
1698 // The source was parsed lazily, so compiling for debugging is not possible. 1701 // The source was parsed lazily, so compiling for debugging is not possible.
1699 DCHECK(!compile_info.is_debug()); 1702 DCHECK(!compile_info.is_debug());
1700 1703
1701 Handle<SharedFunctionInfo> result = CompileToplevel(&compile_info); 1704 Handle<SharedFunctionInfo> result = CompileToplevel(&compile_info);
1702 if (!result.is_null()) isolate->debug()->OnAfterCompile(script); 1705 if (!result.is_null()) isolate->debug()->OnAfterCompile(script);
1703 return result; 1706 return result;
1704 } 1707 }
1705 1708
1706
1707 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo( 1709 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
1708 FunctionLiteral* literal, Handle<Script> script, 1710 FunctionLiteral* literal, Handle<Script> script,
1709 CompilationInfo* outer_info) { 1711 CompilationInfo* outer_info, ShouldCompile should_compile) {
1710 // Precondition: code has been parsed and scopes have been analyzed. 1712 // Precondition: code has been parsed and scopes have been analyzed.
1711 Isolate* isolate = outer_info->isolate(); 1713 Isolate* isolate = outer_info->isolate();
1712 MaybeHandle<SharedFunctionInfo> maybe_existing; 1714 MaybeHandle<SharedFunctionInfo> maybe_existing;
1713 1715
1714 // Find any previously allocated shared function info for the given literal. 1716 // Find any previously allocated shared function info for the given literal.
1715 if (outer_info->shared_info()->never_compiled()) { 1717 if (outer_info->shared_info()->never_compiled() &&
1718 should_compile == ShouldCompile::kIfNecessary) {
1716 // On the first compile, there are no existing shared function info for 1719 // On the first compile, there are no existing shared function info for
1717 // inner functions yet, so do not try to find them. All bets are off for 1720 // inner functions yet, so do not try to find them. All bets are off for
1718 // live edit though. 1721 // live edit though.
1719 SLOW_DCHECK(script->FindSharedFunctionInfo(literal).is_null() || 1722 SLOW_DCHECK(script->FindSharedFunctionInfo(literal).is_null() ||
1720 isolate->debug()->live_edit_enabled()); 1723 isolate->debug()->live_edit_enabled());
1721 } else { 1724 } else {
1722 maybe_existing = script->FindSharedFunctionInfo(literal); 1725 maybe_existing = script->FindSharedFunctionInfo(literal);
1723 } 1726 }
1724 1727
1725 // We found an existing shared function info. If it has any sort of code 1728 // We found an existing shared function info. If it has any sort of code
1726 // attached, don't worry about compiling and simply return it. Otherwise, 1729 // attached, don't worry about compiling and simply return it. Otherwise,
1727 // continue to decide whether to eagerly compile. 1730 // continue to decide whether to eagerly compile.
1728 // Note that we also carry on if we are compiling eager to obtain code for 1731 // Note that we also carry on if we are compiling eager to obtain code for
1729 // debugging, unless we already have code with debug break slots. 1732 // debugging, unless we already have code with debug break slots.
1730 Handle<SharedFunctionInfo> existing; 1733 Handle<SharedFunctionInfo> existing;
1731 if (maybe_existing.ToHandle(&existing)) { 1734 if (maybe_existing.ToHandle(&existing)) {
1732 DCHECK(!existing->is_toplevel()); 1735 DCHECK(!existing->is_toplevel());
1733 if (existing->HasBaselineCode() || existing->HasBytecodeArray()) { 1736 if (existing->HasBaselineCode() || existing->HasBytecodeArray()) {
1734 if (!outer_info->is_debug() || existing->HasDebugCode()) { 1737 if (!outer_info->is_debug() || existing->HasDebugCode()) {
1735 return existing; 1738 return existing;
1736 } 1739 }
1740 } else if (should_compile == ShouldCompile::kNever) {
1741 return existing;
1737 } 1742 }
1738 } 1743 }
1739 1744
1740 // Allocate a shared function info object. 1745 // Allocate a shared function info object.
1741 Handle<SharedFunctionInfo> result; 1746 Handle<SharedFunctionInfo> result;
1742 if (!maybe_existing.ToHandle(&result)) { 1747 if (!maybe_existing.ToHandle(&result)) {
1743 result = NewSharedFunctionInfoForLiteral(isolate, literal, script); 1748 result = NewSharedFunctionInfoForLiteral(isolate, literal, script);
1744 result->set_is_toplevel(false); 1749 result->set_is_toplevel(false);
1745 1750
1746 // If the outer function has been compiled before, we cannot be sure that 1751 // If the outer function has been compiled before, we cannot be sure that
1747 // shared function info for this function literal has been created for the 1752 // shared function info for this function literal has been created for the
1748 // first time. It may have already been compiled previously. 1753 // first time. It may have already been compiled previously.
1749 result->set_never_compiled(outer_info->shared_info()->never_compiled()); 1754 result->set_never_compiled(outer_info->shared_info()->never_compiled());
1750 } 1755 }
1751 1756
1752 Zone zone(isolate->allocator()); 1757 Zone zone(isolate->allocator());
1753 ParseInfo parse_info(&zone, script); 1758 ParseInfo parse_info(&zone, script);
1754 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 1759 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
1755 parse_info.set_literal(literal); 1760 parse_info.set_literal(literal);
1756 parse_info.set_shared_info(result); 1761 parse_info.set_shared_info(result);
1757 parse_info.set_language_mode(literal->scope()->language_mode()); 1762 parse_info.set_language_mode(literal->scope()->language_mode());
1758 if (outer_info->will_serialize()) info.PrepareForSerializing(); 1763 if (outer_info->will_serialize()) info.PrepareForSerializing();
1759 if (outer_info->is_debug()) info.MarkAsDebug(); 1764 if (outer_info->is_debug()) info.MarkAsDebug();
1760 1765
1761 // Generate code 1766 // Generate code
1762 TimerEventScope<TimerEventCompileCode> timer(isolate); 1767 TimerEventScope<TimerEventCompileCode> timer(isolate);
1763 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::CompileCode); 1768 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::CompileCode);
1764 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); 1769 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode");
1765 1770
1766 if (!literal->ShouldEagerCompile()) { 1771 if (!literal->ShouldEagerCompile() ||
1772 should_compile == ShouldCompile::kNever) {
1767 info.SetCode(isolate->builtins()->CompileLazy()); 1773 info.SetCode(isolate->builtins()->CompileLazy());
1768 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext(); 1774 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext();
1769 if (outer_scope) { 1775 if (outer_scope) {
1770 result->set_outer_scope_info(*outer_scope->scope_info()); 1776 result->set_outer_scope_info(*outer_scope->scope_info());
1771 } 1777 }
1772 } else if (Renumber(info.parse_info()) && GenerateUnoptimizedCode(&info)) { 1778 } else if (Renumber(info.parse_info()) && GenerateUnoptimizedCode(&info)) {
1773 // Code generation will ensure that the feedback vector is present and 1779 // Code generation will ensure that the feedback vector is present and
1774 // appropriately sized. 1780 // appropriately sized.
1775 DCHECK(!info.code().is_null()); 1781 DCHECK(!info.code().is_null());
1776 if (literal->should_be_used_once_hint()) { 1782 if (literal->should_be_used_once_hint()) {
(...skipping 47 matching lines...)
1824 } 1830 }
1825 1831
1826 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, 1832 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function,
1827 BailoutId osr_ast_id, 1833 BailoutId osr_ast_id,
1828 JavaScriptFrame* osr_frame) { 1834 JavaScriptFrame* osr_frame) {
1829 DCHECK(!osr_ast_id.IsNone()); 1835 DCHECK(!osr_ast_id.IsNone());
1830 DCHECK_NOT_NULL(osr_frame); 1836 DCHECK_NOT_NULL(osr_frame);
1831 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); 1837 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame);
1832 } 1838 }
1833 1839
1834 CompilationJob* Compiler::PrepareUnoptimizedCompilationJob( 1840 std::vector<std::unique_ptr<CompilationJob>>
1835 CompilationInfo* info) { 1841 Compiler::PrepareUnoptimizedCompilationJob(CompilationInfo* info) {
1836 VMState<COMPILER> state(info->isolate()); 1842 VMState<COMPILER> state(info->isolate());
1837 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info)); 1843 std::vector<std::unique_ptr<CompilationJob>> jobs(
1838 if (job->PrepareJob() != CompilationJob::SUCCEEDED) { 1844 GetUnoptimizedCompilationJob(info));
1839 return nullptr; 1845 for (auto& job : jobs) {
1846 if (job->PrepareJob() != CompilationJob::SUCCEEDED) {
1847 std::vector<std::unique_ptr<CompilationJob>> result;
1848 return result;
1849 }
1840 } 1850 }
1841 return job.release(); 1851 return jobs;
1842 } 1852 }
1843 1853
1844 bool Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { 1854 bool Compiler::FinalizeCompilationJob(CompilationJob* raw_job) {
1845 // Take ownership of compilation job. Deleting job also tears down the zone. 1855 // Take ownership of compilation job. Deleting job also tears down the zone.
1846 std::unique_ptr<CompilationJob> job(raw_job); 1856 std::unique_ptr<CompilationJob> job(raw_job);
1847 1857
1848 VMState<COMPILER> state(job->info()->isolate()); 1858 VMState<COMPILER> state(job->info()->isolate());
1849 if (job->info()->IsOptimizing()) { 1859 if (job->info()->IsOptimizing()) {
1850 return FinalizeOptimizedCompilationJob(job.get()) == 1860 return FinalizeOptimizedCompilationJob(job.get()) ==
1851 CompilationJob::SUCCEEDED; 1861 CompilationJob::SUCCEEDED;
(...skipping 24 matching lines...)
1876 DCHECK(shared->is_compiled()); 1886 DCHECK(shared->is_compiled());
1877 function->set_literals(cached.literals); 1887 function->set_literals(cached.literals);
1878 } else if (shared->is_compiled()) { 1888 } else if (shared->is_compiled()) {
1879 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. 1889 // TODO(mvstanton): pass pretenure flag to EnsureLiterals.
1880 JSFunction::EnsureLiterals(function); 1890 JSFunction::EnsureLiterals(function);
1881 } 1891 }
1882 } 1892 }
1883 1893
1884 } // namespace internal 1894 } // namespace internal
1885 } // namespace v8 1895 } // namespace v8
OLDNEW

Powered by Google App Engine