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/mark-compact.h" | 5 #include "src/heap/mark-compact.h" |
6 | 6 |
7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2223 DCHECK(in_use()); | 2223 DCHECK(in_use()); |
2224 HeapObject* heap_object = HeapObject::cast(*object); | 2224 HeapObject* heap_object = HeapObject::cast(*object); |
2225 DCHECK(heap_->Contains(heap_object)); | 2225 DCHECK(heap_->Contains(heap_object)); |
2226 MarkBit mark_bit = ObjectMarking::MarkBitFrom(heap_object); | 2226 MarkBit mark_bit = ObjectMarking::MarkBitFrom(heap_object); |
2227 MarkObject(heap_object, mark_bit); | 2227 MarkObject(heap_object, mark_bit); |
2228 } | 2228 } |
2229 | 2229 |
2230 class MarkCompactCollector::ObjectStatsVisitor | 2230 class MarkCompactCollector::ObjectStatsVisitor |
2231 : public MarkCompactCollector::HeapObjectVisitor { | 2231 : public MarkCompactCollector::HeapObjectVisitor { |
2232 public: | 2232 public: |
2233 ObjectStatsVisitor(ObjectStats* live_stats, ObjectStats* dead_stats) | 2233 ObjectStatsVisitor(Heap* heap, ObjectStats* live_stats, |
2234 : live_stats_(live_stats), dead_stats_(dead_stats) { | 2234 ObjectStats* dead_stats) |
2235 DCHECK_NOT_NULL(live_stats_); | 2235 : live_collector_(heap, live_stats), dead_collector_(heap, dead_stats) { |
2236 DCHECK_NOT_NULL(dead_stats_); | 2236 DCHECK_NOT_NULL(live_stats); |
| 2237 DCHECK_NOT_NULL(dead_stats); |
| 2238 // Global objects are roots and thus recorded as live. |
| 2239 live_collector_.CollectGlobalStatistics(); |
2237 } | 2240 } |
2238 | 2241 |
2239 bool Visit(HeapObject* obj) override { | 2242 bool Visit(HeapObject* obj) override { |
2240 if (Marking::IsBlack(ObjectMarking::MarkBitFrom(obj))) { | 2243 if (Marking::IsBlack(ObjectMarking::MarkBitFrom(obj))) { |
2241 ObjectStatsCollector::CollectStatistics(live_stats_, obj); | 2244 live_collector_.CollectStatistics(obj); |
2242 } else { | 2245 } else { |
2243 DCHECK(!Marking::IsGrey(ObjectMarking::MarkBitFrom(obj))); | 2246 DCHECK(!Marking::IsGrey(ObjectMarking::MarkBitFrom(obj))); |
2244 ObjectStatsCollector::CollectStatistics(dead_stats_, obj); | 2247 dead_collector_.CollectStatistics(obj); |
2245 } | 2248 } |
2246 return true; | 2249 return true; |
2247 } | 2250 } |
2248 | 2251 |
2249 private: | 2252 private: |
2250 ObjectStats* live_stats_; | 2253 ObjectStatsCollector live_collector_; |
2251 ObjectStats* dead_stats_; | 2254 ObjectStatsCollector dead_collector_; |
2252 }; | 2255 }; |
2253 | 2256 |
2254 void MarkCompactCollector::VisitAllObjects(HeapObjectVisitor* visitor) { | 2257 void MarkCompactCollector::VisitAllObjects(HeapObjectVisitor* visitor) { |
2255 SpaceIterator space_it(heap()); | 2258 SpaceIterator space_it(heap()); |
2256 HeapObject* obj = nullptr; | 2259 HeapObject* obj = nullptr; |
2257 while (space_it.has_next()) { | 2260 while (space_it.has_next()) { |
2258 ObjectIterator* it = space_it.next(); | 2261 ObjectIterator* it = space_it.next(); |
2259 while ((obj = it->Next()) != nullptr) { | 2262 while ((obj = it->Next()) != nullptr) { |
2260 visitor->Visit(obj); | 2263 visitor->Visit(obj); |
2261 } | 2264 } |
2262 } | 2265 } |
2263 } | 2266 } |
2264 | 2267 |
2265 void MarkCompactCollector::RecordObjectStats() { | 2268 void MarkCompactCollector::RecordObjectStats() { |
2266 if (FLAG_track_gc_object_stats) { | 2269 if (FLAG_track_gc_object_stats) { |
2267 ObjectStatsVisitor visitor(heap()->live_object_stats_, | 2270 ObjectStatsVisitor visitor(heap(), heap()->live_object_stats_, |
2268 heap()->dead_object_stats_); | 2271 heap()->dead_object_stats_); |
2269 VisitAllObjects(&visitor); | 2272 VisitAllObjects(&visitor); |
2270 if (FLAG_trace_gc_object_stats) { | 2273 if (FLAG_trace_gc_object_stats) { |
2271 heap()->live_object_stats_->PrintJSON("live"); | 2274 heap()->live_object_stats_->PrintJSON("live"); |
2272 heap()->dead_object_stats_->PrintJSON("dead"); | 2275 heap()->dead_object_stats_->PrintJSON("dead"); |
2273 } | 2276 } |
2274 heap()->live_object_stats_->CheckpointObjectStats(); | 2277 heap()->live_object_stats_->CheckpointObjectStats(); |
2275 heap()->dead_object_stats_->ClearObjectStats(); | 2278 heap()->dead_object_stats_->ClearObjectStats(); |
2276 } | 2279 } |
2277 } | 2280 } |
(...skipping 1760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4038 // The target is always in old space, we don't have to record the slot in | 4041 // The target is always in old space, we don't have to record the slot in |
4039 // the old-to-new remembered set. | 4042 // the old-to-new remembered set. |
4040 DCHECK(!heap()->InNewSpace(target)); | 4043 DCHECK(!heap()->InNewSpace(target)); |
4041 RecordRelocSlot(host, &rinfo, target); | 4044 RecordRelocSlot(host, &rinfo, target); |
4042 } | 4045 } |
4043 } | 4046 } |
4044 } | 4047 } |
4045 | 4048 |
4046 } // namespace internal | 4049 } // namespace internal |
4047 } // namespace v8 | 4050 } // namespace v8 |
OLD | NEW |