Back to index

lightning-sunbird  0.9+nobinonly
gc_hdrs.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
00003  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
00004  *
00005  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
00006  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00007  *
00008  * Permission is hereby granted to use or copy this program
00009  * for any purpose,  provided the above notices are retained on all copies.
00010  * Permission to modify the code and to distribute modified code is granted,
00011  * provided the above notices are retained, and a notice that the code was
00012  * modified is included with the above copyright notice.
00013  */
00014 /* Boehm, July 11, 1995 11:54 am PDT */
00015 # ifndef GC_HEADERS_H
00016 # define GC_HEADERS_H
00017 typedef struct hblkhdr hdr;
00018 
00019 # if CPP_WORDSZ != 32 && CPP_WORDSZ < 36
00020        --> Get a real machine.
00021 # endif
00022 
00023 /*
00024  * The 2 level tree data structure that is used to find block headers.
00025  * If there are more than 32 bits in a pointer, the top level is a hash
00026  * table.
00027  */
00028 
00029 # if CPP_WORDSZ > 32
00030 #   define HASH_TL
00031 # endif
00032 
00033 /* Define appropriate out-degrees for each of the two tree levels     */
00034 # ifdef SMALL_CONFIG
00035 #   define LOG_BOTTOM_SZ 11
00036        /* Keep top index size reasonable with smaller blocks. */
00037 # else
00038 #   define LOG_BOTTOM_SZ 10
00039 # endif
00040 # ifndef HASH_TL
00041 #   define LOG_TOP_SZ (WORDSZ - LOG_BOTTOM_SZ - LOG_HBLKSIZE)
00042 # else
00043 #   define LOG_TOP_SZ 11
00044 # endif
00045 # define TOP_SZ (1 << LOG_TOP_SZ)
00046 # define BOTTOM_SZ (1 << LOG_BOTTOM_SZ)
00047 
00048 typedef struct bi {
00049     hdr * index[BOTTOM_SZ];
00050        /*
00051         * The bottom level index contains one of three kinds of values:
00052         * 0 means we're not responsible for this block.
00053         * 1 < (long)X <= MAX_JUMP means the block starts at least
00054         *        X * HBLKSIZE bytes before the current address.
00055         * A valid pointer points to a hdr structure. (The above can't be
00056         * valid pointers due to the GET_MEM return convention.)
00057         */
00058     struct bi * asc_link;   /* All indices are linked in       */
00059                             /* ascending order.         */
00060     word key;               /* high order address bits. */
00061 # ifdef HASH_TL
00062     struct bi * hash_link;  /* Hash chain link.         */
00063 # endif
00064 } bottom_index;
00065 
00066 /* extern bottom_index GC_all_nils; - really part of GC_arrays */
00067 
00068 /* extern bottom_index * GC_top_index []; - really part of GC_arrays */
00069                             /* Each entry points to a bottom_index.   */
00070                             /* On a 32 bit machine, it points to      */
00071                             /* the index for a set of high order      */
00072                             /* bits equal to the index.  For longer   */
00073                             /* addresses, we hash the high order      */
00074                             /* bits to compute the index in    */
00075                             /* GC_top_index, and each entry points    */
00076                             /* to a hash chain.                */
00077                             /* The last entry in each chain is */
00078                             /* GC_all_nils.                           */
00079 
00080 
00081 # define MAX_JUMP (HBLKSIZE - 1)
00082 
00083 # define HDR_FROM_BI(bi, p) \
00084               ((bi)->index[((word)(p) >> LOG_HBLKSIZE) & (BOTTOM_SZ - 1)])
00085 # ifndef HASH_TL
00086 #   define BI(p) (GC_top_index \
00087               [(word)(p) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE)])
00088 #   define HDR_INNER(p) HDR_FROM_BI(BI(p),p)
00089 #   ifdef SMALL_CONFIG
00090 #      define HDR(p) GC_find_header((ptr_t)(p))
00091 #   else
00092 #      define HDR(p) HDR_INNER(p)
00093 #   endif
00094 #   define GET_BI(p, bottom_indx) (bottom_indx) = BI(p)
00095 #   define GET_HDR(p, hhdr) (hhdr) = HDR(p)
00096 #   define SET_HDR(p, hhdr) HDR_INNER(p) = (hhdr)
00097 #   define GET_HDR_ADDR(p, ha) (ha) = &(HDR_INNER(p))
00098 # else /* hash */
00099 /*  Hash function for tree top level */
00100 #   define TL_HASH(hi) ((hi) & (TOP_SZ - 1))
00101 /*  Set bottom_indx to point to the bottom index for address p */
00102 #   define GET_BI(p, bottom_indx) \
00103        { \
00104            register word hi = \
00105                (word)(p) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE); \
00106            register bottom_index * _bi = GC_top_index[TL_HASH(hi)]; \
00107            \
00108            while (_bi -> key != hi && _bi != GC_all_nils) \
00109               _bi = _bi -> hash_link; \
00110            (bottom_indx) = _bi; \
00111        }
00112 #   define GET_HDR_ADDR(p, ha) \
00113        { \
00114            register bottom_index * bi; \
00115            \
00116            GET_BI(p, bi);   \
00117            (ha) = &(HDR_FROM_BI(bi, p)); \
00118        }
00119 #   define GET_HDR(p, hhdr) { register hdr ** _ha; GET_HDR_ADDR(p, _ha); \
00120                            (hhdr) = *_ha; }
00121 #   define SET_HDR(p, hhdr) { register hdr ** _ha; GET_HDR_ADDR(p, _ha); \
00122                            *_ha = (hhdr); }
00123 #   define HDR(p) GC_find_header((ptr_t)(p))
00124 # endif
00125                          
00126 /* Is the result a forwarding address to someplace closer to the      */
00127 /* beginning of the block or NIL?                              */
00128 # define IS_FORWARDING_ADDR_OR_NIL(hhdr) ((unsigned long) (hhdr) <= MAX_JUMP)
00129 
00130 /* Get an HBLKSIZE aligned address closer to the beginning of the block */
00131 /* h.  Assumes hhdr == HDR(h) and IS_FORWARDING_ADDR(hhdr).           */
00132 # define FORWARDED_ADDR(h, hhdr) ((struct hblk *)(h) - (unsigned long)(hhdr))
00133 # endif /*  GC_HEADERS_H */