Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 mode_ = V8::UseCrankshaft() ? mode : NONOPT; | 122 mode_ = V8::UseCrankshaft() ? mode : NONOPT; |
| 123 if (script_->type()->value() == Script::TYPE_NATIVE) { | 123 if (script_->type()->value() == Script::TYPE_NATIVE) { |
| 124 MarkAsNative(); | 124 MarkAsNative(); |
| 125 } | 125 } |
| 126 if (!shared_info_.is_null()) { | 126 if (!shared_info_.is_null()) { |
| 127 ASSERT(language_mode() == CLASSIC_MODE); | 127 ASSERT(language_mode() == CLASSIC_MODE); |
| 128 SetLanguageMode(shared_info_->language_mode()); | 128 SetLanguageMode(shared_info_->language_mode()); |
| 129 } | 129 } |
| 130 set_bailout_reason("unknown"); | 130 set_bailout_reason(kUnknown); |
| 131 } | 131 } |
| 132 | 132 |
| 133 | 133 |
| 134 CompilationInfo::~CompilationInfo() { | 134 CompilationInfo::~CompilationInfo() { |
| 135 delete deferred_handles_; | 135 delete deferred_handles_; |
| 136 delete no_frame_ranges_; | 136 delete no_frame_ranges_; |
| 137 #ifdef DEBUG | 137 #ifdef DEBUG |
| 138 // Check that no dependent maps have been added or added dependent maps have | 138 // Check that no dependent maps have been added or added dependent maps have |
| 139 // been rolled back or committed. | 139 // been rolled back or committed. |
| 140 for (int i = 0; i < DependentCode::kGroupCount; i++) { | 140 for (int i = 0; i < DependentCode::kGroupCount; i++) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 if (AlwaysFullCompiler(isolate())) { | 335 if (AlwaysFullCompiler(isolate())) { |
| 336 info()->SetCode(code); | 336 info()->SetCode(code); |
| 337 return SetLastStatus(BAILED_OUT); | 337 return SetLastStatus(BAILED_OUT); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // Limit the number of times we re-compile a functions with | 340 // Limit the number of times we re-compile a functions with |
| 341 // the optimizing compiler. | 341 // the optimizing compiler. |
| 342 const int kMaxOptCount = | 342 const int kMaxOptCount = |
| 343 FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; | 343 FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; |
| 344 if (info()->opt_count() > kMaxOptCount) { | 344 if (info()->opt_count() > kMaxOptCount) { |
| 345 info()->set_bailout_reason("optimized too many times"); | 345 info()->set_bailout_reason(kOptimizedTooManyTimes); |
| 346 return AbortOptimization(); | 346 return AbortOptimization(); |
| 347 } | 347 } |
| 348 | 348 |
| 349 // Due to an encoding limit on LUnallocated operands in the Lithium | 349 // Due to an encoding limit on LUnallocated operands in the Lithium |
| 350 // language, we cannot optimize functions with too many formal parameters | 350 // language, we cannot optimize functions with too many formal parameters |
| 351 // or perform on-stack replacement for function with too many | 351 // or perform on-stack replacement for function with too many |
| 352 // stack-allocated local variables. | 352 // stack-allocated local variables. |
| 353 // | 353 // |
| 354 // The encoding is as a signed value, with parameters and receiver using | 354 // The encoding is as a signed value, with parameters and receiver using |
| 355 // the negative indices and locals the non-negative ones. | 355 // the negative indices and locals the non-negative ones. |
| 356 const int parameter_limit = -LUnallocated::kMinFixedSlotIndex; | 356 const int parameter_limit = -LUnallocated::kMinFixedSlotIndex; |
| 357 Scope* scope = info()->scope(); | 357 Scope* scope = info()->scope(); |
| 358 if ((scope->num_parameters() + 1) > parameter_limit) { | 358 if ((scope->num_parameters() + 1) > parameter_limit) { |
| 359 info()->set_bailout_reason("too many parameters"); | 359 info()->set_bailout_reason(kTooManyParameters); |
| 360 return AbortOptimization(); | 360 return AbortOptimization(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 const int locals_limit = LUnallocated::kMaxFixedSlotIndex; | 363 const int locals_limit = LUnallocated::kMaxFixedSlotIndex; |
| 364 if (!info()->osr_ast_id().IsNone() && | 364 if (!info()->osr_ast_id().IsNone() && |
| 365 scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) { | 365 scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) { |
| 366 info()->set_bailout_reason("too many parameters/locals"); | 366 info()->set_bailout_reason(kTooManyParametersLocals); |
| 367 return AbortOptimization(); | 367 return AbortOptimization(); |
| 368 } | 368 } |
| 369 | 369 |
| 370 // Take --hydrogen-filter into account. | 370 // Take --hydrogen-filter into account. |
| 371 if (!info()->closure()->PassesHydrogenFilter()) { | 371 if (!info()->closure()->PassesHydrogenFilter()) { |
| 372 info()->SetCode(code); | 372 info()->SetCode(code); |
| 373 return SetLastStatus(BAILED_OUT); | 373 return SetLastStatus(BAILED_OUT); |
| 374 } | 374 } |
| 375 | 375 |
| 376 // Recompile the unoptimized version of the code if the current version | 376 // Recompile the unoptimized version of the code if the current version |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 | 451 |
| 452 | 452 |
| 453 OptimizingCompiler::Status OptimizingCompiler::OptimizeGraph() { | 453 OptimizingCompiler::Status OptimizingCompiler::OptimizeGraph() { |
| 454 DisallowHeapAllocation no_allocation; | 454 DisallowHeapAllocation no_allocation; |
| 455 DisallowHandleAllocation no_handles; | 455 DisallowHandleAllocation no_handles; |
| 456 DisallowHandleDereference no_deref; | 456 DisallowHandleDereference no_deref; |
| 457 | 457 |
| 458 ASSERT(last_status() == SUCCEEDED); | 458 ASSERT(last_status() == SUCCEEDED); |
| 459 Timer t(this, &time_taken_to_optimize_); | 459 Timer t(this, &time_taken_to_optimize_); |
| 460 ASSERT(graph_ != NULL); | 460 ASSERT(graph_ != NULL); |
| 461 SmartArrayPointer<char> bailout_reason; | 461 BailoutReason bailout_reason = kNoReason; |
| 462 if (!graph_->Optimize(&bailout_reason)) { | 462 if (!graph_->Optimize(&bailout_reason)) { |
| 463 if (!bailout_reason.is_empty()) graph_builder_->Bailout(*bailout_reason); | 463 if (bailout_reason != kNoReason) graph_builder_->Bailout(bailout_reason); |
| 464 return SetLastStatus(BAILED_OUT); | 464 return SetLastStatus(BAILED_OUT); |
| 465 } else { | 465 } else { |
| 466 chunk_ = LChunk::NewChunk(graph_); | 466 chunk_ = LChunk::NewChunk(graph_); |
| 467 if (chunk_ == NULL) { | 467 if (chunk_ == NULL) { |
| 468 return SetLastStatus(BAILED_OUT); | 468 return SetLastStatus(BAILED_OUT); |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 return SetLastStatus(SUCCEEDED); | 471 return SetLastStatus(SUCCEEDED); |
| 472 } | 472 } |
| 473 | 473 |
| 474 | 474 |
| 475 OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { | 475 OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { |
| 476 ASSERT(last_status() == SUCCEEDED); | 476 ASSERT(last_status() == SUCCEEDED); |
| 477 { // Scope for timer. | 477 { // Scope for timer. |
| 478 Timer timer(this, &time_taken_to_codegen_); | 478 Timer timer(this, &time_taken_to_codegen_); |
| 479 ASSERT(chunk_ != NULL); | 479 ASSERT(chunk_ != NULL); |
| 480 ASSERT(graph_ != NULL); | 480 ASSERT(graph_ != NULL); |
| 481 // Deferred handles reference objects that were accessible during | 481 // Deferred handles reference objects that were accessible during |
| 482 // graph creation. To make sure that we don't encounter inconsistencies | 482 // graph creation. To make sure that we don't encounter inconsistencies |
| 483 // between graph creation and code generation, we disallow accessing | 483 // between graph creation and code generation, we disallow accessing |
| 484 // objects through deferred handles during the latter, with exceptions. | 484 // objects through deferred handles during the latter, with exceptions. |
| 485 DisallowDeferredHandleDereference no_deferred_handle_deref; | 485 DisallowDeferredHandleDereference no_deferred_handle_deref; |
| 486 Handle<Code> optimized_code = chunk_->Codegen(); | 486 Handle<Code> optimized_code = chunk_->Codegen(); |
| 487 if (optimized_code.is_null()) { | 487 if (optimized_code.is_null()) { |
| 488 info()->set_bailout_reason("code generation failed"); | 488 if (info()->bailout_reason() != kNoReason) { |
|
Jakob Kummerow
2013/08/02 08:13:47
Sorry, I mixed up the condition in my earlier comm
| |
| 489 info()->set_bailout_reason(kCodeGenerationFailed); | |
| 490 } | |
| 489 return AbortOptimization(); | 491 return AbortOptimization(); |
| 490 } | 492 } |
| 491 info()->SetCode(optimized_code); | 493 info()->SetCode(optimized_code); |
| 492 } | 494 } |
| 493 RecordOptimizationStats(); | 495 RecordOptimizationStats(); |
| 494 return SetLastStatus(SUCCEEDED); | 496 return SetLastStatus(SUCCEEDED); |
| 495 } | 497 } |
| 496 | 498 |
| 497 | 499 |
| 498 static bool GenerateCode(CompilationInfo* info) { | 500 static bool GenerateCode(CompilationInfo* info) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 CompilationInfoWithZone info(script); | 775 CompilationInfoWithZone info(script); |
| 774 info.MarkAsEval(); | 776 info.MarkAsEval(); |
| 775 if (is_global) info.MarkAsGlobal(); | 777 if (is_global) info.MarkAsGlobal(); |
| 776 info.SetLanguageMode(language_mode); | 778 info.SetLanguageMode(language_mode); |
| 777 info.SetParseRestriction(restriction); | 779 info.SetParseRestriction(restriction); |
| 778 info.SetContext(context); | 780 info.SetContext(context); |
| 779 result = MakeFunctionInfo(&info); | 781 result = MakeFunctionInfo(&info); |
| 780 if (!result.is_null()) { | 782 if (!result.is_null()) { |
| 781 // Explicitly disable optimization for eval code. We're not yet prepared | 783 // Explicitly disable optimization for eval code. We're not yet prepared |
| 782 // to handle eval-code in the optimizing compiler. | 784 // to handle eval-code in the optimizing compiler. |
| 783 result->DisableOptimization("eval"); | 785 result->DisableOptimization(kEval); |
| 784 | 786 |
| 785 // If caller is strict mode, the result must be in strict mode or | 787 // If caller is strict mode, the result must be in strict mode or |
| 786 // extended mode as well, but not the other way around. Consider: | 788 // extended mode as well, but not the other way around. Consider: |
| 787 // eval("'use strict'; ..."); | 789 // eval("'use strict'; ..."); |
| 788 ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode()); | 790 ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode()); |
| 789 // If caller is in extended mode, the result must also be in | 791 // If caller is in extended mode, the result must also be in |
| 790 // extended mode. | 792 // extended mode. |
| 791 ASSERT(language_mode != EXTENDED_MODE || | 793 ASSERT(language_mode != EXTENDED_MODE || |
| 792 result->is_extended_mode()); | 794 result->is_extended_mode()); |
| 793 if (!result->dont_cache()) { | 795 if (!result->dont_cache()) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1048 } | 1050 } |
| 1049 | 1051 |
| 1050 Isolate* isolate = info->isolate(); | 1052 Isolate* isolate = info->isolate(); |
| 1051 VMState<COMPILER> state(isolate); | 1053 VMState<COMPILER> state(isolate); |
| 1052 Logger::TimerEventScope timer( | 1054 Logger::TimerEventScope timer( |
| 1053 isolate, Logger::TimerEventScope::v8_recompile_synchronous); | 1055 isolate, Logger::TimerEventScope::v8_recompile_synchronous); |
| 1054 // If crankshaft succeeded, install the optimized code else install | 1056 // If crankshaft succeeded, install the optimized code else install |
| 1055 // the unoptimized code. | 1057 // the unoptimized code. |
| 1056 OptimizingCompiler::Status status = optimizing_compiler->last_status(); | 1058 OptimizingCompiler::Status status = optimizing_compiler->last_status(); |
| 1057 if (info->HasAbortedDueToDependencyChange()) { | 1059 if (info->HasAbortedDueToDependencyChange()) { |
| 1058 info->set_bailout_reason("bailed out due to dependent map"); | 1060 info->set_bailout_reason(kBailedOutDueToDependentMap); |
| 1059 status = optimizing_compiler->AbortOptimization(); | 1061 status = optimizing_compiler->AbortOptimization(); |
| 1060 } else if (status != OptimizingCompiler::SUCCEEDED) { | 1062 } else if (status != OptimizingCompiler::SUCCEEDED) { |
| 1061 info->set_bailout_reason("failed/bailed out last time"); | 1063 info->set_bailout_reason(kFailedBailedOutLastTime); |
| 1062 status = optimizing_compiler->AbortOptimization(); | 1064 status = optimizing_compiler->AbortOptimization(); |
| 1063 } else if (isolate->DebuggerHasBreakPoints()) { | 1065 } else if (isolate->DebuggerHasBreakPoints()) { |
| 1064 info->set_bailout_reason("debugger is active"); | 1066 info->set_bailout_reason(kDebuggerIsActive); |
| 1065 status = optimizing_compiler->AbortOptimization(); | 1067 status = optimizing_compiler->AbortOptimization(); |
| 1066 } else { | 1068 } else { |
| 1067 status = optimizing_compiler->GenerateAndInstallCode(); | 1069 status = optimizing_compiler->GenerateAndInstallCode(); |
| 1068 ASSERT(status == OptimizingCompiler::SUCCEEDED || | 1070 ASSERT(status == OptimizingCompiler::SUCCEEDED || |
| 1069 status == OptimizingCompiler::BAILED_OUT); | 1071 status == OptimizingCompiler::BAILED_OUT); |
| 1070 } | 1072 } |
| 1071 | 1073 |
| 1072 InstallCodeCommon(*info); | 1074 InstallCodeCommon(*info); |
| 1073 if (status == OptimizingCompiler::SUCCEEDED) { | 1075 if (status == OptimizingCompiler::SUCCEEDED) { |
| 1074 Handle<Code> code = info->code(); | 1076 Handle<Code> code = info->code(); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1251 // Trace if the appropriate trace flag is set and the phase name's first | 1253 // Trace if the appropriate trace flag is set and the phase name's first |
| 1252 // character is in the FLAG_trace_phase command line parameter. | 1254 // character is in the FLAG_trace_phase command line parameter. |
| 1253 bool tracing_on = info()->IsStub() ? | 1255 bool tracing_on = info()->IsStub() ? |
| 1254 FLAG_trace_hydrogen_stubs : | 1256 FLAG_trace_hydrogen_stubs : |
| 1255 FLAG_trace_hydrogen; | 1257 FLAG_trace_hydrogen; |
| 1256 return (tracing_on && | 1258 return (tracing_on && |
| 1257 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1259 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
| 1258 } | 1260 } |
| 1259 | 1261 |
| 1260 } } // namespace v8::internal | 1262 } } // namespace v8::internal |
| OLD | NEW |