2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991, 1992 by Xerox Corporation. All rights reserved.
5 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
6 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
8 * Permission is hereby granted to use or copy this program
9 * for any purpose, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
14 /* Boehm, October 9, 1995 1:09 pm PDT */
16 /* Routines for maintaining maps describing heap block
17 * layouts for various object sizes. Allows fast pointer validity checks
18 * and fast location of object start locations on machines (such as SPARC)
24 char * GC_invalid_map = 0;
26 /* Invalidate the object map associated with a block. Free blocks */
27 /* are identified by invalid maps. */
28 void GC_invalidate_map(hhdr)
33 if (GC_invalid_map == 0) {
34 GC_invalid_map = GC_scratch_alloc(MAP_SIZE);
35 if (GC_invalid_map == 0) {
37 "Cant initialize GC_invalid_map: insufficient memory\n");
40 for (displ = 0; displ < HBLKSIZE; displ++) {
41 MAP_ENTRY(GC_invalid_map, displ) = OBJ_INVALID;
44 hhdr -> hb_map = GC_invalid_map;
47 /* Consider pointers that are offset bytes displaced from the beginning */
48 /* of an object to be valid. */
50 # if defined(__STDC__) || defined(__cplusplus)
51 void GC_register_displacement(GC_word offset)
53 void GC_register_displacement(offset)
57 # ifndef ALL_INTERIOR_POINTERS
62 GC_register_displacement_inner(offset);
68 void GC_register_displacement_inner(offset)
71 # ifndef ALL_INTERIOR_POINTERS
74 if (offset > MAX_OFFSET) {
75 ABORT("Bad argument to GC_register_displacement");
77 if (!GC_valid_offsets[offset]) {
78 GC_valid_offsets[offset] = TRUE;
79 GC_modws_valid_offsets[offset % sizeof(word)] = TRUE;
80 for (i = 0; i <= MAXOBJSZ; i++) {
81 if (GC_obj_map[i] != 0) {
83 GC_obj_map[i][offset + HDR_BYTES] = (char)BYTES_TO_WORDS(offset);
86 register unsigned lb = WORDS_TO_BYTES(i);
89 for (j = offset + HDR_BYTES; j < HBLKSIZE; j += lb) {
90 GC_obj_map[i][j] = (char)BYTES_TO_WORDS(offset);
101 /* Add a heap block map for objects of size sz to obj_map. */
102 /* Return FALSE on failure. */
103 GC_bool GC_add_map_entry(sz)
106 register unsigned obj_start;
107 register unsigned displ;
108 register char * new_map;
110 if (sz > MAXOBJSZ) sz = 0;
111 if (GC_obj_map[sz] != 0) {
114 new_map = GC_scratch_alloc(MAP_SIZE);
115 if (new_map == 0) return(FALSE);
117 GC_printf1("Adding block map for size %lu\n", (unsigned long)sz);
119 for (displ = 0; displ < HBLKSIZE; displ++) {
120 MAP_ENTRY(new_map,displ) = OBJ_INVALID;
123 for(displ = 0; displ <= MAX_OFFSET; displ++) {
124 if (OFFSET_VALID(displ)) {
125 MAP_ENTRY(new_map,displ+HDR_BYTES) = BYTES_TO_WORDS(displ);
129 for (obj_start = HDR_BYTES;
130 obj_start + WORDS_TO_BYTES(sz) <= HBLKSIZE;
131 obj_start += WORDS_TO_BYTES(sz)) {
132 for (displ = 0; displ < WORDS_TO_BYTES(sz); displ++) {
133 if (OFFSET_VALID(displ)) {
134 MAP_ENTRY(new_map, obj_start + displ) =
135 BYTES_TO_WORDS(displ);
140 GC_obj_map[sz] = new_map;