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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 | 8 |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); | 631 function_info->set_uses_arguments(lit->scope()->arguments() != NULL); |
632 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); | 632 function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters()); |
633 function_info->set_ast_node_count(lit->ast_node_count()); | 633 function_info->set_ast_node_count(lit->ast_node_count()); |
634 function_info->set_is_function(lit->is_function()); | 634 function_info->set_is_function(lit->is_function()); |
635 function_info->set_bailout_reason(lit->dont_optimize_reason()); | 635 function_info->set_bailout_reason(lit->dont_optimize_reason()); |
636 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); | 636 function_info->set_dont_cache(lit->flags()->Contains(kDontCache)); |
637 function_info->set_kind(lit->kind()); | 637 function_info->set_kind(lit->kind()); |
638 } | 638 } |
639 | 639 |
640 | 640 |
| 641 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 642 CompilationInfo* info, |
| 643 Handle<SharedFunctionInfo> shared) { |
| 644 // SharedFunctionInfo is passed separately, because if CompilationInfo |
| 645 // was created using Script object, it will not have it. |
| 646 |
| 647 // Log the code generation. If source information is available include |
| 648 // script name and line number. Check explicitly whether logging is |
| 649 // enabled as finding the line number is not free. |
| 650 if (info->isolate()->logger()->is_logging_code_events() || |
| 651 info->isolate()->cpu_profiler()->is_profiling()) { |
| 652 Handle<Script> script = info->script(); |
| 653 Handle<Code> code = info->code(); |
| 654 if (code.is_identical_to(info->isolate()->builtins()->CompileLazy())) { |
| 655 return; |
| 656 } |
| 657 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; |
| 658 int column_num = |
| 659 Script::GetColumnNumber(script, shared->start_position()) + 1; |
| 660 String* script_name = script->name()->IsString() |
| 661 ? String::cast(script->name()) |
| 662 : info->isolate()->heap()->empty_string(); |
| 663 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); |
| 664 PROFILE(info->isolate(), |
| 665 CodeCreateEvent(log_tag, *code, *shared, info, script_name, |
| 666 line_num, column_num)); |
| 667 } |
| 668 |
| 669 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
| 670 Handle<Script>(info->script()), Handle<Code>(info->code()), |
| 671 info)); |
| 672 } |
| 673 |
| 674 |
641 static bool CompileUnoptimizedCode(CompilationInfo* info) { | 675 static bool CompileUnoptimizedCode(CompilationInfo* info) { |
642 DCHECK(AllowCompilation::IsAllowed(info->isolate())); | 676 DCHECK(AllowCompilation::IsAllowed(info->isolate())); |
643 DCHECK(info->function() != NULL); | 677 DCHECK(info->function() != NULL); |
644 if (!Rewriter::Rewrite(info)) return false; | 678 if (!Rewriter::Rewrite(info)) return false; |
645 if (!Scope::Analyze(info)) return false; | 679 if (!Scope::Analyze(info)) return false; |
646 DCHECK(info->scope() != NULL); | 680 DCHECK(info->scope() != NULL); |
647 | 681 |
648 if (!FullCodeGenerator::MakeCode(info)) { | 682 if (!FullCodeGenerator::MakeCode(info)) { |
649 Isolate* isolate = info->isolate(); | 683 Isolate* isolate = info->isolate(); |
650 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 684 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
(...skipping 14 matching lines...) Expand all Loading... |
665 FunctionLiteral* lit = info->function(); | 699 FunctionLiteral* lit = info->function(); |
666 shared->set_strict_mode(lit->strict_mode()); | 700 shared->set_strict_mode(lit->strict_mode()); |
667 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 701 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
668 shared->set_bailout_reason(lit->dont_optimize_reason()); | 702 shared->set_bailout_reason(lit->dont_optimize_reason()); |
669 shared->set_ast_node_count(lit->ast_node_count()); | 703 shared->set_ast_node_count(lit->ast_node_count()); |
670 | 704 |
671 // Compile unoptimized code. | 705 // Compile unoptimized code. |
672 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 706 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
673 | 707 |
674 CHECK_EQ(Code::FUNCTION, info->code()->kind()); | 708 CHECK_EQ(Code::FUNCTION, info->code()->kind()); |
675 Compiler::RecordFunctionCompilation( | 709 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); |
676 Logger::LAZY_COMPILE_TAG, info, info->shared_info()); | |
677 | 710 |
678 // Update the shared function info with the scope info. Allocating the | 711 // Update the shared function info with the scope info. Allocating the |
679 // ScopeInfo object may cause a GC. | 712 // ScopeInfo object may cause a GC. |
680 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); | 713 Handle<ScopeInfo> scope_info = ScopeInfo::Create(info->scope(), info->zone()); |
681 shared->set_scope_info(*scope_info); | 714 shared->set_scope_info(*scope_info); |
682 | 715 |
683 // Update the code and feedback vector for the shared function info. | 716 // Update the code and feedback vector for the shared function info. |
684 shared->ReplaceCode(*info->code()); | 717 shared->ReplaceCode(*info->code()); |
685 if (shared->optimization_disabled()) info->code()->set_optimizable(false); | 718 if (shared->optimization_disabled()) info->code()->set_optimizable(false); |
686 shared->set_feedback_vector(*info->feedback_vector()); | 719 shared->set_feedback_vector(*info->feedback_vector()); |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 1259 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
1227 | 1260 |
1228 OptimizedCompileJob job(info); | 1261 OptimizedCompileJob job(info); |
1229 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED) return false; | 1262 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED) return false; |
1230 if (job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED) return false; | 1263 if (job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED) return false; |
1231 if (job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) return false; | 1264 if (job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) return false; |
1232 | 1265 |
1233 // Success! | 1266 // Success! |
1234 DCHECK(!info->isolate()->has_pending_exception()); | 1267 DCHECK(!info->isolate()->has_pending_exception()); |
1235 InsertCodeIntoOptimizedCodeMap(info); | 1268 InsertCodeIntoOptimizedCodeMap(info); |
1236 Compiler::RecordFunctionCompilation( | 1269 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, |
1237 Logger::LAZY_COMPILE_TAG, info, info->shared_info()); | 1270 info->shared_info()); |
1238 return true; | 1271 return true; |
1239 } | 1272 } |
1240 | 1273 |
1241 | 1274 |
1242 static bool GetOptimizedCodeLater(CompilationInfo* info) { | 1275 static bool GetOptimizedCodeLater(CompilationInfo* info) { |
1243 Isolate* isolate = info->isolate(); | 1276 Isolate* isolate = info->isolate(); |
1244 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { | 1277 if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { |
1245 if (FLAG_trace_concurrent_recompilation) { | 1278 if (FLAG_trace_concurrent_recompilation) { |
1246 PrintF(" ** Compilation queue full, will retry optimizing "); | 1279 PrintF(" ** Compilation queue full, will retry optimizing "); |
1247 info->closure()->PrintName(); | 1280 info->closure()->PrintName(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 shared->optimization_disabled() || | 1383 shared->optimization_disabled() || |
1351 info->HasAbortedDueToDependencyChange() || | 1384 info->HasAbortedDueToDependencyChange() || |
1352 isolate->DebuggerHasBreakPoints()) { | 1385 isolate->DebuggerHasBreakPoints()) { |
1353 return Handle<Code>::null(); | 1386 return Handle<Code>::null(); |
1354 } | 1387 } |
1355 | 1388 |
1356 if (job->GenerateCode() != OptimizedCompileJob::SUCCEEDED) { | 1389 if (job->GenerateCode() != OptimizedCompileJob::SUCCEEDED) { |
1357 return Handle<Code>::null(); | 1390 return Handle<Code>::null(); |
1358 } | 1391 } |
1359 | 1392 |
1360 Compiler::RecordFunctionCompilation( | 1393 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info.get(), shared); |
1361 Logger::LAZY_COMPILE_TAG, info.get(), shared); | |
1362 if (info->shared_info()->SearchOptimizedCodeMap( | 1394 if (info->shared_info()->SearchOptimizedCodeMap( |
1363 info->context()->native_context(), info->osr_ast_id()) == -1) { | 1395 info->context()->native_context(), info->osr_ast_id()) == -1) { |
1364 InsertCodeIntoOptimizedCodeMap(info.get()); | 1396 InsertCodeIntoOptimizedCodeMap(info.get()); |
1365 } | 1397 } |
1366 | 1398 |
1367 if (FLAG_trace_concurrent_recompilation) { | 1399 if (FLAG_trace_concurrent_recompilation) { |
1368 PrintF(" ** Optimized code for "); | 1400 PrintF(" ** Optimized code for "); |
1369 info->closure()->PrintName(); | 1401 info->closure()->PrintName(); |
1370 PrintF(" generated.\n"); | 1402 PrintF(" generated.\n"); |
1371 } | 1403 } |
1372 | 1404 |
1373 return Handle<Code>(*info->code()); | 1405 return Handle<Code>(*info->code()); |
1374 } | 1406 } |
1375 | 1407 |
1376 | 1408 |
1377 void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag, | |
1378 CompilationInfo* info, | |
1379 Handle<SharedFunctionInfo> shared) { | |
1380 // SharedFunctionInfo is passed separately, because if CompilationInfo | |
1381 // was created using Script object, it will not have it. | |
1382 | |
1383 // Log the code generation. If source information is available include | |
1384 // script name and line number. Check explicitly whether logging is | |
1385 // enabled as finding the line number is not free. | |
1386 if (info->isolate()->logger()->is_logging_code_events() || | |
1387 info->isolate()->cpu_profiler()->is_profiling()) { | |
1388 Handle<Script> script = info->script(); | |
1389 Handle<Code> code = info->code(); | |
1390 if (code.is_identical_to(info->isolate()->builtins()->CompileLazy())) { | |
1391 return; | |
1392 } | |
1393 int line_num = Script::GetLineNumber(script, shared->start_position()) + 1; | |
1394 int column_num = | |
1395 Script::GetColumnNumber(script, shared->start_position()) + 1; | |
1396 String* script_name = script->name()->IsString() | |
1397 ? String::cast(script->name()) | |
1398 : info->isolate()->heap()->empty_string(); | |
1399 Logger::LogEventsAndTags log_tag = Logger::ToNativeByScript(tag, *script); | |
1400 PROFILE(info->isolate(), CodeCreateEvent( | |
1401 log_tag, *code, *shared, info, script_name, line_num, column_num)); | |
1402 } | |
1403 | |
1404 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | |
1405 Handle<Script>(info->script()), | |
1406 Handle<Code>(info->code()), | |
1407 info)); | |
1408 } | |
1409 | |
1410 | |
1411 bool Compiler::DebuggerWantsEagerCompilation(CompilationInfo* info, | 1409 bool Compiler::DebuggerWantsEagerCompilation(CompilationInfo* info, |
1412 bool allow_lazy_without_ctx) { | 1410 bool allow_lazy_without_ctx) { |
1413 return LiveEditFunctionTracker::IsActive(info->isolate()) || | 1411 return LiveEditFunctionTracker::IsActive(info->isolate()) || |
1414 (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx); | 1412 (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx); |
1415 } | 1413 } |
1416 | 1414 |
1417 | 1415 |
1418 CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) | 1416 CompilationPhase::CompilationPhase(const char* name, CompilationInfo* info) |
1419 : name_(name), info_(info), zone_(info->isolate()) { | 1417 : name_(name), info_(info), zone_(info->isolate()) { |
1420 if (FLAG_hydrogen_stats) { | 1418 if (FLAG_hydrogen_stats) { |
(...skipping 18 matching lines...) Expand all Loading... |
1439 AllowHandleDereference allow_deref; | 1437 AllowHandleDereference allow_deref; |
1440 bool tracing_on = info()->IsStub() | 1438 bool tracing_on = info()->IsStub() |
1441 ? FLAG_trace_hydrogen_stubs | 1439 ? FLAG_trace_hydrogen_stubs |
1442 : (FLAG_trace_hydrogen && | 1440 : (FLAG_trace_hydrogen && |
1443 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1441 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
1444 return (tracing_on && | 1442 return (tracing_on && |
1445 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1443 base::OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1446 } | 1444 } |
1447 | 1445 |
1448 } } // namespace v8::internal | 1446 } } // namespace v8::internal |
OLD | NEW |