Back to index

lightning-sunbird  0.9+nobinonly
gc_inl.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
00003  * Copyright (c) 1991-1995 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, October 3, 1995 2:07 pm PDT */
00015  
00016 # ifndef GC_PRIVATE_H
00017 #   include "private/gc_priv.h"
00018 # endif
00019 
00020 /* USE OF THIS FILE IS NOT RECOMMENDED unless the collector has been  */
00021 /* compiled without -DALL_INTERIOR_POINTERS or with                   */
00022 /* -DDONT_ADD_BYTE_AT_END, or the specified size includes a pointerfree      */
00023 /* word at the end.  In the standard collector configuration,         */
00024 /* the final word of each object may not be scanned.                  */
00025 /* This is most useful for compilers that generate C.                 */
00026 /* Manual use is hereby discouraged.                                  */
00027 
00028 /* Allocate n words (NOT BYTES).  X is made to point to the result.   */
00029 /* It is assumed that n < MAXOBJSZ, and                               */
00030 /* that n > 0.  On machines requiring double word alignment of some   */
00031 /* data, we also assume that n is 1 or even.  This bypasses the              */
00032 /* MERGE_SIZES mechanism.  In order to minimize the number of distinct       */
00033 /* free lists that are maintained, the caller should ensure that a    */
00034 /* small number of distinct values of n are used.  (The MERGE_SIZES   */
00035 /* mechanism normally does this by ensuring that only the leading three      */
00036 /* bits of n may be nonzero.  See misc.c for details.)  We really     */
00037 /* recommend this only in cases in which n is a constant, and no      */
00038 /* locking is required.                                               */
00039 /* In that case it may allow the compiler to perform substantial      */
00040 /* additional optimizations.                                          */
00041 # define GC_MALLOC_WORDS(result,n) \
00042 {      \
00043     register ptr_t op;      \
00044     register ptr_t *opp;    \
00045     DCL_LOCK_STATE;  \
00046        \
00047     opp = &(GC_objfreelist[n]);    \
00048     FASTLOCK();      \
00049     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {   \
00050         FASTUNLOCK();       \
00051         (result) = GC_generic_malloc_words_small((n), NORMAL); \
00052     } else {  \
00053         *opp = obj_link(op);       \
00054         obj_link(op) = 0;   \
00055         GC_words_allocd += (n);    \
00056         FASTUNLOCK();       \
00057         (result) = (GC_PTR) op;    \
00058     }  \
00059 }
00060 
00061 
00062 /* The same for atomic objects:    */
00063 # define GC_MALLOC_ATOMIC_WORDS(result,n) \
00064 {      \
00065     register ptr_t op;      \
00066     register ptr_t *opp;    \
00067     DCL_LOCK_STATE;  \
00068        \
00069     opp = &(GC_aobjfreelist[n]);   \
00070     FASTLOCK();      \
00071     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {   \
00072         FASTUNLOCK();       \
00073         (result) = GC_generic_malloc_words_small((n), PTRFREE);       \
00074     } else {  \
00075         *opp = obj_link(op);       \
00076         obj_link(op) = 0;   \
00077         GC_words_allocd += (n);    \
00078         FASTUNLOCK();       \
00079         (result) = (GC_PTR) op;    \
00080     }  \
00081 }
00082 
00083 /* And once more for two word initialized objects: */
00084 # define GC_CONS(result, first, second) \
00085 {      \
00086     register ptr_t op;      \
00087     register ptr_t *opp;    \
00088     DCL_LOCK_STATE;  \
00089        \
00090     opp = &(GC_objfreelist[2]);    \
00091     FASTLOCK();      \
00092     if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) {   \
00093         FASTUNLOCK();       \
00094         op = GC_generic_malloc_words_small(2, NORMAL);  \
00095     } else {  \
00096         *opp = obj_link(op);       \
00097         GC_words_allocd += 2;      \
00098         FASTUNLOCK();       \
00099     } \
00100     ((word *)op)[0] = (word)(first);      \
00101     ((word *)op)[1] = (word)(second);     \
00102     (result) = (GC_PTR) op; \
00103 }