Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: src/heap/heap.cc

Issue 2045263002: [heap] Avoid the use of cells to point from code to new-space objects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: The IsSmi check in mov(HeapObject) lets some tests fail. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/heap-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 1462
1463 isolate_->compilation_cache()->MarkCompactPrologue(); 1463 isolate_->compilation_cache()->MarkCompactPrologue();
1464 1464
1465 CompletelyClearInstanceofCache(); 1465 CompletelyClearInstanceofCache();
1466 1466
1467 FlushNumberStringCache(); 1467 FlushNumberStringCache();
1468 ClearNormalizedMapCaches(); 1468 ClearNormalizedMapCaches();
1469 } 1469 }
1470 1470
1471 1471
1472 #ifdef VERIFY_HEAP
1473 // Visitor class to verify pointers in code or data space do not point into
1474 // new space.
1475 class VerifyNonPointerSpacePointersVisitor : public ObjectVisitor {
1476 public:
1477 explicit VerifyNonPointerSpacePointersVisitor(Heap* heap) : heap_(heap) {}
1478
1479 void VisitPointers(Object** start, Object** end) override {
1480 for (Object** current = start; current < end; current++) {
1481 if ((*current)->IsHeapObject()) {
1482 CHECK(!heap_->InNewSpace(HeapObject::cast(*current)));
1483 }
1484 }
1485 }
1486
1487 private:
1488 Heap* heap_;
1489 };
1490
1491
1492 static void VerifyNonPointerSpacePointers(Heap* heap) {
1493 // Verify that there are no pointers to new space in spaces where we
1494 // do not expect them.
1495 VerifyNonPointerSpacePointersVisitor v(heap);
1496 HeapObjectIterator code_it(heap->code_space());
1497 for (HeapObject* object = code_it.Next(); object != NULL;
1498 object = code_it.Next())
1499 object->Iterate(&v);
1500 }
1501 #endif // VERIFY_HEAP
1502
1503
1504 void Heap::CheckNewSpaceExpansionCriteria() { 1472 void Heap::CheckNewSpaceExpansionCriteria() {
1505 if (FLAG_experimental_new_space_growth_heuristic) { 1473 if (FLAG_experimental_new_space_growth_heuristic) {
1506 if (new_space_.TotalCapacity() < new_space_.MaximumCapacity() && 1474 if (new_space_.TotalCapacity() < new_space_.MaximumCapacity() &&
1507 survived_last_scavenge_ * 100 / new_space_.TotalCapacity() >= 10) { 1475 survived_last_scavenge_ * 100 / new_space_.TotalCapacity() >= 10) {
1508 // Grow the size of new space if there is room to grow, and more than 10% 1476 // Grow the size of new space if there is room to grow, and more than 10%
1509 // have survived the last scavenge. 1477 // have survived the last scavenge.
1510 new_space_.Grow(); 1478 new_space_.Grow();
1511 survived_since_last_expansion_ = 0; 1479 survived_since_last_expansion_ = 0;
1512 } 1480 }
1513 } else if (new_space_.TotalCapacity() < new_space_.MaximumCapacity() && 1481 } else if (new_space_.TotalCapacity() < new_space_.MaximumCapacity() &&
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 // sweep collection by failing allocations. There is no sense in trying to 1574 // sweep collection by failing allocations. There is no sense in trying to
1607 // trigger one during scavenge: scavenges allocation should always succeed. 1575 // trigger one during scavenge: scavenges allocation should always succeed.
1608 AlwaysAllocateScope scope(isolate()); 1576 AlwaysAllocateScope scope(isolate());
1609 1577
1610 // Bump-pointer allocations done during scavenge are not real allocations. 1578 // Bump-pointer allocations done during scavenge are not real allocations.
1611 // Pause the inline allocation steps. 1579 // Pause the inline allocation steps.
1612 PauseAllocationObserversScope pause_observers(this); 1580 PauseAllocationObserversScope pause_observers(this);
1613 1581
1614 mark_compact_collector()->sweeper().EnsureNewSpaceCompleted(); 1582 mark_compact_collector()->sweeper().EnsureNewSpaceCompleted();
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
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2911 2879
2912 // Initialize descriptor cache. 2880 // Initialize descriptor cache.
2913 isolate_->descriptor_lookup_cache()->Clear(); 2881 isolate_->descriptor_lookup_cache()->Clear();
2914 2882
2915 // Initialize compilation cache. 2883 // Initialize compilation cache.
2916 isolate_->compilation_cache()->Clear(); 2884 isolate_->compilation_cache()->Clear();
2917 2885
2918 CreateFixedStubs(); 2886 CreateFixedStubs();
2919 } 2887 }
2920 2888
2921
2922 bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) { 2889 bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) {
2923 switch (root_index) { 2890 switch (root_index) {
2924 case kNumberStringCacheRootIndex: 2891 case kNumberStringCacheRootIndex:
2925 case kInstanceofCacheFunctionRootIndex: 2892 case kInstanceofCacheFunctionRootIndex:
2926 case kInstanceofCacheMapRootIndex: 2893 case kInstanceofCacheMapRootIndex:
2927 case kInstanceofCacheAnswerRootIndex: 2894 case kInstanceofCacheAnswerRootIndex:
2928 case kCodeStubsRootIndex: 2895 case kCodeStubsRootIndex:
2929 case kEmptyScriptRootIndex: 2896 case kEmptyScriptRootIndex:
2930 case kSymbolRegistryRootIndex: 2897 case kSymbolRegistryRootIndex:
2931 case kScriptListRootIndex: 2898 case kScriptListRootIndex:
2932 case kMaterializedObjectsRootIndex: 2899 case kMaterializedObjectsRootIndex:
2933 case kMicrotaskQueueRootIndex: 2900 case kMicrotaskQueueRootIndex:
2934 case kDetachedContextsRootIndex: 2901 case kDetachedContextsRootIndex:
2935 case kWeakObjectToCodeTableRootIndex: 2902 case kWeakObjectToCodeTableRootIndex:
2903 case kWeakNewSpaceObjectToCodeListRootIndex:
2936 case kRetainedMapsRootIndex: 2904 case kRetainedMapsRootIndex:
2937 case kNoScriptSharedFunctionInfosRootIndex: 2905 case kNoScriptSharedFunctionInfosRootIndex:
2938 case kWeakStackTraceListRootIndex: 2906 case kWeakStackTraceListRootIndex:
2939 case kSerializedTemplatesRootIndex: 2907 case kSerializedTemplatesRootIndex:
2940 // Smi values 2908 // Smi values
2941 #define SMI_ENTRY(type, name, Name) case k##Name##RootIndex: 2909 #define SMI_ENTRY(type, name, Name) case k##Name##RootIndex:
2942 SMI_ROOT_LIST(SMI_ENTRY) 2910 SMI_ROOT_LIST(SMI_ENTRY)
2943 #undef SMI_ENTRY 2911 #undef SMI_ENTRY
2944 // String table 2912 // String table
2945 case kStringTableRootIndex: 2913 case kStringTableRootIndex:
(...skipping 2611 matching lines...) Expand 10 before | Expand all | Expand 10 after
5557 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { 5525 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) {
5558 if (gc_epilogue_callbacks_[i].callback == callback) { 5526 if (gc_epilogue_callbacks_[i].callback == callback) {
5559 gc_epilogue_callbacks_.Remove(i); 5527 gc_epilogue_callbacks_.Remove(i);
5560 return; 5528 return;
5561 } 5529 }
5562 } 5530 }
5563 UNREACHABLE(); 5531 UNREACHABLE();
5564 } 5532 }
5565 5533
5566 // TODO(ishell): Find a better place for this. 5534 // TODO(ishell): Find a better place for this.
5535 void Heap::AddWeakNewSpaceObjectToCodeDependency(Handle<HeapObject> obj,
5536 Handle<WeakCell> code) {
5537 DCHECK(InNewSpace(*obj));
5538 DCHECK(!InNewSpace(*code));
5539 Handle<ArrayList> list(weak_new_space_object_to_code_list(), isolate());
5540 list = ArrayList::Add(list, isolate()->factory()->NewWeakCell(obj), code);
5541 if (*list != weak_new_space_object_to_code_list()) {
5542 set_weak_new_space_object_to_code_list(*list);
5543 }
5544 }
5545
5546 // TODO(ishell): Find a better place for this.
5567 void Heap::AddWeakObjectToCodeDependency(Handle<HeapObject> obj, 5547 void Heap::AddWeakObjectToCodeDependency(Handle<HeapObject> obj,
5568 Handle<DependentCode> dep) { 5548 Handle<DependentCode> dep) {
5569 DCHECK(!InNewSpace(*obj)); 5549 DCHECK(!InNewSpace(*obj));
5570 DCHECK(!InNewSpace(*dep)); 5550 DCHECK(!InNewSpace(*dep));
5571 Handle<WeakHashTable> table(weak_object_to_code_table(), isolate()); 5551 Handle<WeakHashTable> table(weak_object_to_code_table(), isolate());
5572 table = WeakHashTable::Put(table, obj, dep); 5552 table = WeakHashTable::Put(table, obj, dep);
5573 if (*table != weak_object_to_code_table()) 5553 if (*table != weak_object_to_code_table())
5574 set_weak_object_to_code_table(*table); 5554 set_weak_object_to_code_table(*table);
5575 DCHECK_EQ(*dep, LookupWeakObjectToCodeDependency(obj)); 5555 DCHECK_EQ(*dep, LookupWeakObjectToCodeDependency(obj));
5576 } 5556 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
5703 void Heap::ClearRecordedSlotRange(Address start, Address end) { 5683 void Heap::ClearRecordedSlotRange(Address start, Address end) {
5704 Page* page = Page::FromAddress(start); 5684 Page* page = Page::FromAddress(start);
5705 if (!page->InNewSpace()) { 5685 if (!page->InNewSpace()) {
5706 store_buffer()->MoveEntriesToRememberedSet(); 5686 store_buffer()->MoveEntriesToRememberedSet();
5707 DCHECK_EQ(page->owner()->identity(), OLD_SPACE); 5687 DCHECK_EQ(page->owner()->identity(), OLD_SPACE);
5708 RememberedSet<OLD_TO_NEW>::RemoveRange(page, start, end); 5688 RememberedSet<OLD_TO_NEW>::RemoveRange(page, start, end);
5709 RememberedSet<OLD_TO_OLD>::RemoveRange(page, start, end); 5689 RememberedSet<OLD_TO_OLD>::RemoveRange(page, start, end);
5710 } 5690 }
5711 } 5691 }
5712 5692
5693 void Heap::RecordWriteIntoCodeSlow(Code* host, RelocInfo* rinfo,
5694 Object* value) {
5695 DCHECK(InNewSpace(value));
5696 Page* source_page = Page::FromAddress(reinterpret_cast<Address>(host));
5697 RelocInfo::Mode rmode = rinfo->rmode();
5698 Address addr = rinfo->pc();
5699 SlotType slot_type = SlotTypeForRelocInfoMode(rmode);
5700 if (rinfo->IsInConstantPool()) {
5701 addr = rinfo->constant_pool_entry_address();
5702 if (RelocInfo::IsCodeTarget(rmode)) {
5703 slot_type = CODE_ENTRY_SLOT;
5704 } else {
5705 DCHECK(RelocInfo::IsEmbeddedObject(rmode));
5706 slot_type = OBJECT_SLOT;
5707 }
5708 }
5709 RememberedSet<OLD_TO_NEW>::InsertTyped(
5710 source_page, reinterpret_cast<Address>(host), slot_type, addr);
5711 }
5712
5713 Space* AllSpaces::next() { 5713 Space* AllSpaces::next() {
5714 switch (counter_++) { 5714 switch (counter_++) {
5715 case NEW_SPACE: 5715 case NEW_SPACE:
5716 return heap_->new_space(); 5716 return heap_->new_space();
5717 case OLD_SPACE: 5717 case OLD_SPACE:
5718 return heap_->old_space(); 5718 return heap_->old_space();
5719 case CODE_SPACE: 5719 case CODE_SPACE:
5720 return heap_->code_space(); 5720 return heap_->code_space();
5721 case MAP_SPACE: 5721 case MAP_SPACE:
5722 return heap_->map_space(); 5722 return heap_->map_space();
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
6372 } 6372 }
6373 6373
6374 6374
6375 // static 6375 // static
6376 int Heap::GetStaticVisitorIdForMap(Map* map) { 6376 int Heap::GetStaticVisitorIdForMap(Map* map) {
6377 return StaticVisitorBase::GetVisitorId(map); 6377 return StaticVisitorBase::GetVisitorId(map);
6378 } 6378 }
6379 6379
6380 } // namespace internal 6380 } // namespace internal
6381 } // namespace v8 6381 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698