/[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.5 by dtc, Tue Dec 2 02:50:45 1997 UTC revision 1.6 by dtc, Wed Dec 3 08:17:02 1997 UTC
# Line 40  Line 40 
40    
41  /* Debugging variables. */  /* Debugging variables. */
42    
43  boolean gencgc_verbose = FALSE;  /* The verbose level. All non-error messages are disabled at level 0;
44       and only a few rare messages are printed at level 1. */
45    unsigned gencgc_verbose = 0;
46    
47  /* To enable the use of page protection to help avoid the scavenging  /* To enable the use of page protection to help avoid the scavenging
48     of pages that don't have pointers to younger generations. */     of pages that don't have pointers to younger generations. */
# Line 1338  copy_large_object(lispobj object, int nw Line 1340  copy_large_object(lispobj object, int nw
1340    gc_assert(from_space_p(object));    gc_assert(from_space_p(object));
1341    gc_assert((nwords & 0x01) == 0);    gc_assert((nwords & 0x01) == 0);
1342    
1343    if (nwords > 1024*1024)    if ((nwords > 1024*1024) && gencgc_verbose)
1344      fprintf(stderr,"** copy_large_object: %d\n",nwords*4);      fprintf(stderr,"** copy_large_object: %d\n",nwords*4);
1345    
1346    /* Check if it's a large object. */    /* Check if it's a large object. */
# Line 1418  copy_large_object(lispobj object, int nw Line 1420  copy_large_object(lispobj object, int nw
1420        next_page++;        next_page++;
1421      }      }
1422    
1423      if (bytes_freed > 0)      if ((bytes_freed > 0) && gencgc_verbose)
1424        fprintf(stderr,"* copy_large_boxed bytes_freed %d\n", bytes_freed);        fprintf(stderr,"* copy_large_boxed bytes_freed %d\n", bytes_freed);
1425    
1426      generations[from_space].bytes_allocated -= 4*nwords + bytes_freed;      generations[from_space].bytes_allocated -= 4*nwords + bytes_freed;
# Line 1507  copy_large_unboxed_object(lispobj object Line 1509  copy_large_unboxed_object(lispobj object
1509    gc_assert(from_space_p(object));    gc_assert(from_space_p(object));
1510    gc_assert((nwords & 0x01) == 0);    gc_assert((nwords & 0x01) == 0);
1511    
1512    if (nwords > 1024*1024)    if ((nwords > 1024*1024) && gencgc_verbose)
1513      fprintf(stderr,"** copy_large_unboxed_object: %d\n",nwords*4);      fprintf(stderr,"** copy_large_unboxed_object: %d\n",nwords*4);
1514    
1515    /* Check if it's a large object. */    /* Check if it's a large object. */
# Line 1579  copy_large_unboxed_object(lispobj object Line 1581  copy_large_unboxed_object(lispobj object
1581        next_page++;        next_page++;
1582      }      }
1583    
1584      if (bytes_freed > 0)      if ((bytes_freed > 0) && gencgc_verbose)
1585        fprintf(stderr,"* copy_large_unboxed bytes_freed %d\n", bytes_freed);        fprintf(stderr,"* copy_large_unboxed bytes_freed %d\n", bytes_freed);
1586    
1587      generations[from_space].bytes_allocated -= 4*nwords + bytes_freed;      generations[from_space].bytes_allocated -= 4*nwords + bytes_freed;
# Line 1793  sniff_code_object(struct code *code, uns Line 1795  sniff_code_object(struct code *code, uns
1795    if (!check_code_fixups)    if (!check_code_fixups)
1796      return;      return;
1797    
1798    /* It's ok if it's byte compiled code. The trace    /* It's ok if it's byte compiled code. The trace table offset will
1799       table offset will be a fixnum if it's x86       be a fixnum if it's x86 compiled code - check. */
      compiled code - check. */  
