X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FWeak.c;h=ef26e3b7ba93c1280cafc5cd7a62effcfa33c924;hb=a704ee9c4180bf19a431e507f5d32a1f787c5c47;hp=117d6a005c9288fb35987e82117f49987307d643;hpb=d3058014b75ef30cc1535dcc6abcf073b3170697;p=ghc-hetmet.git diff --git a/ghc/rts/Weak.c b/ghc/rts/Weak.c index 117d6a0..ef26e3b 100644 --- a/ghc/rts/Weak.c +++ b/ghc/rts/Weak.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: Weak.c,v 1.14 2000/05/22 13:09:29 simonmar Exp $ + * $Id: Weak.c,v 1.20 2001/11/26 16:54:22 simonmar Exp $ * * (c) The GHC Team, 1998-1999 * @@ -7,6 +7,7 @@ * * ---------------------------------------------------------------------------*/ +#include "PosixSource.h" #include "Rts.h" #include "RtsAPI.h" #include "SchedAPI.h" @@ -34,10 +35,12 @@ finalizeWeakPointersNow(void) while ((w = weak_ptr_list)) { weak_ptr_list = w->link; - IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key)); - w->header.info = &DEAD_WEAK_info; - if (w->finalizer != &NO_FINALIZER_closure) { - rts_evalIO(w->finalizer,NULL); + if (w->header.info != &stg_DEAD_WEAK_info) { + w->header.info = &stg_DEAD_WEAK_info; + IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n", w, w->key)); + if (w->finalizer != &stg_NO_FINALIZER_closure) { + rts_evalIO(w->finalizer,NULL); + } } } } @@ -65,7 +68,7 @@ scheduleFinalizers(StgWeak *list) /* count number of finalizers first... */ for (n = 0, w = list; w; w = w->link) { - if (w->finalizer != &NO_FINALIZER_closure) + if (w->finalizer != &stg_NO_FINALIZER_closure) n++; } @@ -74,15 +77,25 @@ scheduleFinalizers(StgWeak *list) IF_DEBUG(weak,fprintf(stderr,"weak: batching %d finalizers\n", n)); arr = (StgMutArrPtrs *)allocate(sizeofW(StgMutArrPtrs) + n); - SET_HDR(arr, &MUT_ARR_PTRS_FROZEN_info, CCS_SYSTEM); + SET_HDR(arr, &stg_MUT_ARR_PTRS_FROZEN_info, CCS_SYSTEM); arr->ptrs = n; for (n = 0, w = list; w; w = w->link) { - if (w->finalizer != &NO_FINALIZER_closure) { + if (w->finalizer != &stg_NO_FINALIZER_closure) { arr->payload[n] = w->finalizer; n++; } - w->header.info = &DEAD_WEAK_info; + +#ifdef PROFILING + // A weak pointer is inherently used, so we do not need to call + // LDV_recordDead(). + // + // Furthermore, when PROFILING is turned on, dead weak + // pointers are exactly as large as weak pointers, so there is + // no need to fill the slop, either. See stg_DEAD_WEAK_info + // in StgMiscClosures.hc. +#endif + SET_HDR(w, &stg_DEAD_WEAK_info, w->header.prof.ccs); } t = createIOThread(RtsFlags.GcFlags.initialStkSize,