Mercurial > hg > xemacs-beta
comparison src/alloc.c @ 2666:7bf1f40e6acb
[xemacs-hg @ 2005-03-15 11:56:32 by crestani]
* alloc.c: Dynamically allocate KKCC backtrace stack and some
minor typo-fixes for KKCC functions.
* alloc.c (lispdesc_indirect_count_1): Condition kkcc_backtrace on
DEBUG_XEMACS.
* alloc.c (kkcc_bt_init): New.
* alloc.c (kkcc_bt_stack_realloc): New.
* alloc.c (kkcc_bt_free): New.
* alloc.c (kkcc_bt_push): If stack size is exhausted, realloc the
stack.
* alloc.c (kkcc_marking): Init and free backtrace stack.
author | crestani |
---|---|
date | Tue, 15 Mar 2005 11:56:35 +0000 |
parents | 674ee2dfe5fc |
children | 6fa9919a9a0b |
comparison
equal
deleted
inserted
replaced
2665:bac3173b2665 | 2666:7bf1f40e6acb |
---|---|
3089 count = * (long *) irdata; | 3089 count = * (long *) irdata; |
3090 break; | 3090 break; |
3091 default: | 3091 default: |
3092 stderr_out ("Unsupported count type : %d (line = %d, code = %ld)\n", | 3092 stderr_out ("Unsupported count type : %d (line = %d, code = %ld)\n", |
3093 idesc[line].type, line, (long) code); | 3093 idesc[line].type, line, (long) code); |
3094 #ifdef USE_KKCC | 3094 #if defined(USE_KKCC) && defined(DEBUG_XEMACS) |
3095 if (gc_in_progress) | 3095 if (gc_in_progress) |
3096 kkcc_backtrace (); | 3096 kkcc_backtrace (); |
3097 #endif | 3097 #endif |
3098 #ifdef PDUMP | 3098 #ifdef PDUMP |
3099 if (in_pdump) | 3099 if (in_pdump) |
3298 #ifdef USE_KKCC | 3298 #ifdef USE_KKCC |
3299 /* The following functions implement the new mark algorithm. | 3299 /* The following functions implement the new mark algorithm. |
3300 They mark objects according to their descriptions. They | 3300 They mark objects according to their descriptions. They |
3301 are modeled on the corresponding pdumper procedures. */ | 3301 are modeled on the corresponding pdumper procedures. */ |
3302 | 3302 |
3303 /* Object memory descriptions are in the lrecord_implementation structure. | 3303 #ifdef DEBUG_XEMACS |
3304 But copying them to a parallel array is much more cache-friendly. */ | 3304 /* The backtrace for the KKCC mark functions. */ |
3305 const struct memory_description *lrecord_memory_descriptions[countof (lrecord_implementations_table)]; | 3305 #define KKCC_INIT_BT_STACK_SIZE 4096 |
3306 | |
3307 /* the initial stack size in kkcc_gc_stack_entries */ | |
3308 #define KKCC_INIT_GC_STACK_SIZE 16384 | |
3309 | 3306 |
3310 typedef struct | 3307 typedef struct |
3311 { | |
3312 void *data; | |
3313 const struct memory_description *desc; | |
3314 #ifdef DEBUG_XEMACS | |
3315 int level; | |
3316 int pos; | |
3317 #endif | |
3318 } kkcc_gc_stack_entry; | |
3319 | |
3320 static kkcc_gc_stack_entry *kkcc_gc_stack_ptr; | |
3321 static kkcc_gc_stack_entry *kkcc_gc_stack_top; | |
3322 static kkcc_gc_stack_entry *kkcc_gc_stack_last_entry; | |
3323 static int kkcc_gc_stack_size; | |
3324 | |
3325 #ifdef DEBUG_XEMACS | |
3326 #define KKCC_BT_STACK_SIZE 524288 | |
3327 | |
3328 static struct | |
3329 { | 3308 { |
3330 void *obj; | 3309 void *obj; |
3331 const struct memory_description *desc; | 3310 const struct memory_description *desc; |
3332 int pos; | 3311 int pos; |
3333 } kkcc_bt[KKCC_BT_STACK_SIZE]; | 3312 } kkcc_bt_stack_entry; |
3334 | 3313 |
3314 static kkcc_bt_stack_entry *kkcc_bt; | |
3315 static int kkcc_bt_stack_size; | |
3335 static int kkcc_bt_depth = 0; | 3316 static int kkcc_bt_depth = 0; |
3336 | 3317 |
3337 #define KKCC_BT_INIT() kkcc_bt_depth = 0; | 3318 static void |
3319 kkcc_bt_init (void) | |
3320 { | |
3321 kkcc_bt_depth = 0; | |
3322 kkcc_bt_stack_size = KKCC_INIT_BT_STACK_SIZE; | |
3323 kkcc_bt = (kkcc_bt_stack_entry *) | |
3324 malloc (kkcc_bt_stack_size * sizeof (kkcc_bt_stack_entry)); | |
3325 if (!kkcc_bt) | |
3326 { | |
3327 stderr_out ("KKCC backtrace stack init failed for size %d\n", | |
3328 kkcc_bt_stack_size); | |
3329 ABORT (); | |
3330 } | |
3331 } | |
3338 | 3332 |
3339 void | 3333 void |
3340 kkcc_backtrace (void) | 3334 kkcc_backtrace (void) |
3341 { | 3335 { |
3342 int i; | 3336 int i; |
3365 stderr_out ("root set)\n"); | 3359 stderr_out ("root set)\n"); |
3366 } | 3360 } |
3367 } | 3361 } |
3368 | 3362 |
3369 static void | 3363 static void |
3364 kkcc_bt_stack_realloc (void) | |
3365 { | |
3366 kkcc_bt_stack_size *= 2; | |
3367 kkcc_bt = (kkcc_bt_stack_entry *) | |
3368 realloc (kkcc_bt, kkcc_bt_stack_size * sizeof (kkcc_bt_stack_entry)); | |
3369 if (!kkcc_bt) | |
3370 { | |
3371 stderr_out ("KKCC backtrace stack realloc failed for size %d\n", | |
3372 kkcc_bt_stack_size); | |
3373 ABORT (); | |
3374 } | |
3375 } | |
3376 | |
3377 static void | |
3378 kkcc_bt_free (void) | |
3379 { | |
3380 free (kkcc_bt); | |
3381 kkcc_bt = 0; | |
3382 kkcc_bt_stack_size = 0; | |
3383 } | |
3384 | |
3385 static void | |
3370 kkcc_bt_push (void *obj, const struct memory_description *desc, | 3386 kkcc_bt_push (void *obj, const struct memory_description *desc, |
3371 int level, int pos) | 3387 int level, int pos) |
3372 { | 3388 { |
3373 kkcc_bt_depth = level; | 3389 kkcc_bt_depth = level; |
3374 kkcc_bt[kkcc_bt_depth].obj = obj; | 3390 kkcc_bt[kkcc_bt_depth].obj = obj; |
3375 kkcc_bt[kkcc_bt_depth].desc = desc; | 3391 kkcc_bt[kkcc_bt_depth].desc = desc; |
3376 kkcc_bt[kkcc_bt_depth].pos = pos; | 3392 kkcc_bt[kkcc_bt_depth].pos = pos; |
3377 kkcc_bt_depth++; | 3393 kkcc_bt_depth++; |
3378 if (kkcc_bt_depth > KKCC_BT_STACK_SIZE) | 3394 if (kkcc_bt_depth >= kkcc_bt_stack_size) |
3379 { | 3395 kkcc_bt_stack_realloc (); |
3380 stderr_out ("KKCC backtrace overflow, adjust KKCC_BT_STACK_SIZE.\n"); | |
3381 stderr_out ("Maybe it is a loop?\n"); | |
3382 ABORT (); | |
3383 } | |
3384 } | 3396 } |
3385 | 3397 |
3386 #else /* not DEBUG_XEMACS */ | 3398 #else /* not DEBUG_XEMACS */ |
3387 #define KKCC_BT_INIT() | 3399 #define kkcc_bt_init() |
3388 #define kkcc_bt_push(obj, desc, level, pos) | 3400 #define kkcc_bt_push(obj, desc, level, pos) |
3389 #endif /* not DEBUG_XEMACS */ | 3401 #endif /* not DEBUG_XEMACS */ |
3402 | |
3403 /* Object memory descriptions are in the lrecord_implementation structure. | |
3404 But copying them to a parallel array is much more cache-friendly. */ | |
3405 const struct memory_description *lrecord_memory_descriptions[countof (lrecord_implementations_table)]; | |
3406 | |
3407 /* the initial stack size in kkcc_gc_stack_entries */ | |
3408 #define KKCC_INIT_GC_STACK_SIZE 16384 | |
3409 | |
3410 typedef struct | |
3411 { | |
3412 void *data; | |
3413 const struct memory_description *desc; | |
3414 #ifdef DEBUG_XEMACS | |
3415 int level; | |
3416 int pos; | |
3417 #endif | |
3418 } kkcc_gc_stack_entry; | |
3419 | |
3420 static kkcc_gc_stack_entry *kkcc_gc_stack_ptr; | |
3421 static kkcc_gc_stack_entry *kkcc_gc_stack_top; | |
3422 static kkcc_gc_stack_entry *kkcc_gc_stack_last_entry; | |
3423 static int kkcc_gc_stack_size; | |
3390 | 3424 |
3391 static void | 3425 static void |
3392 kkcc_gc_stack_init (void) | 3426 kkcc_gc_stack_init (void) |
3393 { | 3427 { |
3394 kkcc_gc_stack_size = KKCC_INIT_GC_STACK_SIZE; | 3428 kkcc_gc_stack_size = KKCC_INIT_GC_STACK_SIZE; |
3395 kkcc_gc_stack_ptr = (kkcc_gc_stack_entry *) | 3429 kkcc_gc_stack_ptr = (kkcc_gc_stack_entry *) |
3396 malloc (kkcc_gc_stack_size * sizeof (kkcc_gc_stack_entry)); | 3430 malloc (kkcc_gc_stack_size * sizeof (kkcc_gc_stack_entry)); |
3397 if (!kkcc_gc_stack_ptr) | 3431 if (!kkcc_gc_stack_ptr) |
3398 { | 3432 { |
3399 stderr_out ("stack init failed for size %d\n", kkcc_gc_stack_size); | 3433 stderr_out ("stack init failed for size %d\n", kkcc_gc_stack_size); |
3400 exit(23); | 3434 ABORT (); |
3401 } | 3435 } |
3402 kkcc_gc_stack_top = kkcc_gc_stack_ptr - 1; | 3436 kkcc_gc_stack_top = kkcc_gc_stack_ptr - 1; |
3403 kkcc_gc_stack_last_entry = kkcc_gc_stack_ptr + kkcc_gc_stack_size - 1; | 3437 kkcc_gc_stack_last_entry = kkcc_gc_stack_ptr + kkcc_gc_stack_size - 1; |
3404 } | 3438 } |
3405 | 3439 |
3421 realloc (kkcc_gc_stack_ptr, | 3455 realloc (kkcc_gc_stack_ptr, |
3422 kkcc_gc_stack_size * sizeof (kkcc_gc_stack_entry)); | 3456 kkcc_gc_stack_size * sizeof (kkcc_gc_stack_entry)); |
3423 if (!kkcc_gc_stack_ptr) | 3457 if (!kkcc_gc_stack_ptr) |
3424 { | 3458 { |
3425 stderr_out ("stack realloc failed for size %d\n", kkcc_gc_stack_size); | 3459 stderr_out ("stack realloc failed for size %d\n", kkcc_gc_stack_size); |
3426 exit(23); | 3460 ABORT (); |
3427 } | 3461 } |
3428 kkcc_gc_stack_top = kkcc_gc_stack_ptr + current_offset; | 3462 kkcc_gc_stack_top = kkcc_gc_stack_ptr + current_offset; |
3429 kkcc_gc_stack_last_entry = kkcc_gc_stack_ptr + kkcc_gc_stack_size - 1; | 3463 kkcc_gc_stack_last_entry = kkcc_gc_stack_ptr + kkcc_gc_stack_size - 1; |
3430 } | 3464 } |
3431 | 3465 |
3482 GC_CHECK_LHEADER_INVARIANTS (lheader); | 3516 GC_CHECK_LHEADER_INVARIANTS (lheader); |
3483 desc = RECORD_DESCRIPTION (lheader); | 3517 desc = RECORD_DESCRIPTION (lheader); |
3484 if (! MARKED_RECORD_HEADER_P (lheader)) | 3518 if (! MARKED_RECORD_HEADER_P (lheader)) |
3485 { | 3519 { |
3486 MARK_RECORD_HEADER (lheader); | 3520 MARK_RECORD_HEADER (lheader); |
3487 kkcc_gc_stack_push((void*) lheader, desc, level, pos); | 3521 kkcc_gc_stack_push ((void*) lheader, desc, level, pos); |
3488 } | 3522 } |
3489 } | 3523 } |
3490 } | 3524 } |
3491 | 3525 |
3492 #ifdef DEBUG_XEMACS | 3526 #ifdef DEBUG_XEMACS |
3581 void *data = 0; | 3615 void *data = 0; |
3582 const struct memory_description *desc = 0; | 3616 const struct memory_description *desc = 0; |
3583 int pos; | 3617 int pos; |
3584 #ifdef DEBUG_XEMACS | 3618 #ifdef DEBUG_XEMACS |
3585 int level = 0; | 3619 int level = 0; |
3586 KKCC_BT_INIT (); | 3620 kkcc_bt_init (); |
3587 #endif | 3621 #endif |
3588 | 3622 |
3589 while ((stack_entry = kkcc_gc_stack_pop ()) != 0) | 3623 while ((stack_entry = kkcc_gc_stack_pop ()) != 0) |
3590 { | 3624 { |
3591 data = stack_entry->data; | 3625 data = stack_entry->data; |
3689 kkcc_backtrace (); | 3723 kkcc_backtrace (); |
3690 ABORT (); | 3724 ABORT (); |
3691 } | 3725 } |
3692 } | 3726 } |
3693 } | 3727 } |
3728 #ifdef DEBUG_XEMACS | |
3729 kkcc_bt_free (); | |
3730 #endif | |
3694 } | 3731 } |
3695 #endif /* USE_KKCC */ | 3732 #endif /* USE_KKCC */ |
3696 | 3733 |
3697 /* Mark reference to a Lisp_Object. If the object referred to has not been | 3734 /* Mark reference to a Lisp_Object. If the object referred to has not been |
3698 seen yet, recursively mark all the references contained in it. */ | 3735 seen yet, recursively mark all the references contained in it. */ |