/[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.11.2.4 by dtc, Sat Oct 21 12:51:04 2000 UTC revision 1.11.2.5 by dtc, Tue Oct 24 13:33:56 2000 UTC
# Line 140  static int new_space; Line 140  static int new_space;
140   */   */
141    
142  /*  /*
143     * Number of pages within the dynamic heap, setup from the size of the
144     * dynamic space.
145     */
146    unsigned dynamic_space_pages;
147    
148    /*
149   * An array of page structures is statically allocated.   * An array of page structures is statically allocated.
150   * This helps quickly map between an address its page structure.   * This helps quickly map between an address its page structure.
  * NUM_PAGES is set from the size of the dynamic space.  
151   */   */
152  struct page page_table[NUM_PAGES];  struct page *page_table;
153    
154  /*  /*
155   * Heap base, needed for mapping addresses to page structures.   * Heap base, needed for mapping addresses to page structures.
# Line 169  inline int find_page_index(void *addr) Line 174  inline int find_page_index(void *addr)
174    
175    if (index >= 0) {    if (index >= 0) {
176      index = (unsigned int) index / PAGE_SIZE;      index = (unsigned int) index / PAGE_SIZE;
177      if (index < NUM_PAGES)      if (index < dynamic_space_pages)
178        return index;        return index;
179    }    }
180    
# Line 566  static void gc_alloc_new_region(int nbyt Line 571  static void gc_alloc_new_region(int nbyt
571       * not write protected, or marked dont_move.       * not write protected, or marked dont_move.
572       */       */
573    
574      while (first_page < NUM_PAGES) {      while (first_page < dynamic_space_pages) {
575        int flags = page_table[first_page].flags;        int flags = page_table[first_page].flags;
576        if (!(flags & PAGE_ALLOCATED_MASK)        if (!(flags & PAGE_ALLOCATED_MASK)
577            || ((flags & mmask) == mflags &&            || ((flags & mmask) == mflags &&
# Line 576  static void gc_alloc_new_region(int nbyt Line 581  static void gc_alloc_new_region(int nbyt
581      }      }
582    
583      /* Check for a failure */      /* Check for a failure */
584      if (first_page >= NUM_PAGES) {      if (first_page >= dynamic_space_pages) {
585        fprintf(stderr, "*A2 gc_alloc_new_region failed, nbytes=%d.\n", nbytes);        fprintf(stderr, "*A2 gc_alloc_new_region failed, nbytes=%d.\n", nbytes);
586        print_generation_stats(1);        print_generation_stats(1);
587        exit(1);        exit(1);
# Line 599  static void gc_alloc_new_region(int nbyt Line 604  static void gc_alloc_new_region(int nbyt
604      bytes_found = PAGE_SIZE - page_table[first_page].bytes_used;      bytes_found = PAGE_SIZE - page_table[first_page].bytes_used;
605      num_pages = 1;      num_pages = 1;
606      while ((bytes_found < nbytes || num_pages < 2)      while ((bytes_found < nbytes || num_pages < 2)
607             && last_page < NUM_PAGES - 1             && last_page < dynamic_space_pages - 1
608             && !PAGE_ALLOCATED(last_page + 1)) {             && !PAGE_ALLOCATED(last_page + 1)) {
609        last_page++;        last_page++;
610        num_pages++;        num_pages++;
# Line 619  static void gc_alloc_new_region(int nbyt Line 624  static void gc_alloc_new_region(int nbyt
624    
625      restart_page = last_page + 1;      restart_page = last_page + 1;
626    }    }
627    while (restart_page < NUM_PAGES && bytes_found < nbytes);    while (restart_page < dynamic_space_pages && bytes_found < nbytes);
628    
629    /* Check for a failure */    /* Check for a failure */
630    if (restart_page >= NUM_PAGES && bytes_found < nbytes) {    if (restart_page >= dynamic_space_pages && bytes_found < nbytes) {
631      fprintf(stderr, "*A1 gc_alloc_new_region failed, nbytes=%d.\n", nbytes);      fprintf(stderr, "*A1 gc_alloc_new_region failed, nbytes=%d.\n", nbytes);
632      print_generation_stats(1);      print_generation_stats(1);
633      exit(1);      exit(1);
# Line 1007  static void *gc_alloc_large(int  nbytes, Line 1012  static void *gc_alloc_large(int  nbytes,
1012      first_page = restart_page;      first_page = restart_page;
1013    
1014      if (large)      if (large)
1015        while (first_page < NUM_PAGES && PAGE_ALLOCATED(first_page))        while (first_page < dynamic_space_pages && PAGE_ALLOCATED(first_page))
1016          first_page++;          first_page++;
1017      else      else
1018        while (first_page < NUM_PAGES) {        while (first_page < dynamic_space_pages) {
1019          int flags = page_table[first_page].flags;          int flags = page_table[first_page].flags;
1020          if (!(flags & PAGE_ALLOCATED_MASK)          if (!(flags & PAGE_ALLOCATED_MASK)
1021              || ((flags & mmask) == mflags &&              || ((flags & mmask) == mflags &&
# Line 1020  static void *gc_alloc_large(int  nbytes, Line 1025  static void *gc_alloc_large(int  nbytes,
1025        }        }
1026    
1027      /* Check for a failure */      /* Check for a failure */
1028      if (first_page >= NUM_PAGES) {      if (first_page >= dynamic_space_pages) {
1029        fprintf(stderr, "*A2 gc_alloc_large failed, nbytes=%d.\n", nbytes);        fprintf(stderr, "*A2 gc_alloc_large failed, nbytes=%d.\n", nbytes);
1030        print_generation_stats(1);        print_generation_stats(1);
1031        exit(1);        exit(1);
# Line 1037  static void *gc_alloc_large(int  nbytes, Line 1042  static void *gc_alloc_large(int  nbytes,
1042      bytes_found = PAGE_SIZE - page_table[first_page].bytes_used;      bytes_found = PAGE_SIZE - page_table[first_page].bytes_used;
1043      num_pages = 1;      num_pages = 1;
1044      while (bytes_found < nbytes      while (bytes_found < nbytes
1045             && last_page < NUM_PAGES - 1             && last_page < dynamic_space_pages - 1
1046             && !PAGE_ALLOCATED(last_page + 1)) {             && !PAGE_ALLOCATED(last_page + 1)) {
1047        last_page++;        last_page++;
1048        num_pages++;        num_pages++;
# Line 1057  static void *gc_alloc_large(int  nbytes, Line 1062  static void *gc_alloc_large(int  nbytes,
1062    
1063      restart_page = last_page + 1;      restart_page = last_page + 1;
1064    }    }
1065    while ((restart_page < NUM_PAGES) && (bytes_found < nbytes));    while ((restart_page < dynamic_space_pages) && (bytes_found < nbytes));
1066    
1067    /* Check for a failure */    /* Check for a failure */
1068    if (restart_page >= NUM_PAGES && bytes_found < nbytes) {    if (restart_page >= dynamic_space_pages && bytes_found < nbytes) {
1069      fprintf(stderr, "*A1 gc_alloc_large failed, nbytes=%d.\n", nbytes);      fprintf(stderr, "*A1 gc_alloc_large failed, nbytes=%d.\n", nbytes);
1070      print_generation_stats(1);      print_generation_stats(1);
1071      exit(1);      exit(1);
# Line 1434  static inline boolean from_space_p(lispo Line 1439  static inline boolean from_space_p(lispo
1439  {  {
1440    int page_index = (void*) obj - heap_base;    int page_index = (void*) obj - heap_base;
1441    return page_index >= 0    return page_index >= 0
1442      && (page_index = (unsigned int) page_index / PAGE_SIZE) < NUM_PAGES      && (page_index = (unsigned int) page_index / PAGE_SIZE) < dynamic_space_pages
1443      && PAGE_GENERATION(page_index) == from_space;      && PAGE_GENERATION(page_index) == from_space;
1444  }  }
1445    
# Line 1442  static inline boolean new_space_p(lispob Line 1447  static inline boolean new_space_p(lispob
1447  {  {
1448    int page_index = (void*) obj - heap_base;    int page_index = (void*) obj - heap_base;
1449    return page_index >= 0    return page_index >= 0
1450      && (page_index = (unsigned int) page_index / PAGE_SIZE) < NUM_PAGES      && (page_index = (unsigned int) page_index / PAGE_SIZE) < dynamic_space_pages
1451      && PAGE_GENERATION(page_index) == new_space;      && PAGE_GENERATION(page_index) == new_space;
1452  }  }
1453    
# Line 4863  static void scavenge_generation(int gene Line 4868  static void scavenge_generation(int gene
4868  #define SC_GEN_CK 0  #define SC_GEN_CK 0
4869  #if SC_GEN_CK  #if SC_GEN_CK
4870    /* Clear the write_protected_cleared flags on all pages */    /* Clear the write_protected_cleared flags on all pages */
4871    for (i = 0; i < NUM_PAGES; i++)    for (i = 0; i < dynamic_space_pages; i++)
4872      page_table[i].flags &= ~PAGE_WRITE_PROTECTED_CLEADED_MASK;      page_table[i].flags &= ~PAGE_WRITE_PROTECTED_CLEADED_MASK;
4873  #endif  #endif
4874    
# Line 4936  static void scavenge_generation(int gene Line 4941  static void scavenge_generation(int gene
4941     * Check that none of the write_protected pages in this generation     * Check that none of the write_protected pages in this generation
4942     * have been written to.     * have been written to.
4943     */     */
4944    for (i = 0; i < NUM_PAGES; i++)    for (i = 0; i < dynamic_space_pages; i++)
4945      if (PAGE_ALLOCATED(i)      if (PAGE_ALLOCATED(i)
4946          && page_table[i].bytes_used != 0          && page_table[i].bytes_used != 0
4947          && PAGE_GENERATION(i) == generation          && PAGE_GENERATION(i) == generation
# Line 5110  static void scavenge_newspace_generation Line 5115  static void scavenge_newspace_generation
5115  #define SC_NS_GEN_CK 0  #define SC_NS_GEN_CK 0
5116  #if SC_NS_GEN_CK  #if SC_NS_GEN_CK
5117    /* Clear the write_protected_cleared flags on all pages */    /* Clear the write_protected_cleared flags on all pages */
5118    for (i = 0; i < NUM_PAGES; i++)    for (i = 0; i < dynamic_space_pages; i++)
5119      page_table[i].flags &= ~PAGE_WRITE_PROTECTED_CLEARED;      page_table[i].flags &= ~PAGE_WRITE_PROTECTED_CLEARED;
5120  #endif  #endif
5121    
# Line 5229  static void scavenge_newspace_generation Line 5234  static void scavenge_newspace_generation
5234     * Check that none of the write_protected pages in this generation     * Check that none of the write_protected pages in this generation
5235     * have been written to.     * have been written to.
5236     */     */
5237    for (i = 0; i < NUM_PAGES; i++)    for (i = 0; i < dynamic_space_pages; i++)
5238      if (PAGE_ALLOCATED(i)      if (PAGE_ALLOCATED(i)
5239          && page_table[i].bytes_used != 0          && page_table[i].bytes_used != 0
5240          && PAGE_GENERATION(i) == generation          && PAGE_GENERATION(i) == generation
# Line 5935  int    update_x86_dynamic_space_free_pointe Line 5940  int    update_x86_dynamic_space_free_pointe
5940    int last_page = -1;    int last_page = -1;
5941    int i;    int i;
5942    
5943    for (i = 0; i < NUM_PAGES; i++)    for (i = 0; i < dynamic_space_pages; i++)
5944      if (PAGE_ALLOCATED(i) && page_table[i].bytes_used != 0)      if (PAGE_ALLOCATED(i) && page_table[i].bytes_used != 0)
5945        last_page = i;        last_page = i;
5946    
# Line 6111  void   gc_free_heap(void) Line 6116  void   gc_free_heap(void)
6116    if (gencgc_verbose > 1)    if (gencgc_verbose > 1)
6117      fprintf(stderr, "Free heap\n");      fprintf(stderr, "Free heap\n");
6118    
6119    for (page = 0; page < NUM_PAGES; page++)    for (page = 0; page < dynamic_space_pages; page++)
6120      /* Skip Free pages which should already be zero filled. */      /* Skip Free pages which should already be zero filled. */
6121      if (PAGE_ALLOCATED(page)) {      if (PAGE_ALLOCATED(page)) {
6122        void *page_start, *addr;        void *page_start, *addr;
# Line 6207  void gc_init(void) Line 6212  void gc_init(void)
6212    
6213    heap_base = (void*) DYNAMIC_0_SPACE_START;    heap_base = (void*) DYNAMIC_0_SPACE_START;
6214    
6215      /* The number of pages needed for the dynamic space - rounding up. */
6216      dynamic_space_pages = (dynamic_space_size + (PAGE_SIZE - 1)) / PAGE_SIZE;
6217    
6218      page_table = (struct page *)malloc(dynamic_space_pages*sizeof(struct page));
6219      if (page_table == NULL)
6220        {
6221          fprintf(stderr, "Unable to allocate page table.\n");
6222          exit(1);
6223        }
6224    
6225    /* Initialise each page structure. */    /* Initialise each page structure. */
6226    for (i = 0; i < NUM_PAGES; i++) {  
6227      for (i = 0; i < dynamic_space_pages; i++) {
6228      /* Initial all pages as free. */      /* Initial all pages as free. */
6229      page_table[i].flags &= ~PAGE_ALLOCATED_MASK;      page_table[i].flags &= ~PAGE_ALLOCATED_MASK;
6230      page_table[i].bytes_used = 0;      page_table[i].bytes_used = 0;

Legend:
Removed from v.1.11.2.4  
changed lines
  Added in v.1.11.2.5

  ViewVC Help
Powered by ViewVC 1.1.5