Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_HEAP_SCAVENGER_H_ |
| 6 | #define V8_HEAP_SCAVENGER_H_ |
| 7 | |
| 8 | #include "src/heap/objects-visiting.h" |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 9 | #include "src/heap/slot-set.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
| 14 | typedef void (*ScavengingCallback)(Map* map, HeapObject** slot, |
| 15 | HeapObject* object); |
| 16 | |
| 17 | class Scavenger { |
| 18 | public: |
| 19 | explicit Scavenger(Heap* heap) : heap_(heap) {} |
| 20 | |
| 21 | // Initializes static visitor dispatch tables. |
| 22 | static void Initialize(); |
| 23 | |
| 24 | // Callback function passed to Heap::Iterate etc. Copies an object if |
| 25 | // necessary, the object might be promoted to an old space. The caller must |
| 26 | // ensure the precondition that the object is (a) a heap object and (b) in |
| 27 | // the heap's from space. |
| 28 | static inline void ScavengeObject(HeapObject** p, HeapObject* object); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 29 | static inline SlotCallbackResult CheckAndScavengeObject(Heap* heap, |
| 30 | Address slot_address); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 31 | |
| 32 | // Slow part of {ScavengeObject} above. |
| 33 | static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); |
| 34 | |
| 35 | // Chooses an appropriate static visitor table depending on the current state |
| 36 | // of the heap (i.e. incremental marking, logging and profiling). |
| 37 | void SelectScavengingVisitorsTable(); |
| 38 | |
| 39 | Isolate* isolate(); |
| 40 | Heap* heap() { return heap_; } |
| 41 | |
| 42 | private: |
| 43 | Heap* heap_; |
| 44 | VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_; |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | // Helper class for turning the scavenger into an object visitor that is also |
| 49 | // filtering out non-HeapObjects and objects which do not reside in new space. |
| 50 | class ScavengeVisitor : public ObjectVisitor { |
| 51 | public: |
| 52 | explicit ScavengeVisitor(Heap* heap) : heap_(heap) {} |
| 53 | |
| 54 | void VisitPointer(Object** p) override; |
| 55 | void VisitPointers(Object** start, Object** end) override; |
| 56 | |
| 57 | private: |
| 58 | inline void ScavengePointer(Object** p); |
| 59 | |
| 60 | Heap* heap_; |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | // Helper class for turning the scavenger into an object visitor that is also |
| 65 | // filtering out non-HeapObjects and objects which do not reside in new space. |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 66 | template <PromotionMode promotion_mode> |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 67 | class StaticScavengeVisitor |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 68 | : public StaticNewSpaceVisitor<StaticScavengeVisitor<promotion_mode>> { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 69 | public: |
| 70 | static inline void VisitPointer(Heap* heap, HeapObject* object, Object** p); |
| 71 | }; |
| 72 | |
| 73 | } // namespace internal |
| 74 | } // namespace v8 |
| 75 | |
| 76 | #endif // V8_HEAP_SCAVENGER_H_ |