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

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

Issue 2876503002: [heap] Reland "Verify remembered set for objects in the old generation." (Closed)
Patch Set: fix Created 3 years, 7 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/spaces.cc » ('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/assembler-inl.h" 9 #include "src/assembler-inl.h"
10 #include "src/ast/context-slot-cache.h" 10 #include "src/ast/context-slot-cache.h"
(...skipping 4761 matching lines...) Expand 10 before | Expand all | Expand 10 after
4772 VerifyPointersVisitor no_dirty_regions_visitor; 4772 VerifyPointersVisitor no_dirty_regions_visitor;
4773 code_space_->Verify(&no_dirty_regions_visitor); 4773 code_space_->Verify(&no_dirty_regions_visitor);
4774 4774
4775 lo_space_->Verify(); 4775 lo_space_->Verify();
4776 4776
4777 mark_compact_collector()->VerifyWeakEmbeddedObjectsInCode(); 4777 mark_compact_collector()->VerifyWeakEmbeddedObjectsInCode();
4778 if (FLAG_omit_map_checks_for_leaf_maps) { 4778 if (FLAG_omit_map_checks_for_leaf_maps) {
4779 mark_compact_collector()->VerifyOmittedMapChecks(); 4779 mark_compact_collector()->VerifyOmittedMapChecks();
4780 } 4780 }
4781 } 4781 }
4782
4783 class SlotVerifyingVisitor : public ObjectVisitor {
4784 public:
4785 SlotVerifyingVisitor(std::set<Address>* untyped,
4786 std::set<std::pair<SlotType, Address> >* typed)
4787 : untyped_(untyped), typed_(typed) {}
4788
4789 virtual bool ShouldHaveBeenRecorded(HeapObject* host, Object* target) = 0;
4790
4791 void VisitPointers(HeapObject* host, Object** start, Object** end) override {
4792 for (Object** slot = start; slot < end; slot++) {
4793 if (ShouldHaveBeenRecorded(host, *slot)) {
4794 CHECK_GT(untyped_->count(reinterpret_cast<Address>(slot)), 0);
4795 }
4796 }
4797 }
4798
4799 void VisitCodeTarget(Code* host, RelocInfo* rinfo) override {
4800 Object* target = Code::GetCodeFromTargetAddress(rinfo->target_address());
4801 if (ShouldHaveBeenRecorded(host, target)) {
4802 CHECK(
4803 InTypedSet(CODE_TARGET_SLOT, rinfo->pc()) ||
4804 (rinfo->IsInConstantPool() &&
4805 InTypedSet(CODE_ENTRY_SLOT, rinfo->constant_pool_entry_address())));
4806 }
4807 }
4808
4809 void VisitCodeAgeSequence(Code* host, RelocInfo* rinfo) override {
4810 Object* target = rinfo->code_age_stub();
4811 if (ShouldHaveBeenRecorded(host, target)) {
4812 CHECK(
4813 InTypedSet(CODE_TARGET_SLOT, rinfo->pc()) ||
4814 (rinfo->IsInConstantPool() &&
4815 InTypedSet(CODE_ENTRY_SLOT, rinfo->constant_pool_entry_address())));
4816 }
4817 }
4818
4819 void VisitCodeEntry(JSFunction* host, Address entry_address) override {
4820 Object* target = Code::GetObjectFromEntryAddress(entry_address);
4821 if (ShouldHaveBeenRecorded(host, target)) {
4822 CHECK(InTypedSet(CODE_ENTRY_SLOT, entry_address));
4823 }
4824 }
4825
4826 void VisitCellPointer(Code* host, RelocInfo* rinfo) override {
4827 Object* target = rinfo->target_cell();
4828 if (ShouldHaveBeenRecorded(host, target)) {
4829 CHECK(InTypedSet(CELL_TARGET_SLOT, rinfo->pc()) ||
4830 (rinfo->IsInConstantPool() &&
4831 InTypedSet(OBJECT_SLOT, rinfo->constant_pool_entry_address())));
4832 }
4833 }
4834
4835 void VisitDebugTarget(Code* host, RelocInfo* rinfo) override {
4836 Object* target =
4837 Code::GetCodeFromTargetAddress(rinfo->debug_call_address());
4838 if (ShouldHaveBeenRecorded(host, target)) {
4839 CHECK(
4840 InTypedSet(DEBUG_TARGET_SLOT, rinfo->pc()) ||
4841 (rinfo->IsInConstantPool() &&
4842 InTypedSet(CODE_ENTRY_SLOT, rinfo->constant_pool_entry_address())));
4843 }
4844 }
4845
4846 void VisitEmbeddedPointer(Code* host, RelocInfo* rinfo) override {
4847 Object* target = rinfo->target_object();
4848 if (ShouldHaveBeenRecorded(host, target)) {
4849 CHECK(InTypedSet(EMBEDDED_OBJECT_SLOT, rinfo->pc()) ||
4850 (rinfo->IsInConstantPool() &&
4851 InTypedSet(OBJECT_SLOT, rinfo->constant_pool_entry_address())));
4852 }
4853 }
4854
4855 private:
4856 bool InTypedSet(SlotType type, Address slot) {
4857 return typed_->count(std::make_pair(type, slot)) > 0;
4858 }
4859 std::set<Address>* untyped_;
4860 std::set<std::pair<SlotType, Address> >* typed_;
4861 };
4862
4863 class OldToNewSlotVerifyingVisitor : public SlotVerifyingVisitor {
4864 public:
4865 OldToNewSlotVerifyingVisitor(Heap* heap, std::set<Address>* untyped,
4866 std::set<std::pair<SlotType, Address> >* typed)
4867 : SlotVerifyingVisitor(untyped, typed), heap_(heap) {}
4868
4869 bool ShouldHaveBeenRecorded(HeapObject* host, Object* target) override {
4870 return target->IsHeapObject() && heap_->InNewSpace(target) &&
4871 !heap_->InNewSpace(host);
4872 }
4873
4874 private:
4875 Heap* heap_;
4876 };
4877
4878 template <RememberedSetType direction>
4879 void CollectSlots(MemoryChunk* chunk, Address start, Address end,
4880 std::set<Address>* untyped,
4881 std::set<std::pair<SlotType, Address> >* typed) {
4882 RememberedSet<direction>::Iterate(chunk, [start, end, untyped](Address slot) {
4883 if (start <= slot && slot < end) {
4884 untyped->insert(slot);
4885 }
4886 return KEEP_SLOT;
4887 });
4888 RememberedSet<direction>::IterateTyped(
4889 chunk, [start, end, typed](SlotType type, Address host, Address slot) {
4890 if (start <= slot && slot < end) {
4891 typed->insert(std::make_pair(type, slot));
4892 }
4893 return KEEP_SLOT;
4894 });
4895 }
4896
4897 void Heap::VerifyRememberedSetFor(HeapObject* object) {
4898 MemoryChunk* chunk = MemoryChunk::FromAddress(object->address());
4899 base::LockGuard<base::RecursiveMutex> lock_guard(chunk->mutex());
4900 Address start = object->address();
4901 Address end = start + object->Size();
4902 std::set<Address> old_to_new;
4903 std::set<std::pair<SlotType, Address> > typed_old_to_new;
4904 if (!InNewSpace(object)) {
4905 store_buffer()->MoveAllEntriesToRememberedSet();
4906 CollectSlots<OLD_TO_NEW>(chunk, start, end, &old_to_new, &typed_old_to_new);
4907 OldToNewSlotVerifyingVisitor visitor(this, &old_to_new, &typed_old_to_new);
4908 object->IterateBody(&visitor);
4909 }
4910 // TODO(ulan): Add old to old slot set verification once all weak objects
4911 // have their own instance types and slots are recorded for all weal fields.
4912 }
4782 #endif 4913 #endif
4783 4914
4784 4915
4785 void Heap::ZapFromSpace() { 4916 void Heap::ZapFromSpace() {
4786 if (!new_space_->IsFromSpaceCommitted()) return; 4917 if (!new_space_->IsFromSpaceCommitted()) return;
4787 for (Page* page : 4918 for (Page* page :
4788 PageRange(new_space_->FromSpaceStart(), new_space_->FromSpaceEnd())) { 4919 PageRange(new_space_->FromSpaceStart(), new_space_->FromSpaceEnd())) {
4789 for (Address cursor = page->area_start(), limit = page->area_end(); 4920 for (Address cursor = page->area_start(), limit = page->area_end();
4790 cursor < limit; cursor += kPointerSize) { 4921 cursor < limit; cursor += kPointerSize) {
4791 Memory::Address_at(cursor) = kFromSpaceZapValue; 4922 Memory::Address_at(cursor) = kFromSpaceZapValue;
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after
6390 case LO_SPACE: 6521 case LO_SPACE:
6391 return "LO_SPACE"; 6522 return "LO_SPACE";
6392 default: 6523 default:
6393 UNREACHABLE(); 6524 UNREACHABLE();
6394 } 6525 }
6395 return NULL; 6526 return NULL;
6396 } 6527 }
6397 6528
6398 } // namespace internal 6529 } // namespace internal
6399 } // namespace v8 6530 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698