| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (AlwaysFullCompiler(info()->isolate())) { | 235 if (AlwaysFullCompiler(info()->isolate())) { |
| 236 info()->SetCode(code); | 236 info()->SetCode(code); |
| 237 return SetLastStatus(BAILED_OUT); | 237 return SetLastStatus(BAILED_OUT); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Limit the number of times we re-compile a functions with | 240 // Limit the number of times we re-compile a functions with |
| 241 // the optimizing compiler. | 241 // the optimizing compiler. |
| 242 const int kMaxOptCount = | 242 const int kMaxOptCount = |
| 243 FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; | 243 FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; |
| 244 if (info()->shared_info()->opt_count() > kMaxOptCount) { | 244 if (info()->shared_info()->opt_count() > kMaxOptCount) { |
| 245 info()->set_bailout_reason("optimized too many times"); |
| 245 return AbortOptimization(); | 246 return AbortOptimization(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 // Due to an encoding limit on LUnallocated operands in the Lithium | 249 // Due to an encoding limit on LUnallocated operands in the Lithium |
| 249 // language, we cannot optimize functions with too many formal parameters | 250 // language, we cannot optimize functions with too many formal parameters |
| 250 // or perform on-stack replacement for function with too many | 251 // or perform on-stack replacement for function with too many |
| 251 // stack-allocated local variables. | 252 // stack-allocated local variables. |
| 252 // | 253 // |
| 253 // The encoding is as a signed value, with parameters and receiver using | 254 // The encoding is as a signed value, with parameters and receiver using |
| 254 // the negative indices and locals the non-negative ones. | 255 // the negative indices and locals the non-negative ones. |
| 255 const int parameter_limit = -LUnallocated::kMinFixedIndex; | 256 const int parameter_limit = -LUnallocated::kMinFixedIndex; |
| 256 const int locals_limit = LUnallocated::kMaxFixedIndex; | |
| 257 Scope* scope = info()->scope(); | 257 Scope* scope = info()->scope(); |
| 258 if ((scope->num_parameters() + 1) > parameter_limit || | 258 if ((scope->num_parameters() + 1) > parameter_limit) { |
| 259 (!info()->osr_ast_id().IsNone() && | 259 info()->set_bailout_reason("too many parameters"); |
| 260 scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit)) { | |
| 261 return AbortOptimization(); | 260 return AbortOptimization(); |
| 262 } | 261 } |
| 263 | 262 |
| 263 const int locals_limit = LUnallocated::kMaxFixedIndex; |
| 264 if (!info()->osr_ast_id().IsNone() && |
| 265 scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) { |
| 266 info()->set_bailout_reason("too many parameters/locals"); |
| 267 return AbortOptimization(); |
| 268 } |
| 269 |
| 264 // Take --hydrogen-filter into account. | 270 // Take --hydrogen-filter into account. |
| 265 Handle<String> name = info()->function()->debug_name(); | 271 Handle<String> name = info()->function()->debug_name(); |
| 266 if (*FLAG_hydrogen_filter != '\0') { | 272 if (*FLAG_hydrogen_filter != '\0') { |
| 267 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter); | 273 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter); |
| 268 if ((filter[0] == '-' | 274 if ((filter[0] == '-' |
| 269 && name->IsEqualTo(filter.SubVector(1, filter.length()))) | 275 && name->IsEqualTo(filter.SubVector(1, filter.length()))) |
| 270 || (filter[0] != '-' && !name->IsEqualTo(filter))) { | 276 || (filter[0] != '-' && !name->IsEqualTo(filter))) { |
| 271 info()->SetCode(code); | 277 info()->SetCode(code); |
| 272 return SetLastStatus(BAILED_OUT); | 278 return SetLastStatus(BAILED_OUT); |
| 273 } | 279 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 return SetLastStatus(SUCCEEDED); | 366 return SetLastStatus(SUCCEEDED); |
| 361 } | 367 } |
| 362 | 368 |
| 363 | 369 |
| 364 OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { | 370 OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { |
| 365 ASSERT(last_status() == SUCCEEDED); | 371 ASSERT(last_status() == SUCCEEDED); |
| 366 Timer timer(this, &time_taken_to_codegen_); | 372 Timer timer(this, &time_taken_to_codegen_); |
| 367 ASSERT(chunk_ != NULL); | 373 ASSERT(chunk_ != NULL); |
| 368 ASSERT(graph_ != NULL); | 374 ASSERT(graph_ != NULL); |
| 369 Handle<Code> optimized_code = chunk_->Codegen(); | 375 Handle<Code> optimized_code = chunk_->Codegen(); |
| 370 if (optimized_code.is_null()) return AbortOptimization(); | 376 if (optimized_code.is_null()) { |
| 377 info()->set_bailout_reason("code generation failed"); |
| 378 return AbortOptimization(); |
| 379 } |
| 371 info()->SetCode(optimized_code); | 380 info()->SetCode(optimized_code); |
| 372 RecordOptimizationStats(); | 381 RecordOptimizationStats(); |
| 373 return SetLastStatus(SUCCEEDED); | 382 return SetLastStatus(SUCCEEDED); |
| 374 } | 383 } |
| 375 | 384 |
| 376 | 385 |
| 377 static bool GenerateCode(CompilationInfo* info) { | 386 static bool GenerateCode(CompilationInfo* info) { |
| 378 bool is_optimizing = V8::UseCrankshaft() && | 387 bool is_optimizing = V8::UseCrankshaft() && |
| 379 !info->IsCompilingForDebugging() && | 388 !info->IsCompilingForDebugging() && |
| 380 info->IsOptimizing(); | 389 info->IsOptimizing(); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 Handle<Script> script = isolate->factory()->NewScript(source); | 639 Handle<Script> script = isolate->factory()->NewScript(source); |
| 631 CompilationInfoWithZone info(script); | 640 CompilationInfoWithZone info(script); |
| 632 info.MarkAsEval(); | 641 info.MarkAsEval(); |
| 633 if (is_global) info.MarkAsGlobal(); | 642 if (is_global) info.MarkAsGlobal(); |
| 634 info.SetLanguageMode(language_mode); | 643 info.SetLanguageMode(language_mode); |
| 635 info.SetCallingContext(context); | 644 info.SetCallingContext(context); |
| 636 result = MakeFunctionInfo(&info); | 645 result = MakeFunctionInfo(&info); |
| 637 if (!result.is_null()) { | 646 if (!result.is_null()) { |
| 638 // Explicitly disable optimization for eval code. We're not yet prepared | 647 // Explicitly disable optimization for eval code. We're not yet prepared |
| 639 // to handle eval-code in the optimizing compiler. | 648 // to handle eval-code in the optimizing compiler. |
| 640 result->DisableOptimization(); | 649 result->DisableOptimization("eval"); |
| 641 | 650 |
| 642 // If caller is strict mode, the result must be in strict mode or | 651 // If caller is strict mode, the result must be in strict mode or |
| 643 // extended mode as well, but not the other way around. Consider: | 652 // extended mode as well, but not the other way around. Consider: |
| 644 // eval("'use strict'; ..."); | 653 // eval("'use strict'; ..."); |
| 645 ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode()); | 654 ASSERT(language_mode != STRICT_MODE || !result->is_classic_mode()); |
| 646 // If caller is in extended mode, the result must also be in | 655 // If caller is in extended mode, the result must also be in |
| 647 // extended mode. | 656 // extended mode. |
| 648 ASSERT(language_mode != EXTENDED_MODE || | 657 ASSERT(language_mode != EXTENDED_MODE || |
| 649 result->is_extended_mode()); | 658 result->is_extended_mode()); |
| 650 if (!result->dont_cache()) { | 659 if (!result->dont_cache()) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 } | 882 } |
| 874 } | 883 } |
| 875 | 884 |
| 876 | 885 |
| 877 void Compiler::InstallOptimizedCode(OptimizingCompiler* optimizing_compiler) { | 886 void Compiler::InstallOptimizedCode(OptimizingCompiler* optimizing_compiler) { |
| 878 SmartPointer<CompilationInfo> info(optimizing_compiler->info()); | 887 SmartPointer<CompilationInfo> info(optimizing_compiler->info()); |
| 879 // If crankshaft succeeded, install the optimized code else install | 888 // If crankshaft succeeded, install the optimized code else install |
| 880 // the unoptimized code. | 889 // the unoptimized code. |
| 881 OptimizingCompiler::Status status = optimizing_compiler->last_status(); | 890 OptimizingCompiler::Status status = optimizing_compiler->last_status(); |
| 882 if (status != OptimizingCompiler::SUCCEEDED) { | 891 if (status != OptimizingCompiler::SUCCEEDED) { |
| 892 optimizing_compiler->info()->set_bailout_reason( |
| 893 "failed/bailed out last time"); |
| 883 status = optimizing_compiler->AbortOptimization(); | 894 status = optimizing_compiler->AbortOptimization(); |
| 884 } else { | 895 } else { |
| 885 status = optimizing_compiler->GenerateAndInstallCode(); | 896 status = optimizing_compiler->GenerateAndInstallCode(); |
| 886 ASSERT(status == OptimizingCompiler::SUCCEEDED || | 897 ASSERT(status == OptimizingCompiler::SUCCEEDED || |
| 887 status == OptimizingCompiler::BAILED_OUT); | 898 status == OptimizingCompiler::BAILED_OUT); |
| 888 } | 899 } |
| 889 | 900 |
| 890 InstallCodeCommon(*info); | 901 InstallCodeCommon(*info); |
| 891 if (status == OptimizingCompiler::SUCCEEDED) { | 902 if (status == OptimizingCompiler::SUCCEEDED) { |
| 892 Handle<Code> code = info->code(); | 903 Handle<Code> code = info->code(); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 } | 1038 } |
| 1028 } | 1039 } |
| 1029 | 1040 |
| 1030 GDBJIT(AddCode(Handle<String>(shared->DebugName()), | 1041 GDBJIT(AddCode(Handle<String>(shared->DebugName()), |
| 1031 Handle<Script>(info->script()), | 1042 Handle<Script>(info->script()), |
| 1032 Handle<Code>(info->code()), | 1043 Handle<Code>(info->code()), |
| 1033 info)); | 1044 info)); |
| 1034 } | 1045 } |
| 1035 | 1046 |
| 1036 } } // namespace v8::internal | 1047 } } // namespace v8::internal |
| OLD | NEW |