2 * Copyright (c) 1992-1994 by Xerox Corporation. All rights reserved.
4 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 * Permission is hereby granted to use or copy this program
8 * for any purpose, provided the above notices are retained on all copies.
9 * Permission to modify the code and to distribute modified code is granted,
10 * provided the above notices are retained, and a notice that the code was
11 * modified is included with the above copyright notice.
13 /* Boehm, March 29, 1995 12:51 pm PST */
19 # include "private/gc_priv.h"
21 /* This is debugging code intended to verify the results of dirty bit */
22 /* computations. Works only in a single threaded environment. */
23 /* We assume that stubborn objects are changed only when they are */
24 /* enabled for writing. (Certain kinds of writing are actually */
25 /* safe under other conditions.) */
28 # define OFFSET 0x10000
34 struct hblk * block; /* Block to which this refers + OFFSET */
35 /* to hide it from collector. */
38 page_entry GC_sums [NSUMS];
43 register word *p = (word *)h;
44 register word *lim = (word *)(h+1);
45 register word result = 0;
50 return(result | 0x80000000 /* doesn't look like pointer */);
53 # ifdef STUBBORN_ALLOC
54 /* Check whether a stubborn object from the given block appears on */
55 /* the appropriate free list. */
56 GC_bool GC_on_free_list(struct hblk *h)
60 int sz = BYTES_TO_WORDS(hhdr -> hb_sz);
63 if (sz > MAXOBJWORDS) return(FALSE);
64 for (p = GC_sobjfreelist[sz]; p != 0; p = obj_link(p)) {
65 if (HBLKPTR(p) == h) return(TRUE);
71 int GC_n_dirty_errors;
72 int GC_n_changed_errors;
76 void GC_update_check_page(struct hblk *h, int index)
78 page_entry *pe = GC_sums + index;
79 register hdr * hhdr = HDR(h);
82 if (pe -> block != 0 && pe -> block != h + OFFSET) ABORT("goofed");
83 pe -> old_sum = pe -> new_sum;
84 pe -> new_sum = GC_checksum(h);
85 # if !defined(MSWIN32) && !defined(MSWINCE)
86 if (pe -> new_sum != 0x80000000 && !GC_page_was_ever_dirty(h)) {
87 GC_printf("GC_page_was_ever_dirty(%p) is wrong\n", h);
90 if (GC_page_was_dirty(h)) {
96 while (IS_FORWARDING_ADDR_OR_NIL(hhdr) && hhdr != 0) {
101 && hhdr != 0 && hhdr -> hb_descr != 0 /* may contain pointers */
102 && pe -> old_sum != pe -> new_sum) {
103 if (!GC_page_was_dirty(h) || !GC_page_was_ever_dirty(h)) {
104 /* Set breakpoint here */GC_n_dirty_errors++;
106 # ifdef STUBBORN_ALLOC
107 if (!HBLK_IS_FREE(hhdr)
108 && hhdr -> hb_obj_kind == STUBBORN
109 && !GC_page_was_changed(h)
110 && !GC_on_free_list(h)) {
111 /* if GC_on_free_list(h) then reclaim may have touched it */
112 /* without any allocations taking place. */
113 /* Set breakpoint here */GC_n_changed_errors++;
117 pe -> new_valid = TRUE;
118 pe -> block = h + OFFSET;
121 unsigned long GC_bytes_in_used_blocks;
123 void GC_add_block(h, dummy)
128 bytes = hhdr -> hb_sz;
131 bytes &= ~(HBLKSIZE-1);
132 GC_bytes_in_used_blocks += bytes;
135 void GC_check_blocks()
137 unsigned long bytes_in_free_blocks = GC_large_free_bytes;
139 GC_bytes_in_used_blocks = 0;
140 GC_apply_to_all_blocks(GC_add_block, (word)0);
141 GC_printf("GC_bytes_in_used_blocks = %lu, bytes_in_free_blocks = %lu ",
142 GC_bytes_in_used_blocks, bytes_in_free_blocks);
143 GC_printf("GC_heapsize = %lu\n", (unsigned long)GC_heapsize);
144 if (GC_bytes_in_used_blocks + bytes_in_free_blocks != GC_heapsize) {
145 GC_printf("LOST SOME BLOCKS!!\n");
149 /* Should be called immediately after GC_read_dirty and GC_read_changed. */
150 void GC_check_dirty()
154 register struct hblk *h;
155 register ptr_t start;
159 GC_n_dirty_errors = 0;
160 GC_n_changed_errors = 0;
165 for (i = 0; i < GC_n_heap_sects; i++) {
166 start = GC_heap_sects[i].hs_start;
167 for (h = (struct hblk *)start;
168 h < (struct hblk *)(start + GC_heap_sects[i].hs_bytes);
170 GC_update_check_page(h, index);
172 if (index >= NSUMS) goto out;
176 GC_printf("Checked %lu clean and %lu dirty pages\n",
177 (unsigned long) GC_n_clean, (unsigned long) GC_n_dirty);
178 if (GC_n_dirty_errors > 0) {
179 GC_printf("Found %lu dirty bit errors\n",
180 (unsigned long)GC_n_dirty_errors);
182 if (GC_n_changed_errors > 0) {
183 GC_printf("Found %lu changed bit errors\n",
184 (unsigned long)GC_n_changed_errors);
185 GC_printf("These may be benign (provoked by nonpointer changes)\n");
188 "Also expect 1 per thread currently allocating a stubborn obj.\n");
196 /* ANSI C doesn't allow translation units to be empty. */
197 /* So we guarantee this one is nonempty. */
199 # endif /* CHECKSUMS */