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

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

Issue 2091733002: Reland [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: Address comments. 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 2610 matching lines...) Expand 10 before | Expand all | Expand 10 after
5556 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { 5524 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) {
5557 if (gc_epilogue_callbacks_[i].callback == callback) { 5525 if (gc_epilogue_callbacks_[i].callback == callback) {
5558 gc_epilogue_callbacks_.Remove(i); 5526 gc_epilogue_callbacks_.Remove(i);
5559 return; 5527 return;
5560 } 5528 }
5561 } 5529 }
5562 UNREACHABLE(); 5530 UNREACHABLE();
5563 } 5531 }
5564 5532
5565 // TODO(ishell): Find a better place for this. 5533 // TODO(ishell): Find a better place for this.
5534 void Heap::AddWeakNewSpaceObjectToCodeDependency(Handle<HeapObject> obj,
5535 Handle<WeakCell> code) {
5536 DCHECK(InNewSpace(*obj));
5537 DCHECK(!InNewSpace(*code));
5538 Handle<ArrayList> list(weak_new_space_object_to_code_list(), isolate());
5539 list = ArrayList::Add(list, isolate()->factory()->NewWeakCell(obj), code);
5540 if (*list != weak_new_space_object_to_code_list()) {
5541 set_weak_new_space_object_to_code_list(*list);
5542 }
5543 }
5544
5545 // TODO(ishell): Find a better place for this.
5566 void Heap::AddWeakObjectToCodeDependency(Handle<HeapObject> obj, 5546 void Heap::AddWeakObjectToCodeDependency(Handle<HeapObject> obj,
5567 Handle<DependentCode> dep) { 5547 Handle<DependentCode> dep) {
5568 DCHECK(!InNewSpace(*obj)); 5548 DCHECK(!InNewSpace(*obj));
5569 DCHECK(!InNewSpace(*dep)); 5549 DCHECK(!InNewSpace(*dep));
5570 Handle<WeakHashTable> table(weak_object_to_code_table(), isolate()); 5550 Handle<WeakHashTable> table(weak_object_to_code_table(), isolate());
5571 table = WeakHashTable::Put(table, obj, dep); 5551 table = WeakHashTable::Put(table, obj, dep);
5572 if (*table != weak_object_to_code_table()) 5552 if (*table != weak_object_to_code_table())
5573 set_weak_object_to_code_table(*table); 5553 set_weak_object_to_code_table(*table);
5574 DCHECK_EQ(*dep, LookupWeakObjectToCodeDependency(obj)); 5554 DCHECK_EQ(*dep, LookupWeakObjectToCodeDependency(obj));
5575 } 5555 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
5710 void Heap::ClearRecordedSlotRange(Address start, Address end) { 5690 void Heap::ClearRecordedSlotRange(Address start, Address end) {
5711 Page* page = Page::FromAddress(start); 5691 Page* page = Page::FromAddress(start);
5712 if (!page->InNewSpace()) { 5692 if (!page->InNewSpace()) {
5713 store_buffer()->MoveEntriesToRememberedSet(); 5693 store_buffer()->MoveEntriesToRememberedSet();
5714 DCHECK_EQ(page->owner()->identity(), OLD_SPACE); 5694 DCHECK_EQ(page->owner()->identity(), OLD_SPACE);
5715 RememberedSet<OLD_TO_NEW>::RemoveRange(page, start, end); 5695 RememberedSet<OLD_TO_NEW>::RemoveRange(page, start, end);
5716 RememberedSet<OLD_TO_OLD>::RemoveRange(page, start, end); 5696 RememberedSet<OLD_TO_OLD>::RemoveRange(page, start, end);
5717 } 5697 }
5718 } 5698 }
5719 5699
5700 void Heap::RecordWriteIntoCodeSlow(Code* host, RelocInfo* rinfo,
5701 Object* value) {
5702 DCHECK(InNewSpace(value));
5703 Page* source_page = Page::FromAddress(reinterpret_cast<Address>(host));
5704 RelocInfo::Mode rmode = rinfo->rmode();
5705 Address addr = rinfo->pc();
5706 SlotType slot_type = SlotTypeForRelocInfoMode(rmode);
5707 if (rinfo->IsInConstantPool()) {
5708 addr = rinfo->constant_pool_entry_address();
5709 if (RelocInfo::IsCodeTarget(rmode)) {
5710 slot_type = CODE_ENTRY_SLOT;
5711 } else {
5712 DCHECK(RelocInfo::IsEmbeddedObject(rmode));
5713 slot_type = OBJECT_SLOT;
5714 }
5715 }
5716 RememberedSet<OLD_TO_NEW>::InsertTyped(
5717 source_page, reinterpret_cast<Address>(host), slot_type, addr);
5718 }
5719
5720 Space* AllSpaces::next() { 5720 Space* AllSpaces::next() {
5721 switch (counter_++) { 5721 switch (counter_++) {
5722 case NEW_SPACE: 5722 case NEW_SPACE:
5723 return heap_->new_space(); 5723 return heap_->new_space();
5724 case OLD_SPACE: 5724 case OLD_SPACE:
5725 return heap_->old_space(); 5725 return heap_->old_space();
5726 case CODE_SPACE: 5726 case CODE_SPACE:
5727 return heap_->code_space(); 5727 return heap_->code_space();
5728 case MAP_SPACE: 5728 case MAP_SPACE:
5729 return heap_->map_space(); 5729 return heap_->map_space();
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
6379 } 6379 }
6380 6380
6381 6381
6382 // static 6382 // static
6383 int Heap::GetStaticVisitorIdForMap(Map* map) { 6383 int Heap::GetStaticVisitorIdForMap(Map* map) {
6384 return StaticVisitorBase::GetVisitorId(map); 6384 return StaticVisitorBase::GetVisitorId(map);
6385 } 6385 }
6386 6386
6387 } // namespace internal 6387 } // namespace internal
6388 } // namespace v8 6388 } // 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