C:/Users/Dennis/src/lang/russell.orig/src/gc/obj_map.c

Go to the documentation of this file.
00001 /* 
00002  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
00003  * Copyright (c) 1991, 1992 by Xerox Corporation.  All rights reserved.
00004  *
00005  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
00006  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00007  *
00008  * Permission is hereby granted to copy this garbage collector for any purpose,
00009  * provided the above notices are retained on all copies.
00010  */
00011   
00012 /* Routines for maintaining maps describing heap block
00013  * layouts for various object sizes.  Allows fast pointer validity checks
00014  * and fast location of object start locations on machines (such as SPARC)
00015  * with slow division.
00016  *
00017  * Boehm, February 6, 1992 1:00:09 pm PST
00018  */
00019  
00020 # include "gc_private.h"
00021 
00022 char * GC_invalid_map = 0;
00023 
00024 /* Invalidate the object map associated with a block.   Free blocks     */
00025 /* are identified by invalid maps.                                      */
00026 void GC_invalidate_map(hhdr)
00027 hdr *hhdr;
00028 {
00029     register int displ;
00030     
00031     if (GC_invalid_map == 0) {
00032         GC_invalid_map = GC_scratch_alloc(MAP_SIZE);
00033         for (displ = 0; displ < HBLKSIZE; displ++) {
00034             MAP_ENTRY(GC_invalid_map, displ) = OBJ_INVALID;
00035         }
00036     }
00037     hhdr -> hb_map = GC_invalid_map;
00038 }
00039 
00040 /* Consider pointers that are offset bytes displaced from the beginning */
00041 /* of an object to be valid.                                            */
00042 void GC_register_displacement(offset) 
00043 word offset;
00044 {
00045 # ifndef ALL_INTERIOR_POINTERS
00046     DCL_LOCK_STATE;
00047     
00048     DISABLE_SIGNALS();
00049     LOCK();
00050     GC_register_displacement_inner(offset);
00051     UNLOCK();
00052     ENABLE_SIGNALS();
00053 # endif
00054 }
00055 
00056 void GC_register_displacement_inner(offset) 
00057 word offset;
00058 {
00059 # ifndef ALL_INTERIOR_POINTERS
00060     register int i;
00061     
00062     if (offset > MAX_OFFSET) {
00063         ABORT("Bad argument to GC_register_displacement");
00064     }
00065     if (!GC_valid_offsets[offset]) {
00066       GC_valid_offsets[offset] = TRUE;
00067       GC_modws_valid_offsets[offset % sizeof(word)] = TRUE;
00068       for (i = 0; i <= MAXOBJSZ; i++) {
00069           if (GC_obj_map[i] != 0) {
00070              if (i == 0) {
00071                GC_obj_map[i][offset + HDR_BYTES] = offset >> 2;
00072              } else {
00073                register int j;
00074                register int lb = WORDS_TO_BYTES(i);
00075                
00076                if (offset < lb) {
00077                  for (j = offset + HDR_BYTES; j < HBLKSIZE; j += lb) {
00078                    GC_obj_map[i][j] = offset >> 2;
00079                  }
00080                }
00081              }
00082           }
00083       }
00084     }
00085 # endif
00086 }
00087 
00088 
00089 /* Add a heap block map for objects of size sz to obj_map.  */
00090 void GC_add_map_entry(sz)
00091 word sz;
00092 {
00093     register int obj_start;
00094     register int displ;
00095     register char * new_map;
00096     
00097     if (sz > MAXOBJSZ) sz = 0;
00098     if (GC_obj_map[sz] != 0) {
00099         return;
00100     }
00101     new_map = GC_scratch_alloc(MAP_SIZE);
00102 #   ifdef PRINTSTATS
00103         GC_printf1("Adding block map for size %lu\n", (unsigned long)sz);
00104 #   endif
00105     for (displ = 0; displ < HBLKSIZE; displ++) {
00106         MAP_ENTRY(new_map,displ) = OBJ_INVALID;
00107     }
00108     if (sz == 0) {
00109         for(displ = 0; displ <= MAX_OFFSET; displ++) {
00110             if (OFFSET_VALID(displ)) {
00111                 MAP_ENTRY(new_map,displ+HDR_BYTES) = BYTES_TO_WORDS(displ);
00112             }
00113         }
00114     } else {
00115         for (obj_start = HDR_BYTES;
00116              obj_start + WORDS_TO_BYTES(sz) <= HBLKSIZE;
00117              obj_start += WORDS_TO_BYTES(sz)) {
00118              for (displ = 0; displ < WORDS_TO_BYTES(sz); displ++) {
00119                  if (OFFSET_VALID(displ)) {
00120                      MAP_ENTRY(new_map, obj_start + displ) =
00121                                                 BYTES_TO_WORDS(displ);
00122                  }
00123              }
00124         }
00125     }
00126     GC_obj_map[sz] = new_map;
00127 }

Generated on Fri Jan 25 10:39:45 2008 for russell by  doxygen 1.5.4