~ubuntu-branches/ubuntu/quantal/libgc/quantal

« back to all changes in this revision

Viewing changes to new_hblk.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-19 12:19:56 UTC
  • mfrom: (1.3.2 upstream) (0.1.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110219121956-67rb69xlt5nud3v2
Tags: 1:7.1-5
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * This file contains the functions:
16
16
 *      ptr_t GC_build_flXXX(h, old_fl)
17
 
 *      void GC_new_hblk(n)
 
17
 *      void GC_new_hblk(size)
18
18
 */
19
19
/* Boehm, May 19, 1994 2:09 pm PDT */
20
20
 
24
24
 
25
25
#ifndef SMALL_CONFIG
26
26
/*
27
 
 * Build a free list for size 1 objects inside hblk h.  Set the last link to
 
27
 * Build a free list for size 2 (words) cleared objects inside hblk h.
 
28
 * Set the last link to
28
29
 * be ofl.  Return a pointer tpo the first free list entry.
29
30
 */
30
 
ptr_t GC_build_fl1(h, ofl)
31
 
struct hblk *h;
32
 
ptr_t ofl;
33
 
{
34
 
    register word * p = h -> hb_body;
35
 
    register word * lim = (word *)(h + 1);
36
 
    
37
 
    p[0] = (word)ofl;
38
 
    p[1] = (word)(p);
39
 
    p[2] = (word)(p+1);
40
 
    p[3] = (word)(p+2);
41
 
    p += 4;
42
 
    for (; p < lim; p += 4) {
43
 
        p[0] = (word)(p-1);
44
 
        p[1] = (word)(p);
45
 
        p[2] = (word)(p+1);
46
 
        p[3] = (word)(p+2);
47
 
    };
48
 
    return((ptr_t)(p-1));
49
 
}
50
 
 
51
 
/* The same for size 2 cleared objects */
52
 
ptr_t GC_build_fl_clear2(h, ofl)
53
 
struct hblk *h;
54
 
ptr_t ofl;
55
 
{
56
 
    register word * p = h -> hb_body;
57
 
    register word * lim = (word *)(h + 1);
 
31
ptr_t GC_build_fl_clear2(struct hblk *h, ptr_t ofl)
 
32
{
 
33
    word * p = (word *)(h -> hb_body);
 
34
    word * lim = (word *)(h + 1);
58
35
    
59
36
    p[0] = (word)ofl;
60
37
    p[1] = 0;
70
47
    return((ptr_t)(p-2));
71
48
}
72
49
 
73
 
/* The same for size 3 cleared objects */
74
 
ptr_t GC_build_fl_clear3(h, ofl)
75
 
struct hblk *h;
76
 
ptr_t ofl;
77
 
{
78
 
    register word * p = h -> hb_body;
79
 
    register word * lim = (word *)(h + 1) - 2;
80
 
    
81
 
    p[0] = (word)ofl;
82
 
    p[1] = 0;
83
 
    p[2] = 0;
84
 
    p += 3;
85
 
    for (; p < lim; p += 3) {
86
 
        p[0] = (word)(p-3);
87
 
        p[1] = 0;
88
 
        p[2] = 0;
89
 
    };
90
 
    return((ptr_t)(p-3));
91
 
}
92
 
 
93
50
/* The same for size 4 cleared objects */
94
 
ptr_t GC_build_fl_clear4(h, ofl)
95
 
struct hblk *h;
96
 
ptr_t ofl;
 
51
ptr_t GC_build_fl_clear4(struct hblk *h, ptr_t ofl)
97
52
{
98
 
    register word * p = h -> hb_body;
99
 
    register word * lim = (word *)(h + 1);
 
53
    word * p = (word *)(h -> hb_body);
 
54
    word * lim = (word *)(h + 1);
100
55
    
101
56
    p[0] = (word)ofl;
102
57
    p[1] = 0;
113
68
}
114
69
 
115
70
/* The same for size 2 uncleared objects */
116
 
ptr_t GC_build_fl2(h, ofl)
117
 
struct hblk *h;
118
 
ptr_t ofl;
 
71
ptr_t GC_build_fl2(struct hblk *h, ptr_t ofl)
119
72
{
120
 
    register word * p = h -> hb_body;
121
 
    register word * lim = (word *)(h + 1);
 
73
    word * p = (word *)(h -> hb_body);
 
74
    word * lim = (word *)(h + 1);
122
75
    
123
76
    p[0] = (word)ofl;
124
77
    p[2] = (word)p;
131
84
}
132
85
 
133
86
/* The same for size 4 uncleared objects */
134
 
ptr_t GC_build_fl4(h, ofl)
135
 
struct hblk *h;
136
 
ptr_t ofl;
 
87
ptr_t GC_build_fl4(struct hblk *h, ptr_t ofl)
137
88
{
138
 
    register word * p = h -> hb_body;
139
 
    register word * lim = (word *)(h + 1);
 
89
    word * p = (word *)(h -> hb_body);
 
90
    word * lim = (word *)(h + 1);
140
91
    
141
92
    p[0] = (word)ofl;
142
93
    p[4] = (word)p;
158
109
/* This could be called without the main GC lock, if we ensure that     */
159
110
/* there is no concurrent collection which might reclaim objects that   */
160
111
/* we have not yet allocated.                                           */
161
 
ptr_t GC_build_fl(h, sz, clear, list)
162
 
struct hblk *h;
163
 
word sz;
164
 
GC_bool clear;
165
 
ptr_t list;
 
112
ptr_t GC_build_fl(struct hblk *h, size_t sz, GC_bool clear, ptr_t list)
166
113
{
167
114
  word *p, *prev;
168
115
  word *last_object;            /* points to last object in new hblk    */
179
126
  /* the difference is less significant.                                */
180
127
#  ifndef SMALL_CONFIG
181
128
    switch (sz) {
182
 
        case 1: return GC_build_fl1(h, list);
183
129
        case 2: if (clear) {
184
130
                    return GC_build_fl_clear2(h, list);
185
131
                } else {
186
132
                    return GC_build_fl2(h, list);
187
133
                }
188
 
        case 3: if (clear) {
189
 
                    return GC_build_fl_clear3(h, list);
190
 
                } else {
191
 
                    /* It's messy to do better than the default here. */
192
 
                    break;
193
 
                }
194
134
        case 4: if (clear) {
195
135
                    return GC_build_fl_clear4(h, list);
196
136
                } else {
205
145
    if (clear) BZERO(h, HBLKSIZE);
206
146
    
207
147
  /* Add objects to free list */
208
 
    p = &(h -> hb_body[sz]);    /* second object in *h  */
209
 
    prev = &(h -> hb_body[0]);          /* One object behind p  */
 
148
    p = (word *)(h -> hb_body) + sz;    /* second object in *h  */
 
149
    prev = (word *)(h -> hb_body);              /* One object behind p  */
210
150
    last_object = (word *)((char *)h + HBLKSIZE);
211
151
    last_object -= sz;
212
152
                            /* Last place for last object to start */
228
168
      return ((ptr_t)p);
229
169
}
230
170
 
 
171
 
231
172
/*
232
 
 * Allocate a new heapblock for small objects of size n.
 
173
 * Allocate a new heapblock for small objects of size gran granules.
233
174
 * Add all of the heapblock's objects to the free list for objects
234
175
 * of that size.
235
176
 * Set all mark bits if objects are uncollectable.
236
177
 * Will fail to do anything if we are out of memory.
237
178
 */
238
 
void GC_new_hblk(sz, kind)
239
 
register word sz;
240
 
int kind;
 
179
void GC_new_hblk(size_t gran, int kind)
241
180
{
242
 
    register struct hblk *h;    /* the new heap block                   */
243
 
    register GC_bool clear = GC_obj_kinds[kind].ok_init;
 
181
  struct hblk *h;       /* the new heap block                   */
 
182
  GC_bool clear = GC_obj_kinds[kind].ok_init;
244
183
 
245
 
#   ifdef PRINTSTATS
246
 
        if ((sizeof (struct hblk)) > HBLKSIZE) {
247
 
            ABORT("HBLK SZ inconsistency");
248
 
        }
249
 
#   endif
 
184
  /* Ignore gcc "no effect" warning on the following: */
 
185
  GC_STATIC_ASSERT((sizeof (struct hblk)) == HBLKSIZE);
 
186
  
250
187
  if (GC_debugging_started) clear = TRUE;
251
188
 
252
189
  /* Allocate a new heap block */
253
 
    h = GC_allochblk(sz, kind, 0);
 
190
    h = GC_allochblk(GRANULES_TO_BYTES(gran), kind, 0);
254
191
    if (h == 0) return;
255
192
 
256
193
  /* Mark all objects if appropriate. */
257
194
      if (IS_UNCOLLECTABLE(kind)) GC_set_hdr_marks(HDR(h));
258
195
 
259
196
  /* Build the free list */
260
 
      GC_obj_kinds[kind].ok_freelist[sz] =
261
 
        GC_build_fl(h, sz, clear, GC_obj_kinds[kind].ok_freelist[sz]);
 
197
      GC_obj_kinds[kind].ok_freelist[gran] =
 
198
        GC_build_fl(h, GRANULES_TO_WORDS(gran), clear,
 
199
                    GC_obj_kinds[kind].ok_freelist[gran]);
262
200
}
263
201