OLD | NEW |
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/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 6081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6092 MarkingVisitor visitor; | 6092 MarkingVisitor visitor; |
6093 heap_->IterateRoots(&visitor, VISIT_ALL); | 6093 heap_->IterateRoots(&visitor, VISIT_ALL); |
6094 visitor.TransitiveClosure(); | 6094 visitor.TransitiveClosure(); |
6095 } | 6095 } |
6096 | 6096 |
6097 Heap* heap_; | 6097 Heap* heap_; |
6098 DisallowHeapAllocation no_allocation_; | 6098 DisallowHeapAllocation no_allocation_; |
6099 }; | 6099 }; |
6100 | 6100 |
6101 | 6101 |
6102 HeapIterator::HeapIterator(Heap* heap) | |
6103 : make_heap_iterable_helper_(heap), | |
6104 no_heap_allocation_(), | |
6105 heap_(heap), | |
6106 filtering_(HeapIterator::kNoFiltering), | |
6107 filter_(NULL) { | |
6108 Init(); | |
6109 } | |
6110 | |
6111 | |
6112 HeapIterator::HeapIterator(Heap* heap, | 6102 HeapIterator::HeapIterator(Heap* heap, |
6113 HeapIterator::HeapObjectsFiltering filtering) | 6103 HeapIterator::HeapObjectsFiltering filtering) |
6114 : make_heap_iterable_helper_(heap), | 6104 : make_heap_iterable_helper_(heap), |
6115 no_heap_allocation_(), | 6105 no_heap_allocation_(), |
6116 heap_(heap), | 6106 heap_(heap), |
6117 filtering_(filtering), | 6107 filtering_(filtering), |
6118 filter_(NULL) { | 6108 filter_(nullptr), |
6119 Init(); | 6109 space_iterator_(nullptr), |
6120 } | 6110 object_iterator_(nullptr) { |
6121 | |
6122 | |
6123 HeapIterator::~HeapIterator() { Shutdown(); } | |
6124 | |
6125 | |
6126 void HeapIterator::Init() { | |
6127 // Start the iteration. | 6111 // Start the iteration. |
6128 space_iterator_ = new SpaceIterator(heap_); | 6112 space_iterator_ = new SpaceIterator(heap_); |
6129 switch (filtering_) { | 6113 switch (filtering_) { |
6130 case kFilterUnreachable: | 6114 case kFilterUnreachable: |
6131 filter_ = new UnreachableObjectsFilter(heap_); | 6115 filter_ = new UnreachableObjectsFilter(heap_); |
6132 break; | 6116 break; |
6133 default: | 6117 default: |
6134 break; | 6118 break; |
6135 } | 6119 } |
6136 object_iterator_ = space_iterator_->next(); | 6120 object_iterator_ = space_iterator_->next(); |
6137 } | 6121 } |
6138 | 6122 |
6139 | 6123 |
6140 void HeapIterator::Shutdown() { | 6124 HeapIterator::~HeapIterator() { |
6141 #ifdef DEBUG | 6125 #ifdef DEBUG |
6142 // Assert that in filtering mode we have iterated through all | 6126 // Assert that in filtering mode we have iterated through all |
6143 // objects. Otherwise, heap will be left in an inconsistent state. | 6127 // objects. Otherwise, heap will be left in an inconsistent state. |
6144 if (filtering_ != kNoFiltering) { | 6128 if (filtering_ != kNoFiltering) { |
6145 DCHECK(object_iterator_ == NULL); | 6129 DCHECK(object_iterator_ == nullptr); |
6146 } | 6130 } |
6147 #endif | 6131 #endif |
6148 // Make sure the last iterator is deallocated. | 6132 // Make sure the last iterator is deallocated. |
| 6133 delete object_iterator_; |
6149 delete space_iterator_; | 6134 delete space_iterator_; |
6150 space_iterator_ = NULL; | |
6151 object_iterator_ = NULL; | |
6152 delete filter_; | 6135 delete filter_; |
6153 filter_ = NULL; | |
6154 } | 6136 } |
6155 | 6137 |
6156 | 6138 |
6157 HeapObject* HeapIterator::next() { | 6139 HeapObject* HeapIterator::next() { |
6158 if (filter_ == NULL) return NextObject(); | 6140 if (filter_ == nullptr) return NextObject(); |
6159 | 6141 |
6160 HeapObject* obj = NextObject(); | 6142 HeapObject* obj = NextObject(); |
6161 while (obj != NULL && filter_->SkipObject(obj)) obj = NextObject(); | 6143 while ((obj != nullptr) && (filter_->SkipObject(obj))) obj = NextObject(); |
6162 return obj; | 6144 return obj; |
6163 } | 6145 } |
6164 | 6146 |
6165 | 6147 |
6166 HeapObject* HeapIterator::NextObject() { | 6148 HeapObject* HeapIterator::NextObject() { |
6167 // No iterator means we are done. | 6149 // No iterator means we are done. |
6168 if (object_iterator_ == NULL) return NULL; | 6150 if (object_iterator_ == nullptr) return nullptr; |
6169 | 6151 |
6170 if (HeapObject* obj = object_iterator_->next_object()) { | 6152 if (HeapObject* obj = object_iterator_->next_object()) { |
6171 // If the current iterator has more objects we are fine. | 6153 // If the current iterator has more objects we are fine. |
6172 return obj; | 6154 return obj; |
6173 } else { | 6155 } else { |
6174 // Go though the spaces looking for one that has objects. | 6156 // Go though the spaces looking for one that has objects. |
6175 while (space_iterator_->has_next()) { | 6157 while (space_iterator_->has_next()) { |
6176 object_iterator_ = space_iterator_->next(); | 6158 object_iterator_ = space_iterator_->next(); |
6177 if (HeapObject* obj = object_iterator_->next_object()) { | 6159 if (HeapObject* obj = object_iterator_->next_object()) { |
6178 return obj; | 6160 return obj; |
6179 } | 6161 } |
6180 } | 6162 } |
6181 } | 6163 } |
6182 // Done with the last space. | 6164 // Done with the last space. |
6183 object_iterator_ = NULL; | 6165 object_iterator_ = nullptr; |
6184 return NULL; | 6166 return nullptr; |
6185 } | 6167 } |
6186 | 6168 |
6187 | 6169 |
6188 void HeapIterator::reset() { | |
6189 // Restart the iterator. | |
6190 Shutdown(); | |
6191 Init(); | |
6192 } | |
6193 | |
6194 | |
6195 #ifdef DEBUG | 6170 #ifdef DEBUG |
6196 | 6171 |
6197 Object* const PathTracer::kAnyGlobalObject = NULL; | 6172 Object* const PathTracer::kAnyGlobalObject = NULL; |
6198 | 6173 |
6199 class PathTracer::MarkVisitor : public ObjectVisitor { | 6174 class PathTracer::MarkVisitor : public ObjectVisitor { |
6200 public: | 6175 public: |
6201 explicit MarkVisitor(PathTracer* tracer) : tracer_(tracer) {} | 6176 explicit MarkVisitor(PathTracer* tracer) : tracer_(tracer) {} |
6202 void VisitPointers(Object** start, Object** end) { | 6177 void VisitPointers(Object** start, Object** end) { |
6203 // Scan all HeapObject pointers in [start, end) | 6178 // Scan all HeapObject pointers in [start, end) |
6204 for (Object** p = start; !tracer_->found() && (p < end); p++) { | 6179 for (Object** p = start; !tracer_->found() && (p < end); p++) { |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6785 *object_type = "CODE_TYPE"; \ | 6760 *object_type = "CODE_TYPE"; \ |
6786 *object_sub_type = "CODE_AGE/" #name; \ | 6761 *object_sub_type = "CODE_AGE/" #name; \ |
6787 return true; | 6762 return true; |
6788 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) | 6763 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) |
6789 #undef COMPARE_AND_RETURN_NAME | 6764 #undef COMPARE_AND_RETURN_NAME |
6790 } | 6765 } |
6791 return false; | 6766 return false; |
6792 } | 6767 } |
6793 } // namespace internal | 6768 } // namespace internal |
6794 } // namespace v8 | 6769 } // namespace v8 |
OLD | NEW |