1800    if (code->trace_table_offset & 0x3) {    if (code->trace_table_offset & 0x3) {
1801      /* fprintf(stderr,"*** Sniffing byte compiled code object at %x.\n",code);*/      /* fprintf(stderr,"*** Sniffing byte compiled code object at %x.\n",code);*/
1802      return;      return;
# Line 3888  valid_dynamic_space_pointer(lispobj *poi Line 3889  valid_dynamic_space_pointer(lispobj *poi
3889      case type_ByteCodeClosure:      case type_ByteCodeClosure:
3890      case type_DylanFunctionHeader:      case type_DylanFunctionHeader:
3891        if ((int)pointer != ((int)start_addr+type_FunctionPointer)) {        if ((int)pointer != ((int)start_addr+type_FunctionPointer)) {
3892          fprintf(stderr,"*Ef2: %x %x %x\n", pointer, start_addr, *start_addr);          if (gencgc_verbose)
3893              fprintf(stderr,"*Wf2: %x %x %x\n", pointer, start_addr, *start_addr);
3894          return FALSE;          return FALSE;
3895        }        }
3896        break;        break;
3897      default:      default:
3898        fprintf(stderr,"*Ef3: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3899            fprintf(stderr,"*Wf3: %x %x %x\n", pointer, start_addr, *start_addr);
3900        return FALSE;        return FALSE;
3901      }      }
3902      break;      break;
3903    case type_ListPointer:    case type_ListPointer:
3904      if ((int)pointer != ((int)start_addr+type_ListPointer)) {      if ((int)pointer != ((int)start_addr+type_ListPointer)) {
3905        fprintf(stderr,"*El1: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3906            fprintf(stderr,"*Wl1: %x %x %x\n", pointer, start_addr, *start_addr);
3907        return FALSE;        return FALSE;
3908      }      }
3909      /* Is it plausible cons? */      /* Is it plausible cons? */
# Line 3913  valid_dynamic_space_pointer(lispobj *poi Line 3917  valid_dynamic_space_pointer(lispobj *poi
3917             || (TypeOf(start_addr[1]) == type_UnboundMarker)))             || (TypeOf(start_addr[1]) == type_UnboundMarker)))
3918        break;        break;
3919      else {      else {
3920        fprintf(stderr,"*El2: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3921            fprintf(stderr,"*Wl2: %x %x %x\n", pointer, start_addr, *start_addr);
3922        return FALSE;        return FALSE;
3923      }      }
3924    case type_InstancePointer:    case type_InstancePointer:
3925      if ((int)pointer != ((int)start_addr+type_InstancePointer)) {      if ((int)pointer != ((int)start_addr+type_InstancePointer)) {
3926        fprintf(stderr,"*Ei1: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3927            fprintf(stderr,"*Wi1: %x %x %x\n", pointer, start_addr, *start_addr);
3928        return FALSE;        return FALSE;
3929      }      }
3930      if (TypeOf(start_addr[0]) != type_InstanceHeader) {      if (TypeOf(start_addr[0]) != type_InstanceHeader) {
3931        fprintf(stderr,"*Ei2: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3932            fprintf(stderr,"*Wi2: %x %x %x\n", pointer, start_addr, *start_addr);
3933        return FALSE;        return FALSE;
3934      }      }
3935      break;      break;
3936    case type_OtherPointer:    case type_OtherPointer:
3937      if ((int)pointer != ((int)start_addr+type_OtherPointer)) {      if ((int)pointer != ((int)start_addr+type_OtherPointer)) {
3938        fprintf(stderr,"*Eo1: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3939            fprintf(stderr,"*Wo1: %x %x %x\n", pointer, start_addr, *start_addr);
3940        return FALSE;        return FALSE;
3941      }      }
3942      /* Is it plausible?  Not a cons. X should check the headers. */      /* Is it plausible?  Not a cons. X should check the headers. */
3943      if(Pointerp(start_addr[0]) || ((start_addr[0] & 3) == 0)) {      if(Pointerp(start_addr[0]) || ((start_addr[0] & 3) == 0)) {
3944        fprintf(stderr,"*Eo2: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3945            fprintf(stderr,"*Wo2: %x %x %x\n", pointer, start_addr, *start_addr);
3946        return FALSE;        return FALSE;
3947      }      }
3948      switch (TypeOf(start_addr[0])) {      switch (TypeOf(start_addr[0])) {
3949      case type_UnboundMarker:      case type_UnboundMarker:
3950      case type_BaseChar:      case type_BaseChar:
3951        fprintf(stderr,"*Eo3: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3952            fprintf(stderr,"*Wo3: %x %x %x\n", pointer, start_addr, *start_addr);
3953        return FALSE;        return FALSE;
3954    
3955        /* Only pointed to by function pointers? */        /* Only pointed to by function pointers? */
# Line 3948  valid_dynamic_space_pointer(lispobj *poi Line 3958  valid_dynamic_space_pointer(lispobj *poi
3958      case type_ByteCodeFunction:      case type_ByteCodeFunction:
3959      case type_ByteCodeClosure:      case type_ByteCodeClosure:
3960      case type_DylanFunctionHeader:      case type_DylanFunctionHeader:
3961        fprintf(stderr,"*Eo4: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3962            fprintf(stderr,"*Wo4: %x %x %x\n", pointer, start_addr, *start_addr);
3963        return FALSE;        return FALSE;
3964    
3965      case type_InstanceHeader:      case type_InstanceHeader:
3966        fprintf(stderr,"*Eo5: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
3967            fprintf(stderr,"*Wo5: %x %x %x\n", pointer, start_addr, *start_addr);
3968        return FALSE;        return FALSE;
3969    
3970        /* The valid other immediate pointer objects */        /* The valid other immediate pointer objects */
# Line 4010  valid_dynamic_space_pointer(lispobj *poi Line 4022  valid_dynamic_space_pointer(lispobj *poi
4022        break;        break;
4023    
4024      default:      default:
4025        fprintf(stderr,"*Eo6: %x %x %x\n", pointer, start_addr, *start_addr);        if (gencgc_verbose)
4026            fprintf(stderr,"*Wo6: %x %x %x\n", pointer, start_addr, *start_addr);
4027        return FALSE;        return FALSE;
4028      }      }
4029      break;      break;
4030    default:    default:
4031      fprintf(stderr,"*E?: %x %x %x\n", pointer, start_addr, *start_addr);      if (gencgc_verbose)
4032          fprintf(stderr,"*W?: %x %x %x\n", pointer, start_addr, *start_addr);
4033      return FALSE;      return FALSE;
4034    }    }
4035    
# Line 4083  maybe_adjust_large_object(lispobj *where Line 4097  maybe_adjust_large_object(lispobj *where
4097      boxed = UNBOXED_PAGE;      boxed = UNBOXED_PAGE;
4098      break;      break;
4099    default:    default:
     /* fprintf(stderr,"*P2 %x %x\n",where,where[0]);*/  
4100      return;      return;
4101    }    }
4102    
   /*fprintf(stderr,"*P1 %x %x\n",where,where[0]);*/  
   
4103    /* Find its current size. */    /* Find its current size. */
4104    nwords = (sizetab[TypeOf(where[0])])(where);    nwords = (sizetab[TypeOf(where[0])])(where);
4105    
# Line 4161  maybe_adjust_large_object(lispobj *where Line 4172  maybe_adjust_large_object(lispobj *where
4172      next_page++;      next_page++;
4173    }    }
4174    
4175    if (bytes_freed > 0)    if ((bytes_freed > 0) && gencgc_verbose)
4176      fprintf(stderr,"* adjust_large_object freed %d\n", bytes_freed);      fprintf(stderr,"* adjust_large_object freed %d\n", bytes_freed);
4177    
4178    generations[from_space].bytes_allocated -= bytes_freed;    generations[from_space].bytes_allocated -= bytes_freed;
# Line 4235  preserve_pointer(void *addr) Line 4246  preserve_pointer(void *addr)
4246          || (page_table[addr_page_index].bytes_used == 0)          || (page_table[addr_page_index].bytes_used == 0)
4247          /* Check the offset within the page */          /* Check the offset within the page */
4248          || (((int)addr & 0xfff) > page_table[addr_page_index].bytes_used)) {          || (((int)addr & 0xfff) > page_table[addr_page_index].bytes_used)) {
4249        fprintf(stderr,"* ignore pointer 0x%x to freed area of large object\n",        fprintf(stderr,"*W ignore pointer 0x%x to freed area of large object\n",
4250                addr);                addr);
4251        return;        return;
4252      }      }
# Line 4303  scavenge_thread_stacks(void) Line 4314  scavenge_thread_stacks(void)
4314          if (TypeOf(stack->header) != type_SimpleArrayUnsignedByte32)          if (TypeOf(stack->header) != type_SimpleArrayUnsignedByte32)
4315            return;            return;
4316          length = fixnum_value(stack->length);          length = fixnum_value(stack->length);
4317          if (gencgc_verbose)          if (gencgc_verbose > 1)
4318            fprintf(stderr,"Scavenging control stack %d of length %d words\n",            fprintf(stderr,"Scavenging control stack %d of length %d words\n",
4319                    i,length);                    i,length);
4320          for (j = 0; j < length; j++)          for (j = 0; j < length; j++)
# Line 4484  scavenge_generation(int generation) Line 4495  scavenge_generation(int generation)
4495      }      }
4496    }    }
4497    
4498    if (gencgc_verbose && num_wp != 0)    if ((gencgc_verbose > 1) && (num_wp != 0))
4499      fprintf(stderr,"Write protected %d pages within generation %d\n",num_wp);      fprintf(stderr,"Write protected %d pages within generation %d\n",num_wp);
4500    
4501  #if SC_GEN_CK  #if SC_GEN_CK
# Line 4706  scavenge_newspace_generation(int generat Line 4717  scavenge_newspace_generation(int generat
4717        /* New areas of objects allocated have been lost so need to do a        /* New areas of objects allocated have been lost so need to do a
4718           full scan to be sure! If this becomes a problem try           full scan to be sure! If this becomes a problem try
4719           increasing NUM_NEW_AREAS. */           increasing NUM_NEW_AREAS. */
4720        fprintf(stderr,"** new_areas overflow, doing full scavenge\n");        if (gencgc_verbose)
4721            fprintf(stderr,"** new_areas overflow, doing full scavenge\n");
4722    
4723        /* Don't need to record new areas that get scavenge anyway        /* Don't need to record new areas that get scavenge anyway
4724           during scavenge_newspace_generation_one_scan. */           during scavenge_newspace_generation_one_scan. */
# Line 4853  free_oldspace(void) Line 4865  free_oldspace(void)
4865          fprintf(stderr,"gc_zero: page moved, 0x%08x ==> 0x%08x!\n",          fprintf(stderr,"gc_zero: page moved, 0x%08x ==> 0x%08x!\n",
4866                  page_start,addr);                  page_start,addr);
4867      } else {      } else {
4868        int *page_start, *p, *q;        int *page_start;
4869    
4870        page_start = (int *)page_address(first_page);        page_start = (int *)page_address(first_page);
       /* fprintf(stderr,"*M %x %x\n",  
          page_start,4096*(last_page-first_page)); */  
4871        i586_bzero(page_start,4096*(last_page-first_page));        i586_bzero(page_start,4096*(last_page-first_page));
       /* MADV_FREE does not guarantee that the same page will be  
          returned, so it could contain garbaged. */  
       /*if (first_page > 2)  
         madvise((void *)page_start,4096*(last_page-first_page),MADV_FREE);*/  
4872      }      }
4873    
4874      first_page = last_page;      first_page = last_page;
# Line 5165  write_protect_generation_pages(int gener Line 5171  write_protect_generation_pages(int gener
5171        page_table[i].write_protected = 1;        page_table[i].write_protected = 1;
5172      }      }
5173    
5174    if (gencgc_verbose)    if (gencgc_verbose > 1)
5175      fprintf(stderr,"Write protected %d of %d pages in generation %d.\n",      fprintf(stderr,"Write protected %d of %d pages in generation %d.\n",
5176              count_write_protect_generation_pages(generation),              count_write_protect_generation_pages(generation),
5177              count_generation_pages(generation),              count_generation_pages(generation),
# Line 5236  garbage_collect_generation(int generatio Line 5242  garbage_collect_generation(int generatio
5242    scavenge_thread_stacks();    scavenge_thread_stacks();
5243  #endif  #endif
5244    
5245    if (gencgc_verbose) {    if (gencgc_verbose > 1) {
5246      int num_dont_move_pages = count_dont_move_pages();      int num_dont_move_pages = count_dont_move_pages();
5247      fprintf(stderr,"Non-movable pages due to conservative pointers = %d, %d bytes\n",num_dont_move_pages,num_dont_move_pages*4096);      fprintf(stderr,"Non-movable pages due to conservative pointers = %d, %d bytes\n",num_dont_move_pages,num_dont_move_pages*4096);
5248    }    }
# Line 5263  garbage_collect_generation(int generatio Line 5269  garbage_collect_generation(int generatio
5269    
5270    static_space_size = (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER)    static_space_size = (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER)
5271      - static_space;      - static_space;
5272    if (gencgc_verbose)    if (gencgc_verbose > 1)
5273      fprintf(stderr,"Scavenge static space: %d bytes\n",      fprintf(stderr,"Scavenge static space: %d bytes\n",
5274              static_space_size * sizeof(lispobj));              static_space_size * sizeof(lispobj));
5275    scavenge(static_space, static_space_size);    scavenge(static_space, static_space_size);
# Line 5331  garbage_collect_generation(int generatio Line 5337  garbage_collect_generation(int generatio
5337    generations[generation].alloc_large_unboxed_start_page = 0;    generations[generation].alloc_large_unboxed_start_page = 0;
5338    
5339    if(generation >= verify_gens) {    if(generation >= verify_gens) {
5340      fprintf(stderr,"Checking\n");      if (gencgc_verbose)
5341          fprintf(stderr,"Checking\n");
5342      verify_gc();      verify_gc();
5343      verify_dynamic_space();      verify_dynamic_space();
5344    }    }
# Line 5386  collect_garbage(unsigned last_gen) Line 5393  collect_garbage(unsigned last_gen)
5393    
5394    /* Check last_gen */    /* Check last_gen */
5395    if (last_gen > NUM_GENERATIONS) {    if (last_gen > NUM_GENERATIONS) {
5396      fprintf(stderr,"** collect_garbage: last_gen = %d. Doing a level 0 GC.\n",last_gen);      fprintf(stderr,"** collect_garbage: last_gen = %d. Doing a level 0 GC.\n",
5397                last_gen);
5398      last_gen = 0;      last_gen = 0;
5399    }    }
5400    
# Line 5400  collect_garbage(unsigned last_gen) Line 5408  collect_garbage(unsigned last_gen)
5408      verify_generation(0);      verify_generation(0);
5409    }    }
5410    
5411    if (gencgc_verbose)    if (gencgc_verbose > 1)
5412      print_generation_stats(0);      print_generation_stats(0);
5413    
5414    scavenger_hooks = NIL;    scavenger_hooks = NIL;
# Line 5422  collect_garbage(unsigned last_gen) Line 5430  collect_garbage(unsigned last_gen)
5430          else          else
5431            raise = 0;            raise = 0;
5432    
5433      if (gencgc_verbose)      if (gencgc_verbose > 1)
5434        fprintf(stderr,"Starting GC of generation %d with raise=%d alloc=%d trig=%d GCs=%d\n",        fprintf(stderr,"Starting GC of generation %d with raise=%d alloc=%d trig=%d GCs=%d\n",
5435                gen,                gen,
5436                raise,                raise,
# Line 5440  collect_garbage(unsigned last_gen) Line 5448  collect_garbage(unsigned last_gen)
5448      /* Reset the memory age cum_sum */      /* Reset the memory age cum_sum */
5449      generations[gen].cum_sum_bytes_allocated = 0;      generations[gen].cum_sum_bytes_allocated = 0;
5450    
5451      if (gencgc_verbose) {      if (gencgc_verbose > 1) {
5452        fprintf(stderr,"GC of generation %d finished:\n",gen);        fprintf(stderr,"GC of generation %d finished:\n",gen);
5453        print_generation_stats(0);        print_generation_stats(0);
5454      }      }
# Line 5519  gc_free_heap(void) Line 5527  gc_free_heap(void)
5527    unsigned long  allocated = bytes_allocated;    unsigned long  allocated = bytes_allocated;
5528    int page;    int page;
5529    
5530    if (gencgc_verbose)    if (gencgc_verbose > 1)
5531      fprintf(stderr,"Free heap\n");      fprintf(stderr,"Free heap\n");
5532    
5533    for (page = 0; page < NUM_PAGES; page++)    for (page = 0; page < NUM_PAGES; page++)
# Line 5574  gc_free_heap(void) Line 5582  gc_free_heap(void)
5582      generations[page].cum_sum_bytes_allocated = 0;      generations[page].cum_sum_bytes_allocated = 0;
5583    }    }
5584    
5585    if (gencgc_verbose)    if (gencgc_verbose > 1)
5586      print_generation_stats(0);      print_generation_stats(0);
5587    
5588    /* Initialise gc_alloc */    /* Initialise gc_alloc */
# Line 5603  gc_free_heap(void) Line 5611  gc_free_heap(void)
5611    
5612    if (verify_after_free_heap) {    if (verify_after_free_heap) {
5613      /* Check if purify has left any bad pointers. */      /* Check if purify has left any bad pointers. */
5614      fprintf(stderr,"Checking after free_heap.\n");      if (gencgc_verbose)
5615          fprintf(stderr,"Checking after free_heap.\n");
5616      verify_gc();      verify_gc();
5617    }    }
5618  }  }
# Line 5784  char Line 5793  char
5793       */       */
5794      sigset_t mask;      sigset_t mask;
5795      sigprocmask(0,NULL,&mask);      sigprocmask(0,NULL,&mask);
5796      if (!mask) {      if (!mask)
       /*  
       sigset_t block;  
 #ifdef POSIX_SIGS  
       sigemptyset(&block);  
       FILLBLOCKSET(&block);  
       sigprocmask(SIG_BLOCK, &block,NULL);  
 #else  
       sigblock(BLOCKABLE);  
 #endif  
       lose("Alloc non-atomic %x\n", mask);  
       */  
5797        fprintf(stderr,"* Alloc non-atomic %x\n", mask);        fprintf(stderr,"* Alloc non-atomic %x\n", mask);
     }  
5798  #endif  #endif
5799    
5800    retry2:    retry2:

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.5