-
- // Update the THUNK_SELECTOR with an indirection to the
- // EVACUATED closure now at p. Why do this rather than
- // upd_evacuee(q,p)? Because we have an invariant that an
- // 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(q, &stg_IND_info);
- ((StgInd *)q)->indirectee = p;
-
- // For the purposes of LDV profiling, we have created an
- // indirection.
- LDV_RECORD_CREATE(q);
-
- return val;
- }
- }
-
- case IND:
- case IND_OLDGEN:
- // follow chains of indirections, don't evacuate them
- q = ((StgInd*)q)->indirectee;
- goto loop;
-
- case RET_BCO:
- case RET_SMALL:
- case RET_VEC_SMALL:
- case RET_BIG:
- case RET_VEC_BIG:
- case RET_DYN:
- case UPDATE_FRAME:
- case STOP_FRAME:
- case CATCH_FRAME:
- case CATCH_STM_FRAME:
- case CATCH_RETRY_FRAME:
- case ATOMICALLY_FRAME:
- // shouldn't see these
- barf("evacuate: stack frame at %p\n", q);
-
- case PAP:
- return copy(q,pap_sizeW((StgPAP*)q),stp);
-
- case AP:
- return copy(q,ap_sizeW((StgAP*)q),stp);
-
- case AP_STACK:
- return copy(q,ap_stack_sizeW((StgAP_STACK*)q),stp);
-
- case EVACUATED:
- /* Already evacuated, just return the forwarding address.
- * HOWEVER: if the requested destination generation (evac_gen) is
- * older than the actual generation (because the object was
- * already evacuated to a younger generation) then we have to
- * set the failed_to_evac flag to indicate that we couldn't
- * manage to promote the object to the desired generation.
- */
- /*
- * Optimisation: the check is fairly expensive, but we can often
- * shortcut it if either the required generation is 0, or the
- * current object (the EVACUATED) is in a high enough generation.
- * We know that an EVACUATED always points to an object in the
- * same or an older generation. stp is the lowest step that the
- * current object would be evacuated to, so we only do the full
- * check if stp is too low.
- */
- if (evac_gen > 0 && stp->gen_no < evac_gen) { // optimisation
- StgClosure *p = ((StgEvacuated*)q)->evacuee;
- if (HEAP_ALLOCED(p) && Bdescr((P_)p)->gen_no < evac_gen) {
- failed_to_evac = rtsTrue;
- TICK_GC_FAILED_PROMOTION();
- }
- }
- return ((StgEvacuated*)q)->evacuee;
-
- case ARR_WORDS:
- // just copy the block
- return copy_noscav(q,arr_words_sizeW((StgArrWords *)q),stp);
-
- case MUT_ARR_PTRS_CLEAN:
- case MUT_ARR_PTRS_DIRTY:
- case MUT_ARR_PTRS_FROZEN:
- case MUT_ARR_PTRS_FROZEN0:
- // just copy the block
- return copy(q,mut_arr_ptrs_sizeW((StgMutArrPtrs *)q),stp);
-
- case TSO:
- {
- StgTSO *tso = (StgTSO *)q;
-
- /* Deal with redirected TSOs (a TSO that's had its stack enlarged).
- */
- if (tso->what_next == ThreadRelocated) {
- q = (StgClosure *)tso->link;
- goto loop;
- }
-
- /* To evacuate a small TSO, we need to relocate the update frame
- * list it contains.
- */
- {
- StgTSO *new_tso;
- StgPtr p, q;
-
- new_tso = (StgTSO *)copyPart((StgClosure *)tso,
- tso_sizeW(tso),
- sizeofW(StgTSO), stp);
- move_TSO(tso, new_tso);
- for (p = tso->sp, q = new_tso->sp;
- p < tso->stack+tso->stack_size;) {
- *q++ = *p++;
- }
-
- return (StgClosure *)new_tso;
- }
+ // val must be in to-space. Not always: when we recursively
+ // invoke eval_thunk_selector(), the recursive calls will not
+ // evacuate the value (because we want to select on the value,
+ // not evacuate it), so in this case val is in from-space.
+ // ASSERT(!HEAP_ALLOCED(val) || 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 now at p. Why do this rather than
+ // upd_evacuee(q,p)? Because we have an invariant that an
+ // 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).
+ ((StgInd *)p)->indirectee = val;
+ write_barrier();
+ SET_INFO(p, &stg_IND_info);
+
+ // For the purposes of LDV profiling, we have created an
+ // indirection.
+ LDV_RECORD_CREATE(p);
+
+ p = prev;