{
StgPtr to;
step_workspace *ws;
- bdescr *bd;
/* Find out where we're going, using the handy "to" pointer in
* the step of the source object. If it turns out we need to
/* chain a new block onto the to-space for the destination step if
* necessary.
*/
- bd = ws->todo_bd;
- to = bd->free;
- if (to + size >= bd->start + BLOCK_SIZE_W) {
- bd = gc_alloc_todo_block(ws);
- to = bd->free;
+
+ ASSERT(ws->todo_free >= ws->todo_bd->free && ws->todo_free <= ws->todo_lim);
+ to = ws->todo_free;
+ if (to + size >= ws->todo_lim) {
+ to = gc_alloc_todo_block(ws);
}
- bd->free = to + size;
+ ws->todo_free = to + size;
+ ASSERT(ws->todo_free >= ws->todo_bd->free && ws->todo_free <= ws->todo_lim);
return to;
}
-
+
/* -----------------------------------------------------------------------------
The evacuate() code
-------------------------------------------------------------------------- */
prev = NULL;
while (p)
{
+#ifdef THREADED_RTS
+ ASSERT(p->header.info == &stg_WHITEHOLE_info);
+#else
ASSERT(p->header.info == &stg_BLACKHOLE_info);
+#endif
+ // val must be in to-space.
+ ASSERT(Bdescr((P_)val)->gen_no > N || (Bdescr((P_)val)->flags & BF_EVACUATED));
+
prev = (StgSelector*)((StgClosure *)p)->payload[0];
// Update the THUNK_SELECTOR with an indirection to the
// EVACUATED closure always points to an object in the
// same or an older generation (required by the short-cut
// test in the EVACUATED case, below).
- SET_INFO(p, &stg_IND_info);
((StgInd *)p)->indirectee = val;
+ write_barrier();
+ SET_INFO(p, &stg_IND_info);
// For the purposes of LDV profiling, we have created an
// indirection.
// In threaded mode, we'll use WHITEHOLE to lock the selector
// thunk while we evaluate it.
{
- info_ptr = (StgInfoTable *)xchg((StgPtr)&p->header.info, (W_)&stg_WHITEHOLE_info);
- if (info_ptr == (W_)&stg_WHITEHOLE_info) {
- do {
- info_ptr = xchg((StgPtr)&p->header.info, (W_)&stg_WHITEHOLE_info);
- } while (info_ptr == (W_)&stg_WHITEHOLE_info);
- goto bale_out;
- }
- // make sure someone else didn't get here first
+ do {
+ info_ptr = xchg((StgPtr)&p->header.info, (W_)&stg_WHITEHOLE_info);
+ } while (info_ptr == (W_)&stg_WHITEHOLE_info);
+
+ // make sure someone else didn't get here first...
if (INFO_PTR_TO_STRUCT(info_ptr)->type != THUNK_SELECTOR) {
- goto bale_out;
+ // v. tricky now. The THUNK_SELECTOR has been evacuated
+ // by another thread, and is now either EVACUATED or IND.
+ // We need to extract ourselves from the current situation
+ // as cleanly as possible.
+ // - unlock the closure
+ // - update *q, we may have done *some* evaluation
+ // - if evac, we need to call evacuate(), because we
+ // need the write-barrier stuff.
+ // - undo the chain we've built to point to p.
+ SET_INFO(p, (const StgInfoTable *)info_ptr);
+ *q = (StgClosure *)p;
+ if (evac) evacuate(q);
+ unchain_thunk_selectors(prev_thunk_selector, (StgClosure *)p);
+ return;
}
}
#else
#ifdef PROFILING
// For the purposes of LDV profiling, we have destroyed
// the original selector thunk, p.
- SET_INFO(p, info_ptr);
+ SET_INFO(p, (StgInfoTable *)info_ptr);
LDV_RECORD_DEAD_FILL_SLOP_DYNAMIC((StgClosure *)p);
SET_INFO(p, &stg_BLACKHOLE_info);
#endif
// We didn't manage to evaluate this thunk; restore the old info
// pointer. But don't forget: we still need to evacuate the thunk itself.
SET_INFO(p, (const StgInfoTable *)info_ptr);
+ // THREADED_RTS: we just unlocked the thunk, so another thread
+ // might get in and update it. copy() will lock it again and
+ // check whether it was updated in the meantime.
+ *q = (StgClosure *)p;
if (evac) {
- copy(&val,(StgClosure *)p,THUNK_SELECTOR_sizeW(),bd->step->to);
- } else {
- val = (StgClosure *)p;
+ copy(q,(StgClosure *)p,THUNK_SELECTOR_sizeW(),bd->step->to);
}
- *q = val;
- unchain_thunk_selectors(prev_thunk_selector, val);
+ unchain_thunk_selectors(prev_thunk_selector, *q);
return;
}