2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
5 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
8 * Permission is hereby granted to use or copy this program
9 * for any purpose, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
14 /* Boehm, October 3, 1995 2:07 pm PDT */
17 # include "private/gc_priv.h"
20 /* USE OF THIS FILE IS NOT RECOMMENDED unless GC_all_interior_pointers */
21 /* is always set, or the collector has been built with */
22 /* -DDONT_ADD_BYTE_AT_END, or the specified size includes a pointerfree */
23 /* word at the end. In the standard collector configuration, */
24 /* the final word of each object may not be scanned. */
25 /* This iinterface is most useful for compilers that generate C. */
26 /* Manual use is hereby discouraged. */
28 /* Allocate n words (NOT BYTES). X is made to point to the result. */
29 /* It is assumed that n < MAXOBJSZ, and */
30 /* that n > 0. On machines requiring double word alignment of some */
31 /* data, we also assume that n is 1 or even. */
32 /* If the collector is built with -DUSE_MARK_BYTES or -DPARALLEL_MARK, */
33 /* the n = 1 case is also disallowed. */
34 /* Effectively this means that portable code should make sure n is even.*/
35 /* This bypasses the */
36 /* MERGE_SIZES mechanism. In order to minimize the number of distinct */
37 /* free lists that are maintained, the caller should ensure that a */
38 /* small number of distinct values of n are used. (The MERGE_SIZES */
39 /* mechanism normally does this by ensuring that only the leading three */
40 /* bits of n may be nonzero. See misc.c for details.) We really */
41 /* recommend this only in cases in which n is a constant, and no */
42 /* locking is required. */
43 /* In that case it may allow the compiler to perform substantial */
44 /* additional optimizations. */
45 # define GC_MALLOC_WORDS(result,n) \
48 register ptr_t *opp; \
51 opp = &(GC_objfreelist[n]); \
53 if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) { \
55 (result) = GC_generic_malloc_words_small((n), NORMAL); \
57 *opp = obj_link(op); \
59 GC_words_allocd += (n); \
61 (result) = (GC_PTR) op; \
66 /* The same for atomic objects: */
67 # define GC_MALLOC_ATOMIC_WORDS(result,n) \
70 register ptr_t *opp; \
73 opp = &(GC_aobjfreelist[n]); \
75 if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) { \
77 (result) = GC_generic_malloc_words_small((n), PTRFREE); \
79 *opp = obj_link(op); \
81 GC_words_allocd += (n); \
83 (result) = (GC_PTR) op; \
87 /* And once more for two word initialized objects: */
88 # define GC_CONS(result, first, second) \
91 register ptr_t *opp; \
94 opp = &(GC_objfreelist[2]); \
96 if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) { \
98 op = GC_generic_malloc_words_small(2, NORMAL); \
100 *opp = obj_link(op); \
101 GC_words_allocd += 2; \
104 ((word *)op)[0] = (word)(first); \
105 ((word *)op)[1] = (word)(second); \
106 (result) = (GC_PTR) op; \