Fix ia64 execute/930630-1.c miscompilation.
[official-gcc.git] / boehm-gc / gc_typed.h
blobe4a6b94756e767ab79281b2c1245b9ebc3cda939
1 /*
2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4 * Copyright 1996 Silicon Graphics. All rights reserved.
6 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
7 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
9 * Permission is hereby granted to use or copy this program
10 * for any purpose, provided the above notices are retained on all copies.
11 * Permission to modify the code and to distribute modified code is granted,
12 * provided the above notices are retained, and a notice that the code was
13 * modified is included with the above copyright notice.
16 * Some simple primitives for allocation with explicit type information.
17 * Facilities for dynamic type inference may be added later.
18 * Should be used only for extremely performance critical applications,
19 * or if conservative collector leakage is otherwise a problem (unlikely).
20 * Note that this is implemented completely separately from the rest
21 * of the collector, and is not linked in unless referenced.
22 * This does not currently support GC_DEBUG in any interesting way.
24 /* Boehm, May 19, 1994 2:13 pm PDT */
26 #ifndef _GC_TYPED_H
27 # define _GC_TYPED_H
28 # ifndef _GC_H
29 # include "gc.h"
30 # endif
32 typedef GC_word * GC_bitmap;
33 /* The least significant bit of the first word is one if */
34 /* the first word in the object may be a pointer. */
36 # define GC_get_bit(bm, index) \
37 (((bm)[divWORDSZ(index)] >> modWORDSZ(index)) & 1)
38 # define GC_set_bit(bm, index) \
39 (bm)[divWORDSZ(index)] |= (word)1 << modWORDSZ(index)
41 typedef GC_word GC_descr;
43 GC_API GC_descr GC_make_descriptor GC_PROTO((GC_bitmap bm, size_t len));
44 /* Return a type descriptor for the object whose layout */
45 /* is described by the argument. */
46 /* The least significant bit of the first word is one */
47 /* if the first word in the object may be a pointer. */
48 /* The second argument specifies the number of */
49 /* meaningful bits in the bitmap. The actual object */
50 /* may be larger (but not smaller). Any additional */
51 /* words in the object are assumed not to contain */
52 /* pointers. */
53 /* Returns a conservative approximation in the */
54 /* (unlikely) case of insufficient memory to build */
55 /* the descriptor. Calls to GC_make_descriptor */
56 /* may consume some amount of a finite resource. This */
57 /* is intended to be called once per type, not once */
58 /* per allocation. */
60 GC_API GC_PTR GC_malloc_explicitly_typed
61 GC_PROTO((size_t size_in_bytes, GC_descr d));
62 /* Allocate an object whose layout is described by d. */
63 /* The resulting object MAY NOT BE PASSED TO REALLOC. */
65 GC_API GC_PTR GC_malloc_explicitly_typed_ignore_off_page
66 GC_PROTO((size_t size_in_bytes, GC_descr d));
68 GC_API GC_PTR GC_calloc_explicitly_typed
69 GC_PROTO((size_t nelements,
70 size_t element_size_in_bytes,
71 GC_descr d));
72 /* Allocate an array of nelements elements, each of the */
73 /* given size, and with the given descriptor. */
74 /* The elemnt size must be a multiple of the byte */
75 /* alignment required for pointers. E.g. on a 32-bit */
76 /* machine with 16-bit aligned pointers, size_in_bytes */
77 /* must be a multiple of 2. */
79 #ifdef GC_DEBUG
80 # define GC_MALLOC_EXPLICTLY_TYPED(bytes, d) GC_MALLOC(bytes)
81 # define GC_CALLOC_EXPLICTLY_TYPED(n, bytes, d) GC_MALLOC(n*bytes)
82 #else
83 # define GC_MALLOC_EXPLICTLY_TYPED(bytes, d) \
84 GC_malloc_explicitly_typed(bytes, d)
85 # define GC_CALLOC_EXPLICTLY_TYPED(n, bytes, d) \
86 GC_calloc_explicitly_typed(n, bytes, d)
87 #endif /* !GC_DEBUG */
90 #endif /* _GC_TYPED_H */