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

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

Issue 2102243002: [heap] Iterate handles with special left-trim visitor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comment 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 4737 matching lines...) Expand 10 before | Expand all | Expand 10 after
4748 } 4748 }
4749 4749
4750 4750
4751 void Heap::IterateSmiRoots(ObjectVisitor* v) { 4751 void Heap::IterateSmiRoots(ObjectVisitor* v) {
4752 // Acquire execution access since we are going to read stack limit values. 4752 // Acquire execution access since we are going to read stack limit values.
4753 ExecutionAccess access(isolate()); 4753 ExecutionAccess access(isolate());
4754 v->VisitPointers(&roots_[kSmiRootsStart], &roots_[kRootListLength]); 4754 v->VisitPointers(&roots_[kSmiRootsStart], &roots_[kRootListLength]);
4755 v->Synchronize(VisitorSynchronization::kSmiRootList); 4755 v->Synchronize(VisitorSynchronization::kSmiRootList);
4756 } 4756 }
4757 4757
4758 // We cannot avoid stale handles to left-trimmed objects, but can only make
4759 // sure all handles still needed are updated. Filter out a stale pointer
4760 // and clear the slot to allow post processing of handles (needed because
4761 // the sweeper might actually free the underlying page).
4762 class FixStaleLeftTrimmedHandlesVisitor : public ObjectVisitor {
4763 public:
4764 explicit FixStaleLeftTrimmedHandlesVisitor(Heap* heap) : heap_(heap) {
4765 USE(heap_);
4766 }
4767
4768 void VisitPointer(Object** p) override { FixHandle(p); }
4769
4770 void VisitPointers(Object** start, Object** end) override {
4771 for (Object** p = start; p < end; p++) FixHandle(p);
4772 }
4773
4774 private:
4775 inline void FixHandle(Object** p) {
4776 HeapObject* current = reinterpret_cast<HeapObject*>(*p);
4777 if (!current->IsHeapObject()) return;
4778 const MapWord map_word = current->map_word();
4779 if (!map_word.IsForwardingAddress() && current->IsFiller()) {
4780 #ifdef DEBUG
4781 // We need to find a FixedArrayBase map after walking the fillers.
4782 while (current->IsFiller()) {
4783 Address next = reinterpret_cast<Address>(current);
4784 if (current->map() == heap_->one_pointer_filler_map()) {
4785 next += kPointerSize;
4786 } else if (current->map() == heap_->two_pointer_filler_map()) {
4787 next += 2 * kPointerSize;
4788 } else {
4789 next += current->Size();
4790 }
4791 current = reinterpret_cast<HeapObject*>(next);
4792 }
4793 DCHECK(current->IsFixedArrayBase());
4794 #endif // DEBUG
4795 *p = nullptr;
4796 }
4797 }
4798
4799 Heap* heap_;
4800 };
4758 4801
4759 void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) { 4802 void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) {
4760 v->VisitPointers(&roots_[0], &roots_[kStrongRootListLength]); 4803 v->VisitPointers(&roots_[0], &roots_[kStrongRootListLength]);
4761 v->Synchronize(VisitorSynchronization::kStrongRootList); 4804 v->Synchronize(VisitorSynchronization::kStrongRootList);
4762 // The serializer/deserializer iterates the root list twice, first to pick 4805 // The serializer/deserializer iterates the root list twice, first to pick
4763 // off immortal immovable roots to make sure they end up on the first page, 4806 // off immortal immovable roots to make sure they end up on the first page,
4764 // and then again for the rest. 4807 // and then again for the rest.
4765 if (mode == VISIT_ONLY_STRONG_ROOT_LIST) return; 4808 if (mode == VISIT_ONLY_STRONG_ROOT_LIST) return;
4766 4809
4767 isolate_->bootstrapper()->Iterate(v); 4810 isolate_->bootstrapper()->Iterate(v);
4768 v->Synchronize(VisitorSynchronization::kBootstrapper); 4811 v->Synchronize(VisitorSynchronization::kBootstrapper);
4769 isolate_->Iterate(v); 4812 isolate_->Iterate(v);
4770 v->Synchronize(VisitorSynchronization::kTop); 4813 v->Synchronize(VisitorSynchronization::kTop);
4771 Relocatable::Iterate(isolate_, v); 4814 Relocatable::Iterate(isolate_, v);
4772 v->Synchronize(VisitorSynchronization::kRelocatable); 4815 v->Synchronize(VisitorSynchronization::kRelocatable);
4773 isolate_->debug()->Iterate(v); 4816 isolate_->debug()->Iterate(v);
4774 v->Synchronize(VisitorSynchronization::kDebug); 4817 v->Synchronize(VisitorSynchronization::kDebug);
4775 4818
4776 isolate_->compilation_cache()->Iterate(v); 4819 isolate_->compilation_cache()->Iterate(v);
4777 v->Synchronize(VisitorSynchronization::kCompilationCache); 4820 v->Synchronize(VisitorSynchronization::kCompilationCache);
4778 4821
4779 // Iterate over local handles in handle scopes. 4822 // Iterate over local handles in handle scopes.
4823 FixStaleLeftTrimmedHandlesVisitor left_trim_visitor(this);
4824 isolate_->handle_scope_implementer()->Iterate(&left_trim_visitor);
4780 isolate_->handle_scope_implementer()->Iterate(v); 4825 isolate_->handle_scope_implementer()->Iterate(v);
4781 isolate_->IterateDeferredHandles(v); 4826 isolate_->IterateDeferredHandles(v);
4782 v->Synchronize(VisitorSynchronization::kHandleScope); 4827 v->Synchronize(VisitorSynchronization::kHandleScope);
4783 4828
4784 // Iterate over the builtin code objects and code stubs in the 4829 // Iterate over the builtin code objects and code stubs in the
4785 // heap. Note that it is not necessary to iterate over code objects 4830 // heap. Note that it is not necessary to iterate over code objects
4786 // on scavenge collections. 4831 // on scavenge collections.
4787 if (mode != VISIT_ALL_IN_SCAVENGE) { 4832 if (mode != VISIT_ALL_IN_SCAVENGE) {
4788 isolate_->builtins()->IterateBuiltins(v); 4833 isolate_->builtins()->IterateBuiltins(v);
4789 v->Synchronize(VisitorSynchronization::kBuiltins); 4834 v->Synchronize(VisitorSynchronization::kBuiltins);
(...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after
6382 } 6427 }
6383 6428
6384 6429
6385 // static 6430 // static
6386 int Heap::GetStaticVisitorIdForMap(Map* map) { 6431 int Heap::GetStaticVisitorIdForMap(Map* map) {
6387 return StaticVisitorBase::GetVisitorId(map); 6432 return StaticVisitorBase::GetVisitorId(map);
6388 } 6433 }
6389 6434
6390 } // namespace internal 6435 } // namespace internal
6391 } // namespace v8 6436 } // 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