[project @ 2001-11-22 14:25:11 by simonmar]
[ghc-hetmet.git] / ghc / rts / Storage.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Storage.h,v 1.37 2001/11/22 14:25:12 simonmar Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * External Storage Manger Interface
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef STORAGE_H
11 #define STORAGE_H
12
13 #include "Block.h"
14 #include "BlockAlloc.h"
15 #include "StoragePriv.h"
16 #ifdef PROFILING
17 #include "LdvProfile.h"
18 #endif
19
20 /* -----------------------------------------------------------------------------
21    Initialisation / De-initialisation
22    -------------------------------------------------------------------------- */
23
24 extern void initStorage(void);
25 extern void exitStorage(void);
26
27 /* -----------------------------------------------------------------------------
28    Generic allocation
29
30    StgPtr allocate(nat n)       Allocates a chunk of contiguous store
31                                 n words long, returning a pointer to
32                                 the first word.  Always succeeds.
33                                 
34    StgPtr allocatePinned(nat n) Allocates a chunk of contiguous store
35                                 n words long, which is at a fixed
36                                 address (won't be moved by GC).  
37                                 Returns a pointer to the first word.
38                                 Always succeeds.
39                                 
40                                 NOTE: the GC can't in general handle
41                                 pinned objects, so allocatePinned()
42                                 can only be used for ByteArrays at the
43                                 moment.
44
45                                 Don't forget to TICK_ALLOC_XXX(...)
46                                 after calling allocate or
47                                 allocatePinned, for the
48                                 benefit of the ticky-ticky profiler.
49
50    rtsBool doYouWantToGC(void)  Returns True if the storage manager is
51                                 ready to perform a GC, False otherwise.
52
53    lnat  allocated_bytes(void)  Returns the number of bytes allocated
54                                 via allocate() since the last GC.
55                                 Used in the reoprting of statistics.
56
57    SMP: allocate and doYouWantToGC can be used from STG code, they are
58    surrounded by a mutex.
59    -------------------------------------------------------------------------- */
60
61 extern StgPtr  allocate        ( nat n );
62 extern StgPtr  allocatePinned  ( nat n );
63 extern lnat    allocated_bytes ( void );
64
65 static inline rtsBool
66 doYouWantToGC( void )
67 {
68   return (alloc_blocks >= alloc_blocks_lim);
69 }
70
71 /* -----------------------------------------------------------------------------
72    ExtendNursery(hp,hplim)      When hplim is reached, try to grab
73                                 some more allocation space.  Returns
74                                 False if the allocation space is
75                                 exhausted, and the application should
76                                 call GarbageCollect().
77   -------------------------------------------------------------------------- */
78
79 #define ExtendNursery(hp,hplim)                 \
80   (CurrentNursery->free = (P_)(hp)+1,           \
81    CurrentNursery->link == NULL ? rtsFalse :    \
82    (CurrentNursery = CurrentNursery->link,      \
83     OpenNursery(hp,hplim),                      \
84     rtsTrue))
85
86 extern void PleaseStopAllocating(void);
87
88 /* -----------------------------------------------------------------------------
89    Performing Garbage Collection
90
91    GarbageCollect(get_roots)    Performs a garbage collection.  
92                                 'get_roots' is called to find all the 
93                                 roots that the system knows about.
94
95    StgClosure                   Called by get_roots on each root.       
96    MarkRoot(StgClosure *p)      Returns the new location of the root.
97    -------------------------------------------------------------------------- */
98
99 extern void GarbageCollect(void (*get_roots)(evac_fn),rtsBool force_major_gc);
100
101 /* -----------------------------------------------------------------------------
102    Generational garbage collection support
103
104    recordMutable(StgPtr p)       Informs the garbage collector that a
105                                  previously immutable object has
106                                  become (permanently) mutable.  Used
107                                  by thawArray and similar.
108
109    updateWithIndirection(p1,p2)  Updates the object at p1 with an
110                                  indirection pointing to p2.  This is
111                                  normally called for objects in an old
112                                  generation (>0) when they are updated.
113
114    updateWithPermIndirection(p1,p2)  As above but uses a permanent indir.
115
116    -------------------------------------------------------------------------- */
117
118 /*
119  * Storage manager mutex
120  */
121 #ifdef SMP
122 extern pthread_mutex_t sm_mutex;
123 #endif
124
125 /* ToDo: shouldn't recordMutable and recordOldToNewPtrs acquire some
126  * kind of lock in the SMP case?
127  */
128 static inline void
129 recordMutable(StgMutClosure *p)
130 {
131   bdescr *bd;
132
133 #ifdef SMP
134   ASSERT(p->header.info == &stg_WHITEHOLE_info || closure_MUTABLE(p));
135 #else
136   ASSERT(closure_MUTABLE(p));
137 #endif
138
139   bd = Bdescr((P_)p);
140   if (bd->gen_no > 0) {
141     p->mut_link = generations[bd->gen_no].mut_list;
142     generations[bd->gen_no].mut_list = p;
143   }
144 }
145
146 static inline void
147 recordOldToNewPtrs(StgMutClosure *p)
148 {
149   bdescr *bd;
150   
151   bd = Bdescr((P_)p);
152   if (bd->gen_no > 0) {
153     p->mut_link = generations[bd->gen_no].mut_once_list;
154     generations[bd->gen_no].mut_once_list = p;
155   }
156 }
157
158 // @LDV profiling
159 // We zero out the slop when PROFILING is on.
160 // #ifndef DEBUG
161 #if !defined(DEBUG) && !defined(PROFILING)
162 #define updateWithIndirection(info, p1, p2)                             \
163   {                                                                     \
164     bdescr *bd;                                                         \
165                                                                         \
166     bd = Bdescr((P_)p1);                                                \
167     if (bd->gen_no == 0) {                                              \
168       ((StgInd *)p1)->indirectee = p2;                                  \
169       SET_INFO(p1,&stg_IND_info);                                       \
170       TICK_UPD_NEW_IND();                                               \
171     } else {                                                            \
172       ((StgIndOldGen *)p1)->indirectee = p2;                            \
173       if (info != &stg_BLACKHOLE_BQ_info) {                             \
174         ACQUIRE_LOCK(&sm_mutex);                                        \
175         ((StgIndOldGen *)p1)->mut_link = generations[bd->gen_no].mut_once_list; \
176         generations[bd->gen_no].mut_once_list = (StgMutClosure *)p1;                    \
177         RELEASE_LOCK(&sm_mutex);                                        \
178       }                                                                 \
179       SET_INFO(p1,&stg_IND_OLDGEN_info);                                \
180       TICK_UPD_OLD_IND();                                               \
181     }                                                                   \
182   }
183 #elif defined(PROFILING)
184 // @LDV profiling
185 // We call LDV_recordDead_FILL_SLOP_DYNAMIC(p1) regardless of the generation in 
186 // which p1 resides.
187 //
188 // Note: 
189 //   After all, we do *NOT* need to call LDV_recordCreate() for both IND and 
190 //   IND_OLDGEN closures because they are inherently used. But, it corrupts
191 //   the invariants that every closure keeps its creation time in the profiling
192 //   field. So, we call LDV_recordCreate().
193
194 #define updateWithIndirection(info, p1, p2)                             \
195   {                                                                     \
196     bdescr *bd;                                                         \
197                                                                         \
198     LDV_recordDead_FILL_SLOP_DYNAMIC((p1));                             \
199     bd = Bdescr((P_)p1);                                                \
200     if (bd->gen_no == 0) {                                              \
201       ((StgInd *)p1)->indirectee = p2;                                  \
202       SET_INFO(p1,&stg_IND_info);                                       \
203       LDV_recordCreate((p1));                                           \
204       TICK_UPD_NEW_IND();                                               \
205     } else {                                                            \
206       ((StgIndOldGen *)p1)->indirectee = p2;                            \
207       if (info != &stg_BLACKHOLE_BQ_info) {                             \
208         ACQUIRE_LOCK(&sm_mutex);                                        \
209         ((StgIndOldGen *)p1)->mut_link = generations[bd->gen_no].mut_once_list; \
210         generations[bd->gen_no].mut_once_list = (StgMutClosure *)p1;    \
211         RELEASE_LOCK(&sm_mutex);                                        \
212       }                                                                 \
213       SET_INFO(p1,&stg_IND_OLDGEN_info);                                \
214       LDV_recordCreate((p1));                                           \
215     }                                                                   \
216   }
217
218 #else
219
220 /* In the DEBUG case, we also zero out the slop of the old closure,
221  * so that the sanity checker can tell where the next closure is.
222  *
223  * Two important invariants: we should never try to update a closure
224  * to point to itself, and the closure being updated should not
225  * already have been updated (the mutable list will get messed up
226  * otherwise).
227  */
228 #define updateWithIndirection(info, p1, p2)                             \
229   {                                                                     \
230     bdescr *bd;                                                         \
231                                                                         \
232     ASSERT( p1 != p2 && !closure_IND(p1) );                             \
233     bd = Bdescr((P_)p1);                                                \
234     if (bd->gen_no == 0) {                                              \
235       ((StgInd *)p1)->indirectee = p2;                                  \
236       SET_INFO(p1,&stg_IND_info);                                       \
237       TICK_UPD_NEW_IND();                                               \
238     } else {                                                            \
239       if (info != &stg_BLACKHOLE_BQ_info) {                             \
240         {                                                               \
241           StgInfoTable *inf = get_itbl(p1);                             \
242           nat np = inf->layout.payload.ptrs,                            \
243               nw = inf->layout.payload.nptrs, i;                        \
244           if (inf->type != THUNK_SELECTOR) {                            \
245              for (i = np; i < np + nw; i++) {                           \
246                 ((StgClosure *)p1)->payload[i] = 0;                     \
247              }                                                          \
248           }                                                             \
249         }                                                               \
250         ACQUIRE_LOCK(&sm_mutex);                                        \
251         ((StgIndOldGen *)p1)->mut_link = generations[bd->gen_no].mut_once_list; \
252         generations[bd->gen_no].mut_once_list = (StgMutClosure *)p1;                    \
253         RELEASE_LOCK(&sm_mutex);                                        \
254       }                                                                 \
255       ((StgIndOldGen *)p1)->indirectee = p2;                            \
256       SET_INFO(p1,&stg_IND_OLDGEN_info);                                \
257       TICK_UPD_OLD_IND();                                               \
258     }                                                                   \
259   }
260 #endif
261
262 /* Static objects all live in the oldest generation
263  */
264 #define updateWithStaticIndirection(info, p1, p2)                       \
265   {                                                                     \
266     ASSERT( p1 != p2 && !closure_IND(p1) );                             \
267     ASSERT( ((StgMutClosure*)p1)->mut_link == NULL );                   \
268                                                                         \
269     ACQUIRE_LOCK(&sm_mutex);                                            \
270     ((StgMutClosure *)p1)->mut_link = oldest_gen->mut_once_list;        \
271     oldest_gen->mut_once_list = (StgMutClosure *)p1;                    \
272     RELEASE_LOCK(&sm_mutex);                                            \
273                                                                         \
274     ((StgInd *)p1)->indirectee = p2;                                    \
275     SET_INFO((StgInd *)p1, &stg_IND_STATIC_info);                       \
276     TICK_UPD_STATIC_IND();                                              \
277   }
278
279 #if defined(TICKY_TICKY) || defined(PROFILING)
280 static inline void
281 updateWithPermIndirection(const StgInfoTable *info, StgClosure *p1, StgClosure *p2) 
282 {
283   bdescr *bd;
284
285   ASSERT( p1 != p2 && !closure_IND(p1) );
286
287   // @LDV profiling
288   // Destroy the old closure.
289   LDV_recordDead_FILL_SLOP_DYNAMIC(p1);
290   bd = Bdescr((P_)p1);
291   if (bd->gen_no == 0) {
292     ((StgInd *)p1)->indirectee = p2;
293     SET_INFO(p1,&stg_IND_PERM_info);
294     // @LDV profiling
295     // We have just created a new closure.
296     LDV_recordCreate(p1);
297     TICK_UPD_NEW_PERM_IND(p1);
298   } else {
299     ((StgIndOldGen *)p1)->indirectee = p2;
300     if (info != &stg_BLACKHOLE_BQ_info) {
301       ACQUIRE_LOCK(&sm_mutex);
302       ((StgIndOldGen *)p1)->mut_link = generations[bd->gen_no].mut_once_list;
303       generations[bd->gen_no].mut_once_list = (StgMutClosure *)p1;
304       RELEASE_LOCK(&sm_mutex);
305     }
306     SET_INFO(p1,&stg_IND_OLDGEN_PERM_info);
307     // @LDV profiling
308     // We have just created a new closure.
309     LDV_recordCreate(p1);
310     TICK_UPD_OLD_PERM_IND();
311   }
312 }
313 #endif
314
315 /* -----------------------------------------------------------------------------
316    The CAF table - used to let us revert CAFs
317    -------------------------------------------------------------------------- */
318
319 void revertCAFs( void );
320
321 #if defined(DEBUG)
322 void printMutOnceList(generation *gen);
323 void printMutableList(generation *gen);
324 #endif /* DEBUG */
325
326 /* --------------------------------------------------------------------------
327                       Address space layout macros
328    --------------------------------------------------------------------------
329
330    Here are the assumptions GHC makes about address space layout.
331    Broadly, it thinks there are three sections:
332
333      CODE    Read-only.  Contains code and read-only data (such as
334                 info tables)
335              Also called "text"
336
337      DATA    Read-write data.  Contains static closures (and on some
338                 architectures, info tables too)
339
340      HEAP    Dynamically-allocated closures
341
342      USER    None of the above.  The only way USER things arise right 
343              now is when GHCi allocates a constructor info table, which
344              it does by mallocing them.
345
346    Three macros identify these three areas:
347      IS_CODE(p), IS_DATA(p), HEAP_ALLOCED(p)
348
349    HEAP_ALLOCED is called FOR EVERY SINGLE CLOSURE during GC.
350    It needs to be FAST.
351
352    Implementation of HEAP_ALLOCED
353    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354    Concerning HEAP, most of the time (certainly under [Static] and [GHCi],
355    we ensure that the heap is allocated above some fixed address HEAP_BASE
356    (defined in MBlock.h).  In this case we set TEXT_BEFORE_HEAP, and we
357    get a nice fast test.
358
359    Sometimes we can't be quite sure.  For example in Windows, we can't 
360    fix where our heap address space comes from.  In this case we un-set 
361    TEXT_BEFORE_HEAP. That makes it more expensive to test whether a pointer
362    comes from the HEAP section, because we need to look at the allocator's
363    address maps (see HEAP_ALLOCED macro)
364
365    Implementation of CODE and DATA
366    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367    Concerning CODE and DATA, there are three main regimes:
368
369      [Static] Totally      The segments are contiguous, and laid out 
370      statically linked     exactly as above
371
372      [GHCi] Static,        GHCi may load new modules, but it knows the
373      except for GHCi       address map, so for any given address it can
374                            still tell which section it belongs to
375
376      [DLL] OS-supported    Chunks of CODE and DATA may be mixed in 
377      dynamic loading       the address space, and we can't tell how
378
379
380    For the [Static] case, we assume memory is laid out like this
381    (in order of increasing addresses)
382
383        Start of memory
384            CODE section
385        TEXT_SECTION_END_MARKER   (usually _etext)
386            DATA section
387        DATA_SECTION_END_MARKER   (usually _end)
388            USER section
389        HEAP_BASE
390            HEAP section
391
392    For the [GHCi] case, we have to consult GHCi's dynamic linker's
393    address maps, which is done by macros
394          is_dynamically_loaded_code_or_rodata_ptr
395          is_dynamically_loaded_code_or_rwdata_ptr
396
397    For the [DLL] case, IS_CODE and IS_DATA are really not usable at all.
398  */
399
400
401 #undef TEXT_BEFORE_HEAP
402 #ifndef mingw32_TARGET_OS
403 #define TEXT_BEFORE_HEAP 1
404 #endif
405
406 extern void* TEXT_SECTION_END_MARKER_DECL;
407 extern void* DATA_SECTION_END_MARKER_DECL;
408
409 /* Take into account code sections in dynamically loaded object files. */
410 #define IS_CODE_PTR(p) (  ((P_)(p) < (P_)&TEXT_SECTION_END_MARKER) \
411                        || is_dynamically_loaded_code_or_rodata_ptr((char *)p) )
412 #define IS_DATA_PTR(p) ( ((P_)(p) >= (P_)&TEXT_SECTION_END_MARKER && \
413                           (P_)(p) < (P_)&DATA_SECTION_END_MARKER) \
414                        || is_dynamically_loaded_rwdata_ptr((char *)p) )
415 #define IS_USER_PTR(p) ( ((P_)(p) >= (P_)&DATA_SECTION_END_MARKER) \
416                        && is_not_dynamically_loaded_ptr((char *)p) )
417
418 /* The HEAP_ALLOCED test below is called FOR EVERY SINGLE CLOSURE
419  * during GC.  It needs to be FAST.
420  *
421  * BEWARE: when we're dynamically loading code (for GHCi), make sure
422  * that we don't load any code above HEAP_BASE, or this test won't work.
423  */
424 #ifdef TEXT_BEFORE_HEAP
425 # define HEAP_ALLOCED(x)  ((StgPtr)(x) >= (StgPtr)(HEAP_BASE))
426 #else
427 extern int is_heap_alloced(const void* x);
428 # define HEAP_ALLOCED(x)  (is_heap_alloced(x))
429 #endif
430
431
432 /* --------------------------------------------------------------------------
433    Macros for distinguishing data pointers from code pointers
434    --------------------------------------------------------------------------
435
436   Specification
437   ~~~~~~~~~~~~~
438   The garbage collector needs to make some critical distinctions between pointers.
439   In particular we need
440  
441      LOOKS_LIKE_GHC_INFO(p)          p points to an info table
442
443   For both of these macros, p is
444       *either* a pointer to a closure (static or heap allocated)
445       *or* a return address on the (Haskell) stack
446
447   (Return addresses are in fact info-pointers, so that the Haskell stack
448   looks very like a chunk of heap.)
449
450   The garbage collector uses LOOKS_LIKE_GHC_INFO when walking the stack, as it
451   walks over the "pending arguments" on its way to the next return address.
452   It is called moderately often, but not as often as HEAP_ALLOCED
453
454   ToDo: LOOKS_LIKE_GHC_INFO(p) does not return True when p points to a
455   constructor info table allocated by GHCi.  We should really rename 
456   LOOKS_LIKE_GHC_INFO to LOOKS_LIKE_GHC_RETURN_INFO.
457
458   Implementation
459   ~~~~~~~~~~~~~~
460   LOOKS_LIKE_GHC_INFO is more complicated because of the need to distinguish 
461   between static closures and info tables.  It's a known portability problem.
462   We have three approaches:
463
464   Plan A: Address-space partitioning.  
465     Keep info tables in the (single, contiguous) text segment:    IS_CODE_PTR(p)
466     and static closures in the (single, contiguous) data segment: IS_DATA_PTR(p)
467
468   Plan A can fail for two reasons:
469     * In many environments (eg. dynamic loading),
470       text and data aren't in a single contiguous range.  
471     * When we compile through vanilla C (no mangling) we sometimes
472       can't guaranteee to put info tables in the text section.  This
473       happens eg. on MacOS where the C compiler refuses to put const
474       data in the text section if it has any code pointers in it
475       (which info tables do *only* when we're compiling without
476       TABLES_NEXT_TO_CODE).
477     
478   Hence, Plan B: (compile-via-C-with-mangling, or native code generation)
479     Put a zero word before each static closure.
480     When compiling to native code, or via C-with-mangling, info tables
481     are laid out "backwards" from the address specified in the info pointer
482     (the entry code goes forward from the info pointer).  Hence, the word
483     before the one referenced the info pointer is part of the info table,
484     and is guaranteed non-zero.
485
486     For reasons nobody seems to fully understand, the statically-allocated tables
487     of INTLIKE and CHARLIKE closures can't have this zero word, so we
488     have to test separately for them.
489
490     Plan B fails altogether for the compile-through-vanilla-C route, because
491     info tables aren't laid out backwards.
492
493
494   Hence, Plan C: (unregisterised, compile-through-vanilla-C route only)
495     If we didn't manage to get info tables into the text section, then
496     we can distinguish between a static closure pointer and an info
497     pointer as follows:  the first word of an info table is a code pointer,
498     and therefore in text space, whereas the first word of a closure pointer
499     is an info pointer, and therefore not.  Shazam!
500 */
501
502
503 /* When working with Win32 DLLs, static closures are identified by
504    being prefixed with a zero word. This is needed so that we can
505    distinguish between pointers to static closures and (reversed!)
506    info tables.
507
508    This 'scheme' breaks down for closure tables such as CHARLIKE,
509    so we catch these separately.
510   
511    LOOKS_LIKE_STATIC_CLOSURE() 
512        - discriminates between static closures and info tbls
513          (needed by LOOKS_LIKE_GHC_INFO() below - [Win32 DLLs only.])
514    LOOKS_LIKE_STATIC() 
515        - distinguishes between static and heap allocated data.
516  */
517 #if defined(ENABLE_WIN32_DLL_SUPPORT)
518             /* definitely do not enable for mingw DietHEP */
519 #define LOOKS_LIKE_STATIC(r) (!(HEAP_ALLOCED(r)))
520
521 /* Tiresome predicates needed to check for pointers into the closure tables */
522 #define IS_CHARLIKE_CLOSURE(p) \
523     ( (P_)(p) >= (P_)stg_CHARLIKE_closure && \
524       (char*)(p) <= ((char*)stg_CHARLIKE_closure + \
525                      (MAX_CHARLIKE-MIN_CHARLIKE) * sizeof(StgIntCharlikeClosure)) )
526 #define IS_INTLIKE_CLOSURE(p) \
527     ( (P_)(p) >= (P_)stg_INTLIKE_closure && \
528       (char*)(p) <= ((char*)stg_INTLIKE_closure + \
529                      (MAX_INTLIKE-MIN_INTLIKE) * sizeof(StgIntCharlikeClosure)) )
530
531 #define LOOKS_LIKE_STATIC_CLOSURE(r) (((*(((unsigned long *)(r))-1)) == 0) || IS_CHARLIKE_CLOSURE(r) || IS_INTLIKE_CLOSURE(r))
532 #else
533 #define LOOKS_LIKE_STATIC(r) IS_DATA_PTR(r)
534 #define LOOKS_LIKE_STATIC_CLOSURE(r) IS_DATA_PTR(r)
535 #endif
536
537
538 /* -----------------------------------------------------------------------------
539    Macros for distinguishing infotables from closures.
540    
541    You'd think it'd be easy to tell an info pointer from a closure pointer:
542    closures live on the heap and infotables are in read only memory.  Right?
543    Wrong!  Static closures live in read only memory and Hugs allocates
544    infotables for constructors on the (writable) C heap.
545    -------------------------------------------------------------------------- */
546
547 /* not accurate by any means, but stops the assertions failing... */
548 /* TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO */
549 #define IS_HUGS_CONSTR_INFO(info)  IS_USER_PTR(info)
550
551 /* LOOKS_LIKE_GHC_INFO is called moderately often during GC, but
552  * Certainly not as often as HEAP_ALLOCED.
553  */
554 #ifdef TEXT_BEFORE_HEAP /* needed for mingw DietHEP */
555 # define LOOKS_LIKE_GHC_INFO(info) IS_CODE_PTR(info)
556 #else
557 # define LOOKS_LIKE_GHC_INFO(info) (!HEAP_ALLOCED(info) \
558                                     && !LOOKS_LIKE_STATIC_CLOSURE(info))
559 #endif
560
561
562 /* -----------------------------------------------------------------------------
563    Macros for calculating how big a closure will be (used during allocation)
564    -------------------------------------------------------------------------- */
565
566 static __inline__ StgOffset AP_sizeW    ( nat n_args )              
567 { return sizeofW(StgAP_UPD) + n_args; }
568
569 static __inline__ StgOffset PAP_sizeW   ( nat n_args )              
570 { return sizeofW(StgPAP)    + n_args; }
571
572 static __inline__ StgOffset CONSTR_sizeW( nat p, nat np )  
573 { return sizeofW(StgHeader) + p + np; }
574
575 static __inline__ StgOffset THUNK_SELECTOR_sizeW ( void )                    
576 { return sizeofW(StgHeader) + MIN_UPD_SIZE; }
577
578 static __inline__ StgOffset BLACKHOLE_sizeW ( void )                    
579 { return sizeofW(StgHeader) + MIN_UPD_SIZE; }
580
581 /* --------------------------------------------------------------------------
582  * Sizes of closures
583  * ------------------------------------------------------------------------*/
584
585 static __inline__ StgOffset sizeW_fromITBL( const StgInfoTable* itbl ) 
586 { return sizeofW(StgClosure) 
587        + sizeofW(StgPtr)  * itbl->layout.payload.ptrs 
588        + sizeofW(StgWord) * itbl->layout.payload.nptrs; }
589
590 static __inline__ StgOffset pap_sizeW( StgPAP* x )
591 { return PAP_sizeW(x->n_args); }
592
593 static __inline__ StgOffset arr_words_sizeW( StgArrWords* x )
594 { return sizeofW(StgArrWords) + x->words; }
595
596 static __inline__ StgOffset mut_arr_ptrs_sizeW( StgMutArrPtrs* x )
597 { return sizeofW(StgMutArrPtrs) + x->ptrs; }
598
599 static __inline__ StgWord tso_sizeW ( StgTSO *tso )
600 { return TSO_STRUCT_SIZEW + tso->stack_size; }
601
602 #endif /* STORAGE_H */
603