LCOV - code coverage report
Current view: top level - mm/boehm-gc - mark_rts.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 113 185 61.1 %
Date: 2017-07-14 10:03:36 Functions: 16 24 66.7 %

          Line data    Source code
       1             : /*
       2             :  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
       3             :  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
       4             :  *
       5             :  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
       6             :  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
       7             :  *
       8             :  * Permission is hereby granted to use or copy this program
       9             :  * for any purpose,  provided the above notices are retained on all copies.
      10             :  * Permission to modify the code and to distribute modified code is granted,
      11             :  * provided the above notices are retained, and a notice that the code was
      12             :  * modified is included with the above copyright notice.
      13             :  */
      14             : 
      15             : #include "private/gc_priv.h"
      16             : 
      17             : #include <stdio.h>
      18             : 
      19             : /* Data structure for list of root sets.                                */
      20             : /* We keep a hash table, so that we can filter out duplicate additions. */
      21             : /* Under Win32, we need to do a better job of filtering overlaps, so    */
      22             : /* we resort to sequential search, and pay the price.                   */
      23             : /* This is really declared in gc_priv.h:
      24             : struct roots {
      25             :         ptr_t r_start;
      26             :         ptr_t r_end;
      27             : #       if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
      28             :           struct roots * r_next;
      29             : #       endif
      30             :         GC_bool r_tmp;
      31             :                 -- Delete before registering new dynamic libraries
      32             : };
      33             : 
      34             : struct roots GC_static_roots[MAX_ROOT_SETS];
      35             : */
      36             : 
      37             : int GC_no_dls = 0;      /* Register dynamic library data segments.      */
      38             : 
      39             : static int n_root_sets = 0;
      40             :         /* GC_static_roots[0..n_root_sets) contains the valid root sets. */
      41             : 
      42             : #if !defined(NO_DEBUGGING) || defined(GC_ASSERTIONS)
      43             :   /* Should return the same value as GC_root_size.      */
      44           0 :   GC_INNER word GC_compute_root_size(void)
      45             :   {
      46             :     int i;
      47           0 :     word size = 0;
      48             : 
      49           0 :     for (i = 0; i < n_root_sets; i++) {
      50           0 :       size += GC_static_roots[i].r_end - GC_static_roots[i].r_start;
      51             :     }
      52           0 :     return size;
      53             :   }
      54             : #endif /* !NO_DEBUGGING || GC_ASSERTIONS */
      55             : 
      56             : #if !defined(NO_DEBUGGING)
      57             :   /* For debugging:     */
      58           0 :   void GC_print_static_roots(void)
      59             :   {
      60             :     int i;
      61             :     word size;
      62             : 
      63           0 :     for (i = 0; i < n_root_sets; i++) {
      64           0 :         GC_printf("From %p to %p%s\n",
      65             :                   GC_static_roots[i].r_start, GC_static_roots[i].r_end,
      66           0 :                   GC_static_roots[i].r_tmp ? " (temporary)" : "");
      67             :     }
      68           0 :     GC_printf("GC_root_size: %lu\n", (unsigned long)GC_root_size);
      69             : 
      70           0 :     if ((size = GC_compute_root_size()) != GC_root_size)
      71           0 :       GC_err_printf("GC_root_size incorrect!! Should be: %lu\n",
      72             :                     (unsigned long)size);
      73           0 :   }
      74             : #endif /* !NO_DEBUGGING */
      75             : 
      76             : #ifndef THREADS
      77             :   /* Primarily for debugging support:     */
      78             :   /* Is the address p in one of the registered static root sections?      */
      79             :   GC_INNER GC_bool GC_is_static_root(ptr_t p)
      80             :   {
      81             :     static int last_root_set = MAX_ROOT_SETS;
      82             :     int i;
      83             : 
      84             :     if (last_root_set < n_root_sets
      85             :         && (word)p >= (word)GC_static_roots[last_root_set].r_start
      86             :         && (word)p < (word)GC_static_roots[last_root_set].r_end)
      87             :       return(TRUE);
      88             :     for (i = 0; i < n_root_sets; i++) {
      89             :         if ((word)p >= (word)GC_static_roots[i].r_start
      90             :             && (word)p < (word)GC_static_roots[i].r_end) {
      91             :           last_root_set = i;
      92             :           return(TRUE);
      93             :         }
      94             :     }
      95             :     return(FALSE);
      96             :   }
      97             : #endif /* !THREADS */
      98             : 
      99             : #if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
     100             : /*
     101             : #   define LOG_RT_SIZE 6
     102             : #   define RT_SIZE (1 << LOG_RT_SIZE)  -- Power of 2, may be != MAX_ROOT_SETS
     103             : 
     104             :     struct roots * GC_root_index[RT_SIZE];
     105             :         -- Hash table header.  Used only to check whether a range is
     106             :         -- already present.
     107             :         -- really defined in gc_priv.h
     108             : */
     109             : 
     110        5600 :   GC_INLINE int rt_hash(ptr_t addr)
     111             :   {
     112        5600 :     word result = (word) addr;
     113             : #   if CPP_WORDSZ > 8*LOG_RT_SIZE
     114        5600 :         result ^= result >> 8*LOG_RT_SIZE;
     115             : #   endif
     116             : #   if CPP_WORDSZ > 4*LOG_RT_SIZE
     117        5600 :         result ^= result >> 4*LOG_RT_SIZE;
     118             : #   endif
     119        5600 :     result ^= result >> 2*LOG_RT_SIZE;
     120        5600 :     result ^= result >> LOG_RT_SIZE;
     121        5600 :     result &= (RT_SIZE-1);
     122        5600 :     return(result);
     123             :   }
     124             : 
     125             :   /* Is a range starting at b already in the table? If so return a      */
     126             :   /* pointer to it, else NULL.                                          */
     127        2800 :   GC_INNER void * GC_roots_present(ptr_t b)
     128             :   {
     129        2800 :     int h = rt_hash(b);
     130        2800 :     struct roots *p = GC_root_index[h];
     131             : 
     132        5945 :     while (p != 0) {
     133         345 :         if (p -> r_start == (ptr_t)b) return(p);
     134         345 :         p = p -> r_next;
     135             :     }
     136        2800 :     return NULL;
     137             :   }
     138             : 
     139             :   /* Add the given root structure to the index. */
     140        2800 :   GC_INLINE void add_roots_to_index(struct roots *p)
     141             :   {
     142        2800 :     int h = rt_hash(p -> r_start);
     143             : 
     144        2800 :     p -> r_next = GC_root_index[h];
     145        2800 :     GC_root_index[h] = p;
     146        2800 :   }
     147             : #endif /* !MSWIN32 && !MSWINCE && !CYGWIN32 */
     148             : 
     149             : GC_INNER word GC_root_size = 0;
     150             : 
     151           0 : GC_API void GC_CALL GC_add_roots(void *b, void *e)
     152             : {
     153             :     DCL_LOCK_STATE;
     154             : 
     155           0 :     if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
     156           0 :     LOCK();
     157           0 :     GC_add_roots_inner((ptr_t)b, (ptr_t)e, FALSE);
     158           0 :     UNLOCK();
     159           0 : }
     160             : 
     161             : 
     162             : /* Add [b,e) to the root set.  Adding the same interval a second time   */
     163             : /* is a moderately fast no-op, and hence benign.  We do not handle      */
     164             : /* different but overlapping intervals efficiently.  (We do handle      */
     165             : /* them correctly.)                                                     */
     166             : /* Tmp specifies that the interval may be deleted before                */
     167             : /* re-registering dynamic libraries.                                    */
     168        2800 : void GC_add_roots_inner(ptr_t b, ptr_t e, GC_bool tmp)
     169             : {
     170             :     struct roots * old;
     171             : 
     172             :     GC_ASSERT((word)b <= (word)e);
     173        2800 :     b = (ptr_t)(((word)b + (sizeof(word) - 1)) & ~(sizeof(word) - 1));
     174             :                                         /* round b up to word boundary */
     175        2800 :     e = (ptr_t)((word)e & ~(sizeof(word) - 1));
     176             :                                         /* round e down to word boundary */
     177        2800 :     if ((word)b >= (word)e) return; /* nothing to do */
     178             : 
     179             : #   if defined(MSWIN32) || defined(MSWINCE) || defined(CYGWIN32)
     180             :       /* Spend the time to ensure that there are no overlapping */
     181             :       /* or adjacent intervals.                                 */
     182             :       /* This could be done faster with e.g. a                  */
     183             :       /* balanced tree.  But the execution time here is         */
     184             :       /* virtually guaranteed to be dominated by the time it    */
     185             :       /* takes to scan the roots.                               */
     186             :       {
     187             :         register int i;
     188             :         old = 0; /* initialized to prevent warning. */
     189             :         for (i = 0; i < n_root_sets; i++) {
     190             :             old = GC_static_roots + i;
     191             :             if ((word)b <= (word)old->r_end
     192             :                  && (word)e >= (word)old->r_start) {
     193             :                 if ((word)b < (word)old->r_start) {
     194             :                     GC_root_size += old->r_start - b;
     195             :                     old -> r_start = b;
     196             :                 }
     197             :                 if ((word)e > (word)old->r_end) {
     198             :                     GC_root_size += e - old->r_end;
     199             :                     old -> r_end = e;
     200             :                 }
     201             :                 old -> r_tmp &= tmp;
     202             :                 break;
     203             :             }
     204             :         }
     205             :         if (i < n_root_sets) {
     206             :           /* merge other overlapping intervals */
     207             :             struct roots *other;
     208             : 
     209             :             for (i++; i < n_root_sets; i++) {
     210             :               other = GC_static_roots + i;
     211             :               b = other -> r_start;
     212             :               e = other -> r_end;
     213             :               if ((word)b <= (word)old->r_end
     214             :                   && (word)e >= (word)old->r_start) {
     215             :                 if ((word)b < (word)old->r_start) {
     216             :                     GC_root_size += old->r_start - b;
     217             :                     old -> r_start = b;
     218             :                 }
     219             :                 if ((word)e > (word)old->r_end) {
     220             :                     GC_root_size += e - old->r_end;
     221             :                     old -> r_end = e;
     222             :                 }
     223             :                 old -> r_tmp &= other -> r_tmp;
     224             :                 /* Delete this entry. */
     225             :                   GC_root_size -= (other -> r_end - other -> r_start);
     226             :                   other -> r_start = GC_static_roots[n_root_sets-1].r_start;
     227             :                   other -> r_end = GC_static_roots[n_root_sets-1].r_end;
     228             :                   n_root_sets--;
     229             :               }
     230             :             }
     231             :           return;
     232             :         }
     233             :       }
     234             : #   else
     235        2800 :       old = (struct roots *)GC_roots_present(b);
     236        2800 :       if (old != 0) {
     237           0 :         if ((word)e <= (word)old->r_end) /* already there */ return;
     238             :         /* else extend */
     239           0 :         GC_root_size += e - old -> r_end;
     240           0 :         old -> r_end = e;
     241           0 :         return;
     242             :       }
     243             : #   endif
     244        2800 :     if (n_root_sets == MAX_ROOT_SETS) {
     245           0 :         ABORT("Too many root sets");
     246             :     }
     247             : 
     248             : #   ifdef DEBUG_ADD_DEL_ROOTS
     249             :       GC_log_printf("Adding data root section %d: %p .. %p%s\n",
     250             :                     n_root_sets, b, e, tmp ? " (temporary)" : "");
     251             : #   endif
     252        2800 :     GC_static_roots[n_root_sets].r_start = (ptr_t)b;
     253        2800 :     GC_static_roots[n_root_sets].r_end = (ptr_t)e;
     254        2800 :     GC_static_roots[n_root_sets].r_tmp = tmp;
     255             : #   if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
     256        2800 :       GC_static_roots[n_root_sets].r_next = 0;
     257        2800 :       add_roots_to_index(GC_static_roots + n_root_sets);
     258             : #   endif
     259        2800 :     GC_root_size += e - b;
     260        2800 :     n_root_sets++;
     261             : }
     262             : 
     263             : static GC_bool roots_were_cleared = FALSE;
     264             : 
     265           0 : GC_API void GC_CALL GC_clear_roots(void)
     266             : {
     267             :     DCL_LOCK_STATE;
     268             : 
     269           0 :     if (!EXPECT(GC_is_initialized, TRUE)) GC_init();
     270           0 :     LOCK();
     271           0 :     roots_were_cleared = TRUE;
     272           0 :     n_root_sets = 0;
     273           0 :     GC_root_size = 0;
     274             : #   if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
     275           0 :       BZERO(GC_root_index, RT_SIZE * sizeof(void *));
     276             : #   endif
     277             : #   ifdef DEBUG_ADD_DEL_ROOTS
     278             :       GC_log_printf("Clear all data root sections\n");
     279             : #   endif
     280           0 :     UNLOCK();
     281           0 : }
     282             : 
     283             : /* Internal use only; lock held.        */
     284        1127 : STATIC void GC_remove_root_at_pos(int i)
     285             : {
     286             : #   ifdef DEBUG_ADD_DEL_ROOTS
     287             :       GC_log_printf("Remove data root section at %d: %p .. %p%s\n",
     288             :                     i, GC_static_roots[i].r_start, GC_static_roots[i].r_end,
     289             :                     GC_static_roots[i].r_tmp ? " (temporary)" : "");
     290             : #   endif
     291        1127 :     GC_root_size -= (GC_static_roots[i].r_end - GC_static_roots[i].r_start);
     292        1127 :     GC_static_roots[i].r_start = GC_static_roots[n_root_sets-1].r_start;
     293        1127 :     GC_static_roots[i].r_end = GC_static_roots[n_root_sets-1].r_end;
     294        1127 :     GC_static_roots[i].r_tmp = GC_static_roots[n_root_sets-1].r_tmp;
     295        1127 :     n_root_sets--;
     296        1127 : }
     297             : 
     298             : #if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
     299         244 :   STATIC void GC_rebuild_root_index(void)
     300             :   {
     301             :     int i;
     302         244 :     BZERO(GC_root_index, RT_SIZE * sizeof(void *));
     303         244 :     for (i = 0; i < n_root_sets; i++)
     304           0 :         add_roots_to_index(GC_static_roots + i);
     305         244 :   }
     306             : #endif
     307             : 
     308             : #if defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(MSWINCE) \
     309             :      || defined(PCR) || defined(CYGWIN32)
     310             : /* Internal use only; lock held.        */
     311         244 : STATIC void GC_remove_tmp_roots(void)
     312             : {
     313             :     int i;
     314             : 
     315        1615 :     for (i = 0; i < n_root_sets; ) {
     316        1127 :         if (GC_static_roots[i].r_tmp) {
     317        1127 :             GC_remove_root_at_pos(i);
     318             :         } else {
     319           0 :             i++;
     320             :         }
     321             :     }
     322             : #   if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
     323         244 :       GC_rebuild_root_index();
     324             : #   endif
     325         244 : }
     326             : #endif
     327             : 
     328             : #if !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32)
     329             :   STATIC void GC_remove_roots_inner(ptr_t b, ptr_t e);
     330             : 
     331           0 :   GC_API void GC_CALL GC_remove_roots(void *b, void *e)
     332             :   {
     333             :     DCL_LOCK_STATE;
     334             : 
     335             :     /* Quick check whether has nothing to do */
     336           0 :     if ((((word)b + (sizeof(word) - 1)) & ~(sizeof(word) - 1)) >=
     337           0 :         ((word)e & ~(sizeof(word) - 1)))
     338           0 :       return;
     339             : 
     340           0 :     LOCK();
     341           0 :     GC_remove_roots_inner((ptr_t)b, (ptr_t)e);
     342           0 :     UNLOCK();
     343             :   }
     344             : 
     345             :   /* Should only be called when the lock is held */
     346           0 :   STATIC void GC_remove_roots_inner(ptr_t b, ptr_t e)
     347             :   {
     348             :     int i;
     349           0 :     for (i = 0; i < n_root_sets; ) {
     350           0 :         if ((word)GC_static_roots[i].r_start >= (word)b
     351           0 :             && (word)GC_static_roots[i].r_end <= (word)e) {
     352           0 :             GC_remove_root_at_pos(i);
     353             :         } else {
     354           0 :             i++;
     355             :         }
     356             :     }
     357           0 :     GC_rebuild_root_index();
     358           0 :   }
     359             : #endif /* !defined(MSWIN32) && !defined(MSWINCE) && !defined(CYGWIN32) */
     360             : 
     361             : #if (defined(MSWIN32) || defined(MSWINCE) || defined(CYGWIN32)) \
     362             :     && !defined(NO_DEBUGGING)
     363             :   /* Not used at present (except for, may be, debugging purpose).       */
     364             :   /* Workaround for the OS mapping and unmapping behind our back:       */
     365             :   /* Is the address p in one of the temporary static root sections?     */
     366             :   GC_bool GC_is_tmp_root(ptr_t p)
     367             :   {
     368             :     static int last_root_set = MAX_ROOT_SETS;
     369             :     register int i;
     370             : 
     371             :     if (last_root_set < n_root_sets
     372             :         && (word)p >= (word)GC_static_roots[last_root_set].r_start
     373             :         && (word)p < (word)GC_static_roots[last_root_set].r_end)
     374             :         return GC_static_roots[last_root_set].r_tmp;
     375             :     for (i = 0; i < n_root_sets; i++) {
     376             :         if ((word)p >= (word)GC_static_roots[i].r_start
     377             :             && (word)p < (word)GC_static_roots[i].r_end) {
     378             :             last_root_set = i;
     379             :             return GC_static_roots[i].r_tmp;
     380             :         }
     381             :     }
     382             :     return(FALSE);
     383             :   }
     384             : #endif /* MSWIN32 || MSWINCE || CYGWIN32 */
     385             : 
     386      102589 : GC_INNER ptr_t GC_approx_sp(void)
     387             : {
     388             :     volatile word sp;
     389      102589 :     sp = (word)&sp;
     390             :                 /* Also force stack to grow if necessary. Otherwise the */
     391             :                 /* later accesses might cause the kernel to think we're */
     392             :                 /* doing something wrong.                               */
     393      102589 :     return((ptr_t)sp);
     394             :                 /* GNU C: alternatively, we may return the value of     */
     395             :                 /*__builtin_frame_address(0).                           */
     396             : }
     397             : 
     398             : /*
     399             :  * Data structure for excluded static roots.
     400             :  * Real declaration is in gc_priv.h.
     401             : 
     402             : struct exclusion {
     403             :     ptr_t e_start;
     404             :     ptr_t e_end;
     405             : };
     406             : 
     407             : struct exclusion GC_excl_table[MAX_EXCLUSIONS];
     408             :                                         -- Array of exclusions, ascending
     409             :                                         -- address order.
     410             : */
     411             : 
     412             : STATIC size_t GC_excl_table_entries = 0;/* Number of entries in use.      */
     413             : 
     414             : /* Return the first exclusion range that includes an address >= start_addr */
     415             : /* Assumes the exclusion table contains at least one entry (namely the     */
     416             : /* GC data structures).                                                    */
     417        3858 : STATIC struct exclusion * GC_next_exclusion(ptr_t start_addr)
     418             : {
     419        3858 :     size_t low = 0;
     420        3858 :     size_t high = GC_excl_table_entries - 1;
     421             :     size_t mid;
     422             : 
     423       14095 :     while (high > low) {
     424        6379 :         mid = (low + high) >> 1;
     425             :         /* low <= mid < high    */
     426        6379 :         if ((word) GC_excl_table[mid].e_end <= (word) start_addr) {
     427        1255 :             low = mid + 1;
     428             :         } else {
     429        5124 :             high = mid;
     430             :         }
     431             :     }
     432        3858 :     if ((word) GC_excl_table[low].e_end <= (word) start_addr) return 0;
     433        3254 :     return GC_excl_table + low;
     434             : }
     435             : 
     436             : /* Should only be called when the lock is held.  The range boundaries   */
     437             : /* should be properly aligned and valid.                                */
     438         489 : GC_INNER void GC_exclude_static_roots_inner(void *start, void *finish)
     439             : {
     440             :     struct exclusion * next;
     441             :     size_t next_index, i;
     442             : 
     443             :     GC_ASSERT((word)start % sizeof(word) == 0);
     444             :     GC_ASSERT((word)start < (word)finish);
     445             : 
     446         489 :     if (0 == GC_excl_table_entries) {
     447         163 :         next = 0;
     448             :     } else {
     449         326 :         next = GC_next_exclusion(start);
     450             :     }
     451         489 :     if (0 != next) {
     452         326 :       if ((word)(next -> e_start) < (word) finish) {
     453             :         /* incomplete error check. */
     454           0 :         ABORT("Exclusion ranges overlap");
     455             :       }
     456         326 :       if ((word)(next -> e_start) == (word) finish) {
     457             :         /* extend old range backwards   */
     458           0 :           next -> e_start = (ptr_t)start;
     459           0 :           return;
     460             :       }
     461         326 :       next_index = next - GC_excl_table;
     462         652 :       for (i = GC_excl_table_entries; i > next_index; --i) {
     463         326 :         GC_excl_table[i] = GC_excl_table[i-1];
     464             :       }
     465             :     } else {
     466         163 :       next_index = GC_excl_table_entries;
     467             :     }
     468         489 :     if (GC_excl_table_entries == MAX_EXCLUSIONS) ABORT("Too many exclusions");
     469         489 :     GC_excl_table[next_index].e_start = (ptr_t)start;
     470         489 :     GC_excl_table[next_index].e_end = (ptr_t)finish;
     471         489 :     ++GC_excl_table_entries;
     472             : }
     473             : 
     474           0 : GC_API void GC_CALL GC_exclude_static_roots(void *b, void *e)
     475             : {
     476             :     DCL_LOCK_STATE;
     477             : 
     478           0 :     if (b == e) return;  /* nothing to exclude? */
     479             : 
     480             :     /* Round boundaries (in direction reverse to that of GC_add_roots). */
     481           0 :     b = (void *)((word)b & ~(sizeof(word) - 1));
     482           0 :     e = (void *)(((word)e + (sizeof(word) - 1)) & ~(sizeof(word) - 1));
     483           0 :     if (0 == e) e = (void *)(word)(~(sizeof(word) - 1)); /* handle overflow */
     484             : 
     485           0 :     LOCK();
     486           0 :     GC_exclude_static_roots_inner(b, e);
     487           0 :     UNLOCK();
     488             : }
     489             : 
     490             : /* Invoke push_conditional on ranges that are not excluded. */
     491        2800 : STATIC void GC_push_conditional_with_exclusions(ptr_t bottom, ptr_t top,
     492             :                                                 GC_bool all GC_ATTR_UNUSED)
     493             : {
     494             :     struct exclusion * next;
     495             :     ptr_t excl_start;
     496             : 
     497        6332 :     while ((word)bottom < (word)top) {
     498        3532 :         next = GC_next_exclusion(bottom);
     499        3532 :         if (0 == next || (word)(excl_start = next -> e_start) >= (word)top) {
     500        2800 :             GC_PUSH_CONDITIONAL(bottom, top, all);
     501        2800 :             return;
     502             :         }
     503         732 :         if ((word)excl_start > (word)bottom)
     504         732 :           GC_PUSH_CONDITIONAL(bottom, excl_start, all);
     505         732 :         bottom = next -> e_end;
     506             :     }
     507             : }
     508             : 
     509             : #ifdef IA64
     510             :   /* Similar to GC_push_all_stack_sections() but for IA-64 registers store. */
     511             :   GC_INNER void GC_push_all_register_sections(ptr_t bs_lo, ptr_t bs_hi,
     512             :                   int eager, struct GC_traced_stack_sect_s *traced_stack_sect)
     513             :   {
     514             :     while (traced_stack_sect != NULL) {
     515             :         ptr_t frame_bs_lo = traced_stack_sect -> backing_store_end;
     516             :         GC_ASSERT((word)frame_bs_lo <= (word)bs_hi);
     517             :         if (eager) {
     518             :             GC_push_all_eager(frame_bs_lo, bs_hi);
     519             :         } else {
     520             :             GC_push_all_stack(frame_bs_lo, bs_hi);
     521             :         }
     522             :         bs_hi = traced_stack_sect -> saved_backing_store_ptr;
     523             :         traced_stack_sect = traced_stack_sect -> prev;
     524             :     }
     525             :     GC_ASSERT((word)bs_lo <= (word)bs_hi);
     526             :     if (eager) {
     527             :         GC_push_all_eager(bs_lo, bs_hi);
     528             :     } else {
     529             :         GC_push_all_stack(bs_lo, bs_hi);
     530             :     }
     531             :   }
     532             : #endif /* IA64 */
     533             : 
     534             : #ifdef THREADS
     535             : 
     536         487 : GC_INNER void GC_push_all_stack_sections(ptr_t lo, ptr_t hi,
     537             :                         struct GC_traced_stack_sect_s *traced_stack_sect)
     538             : {
     539         974 :     while (traced_stack_sect != NULL) {
     540             :         GC_ASSERT((word)lo HOTTER_THAN (word)traced_stack_sect);
     541             : #       ifdef STACK_GROWS_UP
     542             :             GC_push_all_stack((ptr_t)traced_stack_sect, lo);
     543             : #       else /* STACK_GROWS_DOWN */
     544           0 :             GC_push_all_stack(lo, (ptr_t)traced_stack_sect);
     545             : #       endif
     546           0 :         lo = traced_stack_sect -> saved_stack_ptr;
     547             :         GC_ASSERT(lo != NULL);
     548           0 :         traced_stack_sect = traced_stack_sect -> prev;
     549             :     }
     550             :     GC_ASSERT(!((word)hi HOTTER_THAN (word)lo));
     551             : #   ifdef STACK_GROWS_UP
     552             :         /* We got them backwards! */
     553             :         GC_push_all_stack(hi, lo);
     554             : #   else /* STACK_GROWS_DOWN */
     555         487 :         GC_push_all_stack(lo, hi);
     556             : #   endif
     557         487 : }
     558             : 
     559             : #else /* !THREADS */
     560             : 
     561             : # ifdef TRACE_BUF
     562             :     /* Defined in mark.c.       */
     563             :     void GC_add_trace_entry(char *kind, word arg1, word arg2);
     564             : # endif
     565             : 
     566             :                         /* Similar to GC_push_all_eager, but only the   */
     567             :                         /* part hotter than cold_gc_frame is scanned    */
     568             :                         /* immediately.  Needed to ensure that callee-  */
     569             :                         /* save registers are not missed.               */
     570             : /*
     571             :  * A version of GC_push_all that treats all interior pointers as valid
     572             :  * and scans part of the area immediately, to make sure that saved
     573             :  * register values are not lost.
     574             :  * Cold_gc_frame delimits the stack section that must be scanned
     575             :  * eagerly.  A zero value indicates that no eager scanning is needed.
     576             :  * We don't need to worry about the MANUAL_VDB case here, since this
     577             :  * is only called in the single-threaded case.  We assume that we
     578             :  * cannot collect between an assignment and the corresponding
     579             :  * GC_dirty() call.
     580             :  */
     581             : STATIC void GC_push_all_stack_partially_eager(ptr_t bottom, ptr_t top,
     582             :                                               ptr_t cold_gc_frame)
     583             : {
     584             :   if (!NEED_FIXUP_POINTER && GC_all_interior_pointers) {
     585             :     /* Push the hot end of the stack eagerly, so that register values   */
     586             :     /* saved inside GC frames are marked before they disappear.         */
     587             :     /* The rest of the marking can be deferred until later.             */
     588             :     if (0 == cold_gc_frame) {
     589             :         GC_push_all_stack(bottom, top);
     590             :         return;
     591             :     }
     592             :     GC_ASSERT((word)bottom <= (word)cold_gc_frame
     593             :               && (word)cold_gc_frame <= (word)top);
     594             : #   ifdef STACK_GROWS_DOWN
     595             :         GC_push_all(cold_gc_frame - sizeof(ptr_t), top);
     596             :         GC_push_all_eager(bottom, cold_gc_frame);
     597             : #   else /* STACK_GROWS_UP */
     598             :         GC_push_all(bottom, cold_gc_frame + sizeof(ptr_t));
     599             :         GC_push_all_eager(cold_gc_frame, top);
     600             : #   endif /* STACK_GROWS_UP */
     601             :   } else {
     602             :     GC_push_all_eager(bottom, top);
     603             :   }
     604             : # ifdef TRACE_BUF
     605             :       GC_add_trace_entry("GC_push_all_stack", bottom, top);
     606             : # endif
     607             : }
     608             : 
     609             : /* Similar to GC_push_all_stack_sections() but also uses cold_gc_frame. */
     610             : STATIC void GC_push_all_stack_part_eager_sections(ptr_t lo, ptr_t hi,
     611             :         ptr_t cold_gc_frame, struct GC_traced_stack_sect_s *traced_stack_sect)
     612             : {
     613             :     GC_ASSERT(traced_stack_sect == NULL || cold_gc_frame == NULL ||
     614             :               (word)cold_gc_frame HOTTER_THAN (word)traced_stack_sect);
     615             : 
     616             :     while (traced_stack_sect != NULL) {
     617             :         GC_ASSERT((word)lo HOTTER_THAN (word)traced_stack_sect);
     618             : #       ifdef STACK_GROWS_UP
     619             :             GC_push_all_stack_partially_eager((ptr_t)traced_stack_sect, lo,
     620             :                                               cold_gc_frame);
     621             : #       else /* STACK_GROWS_DOWN */
     622             :             GC_push_all_stack_partially_eager(lo, (ptr_t)traced_stack_sect,
     623             :                                               cold_gc_frame);
     624             : #       endif
     625             :         lo = traced_stack_sect -> saved_stack_ptr;
     626             :         GC_ASSERT(lo != NULL);
     627             :         traced_stack_sect = traced_stack_sect -> prev;
     628             :         cold_gc_frame = NULL; /* Use at most once.      */
     629             :     }
     630             : 
     631             :     GC_ASSERT(!((word)hi HOTTER_THAN (word)lo));
     632             : #   ifdef STACK_GROWS_UP
     633             :         /* We got them backwards! */
     634             :         GC_push_all_stack_partially_eager(hi, lo, cold_gc_frame);
     635             : #   else /* STACK_GROWS_DOWN */
     636             :         GC_push_all_stack_partially_eager(lo, hi, cold_gc_frame);
     637             : #   endif
     638             : }
     639             : 
     640             : #endif /* !THREADS */
     641             : 
     642             :                         /* Push enough of the current stack eagerly to  */
     643             :                         /* ensure that callee-save registers saved in   */
     644             :                         /* GC frames are scanned.                       */
     645             :                         /* In the non-threads case, schedule entire     */
     646             :                         /* stack for scanning.                          */
     647             :                         /* The second argument is a pointer to the      */
     648             :                         /* (possibly null) thread context, for          */
     649             :                         /* (currently hypothetical) more precise        */
     650             :                         /* stack scanning.                              */
     651             : /*
     652             :  * In the absence of threads, push the stack contents.
     653             :  * In the presence of threads, push enough of the current stack
     654             :  * to ensure that callee-save registers saved in collector frames have been
     655             :  * seen.
     656             :  * FIXME: Merge with per-thread stuff.
     657             :  */
     658         244 : STATIC void GC_push_current_stack(ptr_t cold_gc_frame,
     659             :                                   void * context GC_ATTR_UNUSED)
     660             : {
     661             : #   if defined(THREADS)
     662         244 :         if (0 == cold_gc_frame) return;
     663             : #       ifdef STACK_GROWS_DOWN
     664         244 :           GC_push_all_eager(GC_approx_sp(), cold_gc_frame);
     665             :           /* For IA64, the register stack backing store is handled      */
     666             :           /* in the thread-specific code.                               */
     667             : #       else
     668             :           GC_push_all_eager(cold_gc_frame, GC_approx_sp());
     669             : #       endif
     670             : #   else
     671             :         GC_push_all_stack_part_eager_sections(GC_approx_sp(), GC_stackbottom,
     672             :                                         cold_gc_frame, GC_traced_stack_sect);
     673             : #       ifdef IA64
     674             :               /* We also need to push the register stack backing store. */
     675             :               /* This should really be done in the same way as the      */
     676             :               /* regular stack.  For now we fudge it a bit.             */
     677             :               /* Note that the backing store grows up, so we can't use  */
     678             :               /* GC_push_all_stack_partially_eager.                     */
     679             :               {
     680             :                 ptr_t bsp = GC_save_regs_ret_val;
     681             :                 ptr_t cold_gc_bs_pointer = bsp - 2048;
     682             :                 if (GC_all_interior_pointers
     683             :                     && (word)cold_gc_bs_pointer > (word)BACKING_STORE_BASE) {
     684             :                   /* Adjust cold_gc_bs_pointer if below our innermost   */
     685             :                   /* "traced stack section" in backing store.           */
     686             :                   if (GC_traced_stack_sect != NULL
     687             :                       && (word)cold_gc_bs_pointer
     688             :                           < (word)GC_traced_stack_sect->backing_store_end)
     689             :                     cold_gc_bs_pointer =
     690             :                                 GC_traced_stack_sect->backing_store_end;
     691             :                   GC_push_all_register_sections(BACKING_STORE_BASE,
     692             :                         cold_gc_bs_pointer, FALSE, GC_traced_stack_sect);
     693             :                   GC_push_all_eager(cold_gc_bs_pointer, bsp);
     694             :                 } else {
     695             :                   GC_push_all_register_sections(BACKING_STORE_BASE, bsp,
     696             :                                 TRUE /* eager */, GC_traced_stack_sect);
     697             :                 }
     698             :                 /* All values should be sufficiently aligned that we    */
     699             :                 /* don't have to worry about the boundary.              */
     700             :               }
     701             : #       endif
     702             : #   endif /* !THREADS */
     703             : }
     704             : 
     705             : GC_INNER void (*GC_push_typed_structures)(void) = 0;
     706             : 
     707             :                         /* Push GC internal roots.  These are normally  */
     708             :                         /* included in the static data segment, and     */
     709             :                         /* Thus implicitly pushed.  But we must do this */
     710             :                         /* explicitly if normal root processing is      */
     711             :                         /* disabled.                                    */
     712             : /*
     713             :  * Push GC internal roots.  Only called if there is some reason to believe
     714             :  * these would not otherwise get registered.
     715             :  */
     716           0 : STATIC void GC_push_gc_structures(void)
     717             : {
     718             : #   ifndef GC_NO_FINALIZATION
     719           0 :       GC_push_finalizer_structures();
     720             : #   endif
     721             : #   if defined(THREADS)
     722           0 :       GC_push_thread_structures();
     723             : #   endif
     724           0 :     if( GC_push_typed_structures )
     725           0 :       GC_push_typed_structures();
     726           0 : }
     727             : 
     728         244 : GC_INNER void GC_cond_register_dynamic_libraries(void)
     729             : {
     730             : # if defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(MSWINCE) \
     731             :      || defined(CYGWIN32) || defined(PCR)
     732         244 :     GC_remove_tmp_roots();
     733         244 :     if (!GC_no_dls) GC_register_dynamic_libraries();
     734             : # else
     735             :     GC_no_dls = TRUE;
     736             : # endif
     737         244 : }
     738             : 
     739         244 : STATIC void GC_push_regs_and_stack(ptr_t cold_gc_frame)
     740             : {
     741         244 :     GC_with_callee_saves_pushed(GC_push_current_stack, cold_gc_frame);
     742         244 : }
     743             : 
     744             : /*
     745             :  * Call the mark routines (GC_tl_push for a single pointer,
     746             :  * GC_push_conditional on groups of pointers) on every top level
     747             :  * accessible pointer.
     748             :  * If all is FALSE, arrange to push only possibly altered values.
     749             :  * Cold_gc_frame is an address inside a GC frame that
     750             :  * remains valid until all marking is complete.
     751             :  * A zero value indicates that it's OK to miss some
     752             :  * register values.
     753             :  */
     754         244 : GC_INNER void GC_push_roots(GC_bool all, ptr_t cold_gc_frame)
     755             : {
     756             :     int i;
     757             :     unsigned kind;
     758             : 
     759             :     /*
     760             :      * Next push static data.  This must happen early on, since it's
     761             :      * not robust against mark stack overflow.
     762             :      */
     763             :      /* Re-register dynamic libraries, in case one got added.           */
     764             :      /* There is some argument for doing this as late as possible,      */
     765             :      /* especially on win32, where it can change asynchronously.        */
     766             :      /* In those cases, we do it here.  But on other platforms, it's    */
     767             :      /* not safe with the world stopped, so we do it earlier.           */
     768             : #      if !defined(REGISTER_LIBRARIES_EARLY)
     769             :          GC_cond_register_dynamic_libraries();
     770             : #      endif
     771             : 
     772             :      /* Mark everything in static data areas                             */
     773        3044 :        for (i = 0; i < n_root_sets; i++) {
     774        2800 :          GC_push_conditional_with_exclusions(
     775             :                              GC_static_roots[i].r_start,
     776             :                              GC_static_roots[i].r_end, all);
     777             :        }
     778             : 
     779             :      /* Mark all free list header blocks, if those were allocated from  */
     780             :      /* the garbage collected heap.  This makes sure they don't         */
     781             :      /* disappear if we are not marking from static data.  It also      */
     782             :      /* saves us the trouble of scanning them, and possibly that of     */
     783             :      /* marking the freelists.                                          */
     784        1220 :        for (kind = 0; kind < GC_n_kinds; kind++) {
     785         976 :          void *base = GC_base(GC_obj_kinds[kind].ok_freelist);
     786         976 :          if (0 != base) {
     787           0 :            GC_set_mark_bit(base);
     788             :          }
     789             :        }
     790             : 
     791             :      /* Mark from GC internal roots if those might otherwise have       */
     792             :      /* been excluded.                                                  */
     793         244 :        if (GC_no_dls || roots_were_cleared) {
     794           0 :            GC_push_gc_structures();
     795             :        }
     796             : 
     797             :      /* Mark thread local free lists, even if their mark        */
     798             :      /* descriptor excludes the link field.                     */
     799             :      /* If the world is not stopped, this is unsafe.  It is     */
     800             :      /* also unnecessary, since we will do this again with the  */
     801             :      /* world stopped.                                          */
     802             : #      if defined(THREAD_LOCAL_ALLOC)
     803         244 :          if (GC_world_stopped) GC_mark_thread_local_free_lists();
     804             : #      endif
     805             : 
     806             :     /*
     807             :      * Now traverse stacks, and mark from register contents.
     808             :      * These must be done last, since they can legitimately overflow
     809             :      * the mark stack.
     810             :      * This is usually done by saving the current context on the
     811             :      * stack, and then just tracing from the stack.
     812             :      */
     813         244 :       GC_push_regs_and_stack(cold_gc_frame);
     814             : 
     815         244 :     if (GC_push_other_roots != 0) (*GC_push_other_roots)();
     816             :         /* In the threads case, this also pushes thread stacks. */
     817             :         /* Note that without interior pointer recognition lots  */
     818             :         /* of stuff may have been pushed already, and this      */
     819             :         /* should be careful about mark stack overflows.        */
     820         244 : }

Generated by: LCOV version 1.11