1 #ifndef INCLUDED_RTS_GC_H
2 #define INCLUDED_RTS_GC_H
8 #include <unordered_set>
9 #include "rts/thread_local.h"
10 #include <boost/lockfree/queue.hpp>
19 using std::unordered_set;
20 using std::unique_lock;
55 extern mutex gc_mutex;
58 extern uint32_t regions_begin;
59 extern uint32_t regions_end;
60 extern uint64_t * mapped_regions;
61 extern unordered_set<hec*> hecs;
64 extern boost::lockfree::queue<gc_ptr> global_mark_queue[8];
66 static inline bool protected_region(uint32_t r) {
67 assert(regions_begin <= r && r < regions_end);
68 return mapped_regions[r>>6]&(1<<((r-regions_begin)&0x3f));
91 static const uint64_t
mask = 0x7ffffffff8;
93 template <
typename T> T & operator * () {
94 return *
reinterpret_cast<T *
>(addr&
mask);
97 template <
typename T> T * operator -> () {
98 return reinterpret_cast<T *
>(addr&
mask);
101 template <
typename T> T & operator [] (std::ptrdiff_t i) {
102 return *
reinterpret_cast<T *
>((addr&
mask) + (i *
sizeof(T)));
108 void lvb(uint64_t * address,
bool unique_context =
true);
112 void lvb_slow_path(uint64_t * address,
int trigger);
115 inline bool operator==(
const gc_ptr& lhs,
const gc_ptr& rhs){
return lhs.addr == rhs.addr; }
116 inline bool operator!=(
const gc_ptr& lhs,
const gc_ptr& rhs){
return lhs.addr != rhs.addr; }
127 hec & operator = (
hec const &);
132 unique_lock<mutex> lock(gc_mutex);
137 unique_lock<mutex> lock(gc_mutex);
146 inline void gc_ptr::lvb(uint64_t * address,
bool unique_context) {
150 if (protected_region(
region)) trigger |= triggers::relocation;
151 if (!unique_context &&
unique) trigger |= triggers::contraction;
152 if (trigger != 0) lvb_slow_path(address, trigger);
A heap pointer.
Definition: gc.h:74
uint16_t expected_nmt
16 bits, one per space
Definition: gc.h:122
uint64_t offset
offset within a 4k page
Definition: gc.h:79
uint64_t unique
does this reference locally believe it is unique?
Definition: gc.h:79
uint64_t nmt
not-marked-through toggle for LVB read-barrier
Definition: gc.h:79
static const uint64_t mask
mask for the offset, segment and region
Definition: gc.h:91
uint64_t region
which 2mb region in the system? 1tb addressable.
Definition: gc.h:79
void lvb(uint64_t *address, bool unique_context=true)
loaded-value-barrier read-barrier, modified to do contraction of "locally unique" references when the...
Definition: gc.h:146
uint64_t space
which generation/space are we in?
Definition: gc.h:79
static thread_local hec * current
track the current haskell execution context in a thread_local variable.
Definition: gc.h:121
A "Haskell execution context".
Definition: gc.h:119
uint64_t type
what type of this pointer is this?
Definition: gc.h:79
bool get_expected_nmt(int i)
extract an appropriate bit from out expected_nmt mask for what the expected value of the 'not-marked-...
Definition: gc.h:143
uint64_t tag
constructor #
Definition: gc.h:79
std::queue< gc_ptr > local_mark_queue[8]
mark queues for local spaces
Definition: gc.h:123
uint64_t segment
which 4k page within a 2mb region
Definition: gc.h:79