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

« back to all changes in this revision

Viewing changes to gcj_mlc.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:
1
1
/*
2
2
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
3
 
 * Copyright (c) 1999 by Hewlett-Packard Company.  All rights reserved.
 
3
 * Copyright (c) 1999-2004 Hewlett-Packard Development Company, L.P.
4
4
 *
5
5
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6
6
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
58
58
    DCL_LOCK_STATE;
59
59
 
60
60
    GC_init();  /* In case it's not already done.       */
61
 
    DISABLE_SIGNALS();
62
61
    LOCK();
63
62
    if (GC_gcj_malloc_initialized) {
64
63
      UNLOCK();
65
 
      ENABLE_SIGNALS();
66
64
      return;
67
65
    }
68
66
    GC_gcj_malloc_initialized = TRUE;
69
67
    ignore_gcj_info = (0 != GETENV("GC_IGNORE_GCJ_INFO"));
70
 
#   ifdef CONDPRINT
71
 
      if (GC_print_stats && ignore_gcj_info) {
72
 
        GC_printf0("Gcj-style type information is disabled!\n");
73
 
      }
74
 
#   endif
 
68
    if (GC_print_stats && ignore_gcj_info) {
 
69
        GC_log_printf("Gcj-style type information is disabled!\n");
 
70
    }
75
71
    GC_ASSERT(GC_mark_procs[mp_index] == (GC_mark_proc)0); /* unused */
76
72
    GC_mark_procs[mp_index] = (GC_mark_proc)mp;
77
73
    if (mp_index >= GC_n_mark_procs) ABORT("GC_init_gcj_malloc: bad index");
103
99
                                FALSE, TRUE);
104
100
      }
105
101
    UNLOCK();
106
 
    ENABLE_SIGNALS();
107
102
}
108
103
 
109
 
ptr_t GC_clear_stack();
 
104
void * GC_clear_stack(void *);
110
105
 
111
106
#define GENERAL_MALLOC(lb,k) \
112
 
    (GC_PTR)GC_clear_stack(GC_generic_malloc_inner((word)lb, k))
 
107
    GC_clear_stack(GC_generic_malloc_inner((word)lb, k))
113
108
    
114
109
#define GENERAL_MALLOC_IOP(lb,k) \
115
 
    (GC_PTR)GC_clear_stack(GC_generic_malloc_inner_ignore_off_page(lb, k))
 
110
    GC_clear_stack(GC_generic_malloc_inner_ignore_off_page(lb, k))
116
111
 
117
112
/* We need a mechanism to release the lock and invoke finalizers.       */
118
113
/* We don't really have an opportunity to do this on a rarely executed  */
136
131
/* Allocate an object, clear it, and store the pointer to the   */
137
132
/* type structure (vtable in gcj).                              */
138
133
/* This adds a byte at the end of the object if GC_malloc would.*/
139
 
void * GC_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr)
 
134
#ifdef THREAD_LOCAL_ALLOC
 
135
  void * GC_core_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr)
 
136
#else
 
137
  void * GC_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr)
 
138
#endif
140
139
{
141
 
register ptr_t op;
142
 
register ptr_t * opp;
143
 
register word lw;
144
 
DCL_LOCK_STATE;
 
140
    ptr_t op;
 
141
    ptr_t * opp;
 
142
    word lg;
 
143
    DCL_LOCK_STATE;
145
144
 
146
 
    if( EXPECT(SMALL_OBJ(lb), 1) ) {
147
 
#       ifdef MERGE_SIZES
148
 
          lw = GC_size_map[lb];
149
 
#       else
150
 
          lw = ALIGNED_WORDS(lb);
151
 
#       endif
152
 
        opp = &(GC_gcjobjfreelist[lw]);
 
145
    if(SMALL_OBJ(lb)) {
 
146
        lg = GC_size_map[lb];
 
147
        opp = &(GC_gcjobjfreelist[lg]);
153
148
        LOCK();
154
149
        op = *opp;
155
150
        if(EXPECT(op == 0, 0)) {
159
154
                UNLOCK();
160
155
                return(GC_oom_fn(lb));
161
156
            }
162
 
#           ifdef MERGE_SIZES
163
 
                lw = GC_size_map[lb];   /* May have been uninitialized. */
164
 
#           endif
165
157
        } else {
166
158
            *opp = obj_link(op);
167
 
            GC_words_allocd += lw;
 
159
            GC_bytes_allocd += GRANULES_TO_BYTES(lg);
168
160
        }
169
161
        *(void **)op = ptr_to_struct_containing_descr;
170
162
        GC_ASSERT(((void **)op)[1] == 0);
180
172
        *(void **)op = ptr_to_struct_containing_descr;
181
173
        UNLOCK();
182
174
    }
183
 
    return((GC_PTR) op);
 
175
    return((void *) op);
184
176
}
185
177
 
186
178
/* Similar to GC_gcj_malloc, but add debug info.  This is allocated     */
187
179
/* with GC_gcj_debug_kind.                                              */
188
 
GC_PTR GC_debug_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr,
 
180
void * GC_debug_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr,
189
181
                           GC_EXTRA_PARAMS)
