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 the collector has been */
21 /* compiled without -DALL_INTERIOR_POINTERS or 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 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. This bypasses the */
32 /* MERGE_SIZES mechanism. In order to minimize the number of distinct */
33 /* free lists that are maintained, the caller should ensure that a */
34 /* small number of distinct values of n are used. (The MERGE_SIZES */
35 /* mechanism normally does this by ensuring that only the leading three */
36 /* bits of n may be nonzero. See misc.c for details.) We really */
37 /* recommend this only in cases in which n is a constant, and no */
38 /* locking is required. */
39 /* In that case it may allow the compiler to perform substantial */
40 /* additional optimizations. */
41 # define GC_MALLOC_WORDS(result,n) \
44 register ptr_t *opp; \
47 opp = &(GC_objfreelist[n]); \
49 if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) { \
51 (result) = GC_generic_malloc_words_small((n), NORMAL); \
53 *opp = obj_link(op); \
55 GC_words_allocd += (n); \
57 (result) = (GC_PTR) op; \
62 /* The same for atomic objects: */
63 # define GC_MALLOC_ATOMIC_WORDS(result,n) \
66 register ptr_t *opp; \
69 opp = &(GC_aobjfreelist[n]); \
71 if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) { \
73 (result) = GC_generic_malloc_words_small((n), PTRFREE); \
75 *opp = obj_link(op); \
77 GC_words_allocd += (n); \
79 (result) = (GC_PTR) op; \
83 /* And once more for two word initialized objects: */
84 # define GC_CONS(result, first, second) \
87 register ptr_t *opp; \
90 opp = &(GC_objfreelist[2]); \
92 if( !FASTLOCK_SUCCEEDED() || (op = *opp) == 0 ) { \
94 op = GC_generic_malloc_words_small(2, NORMAL); \
96 *opp = obj_link(op); \
97 GC_words_allocd += 2; \
100 ((word *)op)[0] = (word)(first); \
101 ((word *)op)[1] = (word)(second); \
102 (result) = (GC_PTR) op; \