summaryrefslogtreecommitdiff
path: root/obj_map.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2011-07-26 18:09:54 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 18:09:54 +0200
commite35a4171fe47dfbf847e08988ea6cec4dfc8d124 (patch)
tree25f3501669fbf24a4b370c4f8b0c0701b1da4062 /obj_map.c
parentffa0c9ea38b3dd87e91b5ed2118c74002fed6782 (diff)
gc7.0alpha1 tarball importgc7_0alpha1
Diffstat (limited to 'obj_map.c')
-rw-r--r--obj_map.c131
1 files changed, 37 insertions, 94 deletions
diff --git a/obj_map.c b/obj_map.c
index d002d65..3b9a09d 100644
--- a/obj_map.c
+++ b/obj_map.c
@@ -21,127 +21,70 @@
# include "private/gc_priv.h"
-map_entry_type * GC_invalid_map = 0;
-
-/* Invalidate the object map associated with a block. Free blocks */
-/* are identified by invalid maps. */
-void GC_invalidate_map(hhdr)
-hdr *hhdr;
-{
- register int displ;
-
- if (GC_invalid_map == 0) {
- GC_invalid_map = (map_entry_type *)GC_scratch_alloc(MAP_SIZE);
- if (GC_invalid_map == 0) {
- GC_err_printf0(
- "Cant initialize GC_invalid_map: insufficient memory\n");
- EXIT();
- }
- for (displ = 0; displ < HBLKSIZE; displ++) {
- MAP_ENTRY(GC_invalid_map, displ) = OBJ_INVALID;
- }
- }
- hhdr -> hb_map = GC_invalid_map;
-}
-
/* Consider pointers that are offset bytes displaced from the beginning */
/* of an object to be valid. */
-# if defined(__STDC__) || defined(__cplusplus)
- void GC_register_displacement(GC_word offset)
-# else
- void GC_register_displacement(offset)
- GC_word offset;
-# endif
+void GC_register_displacement(size_t offset)
{
DCL_LOCK_STATE;
- DISABLE_SIGNALS();
LOCK();
GC_register_displacement_inner(offset);
UNLOCK();
- ENABLE_SIGNALS();
}
-void GC_register_displacement_inner(offset)
-word offset;
+void GC_register_displacement_inner(size_t offset)
{
- register unsigned i;
- word map_entry = BYTES_TO_WORDS(offset);
-
if (offset >= VALID_OFFSET_SZ) {
ABORT("Bad argument to GC_register_displacement");
}
- if (map_entry > MAX_OFFSET) map_entry = OFFSET_TOO_BIG;
if (!GC_valid_offsets[offset]) {
GC_valid_offsets[offset] = TRUE;
GC_modws_valid_offsets[offset % sizeof(word)] = TRUE;
- if (!GC_all_interior_pointers) {
- for (i = 0; i <= MAXOBJSZ; i++) {
- if (GC_obj_map[i] != 0) {
- if (i == 0) {
- GC_obj_map[i][offset] = (map_entry_type)map_entry;
- } else {
- register unsigned j;
- register unsigned lb = WORDS_TO_BYTES(i);
-
- if (offset < lb) {
- for (j = offset; j < HBLKSIZE; j += lb) {
- GC_obj_map[i][j] = (map_entry_type)map_entry;
- }
- }
- }
- }
- }
- }
}
}
-
-/* Add a heap block map for objects of size sz to obj_map. */
-/* Return FALSE on failure. */
-GC_bool GC_add_map_entry(sz)
-word sz;
+#ifdef MARK_BIT_PER_GRANULE
+/* Add a heap block map for objects of size granules to obj_map. */
+/* Return FALSE on failure. */
+/* A size of 0 granules is used for large objects. */
+GC_bool GC_add_map_entry(size_t granules)
{
- register unsigned obj_start;
- register unsigned displ;
- register map_entry_type * new_map;
- word map_entry;
+ unsigned displ;
+ short * new_map;
- if (sz > MAXOBJSZ) sz = 0;
- if (GC_obj_map[sz] != 0) {
+ if (granules > BYTES_TO_GRANULES(MAXOBJBYTES)) granules = 0;
+ if (GC_obj_map[granules] != 0) {
return(TRUE);
}
- new_map = (map_entry_type *)GC_scratch_alloc(MAP_SIZE);
+ new_map = (short *)GC_scratch_alloc(MAP_LEN * sizeof(short));
if (new_map == 0) return(FALSE);
-# ifdef PRINTSTATS
- GC_printf1("Adding block map for size %lu\n", (unsigned long)sz);
-# endif
- for (displ = 0; displ < HBLKSIZE; displ++) {
- MAP_ENTRY(new_map,displ) = OBJ_INVALID;
- }
- if (sz == 0) {
- for(displ = 0; displ <= HBLKSIZE; displ++) {
- if (OFFSET_VALID(displ)) {
- map_entry = BYTES_TO_WORDS(displ);
- if (map_entry > MAX_OFFSET) map_entry = OFFSET_TOO_BIG;
- MAP_ENTRY(new_map,displ) = (map_entry_type)map_entry;
- }
- }
+ if (GC_print_stats)
+ GC_printf("Adding block map for size of %u granules (%u bytes)\n",
+ (unsigned)granules, (unsigned)(GRANULES_TO_BYTES(granules)));
+ if (granules == 0) {
+ for (displ = 0; displ < BYTES_TO_GRANULES(HBLKSIZE); displ++) {
+ new_map[displ] = 1; /* Nonzero to get us out of marker fast path. */
+ }
} else {
- for (obj_start = 0;
- obj_start + WORDS_TO_BYTES(sz) <= HBLKSIZE;
- obj_start += WORDS_TO_BYTES(sz)) {
- for (displ = 0; displ < WORDS_TO_BYTES(sz); displ++) {
- if (OFFSET_VALID(displ)) {
- map_entry = BYTES_TO_WORDS(displ);
- if (map_entry > MAX_OFFSET) map_entry = OFFSET_TOO_BIG;
- MAP_ENTRY(new_map, obj_start + displ) =
- (map_entry_type)map_entry;
- }
- }
- }
+ for (displ = 0; displ < BYTES_TO_GRANULES(HBLKSIZE); displ++) {
+ new_map[displ] = displ % granules;
+ }
}
- GC_obj_map[sz] = new_map;
+ GC_obj_map[granules] = new_map;
return(TRUE);
}
+#endif
+
+static GC_bool offsets_initialized = FALSE;
+
+void GC_initialize_offsets(void)
+{
+ if (!offsets_initialized) {
+ int i;
+ if (GC_all_interior_pointers) {
+ for (i = 0; i < VALID_OFFSET_SZ; ++i) GC_valid_offsets[i] = TRUE;
+ }
+ offsets_initialized = TRUE;
+ }
+}