| 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 <stdint.h> |
| 17 |
|
| 18 |
#include "gc/Cell.h" |
| 19 |
|
| 20 |
namespace js { |
| 21 |
namespace gc { |
| 22 |
|
| 23 |
/* |
| 24 |
* This structure overlays a Cell that has been moved and provides a way to find |
| 25 |
* its new location. It's used during generational and compacting GC. |
| 26 |
*/ |
| 27 |
class RelocationOverlay : public Cell { |
| 28 |
public: |
| 29 |
/* The location the cell has been moved to, stored in the cell header. */ |
| 30 |
Cell* forwardingAddress() const { |
| 31 |
MOZ_ASSERT(isForwarded()); |
| 32 |
return reinterpret_cast<Cell*>(header_.getForwardingAddress()); |
| 33 |
} |
| 34 |
|
| 35 |
protected: |
| 36 |
/* A list entry to track all relocated things. */ |
| 37 |
RelocationOverlay* next_; |
| 38 |
|
| 39 |
explicit RelocationOverlay(Cell* dst); |
| 40 |
|
| 41 |
public: |
| 42 |
static const RelocationOverlay* fromCell(const Cell* cell) { |
| 43 |
return static_cast<const RelocationOverlay*>(cell); |
| 44 |
} |
| 45 |
|
| 46 |
static RelocationOverlay* fromCell(Cell* cell) { |
| 47 |
return static_cast<RelocationOverlay*>(cell); |
| 48 |
} |
| 49 |
|
| 50 |
static RelocationOverlay* forwardCell(Cell* src, Cell* dst); |
| 51 |
|
| 52 |
void setNext(RelocationOverlay* next) { |
| 53 |
MOZ_ASSERT(isForwarded()); |
| 54 |
next_ = next; |
| 55 |
} |
| 56 |
|
| 57 |
RelocationOverlay* next() const { |
| 58 |
MOZ_ASSERT(isForwarded()); |
| 59 |
return next_; |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
} // namespace gc |
| 64 |
} // namespace js |
| 65 |
|
| 66 |
#endif /* gc_RelocationOverlay_h */ |