190
182
{
191
 
    GC_PTR result;
 
183
    void * result;
192
184
 
193
185
    /* We're careful to avoid extra calls, which could           */
194
186
    /* confuse the backtrace.                                   */
197
189
    result = GC_generic_malloc_inner(lb + DEBUG_BYTES, GC_gcj_debug_kind);
198
190
    if (result == 0) {
199
191
        UNLOCK();
200
 
        GC_err_printf2("GC_debug_gcj_malloc(%ld, 0x%lx) returning NIL (",
201
 
                       (unsigned long) lb,
202
 
                       (unsigned long) ptr_to_struct_containing_descr);
 
192
        GC_err_printf("GC_debug_gcj_malloc(%ld, %p) returning NIL (",
 
193
                      (unsigned long)lb, ptr_to_struct_containing_descr);
203
194
        GC_err_puts(s);
204
 
        GC_err_printf1(":%ld)\n", (unsigned long)i);
 
195
        GC_err_printf(":%d)\n", i);
205
196
        return(GC_oom_fn(lb));
206
197
    }
207
198
    *((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
213
204
    return (GC_store_debug_info(result, (word)lb, s, (word)i));
214
205
}
215
206
 
216
 
/* Similar to GC_gcj_malloc, but the size is in words, and we don't     */
217
 
/* adjust it.  The size is assumed to be such that it can be    */
218
 
/* allocated as a small object.                                 */
219
 
void * GC_gcj_fast_malloc(size_t lw, void * ptr_to_struct_containing_descr)
220
 
{
221
 
ptr_t op;
222
 
ptr_t * opp;
223
 
DCL_LOCK_STATE;
224
 
 
225
 
    opp = &(GC_gcjobjfreelist[lw]);
226
 
    LOCK();
227
 
    op = *opp;
228
 
    if( EXPECT(op == 0, 0) ) {
229
 
        maybe_finalize();
230
 
        op = (ptr_t)GC_clear_stack(
231
 
                GC_generic_malloc_words_small_inner(lw, GC_gcj_kind));
232
 
        if (0 == op) {
233
 
            UNLOCK();
234
 
            return GC_oom_fn(WORDS_TO_BYTES(lw));
235
 
        }
236
 
    } else {
237
 
        *opp = obj_link(op);
238
 
        GC_words_allocd += lw;
239
 
    }
240
 
    *(void **)op = ptr_to_struct_containing_descr;
241
 
    UNLOCK();
242
 
    return((GC_PTR) op);
243
 
}
244
 
 
245
 
/* And a debugging version of the above:        */
246
 
void * GC_debug_gcj_fast_malloc(size_t lw,
247
 
                                void * ptr_to_struct_containing_descr,
248
 
                                GC_EXTRA_PARAMS)
249
 
{
250
 
    GC_PTR result;
251
 
    size_t lb = WORDS_TO_BYTES(lw);
252
 
 
253
 
    /* We clone the code from GC_debug_gcj_malloc, so that we   */
254
 
    /* dont end up with extra frames on the stack, which could  */
255
 
    /* confuse the backtrace.                                   */
256
 
    LOCK();
257
 
    maybe_finalize();
258
 
    result = GC_generic_malloc_inner(lb + DEBUG_BYTES, GC_gcj_debug_kind);
259
 
    if (result == 0) {
260
 
        UNLOCK();
261
 
        GC_err_printf2("GC_debug_gcj_fast_malloc(%ld, 0x%lx) returning NIL (",
262
 
                       (unsigned long) lw,
263
 
                       (unsigned long) ptr_to_struct_containing_descr);
264
 
        GC_err_puts(s);
265
 
        GC_err_printf1(":%ld)\n", (unsigned long)i);
266
 
        return GC_oom_fn(WORDS_TO_BYTES(lw));
267
 
    }
268
 
    *((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
269
 
    UNLOCK();
270
 
    if (!GC_debugging_started) {
271
 
        GC_start_debugging();
272
 
    }
273
 
    ADD_CALL_CHAIN(result, ra);
274
 
    return (GC_store_debug_info(result, (word)lb, s, (word)i));
275
 
}
276
 
 
277
207
void * GC_gcj_malloc_ignore_off_page(size_t lb,
278
208
                                     void * ptr_to_struct_containing_descr) 
279
209
{
280
 
register ptr_t op;
281
 
register ptr_t * opp;
282
 
register word lw;
283
 
DCL_LOCK_STATE;
 
210
    ptr_t op;
 
211
    ptr_t * opp;
 
212
    word lg;
 
213
    DCL_LOCK_STATE;
284
214
 
285
 
    if( SMALL_OBJ(lb) ) {
286
 
#       ifdef MERGE_SIZES
287
 
          lw = GC_size_map[lb];
288
 
#       else
289
 
          lw = ALIGNED_WORDS(lb);
290
 
#       endif
291
 
        opp = &(GC_gcjobjfreelist[lw]);
 
215
    if(SMALL_OBJ(lb)) {
 
216
        lg = GC_size_map[lb];
 
217
        opp = &(GC_gcjobjfreelist[lg]);
292
218
        LOCK();
293
219
        if( (op = *opp) == 0 ) {
294
220
            maybe_finalize();
295
221
            op = (ptr_t)GENERAL_MALLOC_IOP(lb, GC_gcj_kind);
296
 
#           ifdef MERGE_SIZES
297
 
                lw = GC_size_map[lb];   /* May have been uninitialized. */
298
 
#           endif
 
222
            lg = GC_size_map[lb];       /* May have been uninitialized. */
299
223
        } else {
300
224
            *opp = obj_link(op);
301
 
            GC_words_allocd += lw;
 
225
            GC_bytes_allocd += GRANULES_TO_BYTES(lg);
302
226
        }
303
227
        *(void **)op = ptr_to_struct_containing_descr;
304
228
        UNLOCK();
311
235
        }
312
236
        UNLOCK();
313
237
    }
314
 
    return((GC_PTR) op);
 
238
    return((void *) op);
315
239
}
316
240
 
317
241
#else