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