~ubuntu-branches/ubuntu/hardy/libgc/hardy-updates

« back to all changes in this revision

Viewing changes to mark_rts.c

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Murray
  • Date: 2005-02-03 00:50:53 UTC
  • mto: (3.1.1 etch) (1.2.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050203005053-9c0v9r2qcm2g1cfp
Tags: upstream-6.4
ImportĀ upstreamĀ versionĀ 6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
275
275
}
276
276
 
277
277
/* Internal use only; lock held.        */
 
278
static void GC_remove_root_at_pos(i) 
 
279
int i;
 
280
{
 
281
    GC_root_size -= (GC_static_roots[i].r_end - GC_static_roots[i].r_start);
 
282
    GC_static_roots[i].r_start = GC_static_roots[n_root_sets-1].r_start;
 
283
    GC_static_roots[i].r_end = GC_static_roots[n_root_sets-1].r_end;
 
284
    GC_static_roots[i].r_tmp = GC_static_roots[n_root_sets-1].r_tmp;
 
285
    n_root_sets--;
 
286
}
 
287
 
 
288
#if !defined(MSWIN32) && !defined(MSWINCE)
 
289
static void GC_rebuild_root_index()
 
290
{
 
291
    register int i;
 
292
        
 
293
    for (i = 0; i < RT_SIZE; i++) GC_root_index[i] = 0;
 
294
    for (i = 0; i < n_root_sets; i++)
 
295
        add_roots_to_index(GC_static_roots + i);
 
296
}
 
297
#endif
 
298
 
 
299
/* Internal use only; lock held.        */
278
300
void GC_remove_tmp_roots()
279
301
{
280
302
    register int i;
281
303
    
282
304
    for (i = 0; i < n_root_sets; ) {
283
305
        if (GC_static_roots[i].r_tmp) {
284
 
            GC_root_size -=
285
 
                (GC_static_roots[i].r_end - GC_static_roots[i].r_start);
286
 
            GC_static_roots[i].r_start = GC_static_roots[n_root_sets-1].r_start;
287
 
            GC_static_roots[i].r_end = GC_static_roots[n_root_sets-1].r_end;
288
 
            GC_static_roots[i].r_tmp = GC_static_roots[n_root_sets-1].r_tmp;
289
 
            n_root_sets--;
 
306
            GC_remove_root_at_pos(i);
 
307
        } else {
 
308
            i++;
 
309
    }
 
310
    }
 
311
    #if !defined(MSWIN32) && !defined(MSWINCE)
 
312
    GC_rebuild_root_index();
 
313
    #endif
 
314
}
 
315
 
 
316
#if !defined(MSWIN32) && !defined(MSWINCE)
 
317
void GC_remove_roots(b, e)
 
318
char * b; char * e;
 
319
{
 
320
    DCL_LOCK_STATE;
 
321
    
 
322
    DISABLE_SIGNALS();
 
323
    LOCK();
 
324
    GC_remove_roots_inner(b, e);
 
325
    UNLOCK();
 
326
    ENABLE_SIGNALS();
 
327
}
 
328
 
 
329
/* Should only be called when the lock is held */
 
330
void GC_remove_roots_inner(b,e)
 
331
char * b; char * e;
 
332
{
 
333
    int i;
 
334
    for (i = 0; i < n_root_sets; ) {
 
335
        if (GC_static_roots[i].r_start >= (ptr_t)b && GC_static_roots[i].r_end <= (ptr_t)e) {
 
336
            GC_remove_root_at_pos(i);
290
337
        } else {
291
338
            i++;
292
339
        }
293
340
    }
294
 
#   if !defined(MSWIN32) && !defined(MSWINCE)
295
 
    {
296
 
        register int i;
297
 
        
298
 
        for (i = 0; i < RT_SIZE; i++) GC_root_index[i] = 0;
299
 
        for (i = 0; i < n_root_sets; i++)
300
 
                add_roots_to_index(GC_static_roots + i);
301
 
    }
302
 
#   endif
303
 
    
 
341
    GC_rebuild_root_index();
304
342
}
 
