js/src/gc/Nursery-inl.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=4 sw=4 et tw=79 ft=cpp:
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifndef gc_Nursery_inl_h
michael@0 9 #define gc_Nursery_inl_h
michael@0 10
michael@0 11 #ifdef JSGC_GENERATIONAL
michael@0 12
michael@0 13 #include "gc/Nursery.h"
michael@0 14
michael@0 15 #include "gc/Heap.h"
michael@0 16
michael@0 17 namespace js {
michael@0 18 namespace gc {
michael@0 19
michael@0 20 /*
michael@0 21 * This structure overlays a Cell in the Nursery and re-purposes its memory
michael@0 22 * for managing the Nursery collection process.
michael@0 23 */
michael@0 24 class RelocationOverlay
michael@0 25 {
michael@0 26 friend class MinorCollectionTracer;
michael@0 27
michael@0 28 /* The low bit is set so this should never equal a normal pointer. */
michael@0 29 static const uintptr_t Relocated = uintptr_t(0xbad0bad1);
michael@0 30
michael@0 31 /* Set to Relocated when moved. */
michael@0 32 uintptr_t magic_;
michael@0 33
michael@0 34 /* The location |this| was moved to. */
michael@0 35 Cell *newLocation_;
michael@0 36
michael@0 37 /* A list entry to track all relocated things. */
michael@0 38 RelocationOverlay *next_;
michael@0 39
michael@0 40 public:
michael@0 41 static RelocationOverlay *fromCell(Cell *cell) {
michael@0 42 JS_ASSERT(!cell->isTenured());
michael@0 43 return reinterpret_cast<RelocationOverlay *>(cell);
michael@0 44 }
michael@0 45
michael@0 46 bool isForwarded() const {
michael@0 47 return magic_ == Relocated;
michael@0 48 }
michael@0 49
michael@0 50 Cell *forwardingAddress() const {
michael@0 51 JS_ASSERT(isForwarded());
michael@0 52 return newLocation_;
michael@0 53 }
michael@0 54
michael@0 55 void forwardTo(Cell *cell) {
michael@0 56 JS_ASSERT(!isForwarded());
michael@0 57 magic_ = Relocated;
michael@0 58 newLocation_ = cell;
michael@0 59 next_ = nullptr;
michael@0 60 }
michael@0 61
michael@0 62 RelocationOverlay *next() const {
michael@0 63 return next_;
michael@0 64 }
michael@0 65 };
michael@0 66
michael@0 67 } /* namespace gc */
michael@0 68 } /* namespace js */
michael@0 69
michael@0 70 template <typename T>
michael@0 71 MOZ_ALWAYS_INLINE bool
michael@0 72 js::Nursery::getForwardedPointer(T **ref)
michael@0 73 {
michael@0 74 JS_ASSERT(ref);
michael@0 75 JS_ASSERT(isInside(*ref));
michael@0 76 const gc::RelocationOverlay *overlay = reinterpret_cast<const gc::RelocationOverlay *>(*ref);
michael@0 77 if (!overlay->isForwarded())
michael@0 78 return false;
michael@0 79 /* This static cast from Cell* restricts T to valid (GC thing) types. */
michael@0 80 *ref = static_cast<T *>(overlay->forwardingAddress());
michael@0 81 return true;
michael@0 82 }
michael@0 83
michael@0 84 #endif /* JSGC_GENERATIONAL */
michael@0 85
michael@0 86 #endif /* gc_Nursery_inl_h */

mercurial