OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler.h" | 5 #include "src/compiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/ast/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 chunk_ = LChunk::NewChunk(graph_); | 537 chunk_ = LChunk::NewChunk(graph_); |
538 if (chunk_ != NULL) return SetLastStatus(SUCCEEDED); | 538 if (chunk_ != NULL) return SetLastStatus(SUCCEEDED); |
539 } else if (bailout_reason != kNoReason) { | 539 } else if (bailout_reason != kNoReason) { |
540 graph_builder_->Bailout(bailout_reason); | 540 graph_builder_->Bailout(bailout_reason); |
541 } | 541 } |
542 | 542 |
543 return SetLastStatus(BAILED_OUT); | 543 return SetLastStatus(BAILED_OUT); |
544 } | 544 } |
545 | 545 |
546 | 546 |
| 547 namespace { |
| 548 |
| 549 void AddWeakObjectToCodeDependency(Isolate* isolate, Handle<HeapObject> object, |
| 550 Handle<Code> code) { |
| 551 Handle<WeakCell> cell = Code::WeakCellFor(code); |
| 552 Heap* heap = isolate->heap(); |
| 553 Handle<DependentCode> dep(heap->LookupWeakObjectToCodeDependency(object)); |
| 554 dep = DependentCode::InsertWeakCode(dep, DependentCode::kWeakCodeGroup, cell); |
| 555 heap->AddWeakObjectToCodeDependency(object, dep); |
| 556 } |
| 557 |
| 558 |
| 559 void RegisterWeakObjectsInOptimizedCode(Handle<Code> code) { |
| 560 // TODO(turbofan): Move this to pipeline.cc once Crankshaft dies. |
| 561 Isolate* const isolate = code->GetIsolate(); |
| 562 DCHECK(code->is_optimized_code()); |
| 563 std::vector<Handle<Map>> maps; |
| 564 std::vector<Handle<HeapObject>> objects; |
| 565 { |
| 566 DisallowHeapAllocation no_gc; |
| 567 int const mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | |
| 568 RelocInfo::ModeMask(RelocInfo::CELL); |
| 569 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 570 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 571 if (mode == RelocInfo::CELL && |
| 572 code->IsWeakObjectInOptimizedCode(it.rinfo()->target_cell())) { |
| 573 objects.push_back(handle(it.rinfo()->target_cell(), isolate)); |
| 574 } else if (mode == RelocInfo::EMBEDDED_OBJECT && |
| 575 code->IsWeakObjectInOptimizedCode( |
| 576 it.rinfo()->target_object())) { |
| 577 Handle<HeapObject> object(HeapObject::cast(it.rinfo()->target_object()), |
| 578 isolate); |
| 579 if (object->IsMap()) { |
| 580 maps.push_back(Handle<Map>::cast(object)); |
| 581 } else { |
| 582 objects.push_back(object); |
| 583 } |
| 584 } |
| 585 } |
| 586 } |
| 587 for (Handle<Map> map : maps) { |
| 588 if (map->dependent_code()->IsEmpty(DependentCode::kWeakCodeGroup)) { |
| 589 isolate->heap()->AddRetainedMap(map); |
| 590 } |
| 591 Map::AddDependentCode(map, DependentCode::kWeakCodeGroup, code); |
| 592 } |
| 593 for (Handle<HeapObject> object : objects) { |
| 594 AddWeakObjectToCodeDependency(isolate, object, code); |
| 595 } |
| 596 code->set_can_have_weak_objects(true); |
| 597 } |
| 598 |
| 599 } // namespace |
| 600 |
| 601 |
547 OptimizedCompileJob::Status OptimizedCompileJob::GenerateCode() { | 602 OptimizedCompileJob::Status OptimizedCompileJob::GenerateCode() { |
548 DCHECK(last_status() == SUCCEEDED); | 603 DCHECK(last_status() == SUCCEEDED); |
549 // TODO(turbofan): Currently everything is done in the first phase. | 604 // TODO(turbofan): Currently everything is done in the first phase. |
550 if (!info()->code().is_null()) { | 605 if (!info()->code().is_null()) { |
551 info()->dependencies()->Commit(info()->code()); | 606 info()->dependencies()->Commit(info()->code()); |
552 if (info()->is_deoptimization_enabled()) { | 607 if (info()->is_deoptimization_enabled()) { |
553 info()->parse_info()->context()->native_context()->AddOptimizedCode( | 608 info()->parse_info()->context()->native_context()->AddOptimizedCode( |
554 *info()->code()); | 609 *info()->code()); |
| 610 RegisterWeakObjectsInOptimizedCode(info()->code()); |
555 } | 611 } |
556 RecordOptimizationStats(); | 612 RecordOptimizationStats(); |
557 return last_status(); | 613 return last_status(); |
558 } | 614 } |
559 | 615 |
560 DCHECK(!info()->dependencies()->HasAborted()); | 616 DCHECK(!info()->dependencies()->HasAborted()); |
561 DisallowCodeDependencyChange no_dependency_change; | 617 DisallowCodeDependencyChange no_dependency_change; |
562 DisallowJavascriptExecution no_js(isolate()); | 618 DisallowJavascriptExecution no_js(isolate()); |
563 { // Scope for timer. | 619 { // Scope for timer. |
564 Timer timer(this, &time_taken_to_codegen_); | 620 Timer timer(this, &time_taken_to_codegen_); |
565 DCHECK(chunk_ != NULL); | 621 DCHECK(chunk_ != NULL); |
566 DCHECK(graph_ != NULL); | 622 DCHECK(graph_ != NULL); |
567 // Deferred handles reference objects that were accessible during | 623 // Deferred handles reference objects that were accessible during |
568 // graph creation. To make sure that we don't encounter inconsistencies | 624 // graph creation. To make sure that we don't encounter inconsistencies |
569 // between graph creation and code generation, we disallow accessing | 625 // between graph creation and code generation, we disallow accessing |
570 // objects through deferred handles during the latter, with exceptions. | 626 // objects through deferred handles during the latter, with exceptions. |
571 DisallowDeferredHandleDereference no_deferred_handle_deref; | 627 DisallowDeferredHandleDereference no_deferred_handle_deref; |
572 Handle<Code> optimized_code = chunk_->Codegen(); | 628 Handle<Code> optimized_code = chunk_->Codegen(); |
573 if (optimized_code.is_null()) { | 629 if (optimized_code.is_null()) { |
574 if (info()->bailout_reason() == kNoReason) { | 630 if (info()->bailout_reason() == kNoReason) { |
575 return AbortOptimization(kCodeGenerationFailed); | 631 return AbortOptimization(kCodeGenerationFailed); |
576 } | 632 } |
577 return SetLastStatus(BAILED_OUT); | 633 return SetLastStatus(BAILED_OUT); |
578 } | 634 } |
| 635 RegisterWeakObjectsInOptimizedCode(optimized_code); |
579 info()->SetCode(optimized_code); | 636 info()->SetCode(optimized_code); |
580 } | 637 } |
581 RecordOptimizationStats(); | 638 RecordOptimizationStats(); |
582 // Add to the weak list of optimized code objects. | 639 // Add to the weak list of optimized code objects. |
583 info()->context()->native_context()->AddOptimizedCode(*info()->code()); | 640 info()->context()->native_context()->AddOptimizedCode(*info()->code()); |
584 return SetLastStatus(SUCCEEDED); | 641 return SetLastStatus(SUCCEEDED); |
585 } | 642 } |
586 | 643 |
587 | 644 |
588 void OptimizedCompileJob::RecordOptimizationStats() { | 645 void OptimizedCompileJob::RecordOptimizationStats() { |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 } | 1838 } |
1782 | 1839 |
1783 #if DEBUG | 1840 #if DEBUG |
1784 void CompilationInfo::PrintAstForTesting() { | 1841 void CompilationInfo::PrintAstForTesting() { |
1785 PrintF("--- Source from AST ---\n%s\n", | 1842 PrintF("--- Source from AST ---\n%s\n", |
1786 PrettyPrinter(isolate()).PrintProgram(literal())); | 1843 PrettyPrinter(isolate()).PrintProgram(literal())); |
1787 } | 1844 } |
1788 #endif | 1845 #endif |
1789 } // namespace internal | 1846 } // namespace internal |
1790 } // namespace v8 | 1847 } // namespace v8 |
OLD | NEW |