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.
5
5
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6
6
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
60
60
GC_init(); /* In case it's not already done. */
63
62
if (GC_gcj_malloc_initialized) {
68
66
GC_gcj_malloc_initialized = TRUE;
69
67
ignore_gcj_info = (0 != GETENV("GC_IGNORE_GCJ_INFO"));
71
if (GC_print_stats && ignore_gcj_info) {
72
GC_printf0("Gcj-style type information is disabled!\n");
68
if (GC_print_stats && ignore_gcj_info) {
69
GC_log_printf("Gcj-style type information is disabled!\n");
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");
109
ptr_t GC_clear_stack();
104
void * GC_clear_stack(void *);
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))
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))
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)
137
void * GC_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr)
142
register ptr_t * opp;
146
if( EXPECT(SMALL_OBJ(lb), 1) ) {
148
lw = GC_size_map[lb];
150
lw = ALIGNED_WORDS(lb);
152
opp = &(GC_gcjobjfreelist[lw]);
146
lg = GC_size_map[lb];
147
opp = &(GC_gcjobjfreelist[lg]);
155
150
if(EXPECT(op == 0, 0)) {
180
172
*(void **)op = ptr_to_struct_containing_descr;
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,
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) {
200
GC_err_printf2("GC_debug_gcj_malloc(%ld, 0x%lx) returning NIL (",
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);
204
GC_err_printf1(":%ld)\n", (unsigned long)i);
195
GC_err_printf(":%d)\n", i);
205
196
return(GC_oom_fn(lb));
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));
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)
225
opp = &(GC_gcjobjfreelist[lw]);
228
if( EXPECT(op == 0, 0) ) {
230
op = (ptr_t)GC_clear_stack(
231
GC_generic_malloc_words_small_inner(lw, GC_gcj_kind));
234
return GC_oom_fn(WORDS_TO_BYTES(lw));
238
GC_words_allocd += lw;
240
*(void **)op = ptr_to_struct_containing_descr;
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,
251
size_t lb = WORDS_TO_BYTES(lw);
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. */
258
result = GC_generic_malloc_inner(lb + DEBUG_BYTES, GC_gcj_debug_kind);
261
GC_err_printf2("GC_debug_gcj_fast_malloc(%ld, 0x%lx) returning NIL (",
263
(unsigned long) ptr_to_struct_containing_descr);
265
GC_err_printf1(":%ld)\n", (unsigned long)i);
266
return GC_oom_fn(WORDS_TO_BYTES(lw));
268
*((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
270
if (!GC_debugging_started) {
271
GC_start_debugging();
273
ADD_CALL_CHAIN(result, ra);
274
return (GC_store_debug_info(result, (word)lb, s, (word)i));
277
207
void * GC_gcj_malloc_ignore_off_page(size_t lb,
278
208
void * ptr_to_struct_containing_descr)
281
register ptr_t * opp;
285
if( SMALL_OBJ(lb) ) {
287
lw = GC_size_map[lb];
289
lw = ALIGNED_WORDS(lb);
291
opp = &(GC_gcjobjfreelist[lw]);
216
lg = GC_size_map[lb];
217
opp = &(GC_gcjobjfreelist[lg]);
293
219
if( (op = *opp) == 0 ) {
294
220
maybe_finalize();
295
221
op = (ptr_t)GENERAL_MALLOC_IOP(lb, GC_gcj_kind);
297
lw = GC_size_map[lb]; /* May have been uninitialized. */
222
lg = GC_size_map[lb]; /* May have been uninitialized. */
300
224
*opp = obj_link(op);
301
GC_words_allocd += lw;
225
GC_bytes_allocd += GRANULES_TO_BYTES(lg);
303
227
*(void **)op = ptr_to_struct_containing_descr;