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/heap/heap.h" | 5 #include "src/heap/heap.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/ast/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 1452 matching lines...) Loading... |
1463 | 1463 |
1464 isolate_->compilation_cache()->MarkCompactPrologue(); | 1464 isolate_->compilation_cache()->MarkCompactPrologue(); |
1465 | 1465 |
1466 CompletelyClearInstanceofCache(); | 1466 CompletelyClearInstanceofCache(); |
1467 | 1467 |
1468 FlushNumberStringCache(); | 1468 FlushNumberStringCache(); |
1469 ClearNormalizedMapCaches(); | 1469 ClearNormalizedMapCaches(); |
1470 } | 1470 } |
1471 | 1471 |
1472 | 1472 |
1473 #ifdef VERIFY_HEAP | |
1474 // Visitor class to verify pointers in code or data space do not point into | |
1475 // new space. | |
1476 class VerifyNonPointerSpacePointersVisitor : public ObjectVisitor { | |
1477 public: | |
1478 explicit VerifyNonPointerSpacePointersVisitor(Heap* heap) : heap_(heap) {} | |
1479 | |
1480 void VisitPointers(Object** start, Object** end) override { | |
1481 for (Object** current = start; current < end; current++) { | |
1482 if ((*current)->IsHeapObject()) { | |
1483 CHECK(!heap_->InNewSpace(HeapObject::cast(*current))); | |
1484 } | |
1485 } | |
1486 } | |
1487 | |
1488 private: | |
1489 Heap* heap_; | |
1490 }; | |
1491 | |
1492 | |
1493 static void VerifyNonPointerSpacePointers(Heap* heap) { | |
1494 // Verify that there are no pointers to new space in spaces where we | |
1495 // do not expect them. | |
1496 VerifyNonPointerSpacePointersVisitor v(heap); | |
1497 HeapObjectIterator code_it(heap->code_space()); | |
1498 for (HeapObject* object = code_it.Next(); object != NULL; | |
1499 object = code_it.Next()) | |
1500 object->Iterate(&v); | |
1501 } | |
1502 #endif // VERIFY_HEAP | |
1503 | |
1504 | |
1505 void Heap::CheckNewSpaceExpansionCriteria() { | 1473 void Heap::CheckNewSpaceExpansionCriteria() { |
1506 if (FLAG_experimental_new_space_growth_heuristic) { | 1474 if (FLAG_experimental_new_space_growth_heuristic) { |
1507 if (new_space_.TotalCapacity() < new_space_.MaximumCapacity() && | 1475 if (new_space_.TotalCapacity() < new_space_.MaximumCapacity() && |
1508 survived_last_scavenge_ * 100 / new_space_.TotalCapacity() >= 10) { | 1476 survived_last_scavenge_ * 100 / new_space_.TotalCapacity() >= 10) { |
1509 // Grow the size of new space if there is room to grow, and more than 10% | 1477 // Grow the size of new space if there is room to grow, and more than 10% |
1510 // have survived the last scavenge. | 1478 // have survived the last scavenge. |
1511 new_space_.Grow(); | 1479 new_space_.Grow(); |
1512 survived_since_last_expansion_ = 0; | 1480 survived_since_last_expansion_ = 0; |
1513 } | 1481 } |
1514 } else if (new_space_.TotalCapacity() < new_space_.MaximumCapacity() && | 1482 } else if (new_space_.TotalCapacity() < new_space_.MaximumCapacity() && |
(...skipping 90 matching lines...) Loading... |
1605 RelocationLock relocation_lock(this); | 1573 RelocationLock relocation_lock(this); |
1606 // There are soft limits in the allocation code, designed to trigger a mark | 1574 // There are soft limits in the allocation code, designed to trigger a mark |
1607 // sweep collection by failing allocations. There is no sense in trying to | 1575 // sweep collection by failing allocations. There is no sense in trying to |
1608 // trigger one during scavenge: scavenges allocation should always succeed. | 1576 // trigger one during scavenge: scavenges allocation should always succeed. |
1609 AlwaysAllocateScope scope(isolate()); | 1577 AlwaysAllocateScope scope(isolate()); |
1610 | 1578 |
1611 // Bump-pointer allocations done during scavenge are not real allocations. | 1579 // Bump-pointer allocations done during scavenge are not real allocations. |
1612 // Pause the inline allocation steps. | 1580 // Pause the inline allocation steps. |
1613 PauseAllocationObserversScope pause_observers(this); | 1581 PauseAllocationObserversScope pause_observers(this); |
1614 | 1582 |
1615 #ifdef VERIFY_HEAP | |
1616 if (FLAG_verify_heap) VerifyNonPointerSpacePointers(this); | |
1617 #endif | |
1618 | |
1619 gc_state_ = SCAVENGE; | 1583 gc_state_ = SCAVENGE; |
1620 | 1584 |
1621 // Implements Cheney's copying algorithm | 1585 // Implements Cheney's copying algorithm |
1622 LOG(isolate_, ResourceEvent("scavenge", "begin")); | 1586 LOG(isolate_, ResourceEvent("scavenge", "begin")); |
1623 | 1587 |
1624 // Used for updating survived_since_last_expansion_ at function end. | 1588 // Used for updating survived_since_last_expansion_ at function end. |
1625 intptr_t survived_watermark = PromotedSpaceSizeOfObjects(); | 1589 intptr_t survived_watermark = PromotedSpaceSizeOfObjects(); |
1626 | 1590 |
1627 scavenge_collector_->SelectScavengingVisitorsTable(); | 1591 scavenge_collector_->SelectScavengingVisitorsTable(); |
1628 | 1592 |
(...skipping 1222 matching lines...) Loading... |
2851 set_cleared_optimized_code_map(*cleared_optimized_code_map); | 2815 set_cleared_optimized_code_map(*cleared_optimized_code_map); |
2852 } | 2816 } |
2853 | 2817 |
2854 set_detached_contexts(empty_fixed_array()); | 2818 set_detached_contexts(empty_fixed_array()); |
2855 set_retained_maps(ArrayList::cast(empty_fixed_array())); | 2819 set_retained_maps(ArrayList::cast(empty_fixed_array())); |
2856 | 2820 |
2857 set_weak_object_to_code_table( | 2821 set_weak_object_to_code_table( |
2858 *WeakHashTable::New(isolate(), 16, USE_DEFAULT_MINIMUM_CAPACITY, | 2822 *WeakHashTable::New(isolate(), 16, USE_DEFAULT_MINIMUM_CAPACITY, |
2859 TENURED)); | 2823 TENURED)); |
2860 | 2824 |
| 2825 set_weak_new_space_object_to_code_list( |
| 2826 ArrayList::cast(*(factory->NewFixedArray(16, TENURED)))); |
| 2827 weak_new_space_object_to_code_list()->SetLength(0); |
| 2828 |
2861 set_script_list(Smi::FromInt(0)); | 2829 set_script_list(Smi::FromInt(0)); |
2862 | 2830 |
2863 Handle<SeededNumberDictionary> slow_element_dictionary = | 2831 Handle<SeededNumberDictionary> slow_element_dictionary = |
2864 SeededNumberDictionary::New(isolate(), 0, TENURED); | 2832 SeededNumberDictionary::New(isolate(), 0, TENURED); |
2865 slow_element_dictionary->set_requires_slow_elements(); | 2833 slow_element_dictionary->set_requires_slow_elements(); |
2866 set_empty_slow_element_dictionary(*slow_element_dictionary); | 2834 set_empty_slow_element_dictionary(*slow_element_dictionary); |
2867 | 2835 |
2868 set_materialized_objects(*factory->NewFixedArray(0, TENURED)); | 2836 set_materialized_objects(*factory->NewFixedArray(0, TENURED)); |
2869 | 2837 |
2870 // Handling of script id generation is in Heap::NextScriptId(). | 2838 // Handling of script id generation is in Heap::NextScriptId(). |
(...skipping 36 matching lines...) Loading... |
2907 | 2875 |
2908 // Initialize descriptor cache. | 2876 // Initialize descriptor cache. |
2909 isolate_->descriptor_lookup_cache()->Clear(); | 2877 isolate_->descriptor_lookup_cache()->Clear(); |
2910 | 2878 |
2911 // Initialize compilation cache. | 2879 // Initialize compilation cache. |
2912 isolate_->compilation_cache()->Clear(); | 2880 isolate_->compilation_cache()->Clear(); |
2913 | 2881 |
2914 CreateFixedStubs(); | 2882 CreateFixedStubs(); |
2915 } | 2883 } |
2916 | 2884 |
2917 | |
2918 bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) { | 2885 bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) { |
2919 switch (root_index) { | 2886 switch (root_index) { |
2920 case kNumberStringCacheRootIndex: | 2887 case kNumberStringCacheRootIndex: |
2921 case kInstanceofCacheFunctionRootIndex: | 2888 case kInstanceofCacheFunctionRootIndex: |
2922 case kInstanceofCacheMapRootIndex: | 2889 case kInstanceofCacheMapRootIndex: |
2923 case kInstanceofCacheAnswerRootIndex: | 2890 case kInstanceofCacheAnswerRootIndex: |
2924 case kCodeStubsRootIndex: | 2891 case kCodeStubsRootIndex: |
2925 case kEmptyScriptRootIndex: | 2892 case kEmptyScriptRootIndex: |
2926 case kSymbolRegistryRootIndex: | 2893 case kSymbolRegistryRootIndex: |
2927 case kScriptListRootIndex: | 2894 case kScriptListRootIndex: |
2928 case kMaterializedObjectsRootIndex: | 2895 case kMaterializedObjectsRootIndex: |
2929 case kMicrotaskQueueRootIndex: | 2896 case kMicrotaskQueueRootIndex: |
2930 case kDetachedContextsRootIndex: | 2897 case kDetachedContextsRootIndex: |
2931 case kWeakObjectToCodeTableRootIndex: | 2898 case kWeakObjectToCodeTableRootIndex: |
| 2899 case kWeakNewSpaceObjectToCodeListRootIndex: |
2932 case kRetainedMapsRootIndex: | 2900 case kRetainedMapsRootIndex: |
2933 case kNoScriptSharedFunctionInfosRootIndex: | 2901 case kNoScriptSharedFunctionInfosRootIndex: |
2934 case kWeakStackTraceListRootIndex: | 2902 case kWeakStackTraceListRootIndex: |
2935 // Smi values | 2903 // Smi values |
2936 #define SMI_ENTRY(type, name, Name) case k##Name##RootIndex: | 2904 #define SMI_ENTRY(type, name, Name) case k##Name##RootIndex: |
2937 SMI_ROOT_LIST(SMI_ENTRY) | 2905 SMI_ROOT_LIST(SMI_ENTRY) |
2938 #undef SMI_ENTRY | 2906 #undef SMI_ENTRY |
2939 // String table | 2907 // String table |
2940 case kStringTableRootIndex: | 2908 case kStringTableRootIndex: |
2941 return true; | 2909 return true; |
(...skipping 2642 matching lines...) Loading... |
5584 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { | 5552 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { |
5585 if (gc_epilogue_callbacks_[i].callback == callback) { | 5553 if (gc_epilogue_callbacks_[i].callback == callback) { |
5586 gc_epilogue_callbacks_.Remove(i); | 5554 gc_epilogue_callbacks_.Remove(i); |
5587 return; | 5555 return; |
5588 } | 5556 } |
5589 } | 5557 } |
5590 UNREACHABLE(); | 5558 UNREACHABLE(); |
5591 } | 5559 } |
5592 | 5560 |
5593 // TODO(ishell): Find a better place for this. | 5561 // TODO(ishell): Find a better place for this. |
| 5562 void Heap::AddWeakNewSpaceObjectToCodeDependency(Handle<HeapObject> obj, |
| 5563 Handle<WeakCell> code) { |
| 5564 DCHECK(InNewSpace(*obj)); |
| 5565 DCHECK(!InNewSpace(*code)); |
| 5566 Handle<ArrayList> list(weak_new_space_object_to_code_list(), isolate()); |
| 5567 list = ArrayList::Add(list, isolate()->factory()->NewWeakCell(obj), code); |
| 5568 if (*list != weak_new_space_object_to_code_list()) { |
| 5569 set_weak_new_space_object_to_code_list(*list); |
| 5570 } |
| 5571 } |
| 5572 |
| 5573 // TODO(ishell): Find a better place for this. |
5594 void Heap::AddWeakObjectToCodeDependency(Handle<HeapObject> obj, | 5574 void Heap::AddWeakObjectToCodeDependency(Handle<HeapObject> obj, |
5595 Handle<DependentCode> dep) { | 5575 Handle<DependentCode> dep) { |
5596 DCHECK(!InNewSpace(*obj)); | 5576 DCHECK(!InNewSpace(*obj)); |
5597 DCHECK(!InNewSpace(*dep)); | 5577 DCHECK(!InNewSpace(*dep)); |
5598 Handle<WeakHashTable> table(weak_object_to_code_table(), isolate()); | 5578 Handle<WeakHashTable> table(weak_object_to_code_table(), isolate()); |
5599 table = WeakHashTable::Put(table, obj, dep); | 5579 table = WeakHashTable::Put(table, obj, dep); |
5600 if (*table != weak_object_to_code_table()) | 5580 if (*table != weak_object_to_code_table()) |
5601 set_weak_object_to_code_table(*table); | 5581 set_weak_object_to_code_table(*table); |
5602 DCHECK_EQ(*dep, LookupWeakObjectToCodeDependency(obj)); | 5582 DCHECK_EQ(*dep, LookupWeakObjectToCodeDependency(obj)); |
5603 } | 5583 } |
(...skipping 152 matching lines...) Loading... |
5756 void Heap::ClearRecordedSlotRange(Address start, Address end) { | 5736 void Heap::ClearRecordedSlotRange(Address start, Address end) { |
5757 Page* page = Page::FromAddress(start); | 5737 Page* page = Page::FromAddress(start); |
5758 if (!page->InNewSpace()) { | 5738 if (!page->InNewSpace()) { |
5759 store_buffer()->MoveEntriesToRememberedSet(); | 5739 store_buffer()->MoveEntriesToRememberedSet(); |
5760 DCHECK_EQ(page->owner()->identity(), OLD_SPACE); | 5740 DCHECK_EQ(page->owner()->identity(), OLD_SPACE); |
5761 RememberedSet<OLD_TO_NEW>::RemoveRange(page, start, end); | 5741 RememberedSet<OLD_TO_NEW>::RemoveRange(page, start, end); |
5762 RememberedSet<OLD_TO_OLD>::RemoveRange(page, start, end); | 5742 RememberedSet<OLD_TO_OLD>::RemoveRange(page, start, end); |
5763 } | 5743 } |
5764 } | 5744 } |
5765 | 5745 |
| 5746 void Heap::RecordWriteIntoCodeSlow(Code* host, RelocInfo* rinfo, |
| 5747 Object* value) { |
| 5748 DCHECK(InNewSpace(value)); |
| 5749 Page* source_page = Page::FromAddress(reinterpret_cast<Address>(host)); |
| 5750 RelocInfo::Mode rmode = rinfo->rmode(); |
| 5751 Address addr = rinfo->pc(); |
| 5752 SlotType slot_type = SlotTypeForRelocInfoMode(rmode); |
| 5753 if (rinfo->IsInConstantPool()) { |
| 5754 addr = rinfo->constant_pool_entry_address(); |
| 5755 if (RelocInfo::IsCodeTarget(rmode)) { |
| 5756 slot_type = CODE_ENTRY_SLOT; |
| 5757 } else { |
| 5758 DCHECK(RelocInfo::IsEmbeddedObject(rmode)); |
| 5759 slot_type = OBJECT_SLOT; |
| 5760 } |
| 5761 } |
| 5762 RememberedSet<OLD_TO_NEW>::InsertTyped( |
| 5763 source_page, reinterpret_cast<Address>(host), slot_type, addr); |
| 5764 } |
| 5765 |
5766 Space* AllSpaces::next() { | 5766 Space* AllSpaces::next() { |
5767 switch (counter_++) { | 5767 switch (counter_++) { |
5768 case NEW_SPACE: | 5768 case NEW_SPACE: |
5769 return heap_->new_space(); | 5769 return heap_->new_space(); |
5770 case OLD_SPACE: | 5770 case OLD_SPACE: |
5771 return heap_->old_space(); | 5771 return heap_->old_space(); |
5772 case CODE_SPACE: | 5772 case CODE_SPACE: |
5773 return heap_->code_space(); | 5773 return heap_->code_space(); |
5774 case MAP_SPACE: | 5774 case MAP_SPACE: |
5775 return heap_->map_space(); | 5775 return heap_->map_space(); |
(...skipping 649 matching lines...) Loading... |
6425 } | 6425 } |
6426 | 6426 |
6427 | 6427 |
6428 // static | 6428 // static |
6429 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6429 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6430 return StaticVisitorBase::GetVisitorId(map); | 6430 return StaticVisitorBase::GetVisitorId(map); |
6431 } | 6431 } |
6432 | 6432 |
6433 } // namespace internal | 6433 } // namespace internal |
6434 } // namespace v8 | 6434 } // namespace v8 |
OLD | NEW |