/[cmucl]/src/lisp/gencgc.c
ViewVC logotype

Diff of /src/lisp/gencgc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by dtc, Thu Sep 16 15:25:18 1999 UTC revision 1.17 by dtc, Sun Jan 9 19:36:07 2000 UTC
# Line 108  boolean gencgc_zero_check_during_free_he Line 108  boolean gencgc_zero_check_during_free_he
108  /*  /*
109   * The minimum size for a large object.   * The minimum size for a large object.
110   */   */
111  unsigned large_object_size = 4*4096;  unsigned large_object_size = 4 * PAGE_SIZE;
112    
113  /*  /*
114   * Enable the filtering of stack/register pointers. This could reduce   * Enable the filtering of stack/register pointers. This could reduce
# Line 135  static int new_space; Line 135  static int new_space;
135   * GC structures and variables.   * GC structures and variables.
136   */   */
137    
 #define PAGE_BYTES 4096  
   
138  /*  /*
139   * An array of page structures is statically allocated.   * An array of page structures is statically allocated.
140   * This helps quickly map between an address its page structure.   * This helps quickly map between an address its page structure.
# Line 154  static void *heap_base = NULL; Line 152  static void *heap_base = NULL;
152   */   */
153  inline void *page_address(int page_num)  inline void *page_address(int page_num)
154  {  {
155    return heap_base + page_num * 4096;    return heap_base + PAGE_SIZE * page_num;
156  }  }
157    
158  /*  /*
# Line 166  inline int find_page_index(void *addr) Line 164  inline int find_page_index(void *addr)
164    int index = addr-heap_base;    int index = addr-heap_base;
165    
166    if (index >= 0) {    if (index >= 0) {
167      index = (unsigned int) index / 4096;      index = (unsigned int) index / PAGE_SIZE;
168      if (index < NUM_PAGES)      if (index < NUM_PAGES)
169        return index;        return index;
170    }    }
# Line 238  struct generation { Line 236  struct generation {
236   * generation structure than actual generations as the oldest   * generation structure than actual generations as the oldest
237   * generations is temporarily raised then lowered.   * generations is temporarily raised then lowered.
238   */   */
239  static struct generation generations[NUM_GENERATIONS+1];  static struct generation generations[NUM_GENERATIONS + 1];
240    
241  /*  /*
242   * The oldest generation that will currently be GCed by default.   * The oldest generation that will currently be GCed by default.
# Line 264  unsigned int  gencgc_oldest_gen_to_gc = Line 262  unsigned int  gencgc_oldest_gen_to_gc =
262   * integrated with the lisp code.   * integrated with the lisp code.
263   */   */
264  static int  last_free_page;  static int  last_free_page;
 static int  last_used_page = 0;  
