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

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

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