| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 Zone* zone) { | 105 Zone* zone) { |
| 106 isolate_ = isolate; | 106 isolate_ = isolate; |
| 107 function_ = NULL; | 107 function_ = NULL; |
| 108 scope_ = NULL; | 108 scope_ = NULL; |
| 109 global_scope_ = NULL; | 109 global_scope_ = NULL; |
| 110 extension_ = NULL; | 110 extension_ = NULL; |
| 111 pre_parse_data_ = NULL; | 111 pre_parse_data_ = NULL; |
| 112 zone_ = zone; | 112 zone_ = zone; |
| 113 deferred_handles_ = NULL; | 113 deferred_handles_ = NULL; |
| 114 code_stub_ = NULL; | 114 code_stub_ = NULL; |
| 115 prologue_offset_ = kPrologueOffsetNotSet; | 115 prologue_offset_ = Code::kPrologueOffsetNotSet; |
| 116 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); | 116 opt_count_ = shared_info().is_null() ? 0 : shared_info()->opt_count(); |
| 117 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() | 117 no_frame_ranges_ = isolate->cpu_profiler()->is_profiling() |
| 118 ? new List<OffsetRange>(2) : NULL; | 118 ? new List<OffsetRange>(2) : NULL; |
| 119 for (int i = 0; i < DependentCode::kGroupCount; i++) { | 119 for (int i = 0; i < DependentCode::kGroupCount; i++) { |
| 120 dependencies_[i] = NULL; | 120 dependencies_[i] = NULL; |
| 121 } | 121 } |
| 122 if (mode == STUB) { | 122 if (mode == STUB) { |
| 123 mode_ = STUB; | 123 mode_ = STUB; |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 mode_ = isolate->use_crankshaft() ? mode : NONOPT; | 126 mode_ = mode; |
| 127 abort_due_to_dependency_ = false; | 127 abort_due_to_dependency_ = false; |
| 128 if (script_->type()->value() == Script::TYPE_NATIVE) { | 128 if (script_->type()->value() == Script::TYPE_NATIVE) { |
| 129 MarkAsNative(); | 129 MarkAsNative(); |
| 130 } | 130 } |
| 131 if (!shared_info_.is_null()) { | 131 if (!shared_info_.is_null()) { |
| 132 ASSERT(language_mode() == CLASSIC_MODE); | 132 ASSERT(language_mode() == CLASSIC_MODE); |
| 133 SetLanguageMode(shared_info_->language_mode()); | 133 SetLanguageMode(shared_info_->language_mode()); |
| 134 } | 134 } |
| 135 set_bailout_reason(kUnknown); | 135 set_bailout_reason(kUnknown); |
| 136 } | 136 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 status = job.OptimizeGraph(); | 306 status = job.OptimizeGraph(); |
| 307 if (status != RecompileJob::SUCCEEDED) { | 307 if (status != RecompileJob::SUCCEEDED) { |
| 308 status = job.AbortOptimization(); | 308 status = job.AbortOptimization(); |
| 309 return status != RecompileJob::FAILED; | 309 return status != RecompileJob::FAILED; |
| 310 } | 310 } |
| 311 status = job.GenerateAndInstallCode(); | 311 status = job.GenerateAndInstallCode(); |
| 312 return status != RecompileJob::FAILED; | 312 return status != RecompileJob::FAILED; |
| 313 } | 313 } |
| 314 | 314 |
| 315 | 315 |
| 316 class HOptimizedGraphBuilderWithPotisions: public HOptimizedGraphBuilder { |
| 317 public: |
| 318 explicit HOptimizedGraphBuilderWithPotisions(CompilationInfo* info) |
| 319 : HOptimizedGraphBuilder(info) { |
| 320 } |
| 321 |
| 322 #define DEF_VISIT(type) \ |
| 323 virtual void Visit##type(type* node) V8_OVERRIDE { \ |
| 324 if (node->position() != RelocInfo::kNoPosition) { \ |
| 325 SetSourcePosition(node->position()); \ |
| 326 } \ |
| 327 HOptimizedGraphBuilder::Visit##type(node); \ |
| 328 } |
| 329 EXPRESSION_NODE_LIST(DEF_VISIT) |
| 330 #undef DEF_VISIT |
| 331 |
| 332 #define DEF_VISIT(type) \ |
| 333 virtual void Visit##type(type* node) V8_OVERRIDE { \ |
| 334 if (node->position() != RelocInfo::kNoPosition) { \ |
| 335 SetSourcePosition(node->position()); \ |
| 336 } \ |
| 337 HOptimizedGraphBuilder::Visit##type(node); \ |
| 338 } |
| 339 STATEMENT_NODE_LIST(DEF_VISIT) |
| 340 #undef DEF_VISIT |
| 341 |
| 342 #define DEF_VISIT(type) \ |
| 343 virtual void Visit##type(type* node) V8_OVERRIDE { \ |
| 344 HOptimizedGraphBuilder::Visit##type(node); \ |
| 345 } |
| 346 MODULE_NODE_LIST(DEF_VISIT) |
| 347 DECLARATION_NODE_LIST(DEF_VISIT) |
| 348 AUXILIARY_NODE_LIST(DEF_VISIT) |
| 349 #undef DEF_VISIT |
| 350 }; |
| 351 |
| 352 |
| 316 RecompileJob::Status RecompileJob::CreateGraph() { | 353 RecompileJob::Status RecompileJob::CreateGraph() { |
| 317 ASSERT(isolate()->use_crankshaft()); | 354 ASSERT(isolate()->use_crankshaft()); |
| 318 ASSERT(info()->IsOptimizing()); | 355 ASSERT(info()->IsOptimizing()); |
| 319 ASSERT(!info()->IsCompilingForDebugging()); | 356 ASSERT(!info()->IsCompilingForDebugging()); |
| 320 | 357 |
| 321 // We should never arrive here if there is no code object on the | 358 // We should never arrive here if there is no code object on the |
| 322 // shared function object. | 359 // shared function object. |
| 323 ASSERT(info()->shared_info()->code()->kind() == Code::FUNCTION); | 360 ASSERT(info()->shared_info()->code()->kind() == Code::FUNCTION); |
| 324 | 361 |
| 325 // We should never arrive here if optimization has been disabled on the | 362 // We should never arrive here if optimization has been disabled on the |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 if (FLAG_trace_hydrogen) { | 449 if (FLAG_trace_hydrogen) { |
| 413 Handle<String> name = info()->function()->debug_name(); | 450 Handle<String> name = info()->function()->debug_name(); |
| 414 PrintF("-----------------------------------------------------------\n"); | 451 PrintF("-----------------------------------------------------------\n"); |
| 415 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); | 452 PrintF("Compiling method %s using hydrogen\n", *name->ToCString()); |
| 416 isolate()->GetHTracer()->TraceCompilation(info()); | 453 isolate()->GetHTracer()->TraceCompilation(info()); |
| 417 } | 454 } |
| 418 | 455 |
| 419 // Type-check the function. | 456 // Type-check the function. |
| 420 AstTyper::Run(info()); | 457 AstTyper::Run(info()); |
| 421 | 458 |
| 422 graph_builder_ = new(info()->zone()) HOptimizedGraphBuilder(info()); | 459 graph_builder_ = FLAG_emit_opt_code_positions |
| 460 ? new(info()->zone()) HOptimizedGraphBuilderWithPotisions(info()) |
| 461 : new(info()->zone()) HOptimizedGraphBuilder(info()); |
| 423 | 462 |
| 424 Timer t(this, &time_taken_to_create_graph_); | 463 Timer t(this, &time_taken_to_create_graph_); |
| 425 graph_ = graph_builder_->CreateGraph(); | 464 graph_ = graph_builder_->CreateGraph(); |
| 426 | 465 |
| 427 if (isolate()->has_pending_exception()) { | 466 if (isolate()->has_pending_exception()) { |
| 428 info()->SetCode(Handle<Code>::null()); | 467 info()->SetCode(Handle<Code>::null()); |
| 429 return SetLastStatus(FAILED); | 468 return SetLastStatus(FAILED); |
| 430 } | 469 } |
| 431 | 470 |
| 432 // The function being compiled may have bailed out due to an inline | 471 // The function being compiled may have bailed out due to an inline |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 #endif | 587 #endif |
| 549 | 588 |
| 550 | 589 |
| 551 static bool DebuggerWantsEagerCompilation(CompilationInfo* info, | 590 static bool DebuggerWantsEagerCompilation(CompilationInfo* info, |
| 552 bool allow_lazy_without_ctx = false) { | 591 bool allow_lazy_without_ctx = false) { |
| 553 return LiveEditFunctionTracker::IsActive(info->isolate()) || | 592 return LiveEditFunctionTracker::IsActive(info->isolate()) || |
| 554 (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx); | 593 (info->isolate()->DebuggerHasBreakPoints() && !allow_lazy_without_ctx); |
| 555 } | 594 } |
| 556 | 595 |
| 557 | 596 |
| 597 // Sets the expected number of properties based on estimate from compiler. |
| 598 void SetExpectedNofPropertiesFromEstimate(Handle<SharedFunctionInfo> shared, |
| 599 int estimate) { |
| 600 // See the comment in SetExpectedNofProperties. |
| 601 if (shared->live_objects_may_exist()) return; |
| 602 |
| 603 // If no properties are added in the constructor, they are more likely |
| 604 // to be added later. |
| 605 if (estimate == 0) estimate = 2; |
| 606 |
| 607 // TODO(yangguo): check whether those heuristics are still up-to-date. |
| 608 // We do not shrink objects that go into a snapshot (yet), so we adjust |
| 609 // the estimate conservatively. |
| 610 if (Serializer::enabled()) { |
| 611 estimate += 2; |
| 612 } else if (FLAG_clever_optimizations) { |
| 613 // Inobject slack tracking will reclaim redundant inobject space later, |
| 614 // so we can afford to adjust the estimate generously. |
| 615 estimate += 8; |
| 616 } else { |
| 617 estimate += 3; |
| 618 } |
| 619 |
| 620 shared->set_expected_nof_properties(estimate); |
| 621 } |
| 622 |
| 623 |
| 558 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { | 624 static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) { |
| 559 Isolate* isolate = info->isolate(); | 625 Isolate* isolate = info->isolate(); |
| 560 PostponeInterruptsScope postpone(isolate); | 626 PostponeInterruptsScope postpone(isolate); |
| 561 | 627 |
| 562 ASSERT(!isolate->native_context().is_null()); | 628 ASSERT(!isolate->native_context().is_null()); |
| 563 Handle<Script> script = info->script(); | 629 Handle<Script> script = info->script(); |
| 564 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 630 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
| 565 FixedArray* array = isolate->native_context()->embedder_data(); | 631 FixedArray* array = isolate->native_context()->embedder_data(); |
| 566 script->set_context_data(array->get(0)); | 632 script->set_context_data(array->get(0)); |
| 567 | 633 |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 AllowHandleDereference allow_deref; | 1346 AllowHandleDereference allow_deref; |
| 1281 bool tracing_on = info()->IsStub() | 1347 bool tracing_on = info()->IsStub() |
| 1282 ? FLAG_trace_hydrogen_stubs | 1348 ? FLAG_trace_hydrogen_stubs |
| 1283 : (FLAG_trace_hydrogen && | 1349 : (FLAG_trace_hydrogen && |
| 1284 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); | 1350 info()->closure()->PassesFilter(FLAG_trace_hydrogen_filter)); |
| 1285 return (tracing_on && | 1351 return (tracing_on && |
| 1286 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); | 1352 OS::StrChr(const_cast<char*>(FLAG_trace_phase), name_[0]) != NULL); |
| 1287 } | 1353 } |
| 1288 | 1354 |
| 1289 } } // namespace v8::internal | 1355 } } // namespace v8::internal |
| OLD | NEW |