343
#endif /* !defined(MSWIN32) && !defined(MSWINCE) */
305
344
 
306
345
#if defined(MSWIN32) || defined(_WIN32_WCE_EMULATION)
307
346
/* Workaround for the OS mapping and unmapping behind our back:         */
506
545
  void GC_mark_thread_local_free_lists();
507
546
#endif
508
547
 
 
548
void GC_cond_register_dynamic_libraries()
 
549
{
 
550
# if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(MSWINCE) \
 
551
     || defined(PCR)) && !defined(SRC_M3)
 
552
    GC_remove_tmp_roots();
 
553
    if (!GC_no_dls) GC_register_dynamic_libraries();
 
554
# else
 
555
    GC_no_dls = TRUE;
 
556
# endif
 
557
}
 
558
 
509
559
/*
510
560
 * Call the mark routines (GC_tl_push for a single pointer, GC_push_conditional
511
561
 * on groups of pointers) on every top level accessible pointer.
519
569
GC_bool all;
520
570
ptr_t cold_gc_frame;
521
571
{
522
 
    register int i;
 
572
    int i;
 
573
    int kind;
523
574
 
524
575
    /*
525
576
     * Next push static data.  This must happen early on, since it's
526
577
     * not robust against mark stack overflow.
527
578
     */
528
 
     /* Reregister dynamic libraries, in case one got added.    */
529
 
#      if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(MSWINCE) \
530
 
           || defined(PCR)) && !defined(SRC_M3)
531
 
         GC_remove_tmp_roots();
532
 
         if (!GC_no_dls) GC_register_dynamic_libraries();
533
 
#      else
534
 
         GC_no_dls = TRUE;
 
579
     /* Reregister dynamic libraries, in case one got added.            */
 
580
     /* There is some argument for doing this as late as possible,      */
 
581
     /* especially on win32, where it can change asynchronously.        */
 
582
     /* In those cases, we do it here.  But on other platforms, it's    */
 
583
     /* not safe with the world stopped, so we do it earlier.           */
 
584
#      if !defined(REGISTER_LIBRARIES_EARLY)
 
585
         GC_cond_register_dynamic_libraries();
535
586
#      endif
536
587
 
537
588
     /* Mark everything in static data areas                             */
541
592
                             GC_static_roots[i].r_end, all);
542
593
       }
543
594
 
 
595
     /* Mark all free list header blocks, if those were allocated from  */
 
596
     /* the garbage collected heap.  This makes sure they don't         */
 
597
     /* disappear if we are not marking from static data.  It also      */
 
598
     /* saves us the trouble of scanning them, and possibly that of     */
 
599
     /* marking the freelists.                                          */
 
600
       for (kind = 0; kind < GC_n_kinds; kind++) {
 
601
         GC_PTR base = GC_base(GC_obj_kinds[kind].ok_freelist);
 
602
         if (0 != base) {
 
603
           GC_set_mark_bit(base);
 
604
         }
 
605
       }
 
606
       
544
607
     /* Mark from GC internal roots if those might otherwise have       */
545
608
     /* been excluded.                                                  */
546
609
       if (GC_no_dls || roots_were_cleared) {
549
612
 
550
613
     /* Mark thread local free lists, even if their mark        */
551
614
     /* descriptor excludes the link field.                     */
 
615
     /* If the world is not stopped, this is unsafe.  It is     */
 
616
     /* also unnecessary, since we will do this again with the  */
 
617
     /* world stopped.                                          */
552
618
#      ifdef THREAD_LOCAL_ALLOC
553
 
         GC_mark_thread_local_free_lists();
 
619
         if (GC_world_stopped) GC_mark_thread_local_free_lists();
554
620
#      endif
555
621
 
556
622
    /*