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

« back to all changes in this revision

Viewing changes to finalize.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:
761
761
/* Should be called without allocation lock.                            */
762
762
int GC_invoke_finalizers()
763
763
{
764
 
    register struct finalizable_object * curr_fo;
765
 
    register int count = 0;
 
764
    struct finalizable_object * curr_fo;
 
765
    int count = 0;
 
766
    word mem_freed_before;
766
767
    DCL_LOCK_STATE;
767
768
    
768
769
    while (GC_finalize_now != 0) {
770
771
            DISABLE_SIGNALS();
771
772
            LOCK();
772
773
#       endif
 
774
        if (count == 0) {
 
775
            mem_freed_before = GC_mem_freed;
 
776
        }
773
777
        curr_fo = GC_finalize_now;
774
778
#       ifdef THREADS
775
779
            if (curr_fo != 0) GC_finalize_now = fo_next(curr_fo);
791
795
            GC_free((GC_PTR)curr_fo);
792
796
#       endif
793
797
    }
 
798
    if (count != 0 && mem_freed_before != GC_mem_freed) {
 
799
        LOCK();
 
800
        GC_finalizer_mem_freed += (GC_mem_freed - mem_freed_before);
 
801
        UNLOCK();
 
802
    }
794
803
    return count;
795
804
}
796
805
 
800
809
 
801
810
void GC_notify_or_invoke_finalizers GC_PROTO((void))
802
811
{
 
812
    /* This is a convenient place to generate backtraces if appropriate, */
 
813
    /* since that code is not callable with the allocation lock.         */
 
814
#   if defined(KEEP_BACK_PTRS) || defined(MAKE_BACK_GRAPH)
 
815
      static word last_back_trace_gc_no = 1;    /* Skip first one. */
 
816
 
 
817
      if (GC_gc_no > last_back_trace_gc_no) {
 
818
        word i;
 
819
 
 
820
#       ifdef KEEP_BACK_PTRS
 
821
          LOCK();
 
822
          /* Stops when GC_gc_no wraps; that's OK.      */
 
823
          last_back_trace_gc_no = (word)(-1);  /* disable others. */
 
824
          for (i = 0; i < GC_backtraces; ++i) {
 
825
              /* FIXME: This tolerates concurrent heap mutation,        */
 
826
              /* which may cause occasional mysterious results.         */
 
827
              /* We need to release the GC lock, since GC_print_callers */
 
828
              /* acquires it.  It probably shouldn't.                   */
 
829
              UNLOCK();
 
830
              GC_generate_random_backtrace_no_gc();
 
831
              LOCK();
 
832
          }
 
833
          last_back_trace_gc_no = GC_gc_no;
 
834
          UNLOCK();
 
835
#       endif
 
836
#       ifdef MAKE_BACK_GRAPH
 
837
          if (GC_print_back_height)
 
838
            GC_print_back_graph_stats();
 
839
#       endif
 
840
      }
 
841
#   endif
803
842
    if (GC_finalize_now == 0) return;
804
843
    if (!GC_finalize_on_demand) {
805
844
        (void) GC_invoke_finalizers();
806
 
        GC_ASSERT(GC_finalize_now == 0);
 
845
#       ifndef THREADS
 
846
          GC_ASSERT(GC_finalize_now == 0);
 
847
#       endif   /* Otherwise GC can run concurrently and add more */
807
848
        return;
808
849
    }
809
850
    if (GC_finalizer_notifier != (void (*) GC_PROTO((void)))0
841
882
    return(result);
842
883
}
843
884
 
 
885
#if !defined(NO_DEBUGGING)
 
886
 
 
887
void GC_print_finalization_stats()
 
888
{
 
889
    struct finalizable_object *fo = GC_finalize_now;
 
890
    size_t ready = 0;
 
891
 
 
892
    GC_printf2("%lu finalization table entries; %lu disappearing links\n",
 
893
               GC_fo_entries, GC_dl_entries);
 
894
    for (; 0 != fo; fo = fo_next(fo)) ++ready;
 
895
    GC_printf1("%lu objects are eligible for immediate finalization\n", ready);
 
896
}
 
897
 
 
898
#endif /* NO_DEBUGGING */