| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 namespace v8 { | 53 namespace v8 { |
| 54 namespace internal { | 54 namespace internal { |
| 55 | 55 |
| 56 | 56 |
| 57 CompilationInfo::CompilationInfo(Handle<Script> script, | 57 CompilationInfo::CompilationInfo(Handle<Script> script, |
| 58 Zone* zone) | 58 Zone* zone) |
| 59 : flags_(LanguageModeField::encode(CLASSIC_MODE)), | 59 : flags_(LanguageModeField::encode(CLASSIC_MODE)), |
| 60 script_(script), | 60 script_(script), |
| 61 osr_ast_id_(BailoutId::None()), | 61 osr_ast_id_(BailoutId::None()), |
| 62 parameter_count_(0), | 62 parameter_count_(0), |
| 63 this_has_uses_(true), | 63 this_has_uses_(true) { |
| 64 optimization_id_(-1) { | |
| 65 Initialize(script->GetIsolate(), BASE, zone); | 64 Initialize(script->GetIsolate(), BASE, zone); |
| 66 } | 65 } |
| 67 | 66 |
| 68 | 67 |
| 69 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, | 68 CompilationInfo::CompilationInfo(Handle<SharedFunctionInfo> shared_info, |
| 70 Zone* zone) | 69 Zone* zone) |
| 71 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), | 70 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
| 72 shared_info_(shared_info), | 71 shared_info_(shared_info), |
| 73 script_(Handle<Script>(Script::cast(shared_info->script()))), | 72 script_(Handle<Script>(Script::cast(shared_info->script()))), |
| 74 osr_ast_id_(BailoutId::None()), | 73 osr_ast_id_(BailoutId::None()), |
| 75 parameter_count_(0), | 74 parameter_count_(0), |
| 76 this_has_uses_(true), | 75 this_has_uses_(true) { |
| 77 optimization_id_(-1) { | |
| 78 Initialize(script_->GetIsolate(), BASE, zone); | 76 Initialize(script_->GetIsolate(), BASE, zone); |
| 79 } | 77 } |
| 80 | 78 |
| 81 | 79 |
| 82 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, | 80 CompilationInfo::CompilationInfo(Handle<JSFunction> closure, |
| 83 Zone* zone) | 81 Zone* zone) |
| 84 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), | 82 : flags_(LanguageModeField::encode(CLASSIC_MODE) | IsLazy::encode(true)), |
| 85 closure_(closure), | 83 closure_(closure), |
| 86 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), | 84 shared_info_(Handle<SharedFunctionInfo>(closure->shared())), |
| 87 script_(Handle<Script>(Script::cast(shared_info_->script()))), | 85 script_(Handle<Script>(Script::cast(shared_info_->script()))), |
| 88 context_(closure->context()), | 86 context_(closure->context()), |
| 89 osr_ast_id_(BailoutId::None()), | 87 osr_ast_id_(BailoutId::None()), |
| 90 parameter_count_(0), | 88 parameter_count_(0), |
| 91 this_has_uses_(true), | 89 this_has_uses_(true) { |
| 92 optimization_id_(-1) { | |
| 93 Initialize(script_->GetIsolate(), BASE, zone); | 90 Initialize(script_->GetIsolate(), BASE, zone); |
| 94 } | 91 } |
| 95 | 92 |
| 96 | 93 |
| 97 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, | 94 CompilationInfo::CompilationInfo(HydrogenCodeStub* stub, |
| 98 Isolate* isolate, | 95 Isolate* isolate, |
| 99 Zone* zone) | 96 Zone* zone) |
| 100 : flags_(LanguageModeField::encode(CLASSIC_MODE) | | 97 : flags_(LanguageModeField::encode(CLASSIC_MODE) | |
| 101 IsLazy::encode(true)), | 98 IsLazy::encode(true)), |
| 102 osr_ast_id_(BailoutId::None()), | 99 osr_ast_id_(BailoutId::None()), |
| 103 parameter_count_(0), | 100 parameter_count_(0), |
| 104 this_has_uses_(true), | 101 this_has_uses_(true) { |
| 105 optimization_id_(-1) { | |
| 106 Initialize(isolate, STUB, zone); | 102 Initialize(isolate, STUB, zone); |
| 107 code_stub_ = stub; | 103 code_stub_ = stub; |
| 108 } | 104 } |
| 109 | 105 |
| 110 | 106 |
| 111 void CompilationInfo::Initialize(Isolate* isolate, | 107 void CompilationInfo::Initialize(Isolate* isolate, |
| 112 Mode mode, | 108 Mode mode, |
| 113 Zone* zone) { | 109 Zone* zone) { |
| 114 isolate_ = isolate; | 110 isolate_ = isolate; |
| 115 function_ = NULL; | 111 function_ = NULL; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 return scope()->num_heap_slots(); | 204 return scope()->num_heap_slots(); |
| 209 } | 205 } |
| 210 } | 206 } |
| 211 | 207 |
| 212 | 208 |
| 213 Code::Flags CompilationInfo::flags() const { | 209 Code::Flags CompilationInfo::flags() const { |
| 214 if (IsStub()) { | 210 if (IsStub()) { |
| 215 return Code::ComputeFlags(code_stub()->GetCodeKind(), | 211 return Code::ComputeFlags(code_stub()->GetCodeKind(), |
| 216 code_stub()->GetICState(), | 212 code_stub()->GetICState(), |
| 217 code_stub()->GetExtraICState(), | 213 code_stub()->GetExtraICState(), |
| 218 code_stub()->GetStubType()); | 214 code_stub()->GetStubType(), |
| 215 code_stub()->GetStubFlags()); |
| 219 } else { | 216 } else { |
| 220 return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION); | 217 return Code::ComputeFlags(Code::OPTIMIZED_FUNCTION); |
| 221 } | 218 } |
| 222 } | 219 } |
| 223 | 220 |
| 224 | 221 |
| 225 // Disable optimization for the rest of the compilation pipeline. | 222 // Disable optimization for the rest of the compilation pipeline. |
| 226 void CompilationInfo::DisableOptimization() { | 223 void CompilationInfo::DisableOptimization() { |
| 227 bool is_optimizable_closure = | 224 bool is_optimizable_closure = |
| 228 FLAG_optimize_closures && | 225 FLAG_optimize_closures && |
| (...skipping 10 matching lines...) Expand all Loading... |
| 239 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. | 236 // for the SharedFunctionInfo::kCallsUntilPrimitiveOptimization-th time. |
| 240 bool CompilationInfo::ShouldSelfOptimize() { | 237 bool CompilationInfo::ShouldSelfOptimize() { |
| 241 return FLAG_crankshaft && | 238 return FLAG_crankshaft && |
| 242 !function()->flags()->Contains(kDontSelfOptimize) && | 239 !function()->flags()->Contains(kDontSelfOptimize) && |
| 243 !function()->dont_optimize() && | 240 !function()->dont_optimize() && |
| 244 function()->scope()->AllowsLazyCompilation() && | 241 function()->scope()->AllowsLazyCompilation() && |
| 245 (shared_info().is_null() || !shared_info()->optimization_disabled()); | 242 (shared_info().is_null() || !shared_info()->optimization_disabled()); |
| 246 } | 243 } |
| 247 | 244 |
| 248 | 245 |
| 249 void CompilationInfo::PrepareForCompilation(Scope* scope) { | |
| 250 ASSERT(scope_ == NULL); | |
| 251 scope_ = scope; | |
| 252 function()->ProcessFeedbackSlots(isolate_); | |
| 253 } | |
| 254 | |
| 255 | |
| 256 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { | 246 class HOptimizedGraphBuilderWithPositions: public HOptimizedGraphBuilder { |
| 257 public: | 247 public: |
| 258 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) | 248 explicit HOptimizedGraphBuilderWithPositions(CompilationInfo* info) |
| 259 : HOptimizedGraphBuilder(info) { | 249 : HOptimizedGraphBuilder(info) { |
| 260 } | 250 } |
| 261 | 251 |
| 262 #define DEF_VISIT(type) \ | 252 #define DEF_VISIT(type) \ |
| 263 virtual void Visit##type(type* node) V8_OVERRIDE { \ | 253 virtual void Visit##type(type* node) V8_OVERRIDE { \ |
| 264 if (node->position() != RelocInfo::kNoPosition) { \ | 254 if (node->position() != RelocInfo::kNoPosition) { \ |
| 265 SetSourcePosition(node->position()); \ | 255 SetSourcePosition(node->position()); \ |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 bool should_recompile = !info()->shared_info()->has_deoptimization_support(); | 356 bool should_recompile = !info()->shared_info()->has_deoptimization_support(); |
| 367 if (should_recompile || FLAG_hydrogen_stats) { | 357 if (should_recompile || FLAG_hydrogen_stats) { |
| 368 ElapsedTimer timer; | 358 ElapsedTimer timer; |
| 369 if (FLAG_hydrogen_stats) { | 359 if (FLAG_hydrogen_stats) { |
| 370 timer.Start(); | 360 timer.Start(); |
| 371 } | 361 } |
| 372 CompilationInfoWithZone unoptimized(info()->shared_info()); | 362 CompilationInfoWithZone unoptimized(info()->shared_info()); |
| 373 // Note that we use the same AST that we will use for generating the | 363 // Note that we use the same AST that we will use for generating the |
| 374 // optimized code. | 364 // optimized code. |
| 375 unoptimized.SetFunction(info()->function()); | 365 unoptimized.SetFunction(info()->function()); |
| 376 unoptimized.PrepareForCompilation(info()->scope()); | 366 unoptimized.SetScope(info()->scope()); |
| 377 unoptimized.SetContext(info()->context()); | 367 unoptimized.SetContext(info()->context()); |
| 378 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); | 368 if (should_recompile) unoptimized.EnableDeoptimizationSupport(); |
| 379 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); | 369 bool succeeded = FullCodeGenerator::MakeCode(&unoptimized); |
| 380 if (should_recompile) { | 370 if (should_recompile) { |
| 381 if (!succeeded) return SetLastStatus(FAILED); | 371 if (!succeeded) return SetLastStatus(FAILED); |
| 382 Handle<SharedFunctionInfo> shared = info()->shared_info(); | 372 Handle<SharedFunctionInfo> shared = info()->shared_info(); |
| 383 shared->EnableDeoptimizationSupport(*unoptimized.code()); | 373 shared->EnableDeoptimizationSupport(*unoptimized.code()); |
| 384 // The existing unoptimized code was replaced with the new one. | 374 // The existing unoptimized code was replaced with the new one. |
| 385 Compiler::RecordFunctionCompilation( | 375 Compiler::RecordFunctionCompilation( |
| 386 Logger::LAZY_COMPILE_TAG, &unoptimized, shared); | 376 Logger::LAZY_COMPILE_TAG, &unoptimized, shared); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 401 if (FLAG_trace_hydrogen) { | 391 if (FLAG_trace_hydrogen) { |
| 402 Handle<String> name = info()->function()->debug_name(); | 392 Handle<String> name = info()->function()->debug_name(); |
| 403 PrintF("-----------------------------------------------------------\n"); | 393 PrintF("-----------------------------------------------------------\n"); |
| 404 PrintF("Compiling method %s using hydrogen\n", name->ToCString().get()); | 394 PrintF("Compiling method %s using hydrogen\n", name->ToCString().get()); |
| 405 isolate()->GetHTracer()->TraceCompilation(info()); | 395 isolate()->GetHTracer()->TraceCompilation(info()); |
| 406 } | 396 } |
| 407 | 397 |
| 408 // Type-check the function. | 398 // Type-check the function. |
| 409 AstTyper::Run(info()); | 399 AstTyper::Run(info()); |
| 410 | 400 |
| 411 graph_builder_ = FLAG_hydrogen_track_positions | 401 graph_builder_ = FLAG_emit_opt_code_positions |
| 412 ? new(info()->zone()) HOptimizedGraphBuilderWithPositions(info()) | 402 ? new(info()->zone()) HOptimizedGraphBuilderWithPositions(info()) |
| 413 : new(info()->zone()) HOptimizedGraphBuilder(info()); | 403 : new(info()->zone()) HOptimizedGraphBuilder(info()); |
| 414 | 404 |
| 415 Timer t(this, &time_taken_to_create_graph_); | 405 Timer t(this, &time_taken_to_create_graph_); |
| 416 info()->set_this_has_uses(false); | 406 info()->set_this_has_uses(false); |
| 417 graph_ = graph_builder_->CreateGraph(); | 407 graph_ = graph_builder_->CreateGraph(); |
| 418 | 408 |
| 419 if (isolate()->has_pending_exception()) { | 409 if (isolate()->has_pending_exception()) { |
| 420 return SetLastStatus(FAILED); | 410 return SetLastStatus(FAILED); |
| 421 } | 411 } |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 isolate->debugger()->OnBeforeCompile(script); | 772 isolate->debugger()->OnBeforeCompile(script); |
| 783 #endif | 773 #endif |
| 784 | 774 |
| 785 ASSERT(info->is_eval() || info->is_global()); | 775 ASSERT(info->is_eval() || info->is_global()); |
| 786 | 776 |
| 787 bool parse_allow_lazy = | 777 bool parse_allow_lazy = |
| 788 (info->pre_parse_data() != NULL || | 778 (info->pre_parse_data() != NULL || |
| 789 String::cast(script->source())->length() > FLAG_min_preparse_length) && | 779 String::cast(script->source())->length() > FLAG_min_preparse_length) && |
| 790 !DebuggerWantsEagerCompilation(info); | 780 !DebuggerWantsEagerCompilation(info); |
| 791 | 781 |
| 792 if (!parse_allow_lazy && info->pre_parse_data() != NULL) { | |
| 793 // We are going to parse eagerly, but we have preparse data produced by lazy | |
| 794 // preparsing. We cannot use it, since it won't contain all the symbols we | |
| 795 // need for eager parsing. | |
| 796 info->SetPreParseData(NULL); | |
| 797 } | |
| 798 | |
| 799 Handle<SharedFunctionInfo> result; | 782 Handle<SharedFunctionInfo> result; |
| 800 | 783 |
| 801 { VMState<COMPILER> state(info->isolate()); | 784 { VMState<COMPILER> state(info->isolate()); |
| 802 if (!Parser::Parse(info, parse_allow_lazy)) { | 785 if (!Parser::Parse(info, parse_allow_lazy)) { |
| 803 return Handle<SharedFunctionInfo>::null(); | 786 return Handle<SharedFunctionInfo>::null(); |
| 804 } | 787 } |
| 805 | 788 |
| 806 FunctionLiteral* lit = info->function(); | 789 FunctionLiteral* lit = info->function(); |
| 807 LiveEditFunctionTracker live_edit_tracker(isolate, lit); | 790 LiveEditFunctionTracker live_edit_tracker(isolate, lit); |
| 808 | 791 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 if (result.is_null()) isolate->ReportPendingMessages(); | 975 if (result.is_null()) isolate->ReportPendingMessages(); |
| 993 return result; | 976 return result; |
| 994 } | 977 } |
| 995 | 978 |
| 996 | 979 |
| 997 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, | 980 Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal, |
| 998 Handle<Script> script) { | 981 Handle<Script> script) { |
| 999 // Precondition: code has been parsed and scopes have been analyzed. | 982 // Precondition: code has been parsed and scopes have been analyzed. |
| 1000 CompilationInfoWithZone info(script); | 983 CompilationInfoWithZone info(script); |
| 1001 info.SetFunction(literal); | 984 info.SetFunction(literal); |
| 1002 info.PrepareForCompilation(literal->scope()); | 985 info.SetScope(literal->scope()); |
| 1003 info.SetLanguageMode(literal->scope()->language_mode()); | 986 info.SetLanguageMode(literal->scope()->language_mode()); |
| 1004 | 987 |
| 1005 Isolate* isolate = info.isolate(); | 988 Isolate* isolate = info.isolate(); |
| 1006 Factory* factory = isolate->factory(); | 989 Factory* factory = isolate->factory(); |
| 1007 LiveEditFunctionTracker live_edit_tracker(isolate, literal); | 990 LiveEditFunctionTracker live_edit_tracker(isolate, literal); |
| 1008 // Determine if the function can be lazily compiled. This is necessary to | 991 // Determine if the function can be lazily compiled. This is necessary to |
| 1009 // allow some of our builtin JS files to be lazily compiled. These | 992 // allow some of our builtin JS files to be lazily compiled. These |
| 1010 // builtins cannot be handled lazily by the parser, since we have to know | 993 // builtins cannot be handled lazily by the parser, since we have to know |
| 1011 // if a function uses the special natives syntax, which is something the | 994 // if a function uses the special natives syntax, which is something the |
| 1012 // parser records. | 995 // parser records. |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 return isolate->builtins()->InOptimizationQueue(); | 1171 return isolate->builtins()->InOptimizationQueue(); |
| 1189 } | 1172 } |
| 1190 } else { | 1173 } else { |
| 1191 if (GetOptimizedCodeNow(info.get())) return info->code(); | 1174 if (GetOptimizedCodeNow(info.get())) return info->code(); |
| 1192 } | 1175 } |
| 1193 | 1176 |
| 1194 // Failed. | 1177 // Failed. |
| 1195 if (FLAG_trace_opt) { | 1178 if (FLAG_trace_opt) { |
| 1196 PrintF("[failed to optimize "); | 1179 PrintF("[failed to optimize "); |
| 1197 function->PrintName(); | 1180 function->PrintName(); |
| 1198 PrintF(": %s]\n", GetBailoutReason(info->bailout_reason())); | 1181 PrintF("]\n"); |
| 1199 } | 1182 } |
| 1200 | 1183 |
| 1201 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); | 1184 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); |
| 1202 return Handle<Code>::null(); | 1185 return Handle<Code>::null(); |
| 1203 } | 1186 } |
| 1204 | 1187 |
| 1205 | 1188 |
| 1206 Handle<Code> Compiler::GetConcurrentlyOptimizedCode(OptimizedCompileJob* job) { | 1189 Handle<Code> Compiler::GetConcurrentlyOptimizedCode(OptimizedCompileJob* job) { |
| 1207 // Take ownership of compilation info. Deleting compilation info | 1190 // Take ownership of compilation info. Deleting compilation info |
| 1208 // also tears down the zone and the recompile job. | 1191 // also tears down the zone and the recompile job. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 AllowHandleDereference allow_deref; | 1291 AllowHandleDereference allow_deref; |
| 1309 bool tracing_on = info()->IsStub() | 1292 bool tracing_on = info()->IsStub() |
| 1310 ? FLAG_trace_hydrogen_stubs | 1293 ? FLAG_trace_hydrogen_stubs |
| 1311 : (FLAG_trace_hydrogen && | 1294 : (FLAG_trace_hydrogen && |
| 1312 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1295 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
| 1313 return (tracing_on && | 1296 return (tracing_on && |
| 1314 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1297 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
| 1315 } | 1298 } |
| 1316 | 1299 |
| 1317 } } // namespace v8::internal | 1300 } } // namespace v8::internal |
| OLD | NEW |