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(kUnknown); | 130 set_bailout_reason("unknown"); |
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(kOptimizedTooManyTimes); | 345 info()->set_bailout_reason("optimized too many times"); |
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(kTooManyParameters); | 359 info()->set_bailout_reason("too many parameters"); |
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(kTooManyParametersLocals); | 366 info()->set_bailout_reason("too many parameters/locals"); |
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 BailoutReason bailout_reason = kNoReason; | 461 SmartArrayPointer<char> bailout_reason; |
462 if (!graph_->Optimize(&bailout_reason)) { | 462 if (!graph_->Optimize(&bailout_reason)) { |
463 if (bailout_reason == kNoReason) graph_builder_->Bailout(bailout_reason); | 463 if (!bailout_reason.is_empty()) 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 if (info()->bailout_reason() != kNoReason) { | 488 info()->set_bailout_reason("code generation failed"); |
489 info()->set_bailout_reason(kCodeGenerationFailed); | |
490 } | |
491 return AbortOptimization(); | 489 return AbortOptimization(); |
492 } | 490 } |
493 info()->SetCode(optimized_code); | 491 info()->SetCode(optimized_code); |
494 } | 492 } |
495 RecordOptimizationStats(); | 493 RecordOptimizationStats(); |
496 return SetLastStatus(SUCCEEDED); | 494 return SetLastStatus(SUCCEEDED); |
497 } | 495 } |
498 | 496 |
499 | 497 |
500 static bool GenerateCode(CompilationInfo* info) { | 498 static bool GenerateCode(CompilationInfo* info) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 CompilationInfoWithZone info(script); | 773 CompilationInfoWithZone info(script); |
776 info.MarkAsEval(); | 774 info.MarkAsEval(); |
777 if (is_global) info.MarkAsGlobal(); | 775 if (is_global) info.MarkAsGlobal(); |
778 info.SetLanguageMode(language_mode); | 776 info.SetLanguageMode(language_mode); |
779 info.SetParseRestriction(restriction); | 777 info.SetParseRestriction(restriction); |
780 info.SetContext(context); | 778 info.SetContext(context); |
781 result = MakeFunctionInfo(&info); | 779 result = MakeFunctionInfo(&info); |
782 if (!result.is_null()) { | 780 if (!result.is_null()) { |
783 // Explicitly disable optimization for eval code. We're not yet prepared | 781 // Explicitly disable optimization for eval code. We're not yet prepared |
784 // to handle eval-code in the optimizing compiler. | 782 // to handle eval-code in the optimizing compiler. |
785 result->DisableOptimization(kEval); | 783 result->DisableOptimization("eval"); |
786 | 784 |
787 // If caller is strict mode, the result must be in strict mode or | 785 // If caller is strict mode, the result must be in strict mode or |
788 // extended mode as well, but not the other way around. Consider: | 786 // extended mode as well, but not the other way around. Consider: |
789 // eval("'use strict'; ..."); | 787 // eval("'use strict'; ..."); |
790 ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode()); | 788 ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode()); |
791 // If caller is in extended mode, the result must also be in | 789 // If caller is in extended mode, the result must also be in |
792 // extended mode. | 790 // extended mode. |
793 ASSERT(language_mode != EXTENDED_MODE || | 791 ASSERT(language_mode != EXTENDED_MODE || |
794 result->is_extended_mode()); | 792 result->is_extended_mode()); |
795 if (!result->dont_cache()) { | 793 if (!result->dont_cache()) { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 } | 1048 } |
1051 | 1049 |
1052 Isolate* isolate = info->isolate(); | 1050 Isolate* isolate = info->isolate(); |
1053 VMState<COMPILER> state(isolate); | 1051 VMState<COMPILER> state(isolate); |
1054 Logger::TimerEventScope timer( | 1052 Logger::TimerEventScope timer( |
1055 isolate, Logger::TimerEventScope::v8_recompile_synchronous); | 1053 isolate, Logger::TimerEventScope::v8_recompile_synchronous); |
1056 // If crankshaft succeeded, install the optimized code else install | 1054 // If crankshaft succeeded, install the optimized code else install |
1057 // the unoptimized code. | 1055 // the unoptimized code. |
1058 OptimizingCompiler::Status status = optimizing_compiler->last_status(); | 1056 OptimizingCompiler::Status status = optimizing_compiler->last_status(); |
1059 if (info->HasAbortedDueToDependencyChange()) { | 1057 if (info->HasAbortedDueToDependencyChange()) { |
1060 info->set_bailout_reason(kBailedOutDueToDependentMap); | 1058 info->set_bailout_reason("bailed out due to dependent map"); |
1061 status = optimizing_compiler->AbortOptimization(); | 1059 status = optimizing_compiler->AbortOptimization(); |
1062 } else if (status != OptimizingCompiler::SUCCEEDED) { | 1060 } else if (status != OptimizingCompiler::SUCCEEDED) { |
1063 info->set_bailout_reason(kFailedBailedOutLastTime); | 1061 info->set_bailout_reason("failed/bailed out last time"); |
1064 status = optimizing_compiler->AbortOptimization(); | 1062 status = optimizing_compiler->AbortOptimization(); |
1065 } else if (isolate->DebuggerHasBreakPoints()) { | 1063 } else if (isolate->DebuggerHasBreakPoints()) { |
1066 info->set_bailout_reason(kDebuggerIsActive); | 1064 info->set_bailout_reason("debugger is active"); |
1067 status = optimizing_compiler->AbortOptimization(); | 1065 status = optimizing_compiler->AbortOptimization(); |
1068 } else { | 1066 } else { |
1069 status = optimizing_compiler->GenerateAndInstallCode(); | 1067 status = optimizing_compiler->GenerateAndInstallCode(); |
1070 ASSERT(status == OptimizingCompiler::SUCCEEDED || | 1068 ASSERT(status == OptimizingCompiler::SUCCEEDED || |
1071 status == OptimizingCompiler::BAILED_OUT); | 1069 status == OptimizingCompiler::BAILED_OUT); |
1072 } | 1070 } |
1073 | 1071 |
1074 InstallCodeCommon(*info); | 1072 InstallCodeCommon(*info); |
1075 if (status == OptimizingCompiler::SUCCEEDED) { | 1073 if (status == OptimizingCompiler::SUCCEEDED) { |
1076 Handle<Code> code = info->code(); | 1074 Handle<Code> code = info->code(); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 // Trace if the appropriate trace flag is set and the phase name's first | 1251 // Trace if the appropriate trace flag is set and the phase name's first |
1254 // character is in the FLAG_trace_phase command line parameter. | 1252 // character is in the FLAG_trace_phase command line parameter. |
1255 bool tracing_on = info()->IsStub() ? | 1253 bool tracing_on = info()->IsStub() ? |
1256 FLAG_trace_hydrogen_stubs : | 1254 FLAG_trace_hydrogen_stubs : |
1257 FLAG_trace_hydrogen; | 1255 FLAG_trace_hydrogen; |
1258 return (tracing_on && | 1256 return (tracing_on && |
1259 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1257 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
1260 } | 1258 } |
1261 | 1259 |
1262 } } // namespace v8::internal | 1260 } } // namespace v8::internal |
OLD | NEW |