RelocationOverlay.h (1676B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* 8 * GC-internal definition of relocation overlay used while moving cells. 9 */ 10 11 #ifndef gc_RelocationOverlay_h 12 #define gc_RelocationOverlay_h 13 14 #include "mozilla/Assertions.h" 15 16 #include "gc/Cell.h" 17 18 namespace js { 19 namespace gc { 20 21 /* 22 * This structure overlays a Cell that has been moved and provides a way to find 23 * its new location. It's used during generational and compacting GC. 24 */ 25 class RelocationOverlay : public Cell { 26 public: 27 /* The location the cell has been moved to, stored in the cell header. */ 28 Cell* forwardingAddress() const { 29 MOZ_ASSERT(isForwarded()); 30 return reinterpret_cast<Cell*>(header_.getForwardingAddress()); 31 } 32 33 protected: 34 /* A list entry to track all relocated things. */ 35 RelocationOverlay* next_; 36 37 explicit RelocationOverlay(Cell* dst); 38 39 public: 40 static const RelocationOverlay* fromCell(const Cell* cell) { 41 return static_cast<const RelocationOverlay*>(cell); 42 } 43 44 static RelocationOverlay* fromCell(Cell* cell) { 45 return static_cast<RelocationOverlay*>(cell); 46 } 47 48 static RelocationOverlay* forwardCell(Cell* src, Cell* dst); 49 50 void setNext(RelocationOverlay* next) { 51 MOZ_ASSERT(isForwarded()); 52 next_ = next; 53 } 54 55 RelocationOverlay* next() const { 56 MOZ_ASSERT(isForwarded()); 57 return next_; 58 } 59 }; 60 61 } // namespace gc 62 } // namespace js 63 64 #endif /* gc_RelocationOverlay_h */