265    
266    
267    
# Line 415  static void print_generation_stats(int Line 412  static void print_generation_stats(int
412      fprintf(stderr, "   %8d: %5d %5d %5d %5d %8d %5d %8d %4d %3d %7.4lf\n",      fprintf(stderr, "   %8d: %5d %5d %5d %5d %8d %5d %8d %4d %3d %7.4lf\n",
413              i, boxed_cnt, unboxed_cnt, large_boxed_cnt, large_unboxed_cnt,              i, boxed_cnt, unboxed_cnt, large_boxed_cnt, large_unboxed_cnt,
414              generations[i].bytes_allocated,              generations[i].bytes_allocated,
415              count_generation_pages(i) * 4096 - generations[i].bytes_allocated,              PAGE_SIZE * count_generation_pages(i) -
416                generations[i].bytes_allocated,
417              generations[i].gc_trigger,              generations[i].gc_trigger,
418              count_write_protect_generation_pages(i),              count_write_protect_generation_pages(i),
419              generations[i].num_gc,              generations[i].num_gc,
# Line 568  static void gc_alloc_new_region(int nbyt Line 566  static void gc_alloc_new_region(int nbyt
566        int flags = page_table[first_page].flags;        int flags = page_table[first_page].flags;
567        if (!(flags & PAGE_ALLOCATED_MASK)        if (!(flags & PAGE_ALLOCATED_MASK)
568            || ((flags & mmask) == mflags &&            || ((flags & mmask) == mflags &&
569                page_table[first_page].bytes_used < 4096 - 32))                page_table[first_page].bytes_used < PAGE_SIZE - 32))
570          break;          break;
571        first_page++;        first_page++;
572      }      }
# Line 594  static void gc_alloc_new_region(int nbyt Line 592  static void gc_alloc_new_region(int nbyt
592       * number of pages in a region.       * number of pages in a region.
593       */       */
594      last_page = first_page;      last_page = first_page;
595      bytes_found = 4096 - page_table[first_page].bytes_used;      bytes_found = PAGE_SIZE - page_table[first_page].bytes_used;
596      num_pages = 1;      num_pages = 1;
597      while ((bytes_found < nbytes || num_pages < 2)      while ((bytes_found < nbytes || num_pages < 2)
598             && last_page < NUM_PAGES - 1             && last_page < NUM_PAGES - 1
599             && !PAGE_ALLOCATED(last_page + 1)) {             && !PAGE_ALLOCATED(last_page + 1)) {
600        last_page++;        last_page++;
601        num_pages++;        num_pages++;
602        bytes_found += 4096;        bytes_found += PAGE_SIZE;
603        gc_assert(!PAGE_WRITE_PROTECTED(last_page));        gc_assert(!PAGE_WRITE_PROTECTED(last_page));
604      }      }
605    
606      region_size = (4096 - page_table[first_page].bytes_used)      region_size = (PAGE_SIZE - page_table[first_page].bytes_used)
607        + 4096 * (last_page - first_page);        + PAGE_SIZE * (last_page - first_page);
608    
609      gc_assert(bytes_found == region_size);      gc_assert(bytes_found == region_size);
610    
# Line 674  static void gc_alloc_new_region(int nbyt Line 672  static void gc_alloc_new_region(int nbyt
672        alloc_region->start_addr - page_address(i);        alloc_region->start_addr - page_address(i);
673    }    }
674    
675    /* Bump up last_free_page */    /* Bump up the last_free_page */
676    if (last_page + 1 > last_free_page) {    if (last_page + 1 > last_free_page) {
677      last_free_page = last_page + 1;      last_free_page = last_page + 1;
678      SetSymbolValue(ALLOCATION_POINTER,      SetSymbolValue(ALLOCATION_POINTER,
679                     (lispobj) ((char *) heap_base + last_free_page * 4096));                     (lispobj) ((char *) heap_base +
680      if (last_page + 1 > last_used_page)                                PAGE_SIZE * last_free_page));
       last_used_page = last_page + 1;  
681    }    }
682  }  }
683    
# Line 739  static void add_new_area(int first_page, Line 736  static void add_new_area(int first_page,
736      gc_abort();      gc_abort();
737    }    }
738    
739    new_area_start = 4096 * first_page + offset;    new_area_start = PAGE_SIZE * first_page + offset;
740    
741    /*    /*
742     * Search backwards for a prior area that this follows from.  If     * Search backwards for a prior area that this follows from.  If
743     * found this will save adding a new area.     * found this will save adding a new area.
744     */     */
745    for (i = new_areas_index - 1, c = 0; i >= 0 && c < 8; i--, c++) {    for (i = new_areas_index - 1, c = 0; i >= 0 && c < 8; i--, c++) {
746      unsigned area_end = 4096 * (*new_areas)[i].page      unsigned area_end = PAGE_SIZE * (*new_areas)[i].page
747        + (*new_areas)[i].offset + (*new_areas)[i].size;        + (*new_areas)[i].offset + (*new_areas)[i].size;
748  #if 0  #if 0
749      fprintf(stderr, "*S1 %d %d %d %d\n", i, c, new_area_start, area_end);      fprintf(stderr, "*S1 %d %d %d %d\n", i, c, new_area_start, area_end);
# Line 845  void gc_alloc_update_page_tables(int unb Line 842  void gc_alloc_update_page_tables(int unb
842       */       */
843      more = 0;      more = 0;
844      bytes_used = alloc_region->free_pointer - page_address(first_page);      bytes_used = alloc_region->free_pointer - page_address(first_page);
845      if (bytes_used > 4096) {      if (bytes_used > PAGE_SIZE) {
846        bytes_used = 4096;        bytes_used = PAGE_SIZE;
847        more = 1;        more = 1;
848      }      }
849      page_table[first_page].bytes_used = bytes_used;      page_table[first_page].bytes_used = bytes_used;
# Line 873  void gc_alloc_update_page_tables(int unb Line 870  void gc_alloc_update_page_tables(int unb
870        /* Calc. the number of bytes used in this page. */        /* Calc. the number of bytes used in this page. */
871        more = 0;        more = 0;
872        bytes_used = alloc_region->free_pointer - page_address(next_page);        bytes_used = alloc_region->free_pointer - page_address(next_page);
873        if (bytes_used > 4096) {        if (bytes_used > PAGE_SIZE) {
874          bytes_used = 4096;          bytes_used = PAGE_SIZE;
875          more = 1;          more = 1;
876        }        }
877        page_table[next_page].bytes_used = bytes_used;        page_table[next_page].bytes_used = bytes_used;
# Line 1013  static void *gc_alloc_large(int  nbytes, Line 1010  static void *gc_alloc_large(int  nbytes,
1010          int flags = page_table[first_page].flags;          int flags = page_table[first_page].flags;
1011          if (!(flags & PAGE_ALLOCATED_MASK)          if (!(flags & PAGE_ALLOCATED_MASK)
1012              || ((flags & mmask) == mflags &&              || ((flags & mmask) == mflags &&
1013                  page_table[first_page].bytes_used < 4096 - 32))                  page_table[first_page].bytes_used < PAGE_SIZE - 32))
1014            break;            break;
1015          first_page++;          first_page++;
1016        }        }
# Line 1033  static void *gc_alloc_large(int  nbytes, Line 1030  static void *gc_alloc_large(int  nbytes,
1030  #endif  #endif
1031    
1032      last_page = first_page;      last_page = first_page;
1033      bytes_found = 4096 - page_table[first_page].bytes_used;      bytes_found = PAGE_SIZE - page_table[first_page].bytes_used;
1034      num_pages = 1;      num_pages = 1;
1035      while (bytes_found < nbytes      while (bytes_found < nbytes
1036             && last_page < NUM_PAGES - 1             && last_page < NUM_PAGES - 1
1037             && !PAGE_ALLOCATED(last_page + 1)) {             && !PAGE_ALLOCATED(last_page + 1)) {
1038        last_page++;        last_page++;
1039        num_pages++;        num_pages++;
1040        bytes_found += 4096;        bytes_found += PAGE_SIZE;
1041        gc_assert(!PAGE_WRITE_PROTECTED(last_page));        gc_assert(!PAGE_WRITE_PROTECTED(last_page));
1042      }      }
1043    
1044      region_size = (4096 - page_table[first_page].bytes_used)      region_size = (PAGE_SIZE - page_table[first_page].bytes_used)
1045        + 4096 * (last_page - first_page);        + PAGE_SIZE * (last_page - first_page);
1046    
1047      gc_assert(bytes_found == region_size);      gc_assert(bytes_found == region_size);
1048    
# Line 1107  static void *gc_alloc_large(int  nbytes, Line 1104  static void *gc_alloc_large(int  nbytes,
1104     */     */
1105    more = 0;    more = 0;
1106    bytes_used = nbytes + orig_first_page_bytes_used;    bytes_used = nbytes + orig_first_page_bytes_used;
1107    if (bytes_used > 4096) {    if (bytes_used > PAGE_SIZE) {
1108      bytes_used = 4096;      bytes_used = PAGE_SIZE;
1109      more = 1;      more = 1;
1110    }    }
1111    page_table[first_page].bytes_used = bytes_used;    page_table[first_page].bytes_used = bytes_used;
# Line 1131  static void *gc_alloc_large(int  nbytes, Line 1128  static void *gc_alloc_large(int  nbytes,
1128      PAGE_FLAGS_UPDATE(next_page, mmask, mflags);      PAGE_FLAGS_UPDATE(next_page, mmask, mflags);
1129    
1130      page_table[next_page].first_object_offset =      page_table[next_page].first_object_offset =
1131        orig_first_page_bytes_used - 4096 * (next_page - first_page);        orig_first_page_bytes_used - PAGE_SIZE * (next_page - first_page);
1132    
1133      /* Calc. the number of bytes used in this page. */      /* Calc. the number of bytes used in this page. */
1134      more = 0;      more = 0;
1135      bytes_used = nbytes + orig_first_page_bytes_used - byte_cnt;      bytes_used = nbytes + orig_first_page_bytes_used - byte_cnt;
1136      if (bytes_used > 4096) {      if (bytes_used > PAGE_SIZE) {
1137        bytes_used = 4096;        bytes_used = PAGE_SIZE;
1138        more = 1;        more = 1;
1139      }      }
1140      page_table[next_page].bytes_used = bytes_used;      page_table[next_page].bytes_used = bytes_used;
# Line 1155  static void *gc_alloc_large(int  nbytes, Line 1152  static void *gc_alloc_large(int  nbytes,
1152    if (!unboxed)    if (!unboxed)
1153      add_new_area(first_page, orig_first_page_bytes_used, nbytes);      add_new_area(first_page, orig_first_page_bytes_used, nbytes);
1154    
1155    /* Bump up last_free_page */    /* Bump up the last_free_page */
1156    if (last_page + 1 > last_free_page) {    if (last_page + 1 > last_free_page) {
1157      last_free_page = last_page + 1;      last_free_page = last_page + 1;
1158      SetSymbolValue(ALLOCATION_POINTER,      SetSymbolValue(ALLOCATION_POINTER,
1159                     (lispobj) ((char *) heap_base + last_free_page * 4096));                     (lispobj) ((char *) heap_base +
1160      if (last_page + 1 > last_used_page)                                PAGE_SIZE * last_free_page));
       last_used_page = last_page + 1;  
1161    }    }
1162    
1163    return (void *) (page_address(first_page) + orig_first_page_bytes_used);    return (void *) (page_address(first_page) + orig_first_page_bytes_used);
# Line 1434  static inline boolean from_space_p(lispo Line 1430  static inline boolean from_space_p(lispo
1430  {  {
1431    int page_index = (void*) obj - heap_base;    int page_index = (void*) obj - heap_base;
1432    return page_index >= 0    return page_index >= 0
1433      && (page_index = (unsigned int) page_index / 4096) < NUM_PAGES      && (page_index = (unsigned int) page_index / PAGE_SIZE) < NUM_PAGES
1434      && PAGE_GENERATION(page_index) == from_space;      && PAGE_GENERATION(page_index) == from_space;
1435  }  }
1436    
# Line 1442  static inline boolean new_space_p(lispob Line 1438  static inline boolean new_space_p(lispob
1438  {  {
1439    int page_index = (void*) obj - heap_base;    int page_index = (void*) obj - heap_base;
1440    return page_index >= 0    return page_index >= 0
1441      && (page_index = (unsigned int)page_index / 4096) < NUM_PAGES      && (page_index = (unsigned int) page_index / PAGE_SIZE) < NUM_PAGES
1442      && PAGE_GENERATION(page_index) == new_space;      && PAGE_GENERATION(page_index) == new_space;
1443  }  }
1444    
# Line 1529  static lispobj copy_large_object(lispobj Line 1525  static lispobj copy_large_object(lispobj
1525    
1526      next_page = first_page;      next_page = first_page;
1527      remaining_bytes = nwords * 4;      remaining_bytes = nwords * 4;
1528      while (remaining_bytes > 4096) {      while (remaining_bytes > PAGE_SIZE) {
1529        gc_assert(PAGE_GENERATION(next_page) == from_space);        gc_assert(PAGE_GENERATION(next_page) == from_space);
1530        gc_assert(PAGE_ALLOCATED(next_page));        gc_assert(PAGE_ALLOCATED(next_page));
1531        gc_assert(!PAGE_UNBOXED(next_page));        gc_assert(!PAGE_UNBOXED(next_page));
1532        gc_assert(PAGE_LARGE_OBJECT(next_page));        gc_assert(PAGE_LARGE_OBJECT(next_page));
1533        gc_assert(page_table[next_page].first_object_offset ==        gc_assert(page_table[next_page].first_object_offset ==
1534                  4096 * (first_page - next_page));                  PAGE_SIZE * (first_page - next_page));
1535        gc_assert(page_table[next_page].bytes_used == 4096);        gc_assert(page_table[next_page].bytes_used == PAGE_SIZE);
1536    
1537        PAGE_FLAGS_UPDATE(next_page, PAGE_GENERATION_MASK, new_space);        PAGE_FLAGS_UPDATE(next_page, PAGE_GENERATION_MASK, new_space);
1538    
# Line 1545  static lispobj copy_large_object(lispobj Line 1541  static lispobj copy_large_object(lispobj
1541         * WP flag to avoid redundant calls.         * WP flag to avoid redundant calls.
1542         */         */
1543        if (PAGE_WRITE_PROTECTED(next_page)) {        if (PAGE_WRITE_PROTECTED(next_page)) {
1544          os_protect(page_address(next_page), 4096, OS_VM_PROT_ALL);          os_protect(page_address(next_page), PAGE_SIZE, OS_VM_PROT_ALL);
1545          page_table[next_page].flags &= ~PAGE_WRITE_PROTECTED_MASK;          page_table[next_page].flags &= ~PAGE_WRITE_PROTECTED_MASK;
1546        }        }
1547        remaining_bytes -= 4096;        remaining_bytes -= PAGE_SIZE;
1548        next_page++;        next_page++;
1549      }      }
1550    
# Line 1576  static lispobj copy_large_object(lispobj Line 1572  static lispobj copy_large_object(lispobj
1572    
1573      /* Free any remaining pages; needs care. */      /* Free any remaining pages; needs care. */
1574      next_page++;      next_page++;
1575      while (old_bytes_used == 4096 &&      while (old_bytes_used == PAGE_SIZE &&
1576             PAGE_FLAGS(next_page, mmask) == mflags &&             PAGE_FLAGS(next_page, mmask) == mflags &&
1577             page_table[next_page].first_object_offset == (first_page             page_table[next_page].first_object_offset == PAGE_SIZE * (first_page
1578                                                           - next_page) * 4096) {                                                                       - next_page)) {
1579        /*        /*
1580         * Checks out OK, free the page. Don't need to both zeroing         * Checks out OK, free the page. Don't need to both zeroing
1581         * pages as this should have been done before shrinking the         * pages as this should have been done before shrinking the
# Line 1707  static lispobj copy_large_unboxed_object Line 1703  static lispobj copy_large_unboxed_object
1703    
1704      next_page = first_page;      next_page = first_page;
1705      remaining_bytes = nwords * 4;      remaining_bytes = nwords * 4;
1706      while (remaining_bytes > 4096) {      while (remaining_bytes > PAGE_SIZE) {
1707        gc_assert(PAGE_GENERATION(next_page) == from_space);        gc_assert(PAGE_GENERATION(next_page) == from_space);
1708        gc_assert(PAGE_ALLOCATED(next_page));        gc_assert(PAGE_ALLOCATED(next_page));
1709        gc_assert(PAGE_LARGE_OBJECT(next_page));        gc_assert(PAGE_LARGE_OBJECT(next_page));
1710        gc_assert(page_table[next_page].first_object_offset ==        gc_assert(page_table[next_page].first_object_offset ==
1711                  4096 * (first_page - next_page));                  PAGE_SIZE * (first_page - next_page));
1712        gc_assert(page_table[next_page].bytes_used == 4096);        gc_assert(page_table[next_page].bytes_used == PAGE_SIZE);
1713    
1714        PAGE_FLAGS_UPDATE(next_page, PAGE_UNBOXED_MASK | PAGE_GENERATION_MASK,        PAGE_FLAGS_UPDATE(next_page, PAGE_UNBOXED_MASK | PAGE_GENERATION_MASK,
1715                          PAGE_UNBOXED_MASK | new_space);                          PAGE_UNBOXED_MASK | new_space);
1716        remaining_bytes -= 4096;        remaining_bytes -= PAGE_SIZE;
1717        next_page++;        next_page++;
1718      }      }
1719    
# Line 1745  static lispobj copy_large_unboxed_object Line 1741  static lispobj copy_large_unboxed_object
1741    
1742      /* Free any remaining pages; needs care. */      /* Free any remaining pages; needs care. */
1743      next_page++;      next_page++;
1744      while (old_bytes_used == 4096 &&      while (old_bytes_used == PAGE_SIZE &&
1745             PAGE_FLAGS(next_page, mmask) == mflags &&             PAGE_FLAGS(next_page, mmask) == mflags &&
1746             page_table[next_page].first_object_offset == (first_page             page_table[next_page].first_object_offset == PAGE_SIZE * (first_page
1747                                                           - next_page) * 4096) {                                                                       - next_page)) {
1748        /*        /*
1749         * Checks out OK, free the page. Don't need to both zeroing         * Checks out OK, free the page. Don't need to both zeroing
1750         * pages as this should have been done before shrinking the         * pages as this should have been done before shrinking the
# Line 4495  static void maybe_adjust_large_object(li Line 4491  static void maybe_adjust_large_object(li
4491    
4492    next_page = first_page;    next_page = first_page;
4493    remaining_bytes = nwords*4;    remaining_bytes = nwords*4;
4494    while (remaining_bytes > 4096) {    while (remaining_bytes > PAGE_SIZE) {
4495      gc_assert(PAGE_GENERATION(next_page) == from_space);      gc_assert(PAGE_GENERATION(next_page) == from_space);
4496      gc_assert(PAGE_ALLOCATED(next_page));      gc_assert(PAGE_ALLOCATED(next_page));
4497      gc_assert(PAGE_LARGE_OBJECT(next_page));      gc_assert(PAGE_LARGE_OBJECT(next_page));
4498      gc_assert(page_table[next_page].first_object_offset ==      gc_assert(page_table[next_page].first_object_offset ==
4499                4096 * (first_page - next_page));                PAGE_SIZE * (first_page - next_page));
4500      gc_assert(page_table[next_page].bytes_used == 4096);      gc_assert(page_table[next_page].bytes_used == PAGE_SIZE);
4501    
4502      PAGE_FLAGS_UPDATE(next_page, PAGE_UNBOXED_MASK,      PAGE_FLAGS_UPDATE(next_page, PAGE_UNBOXED_MASK,
4503                        unboxed << PAGE_UNBOXED_SHIFT);                        unboxed << PAGE_UNBOXED_SHIFT);
# Line 4511  static void maybe_adjust_large_object(li Line 4507  static void maybe_adjust_large_object(li
4507       * pages aren't.       * pages aren't.
4508       */       */
4509      gc_assert(!PAGE_WRITE_PROTECTED(next_page));      gc_assert(!PAGE_WRITE_PROTECTED(next_page));
4510      remaining_bytes -= 4096;      remaining_bytes -= PAGE_SIZE;
4511      next_page++;      next_page++;
4512    }    }
4513    
# Line 4539  static void maybe_adjust_large_object(li Line 4535  static void maybe_adjust_large_object(li
4535    
4536    /* Free any remaining pages; needs care. */    /* Free any remaining pages; needs care. */
4537    next_page++;    next_page++;
4538    while (old_bytes_used == 4096 &&    while (old_bytes_used == PAGE_SIZE &&
4539           PAGE_FLAGS(next_page, mmask) == mflags &&           PAGE_FLAGS(next_page, mmask) == mflags &&
4540           page_table[next_page].first_object_offset == (first_page           page_table[next_page].first_object_offset == PAGE_SIZE * (first_page
4541                                                         - next_page) * 4096) {                                                                     - next_page)) {
4542      /*      /*
4543       * Checks out OK, free the page. Don't need to bother zeroing       * Checks out OK, free the page. Don't need to bother zeroing
4544       * pages as this should have been done before shrinking the       * pages as this should have been done before shrinking the
# Line 4619  static void preserve_pointer(void *addr) Line 4615  static void preserve_pointer(void *addr)
4615    while (page_table[first_page].first_object_offset != 0) {    while (page_table[first_page].first_object_offset != 0) {
4616      first_page--;      first_page--;
4617      /* Do some checks */      /* Do some checks */
4618      gc_assert(page_table[first_page].bytes_used == 4096);      gc_assert(page_table[first_page].bytes_used == PAGE_SIZE);
4619      gc_assert(PAGE_GENERATION(first_page) == from_space);      gc_assert(PAGE_GENERATION(first_page) == from_space);
4620      gc_assert(PAGE_ALLOCATED(first_page));      gc_assert(PAGE_ALLOCATED(first_page));
4621      gc_assert(PAGE_UNBOXED(first_page) == region_unboxed);      gc_assert(PAGE_UNBOXED(first_page) == region_unboxed);
# Line 4680  static void preserve_pointer(void *addr) Line 4676  static void preserve_pointer(void *addr)
4676      gc_assert(!PAGE_WRITE_PROTECTED(i));      gc_assert(!PAGE_WRITE_PROTECTED(i));
4677    
4678      /* Check if this is the last page in this contiguous block */      /* Check if this is the last page in this contiguous block */
4679      if (page_table[i].bytes_used < 4096      if (page_table[i].bytes_used < PAGE_SIZE
4680          /* Or it is 4096 and is the last in the block */          /* Or it is PAGE_SIZE and is the last in the block */
4681          || !PAGE_ALLOCATED(i + 1)          || !PAGE_ALLOCATED(i + 1)
4682          || page_table[i + 1].bytes_used == 0 /* Next page free */          || page_table[i + 1].bytes_used == 0 /* Next page free */
4683          || PAGE_GENERATION(i + 1) != from_space /* Diff. gen */          || PAGE_GENERATION(i + 1) != from_space /* Diff. gen */
# Line 4809  static int update_page_write_prot(page) Line 4805  static int update_page_write_prot(page)
4805      fprintf(stderr, "* WP page %d of gen %d\n", page, gen);      fprintf(stderr, "* WP page %d of gen %d\n", page, gen);
4806  #endif  #endif
4807    
4808      os_protect((void *) page_addr, 4096, OS_VM_PROT_READ | OS_VM_PROT_EXECUTE);      os_protect((void *) page_addr, PAGE_SIZE,
4809                   OS_VM_PROT_READ | OS_VM_PROT_EXECUTE);
4810    
4811      /* Note the page as protected in the page tables */      /* Note the page as protected in the page tables */
4812      page_table[page].flags |= PAGE_WRITE_PROTECTED_MASK;      page_table[page].flags |= PAGE_WRITE_PROTECTED_MASK;
# Line 4885  static void scavenge_generation(int gene Line 4882  static void scavenge_generation(int gene
4882         */         */
4883        for (last_page = i; ;last_page++)        for (last_page = i; ;last_page++)
4884          /* Check if this is the last page in this contiguous block */          /* Check if this is the last page in this contiguous block */
4885          if (page_table[last_page].bytes_used < 4096          if (page_table[last_page].bytes_used < PAGE_SIZE
4886              /* Or it is 4096 and is the last in the block */              /* Or it is PAGE_SIZE and is the last in the block */
4887              || !PAGE_ALLOCATED(last_page + 1)              || !PAGE_ALLOCATED(last_page + 1)
4888              || PAGE_UNBOXED(last_page + 1)              || PAGE_UNBOXED(last_page + 1)
4889              || page_table[last_page + 1].bytes_used == 0              || page_table[last_page + 1].bytes_used == 0
# Line 4910  static void scavenge_generation(int gene Line 4907  static void scavenge_generation(int gene
4907  #endif  #endif
4908            {            {
4909              scavenge(page_address(i), (page_table[last_page].bytes_used              scavenge(page_address(i), (page_table[last_page].bytes_used
4910                                         + (last_page - i) * 4096) / 4);                                         + PAGE_SIZE * (last_page - i)) / 4);
4911    
4912              /*              /*
4913               * Now scan the pages and write protect those that don't               * Now scan the pages and write protect those that don't
# Line 5012  static void scavenge_newspace_generation Line 5009  static void scavenge_newspace_generation
5009         */         */
5010        for (last_page = i; ; last_page++)        for (last_page = i; ; last_page++)
5011          /* Check if this is the last page in this contiguous block */          /* Check if this is the last page in this contiguous block */
5012          if (page_table[last_page].bytes_used < 4096          if (page_table[last_page].bytes_used < PAGE_SIZE
5013              /* Or it is 4096 and is the last in the block */              /* Or it is PAGE_SIZE and is the last in the block */
5014              || !PAGE_ALLOCATED(last_page + 1)              || !PAGE_ALLOCATED(last_page + 1)
5015              || PAGE_UNBOXED(last_page + 1)              || PAGE_UNBOXED(last_page + 1)
5016              || page_table[last_page + 1].bytes_used == 0              || page_table[last_page + 1].bytes_used == 0
# Line 5044  static void scavenge_newspace_generation Line 5041  static void scavenge_newspace_generation
5041                size = (page_table[last_page].bytes_used                size = (page_table[last_page].bytes_used
5042                        - page_table[i].first_object_offset) / 4;                        - page_table[i].first_object_offset) / 4;
5043              else              else
5044                size = (page_table[last_page].bytes_used + (last_page - i) * 4096                size = (page_table[last_page].bytes_used +
5045                        - page_table[i].first_object_offset) / 4;                        PAGE_SIZE * (last_page - i) -
5046                          page_table[i].first_object_offset) / 4;
5047    
5048              {              {
5049  #if SC_NS_GEN_CK  #if SC_NS_GEN_CK
# Line 5263  static void unprotect_oldspace(void) Line 5261  static void unprotect_oldspace(void)
5261         * WP flag to avoid redundant calls.         * WP flag to avoid redundant calls.
5262         */         */
5263        if (PAGE_WRITE_PROTECTED(i)) {        if (PAGE_WRITE_PROTECTED(i)) {
5264          os_protect(page_start, 4096, OS_VM_PROT_ALL);          os_protect(page_start, PAGE_SIZE, OS_VM_PROT_ALL);
5265          page_table[i].flags &= ~PAGE_WRITE_PROTECTED_MASK;          page_table[i].flags &= ~PAGE_WRITE_PROTECTED_MASK;
5266        }        }
5267      }      }
# Line 5312  static int free_oldspace(void) Line 5310  static int free_oldspace(void)
5310          void  *page_start = (void *)page_address(last_page);          void  *page_start = (void *)page_address(last_page);
5311    
5312          if (PAGE_WRITE_PROTECTED(last_page)) {          if (PAGE_WRITE_PROTECTED(last_page)) {
5313            os_protect(page_start, 4096, OS_VM_PROT_ALL);            os_protect(page_start, PAGE_SIZE, OS_VM_PROT_ALL);
5314            page_table[last_page].flags &= ~PAGE_WRITE_PROTECTED_MASK;            page_table[last_page].flags &= ~PAGE_WRITE_PROTECTED_MASK;
5315          }          }
5316        }        }
# Line 5329  static int free_oldspace(void) Line 5327  static int free_oldspace(void)
5327    
5328        page_start = (void *) page_address(first_page);        page_start = (void *) page_address(first_page);
5329    
5330        os_invalidate(page_start, 4096 * (last_page - first_page));        os_invalidate(page_start, PAGE_SIZE * (last_page - first_page));
5331        addr = os_validate(page_start, 4096 * (last_page - first_page));        addr = os_validate(page_start, PAGE_SIZE * (last_page - first_page));
5332        if(addr == NULL || addr != page_start)        if(addr == NULL || addr != page_start)
5333          fprintf(stderr, "gc_zero: page moved, 0x%08x ==> 0x%08x!\n",          fprintf(stderr, "gc_zero: page moved, 0x%08x ==> 0x%08x!\n",
5334                  page_start, addr);                  page_start, addr);
# Line 5338  static int free_oldspace(void) Line 5336  static int free_oldspace(void)
5336        int *page_start;        int *page_start;
5337    
5338        page_start = (int *) page_address(first_page);        page_start = (int *) page_address(first_page);
5339        i586_bzero(page_start, 4096 * (last_page - first_page));        i586_bzero(page_start, PAGE_SIZE * (last_page - first_page));
5340      }      }
5341    
5342      first_page = last_page;      first_page = last_page;
# Line 5614  static void verify_generation(int  gener Line 5612  static void verify_generation(int  gener
5612         */         */
5613        for (last_page = i; ; last_page++)        for (last_page = i; ; last_page++)
5614          /* Check if this is the last page in this contiguous block */          /* Check if this is the last page in this contiguous block */
5615          if (page_table[last_page].bytes_used < 4096          if (page_table[last_page].bytes_used < PAGE_SIZE
5616              /* Or it is 4096 and is the last in the block */              /* Or it is PAGE_SIZE and is the last in the block */
5617              || !PAGE_ALLOCATED(last_page + 1)              || !PAGE_ALLOCATED(last_page + 1)
5618              || PAGE_UNBOXED(last_page + 1) != region_unboxed              || PAGE_UNBOXED(last_page + 1) != region_unboxed
5619              || page_table[last_page + 1].bytes_used == 0              || page_table[last_page + 1].bytes_used == 0
# Line 5624  static void verify_generation(int  gener Line 5622  static void verify_generation(int  gener
5622            break;            break;
5623    
5624        verify_space(page_address(i),        verify_space(page_address(i),
5625                     (page_table[last_page].bytes_used + (last_page-i)*4096)/4);                     (page_table[last_page].bytes_used +
5626                        PAGE_SIZE * (last_page - i)) / 4);
5627        i = last_page;        i = last_page;
5628      }      }
5629    }    }
# Line 5645  static void verify_zero_fill(void) Line 5644  static void verify_zero_fill(void)
5644          if (start_addr[i] != 0)          if (start_addr[i] != 0)
5645            fprintf(stderr, "** free page not zero @ %x\n", start_addr + i);            fprintf(stderr, "** free page not zero @ %x\n", start_addr + i);
5646      } else {      } else {
5647        int free_bytes = 4096 - page_table[page].bytes_used;        int free_bytes = PAGE_SIZE - page_table[page].bytes_used;
5648        if (free_bytes > 0) {        if (free_bytes > 0) {
5649          int *start_addr = (int *) ((int) page_address(page)          int *start_addr = (int *) ((int) page_address(page)
5650                                     + page_table[page].bytes_used);                                     + page_table[page].bytes_used);
# Line 5703  static void write_protect_generation_pag Line 5702  static void write_protect_generation_pag
5702    
5703        page_start = (void *) page_address(i);        page_start = (void *) page_address(i);
5704    
5705        os_protect(page_start, 4096, OS_VM_PROT_READ | OS_VM_PROT_EXECUTE);        os_protect(page_start, PAGE_SIZE, OS_VM_PROT_READ | OS_VM_PROT_EXECUTE);
5706    
5707        /* Note the page as protected in the page tables */        /* Note the page as protected in the page tables */
5708        page_table[i].flags |= PAGE_WRITE_PROTECTED_MASK;        page_table[i].flags |= PAGE_WRITE_PROTECTED_MASK;
# Line 5755  static void    garbage_collect_generation(i Line 5754  static void    garbage_collect_generation(i
5754    /*    /*
5755     * Change to a new space for allocation, reseting the alloc_start_page.     * Change to a new space for allocation, reseting the alloc_start_page.
5756     */     */
5757    
5758    gc_alloc_generation = new_space;    gc_alloc_generation = new_space;
5759    generations[new_space].alloc_start_page = 0;    generations[new_space].alloc_start_page = 0;
5760    generations[new_space].alloc_unboxed_start_page = 0;    generations[new_space].alloc_unboxed_start_page = 0;
# Line 5791  static void    garbage_collect_generation(i Line 5791  static void    garbage_collect_generation(i
5791    if (gencgc_verbose > 1) {    if (gencgc_verbose > 1) {
5792      int num_dont_move_pages = count_dont_move_pages();      int num_dont_move_pages = count_dont_move_pages();
5793      fprintf(stderr, "Non-movable pages due to conservative pointers = %d, %d bytes\n",      fprintf(stderr, "Non-movable pages due to conservative pointers = %d, %d bytes\n",
5794              num_dont_move_pages, num_dont_move_pages * 4096);              num_dont_move_pages, PAGE_SIZE * num_dont_move_pages);
5795    }    }
5796    
5797    /* Scavenge all the rest of the roots. */    /* Scavenge all the rest of the roots. */
# Line 5936  int    update_x86_dynamic_space_free_pointe Line 5936  int    update_x86_dynamic_space_free_pointe
5936    last_free_page = last_page + 1;    last_free_page = last_page + 1;
5937    
5938    SetSymbolValue(ALLOCATION_POINTER,    SetSymbolValue(ALLOCATION_POINTER,
5939                   (lispobj) ((char *) heap_base + last_free_page * 4096));                   (lispobj) ((char *) heap_base + PAGE_SIZE * last_free_page));
5940  }  }
5941    
5942    
# Line 6097  void   collect_garbage(unsigned last_gen) Line 6097  void   collect_garbage(unsigned last_gen)
6097  /*  /*
6098   * The is called by purify when it is finished. All live objects will   * The is called by purify when it is finished. All live objects will
6099   * have been moved to the RO and Static heaps. The dynamic space will   * have been moved to the RO and Static heaps. The dynamic space will
6100   * need a full re-initialisation. I don't bother having purify flush   * need a full re-initialisation. Do not bother having purify flush
6101   * the current gc_alloc region, as the page_tables are re-initialised,   * the current allocation region, as the page_tables are re-initialised,
6102   * and every page is zeroed to be sure.   * and every page is zeroed to be sure.
6103   */   */
6104    
# Line 6125  void   gc_free_heap(void) Line 6125  void   gc_free_heap(void)
6125        page_table[page].bytes_used = 0;        page_table[page].bytes_used = 0;
6126    
6127        /* Zero the page. */        /* Zero the page. */
6128        page_start = (void *)page_address(page);        page_start = (void *) page_address(page);
6129    
6130        /* First remove any write protection */        /* First remove any write protection */
6131        os_protect(page_start, 4096, OS_VM_PROT_ALL);        os_protect(page_start, PAGE_SIZE, OS_VM_PROT_ALL);
6132        page_table[page].flags &= ~PAGE_WRITE_PROTECTED_MASK;        page_table[page].flags &= ~PAGE_WRITE_PROTECTED_MASK;
6133    
6134        os_invalidate(page_start,4096);        os_invalidate(page_start, PAGE_SIZE);
6135        addr = os_validate(page_start, 4096);        addr = os_validate(page_start, PAGE_SIZE);
6136        if(addr == NULL || addr != page_start)        if(addr == NULL || addr != page_start)
6137          fprintf(stderr, "gc_zero: page moved, 0x%08x ==> 0x%08x!\n",          fprintf(stderr, "gc_zero: page moved, 0x%08x ==> 0x%08x!\n",
6138                  page_start, addr);                  page_start, addr);
# Line 6146  void   gc_free_heap(void) Line 6146  void   gc_free_heap(void)
6146    
6147        page_start = (int *) page_address(page);        page_start = (int *) page_address(page);
6148    
6149        for(i=0; i<1024; i++)        for(i = 0; i < 1024; i++)
6150          if (page_start[i] != 0)          if (page_start[i] != 0)
6151            fprintf(stderr, "** Free region not zero @ %x\n", page_start+i);            fprintf(stderr, "** Free region not zero @ %x\n", page_start + i);
6152      }      }
6153    
6154    bytes_allocated = 0;    bytes_allocated = 0;
# Line 6278  void   gencgc_pickup_dynamic(void) Line 6278  void   gencgc_pickup_dynamic(void)
6278      page_table[page].flags |= PAGE_ALLOCATED_MASK;      page_table[page].flags |= PAGE_ALLOCATED_MASK;
6279      page_table[page].flags &= ~(PAGE_UNBOXED_MASK | PAGE_GENERATION_MASK      page_table[page].flags &= ~(PAGE_UNBOXED_MASK | PAGE_GENERATION_MASK
6280                                  | PAGE_LARGE_OBJECT_MASK);                                  | PAGE_LARGE_OBJECT_MASK);
6281      page_table[page].bytes_used = 4096;      page_table[page].bytes_used = PAGE_SIZE;
6282      page_table[page].first_object_offset =      page_table[page].first_object_offset =
6283        (void *) DYNAMIC_0_SPACE_START - page_address(page);        (void *) DYNAMIC_0_SPACE_START - page_address(page);
6284      addr += 4096;      addr += PAGE_SIZE;
6285      page++;      page++;
6286    }    }
6287    while (addr < alloc_ptr);    while (addr < alloc_ptr);
6288    
6289    generations[0].bytes_allocated = 4096*page;    generations[0].bytes_allocated = PAGE_SIZE * page;
6290    bytes_allocated = 4096*page;    bytes_allocated = PAGE_SIZE * page;
6291    
6292    current_region_free_pointer = boxed_region.free_pointer;    current_region_free_pointer = boxed_region.free_pointer;
6293    current_region_end_addr = boxed_region.end_addr;    current_region_end_addr = boxed_region.end_addr;
# Line 6459  void clear_auto_gc_trigger(void) Line 6459  void clear_auto_gc_trigger(void)
6459  /* Find the code object for the given pc. Return NULL on failure */  /* Find the code object for the given pc. Return NULL on failure */
6460  lispobj * component_ptr_from_pc(lispobj *pc)  lispobj * component_ptr_from_pc(lispobj *pc)
6461  {  {
6462    lispobj *object;    lispobj *ptr;
6463    
6464    object = search_read_only_space(pc);    ptr = search_read_only_space(pc);
6465    
6466    if (!object)    if (!ptr)
6467      object = search_static_space(pc);      ptr = search_static_space(pc);
6468    
6469    if (!object)    if (!ptr)
6470      object = search_dynamic_space(pc);      ptr = search_dynamic_space(pc);
6471    
6472    /* Found anything? Check if it is a code object.  */    /* Found anything? Check if it is a code object.  */
6473    if (object && TypeOf(*object) == type_CodeHeader)    if (ptr && TypeOf(*ptr) == type_CodeHeader)
6474      return object;      return ptr;
6475    
6476    return NULL;    return NULL;
6477  }  }

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.5