/Src/Dependencies/Boost/tools/build/v2/engine/boehm_gc/checksums.c

http://hadesmem.googlecode.com/ · C · 196 lines · 146 code · 24 blank · 26 comment · 41 complexity · c49b9452fa4c1cadce7bcf95c34e07a3 MD5 · raw file

  1. /*
  2. * Copyright (c) 1992-1994 by Xerox Corporation. All rights reserved.
  3. *
  4. * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  5. * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
  6. *
  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.
  12. */
  13. /* Boehm, March 29, 1995 12:51 pm PST */
  14. # ifdef CHECKSUMS
  15. # include "private/gc_priv.h"
  16. /* This is debugging code intended to verify the results of dirty bit */
  17. /* computations. Works only in a single threaded environment. */
  18. /* We assume that stubborn objects are changed only when they are */
  19. /* enabled for writing. (Certain kinds of writing are actually */
  20. /* safe under other conditions.) */
  21. # define NSUMS 10000
  22. # define OFFSET 0x10000
  23. typedef struct {
  24. GC_bool new_valid;
  25. word old_sum;
  26. word new_sum;
  27. struct hblk * block; /* Block to which this refers + OFFSET */
  28. /* to hide it from collector. */
  29. } page_entry;
  30. page_entry GC_sums [NSUMS];
  31. word GC_checksum(h)
  32. struct hblk *h;
  33. {
  34. register word *p = (word *)h;
  35. register word *lim = (word *)(h+1);
  36. register word result = 0;
  37. while (p < lim) {
  38. result += *p++;
  39. }
  40. return(result | 0x80000000 /* doesn't look like pointer */);
  41. }
  42. # ifdef STUBBORN_ALLOC
  43. /* Check whether a stubborn object from the given block appears on */
  44. /* the appropriate free list. */
  45. GC_bool GC_on_free_list(struct hblk *h)
  46. struct hblk *h;
  47. {
  48. hdr * hhdr = HDR(h);
  49. int sz = BYTES_TO_WORDS(hhdr -> hb_sz);
  50. ptr_t p;
  51. if (sz > MAXOBJWORDS) return(FALSE);
  52. for (p = GC_sobjfreelist[sz]; p != 0; p = obj_link(p)) {
  53. if (HBLKPTR(p) == h) return(TRUE);
  54. }
  55. return(FALSE);
  56. }
  57. # endif
  58. int GC_n_dirty_errors;
  59. int GC_n_changed_errors;
  60. int GC_n_clean;
  61. int GC_n_dirty;
  62. void GC_update_check_page(struct hblk *h, int index)
  63. {
  64. page_entry *pe = GC_sums + index;
  65. register hdr * hhdr = HDR(h);
  66. struct hblk *b;
  67. if (pe -> block != 0 && pe -> block != h + OFFSET) ABORT("goofed");
  68. pe -> old_sum = pe -> new_sum;
  69. pe -> new_sum = GC_checksum(h);
  70. # if !defined(MSWIN32) && !defined(MSWINCE)
  71. if (pe -> new_sum != 0x80000000 && !GC_page_was_ever_dirty(h)) {
  72. GC_printf("GC_page_was_ever_dirty(%p) is wrong\n", h);
  73. }
  74. # endif
  75. if (GC_page_was_dirty(h)) {
  76. GC_n_dirty++;
  77. } else {
  78. GC_n_clean++;
  79. }
  80. b = h;
  81. while (IS_FORWARDING_ADDR_OR_NIL(hhdr) && hhdr != 0) {
  82. b -= (word)hhdr;
  83. hhdr = HDR(b);
  84. }
  85. if (pe -> new_valid
  86. && hhdr != 0 && hhdr -> hb_descr != 0 /* may contain pointers */
  87. && pe -> old_sum != pe -> new_sum) {
  88. if (!GC_page_was_dirty(h) || !GC_page_was_ever_dirty(h)) {
  89. /* Set breakpoint here */GC_n_dirty_errors++;
  90. }
  91. # ifdef STUBBORN_ALLOC
  92. if (!HBLK_IS_FREE(hhdr)
  93. && hhdr -> hb_obj_kind == STUBBORN
  94. && !GC_page_was_changed(h)
  95. && !GC_on_free_list(h)) {
  96. /* if GC_on_free_list(h) then reclaim may have touched it */
  97. /* without any allocations taking place. */
  98. /* Set breakpoint here */GC_n_changed_errors++;
  99. }
  100. # endif
  101. }
  102. pe -> new_valid = TRUE;
  103. pe -> block = h + OFFSET;
  104. }
  105. unsigned long GC_bytes_in_used_blocks;
  106. void GC_add_block(h, dummy)
  107. struct hblk *h;
  108. word dummy;
  109. {
  110. hdr * hhdr = HDR(h);
  111. bytes = hhdr -> hb_sz;
  112. bytes += HBLKSIZE-1;
  113. bytes &= ~(HBLKSIZE-1);
  114. GC_bytes_in_used_blocks += bytes;
  115. }
  116. void GC_check_blocks()
  117. {
  118. unsigned long bytes_in_free_blocks = GC_large_free_bytes;
  119. GC_bytes_in_used_blocks = 0;
  120. GC_apply_to_all_blocks(GC_add_block, (word)0);
  121. GC_printf("GC_bytes_in_used_blocks = %lu, bytes_in_free_blocks = %lu ",
  122. GC_bytes_in_used_blocks, bytes_in_free_blocks);
  123. GC_printf("GC_heapsize = %lu\n", (unsigned long)GC_heapsize);
  124. if (GC_bytes_in_used_blocks + bytes_in_free_blocks != GC_heapsize) {
  125. GC_printf("LOST SOME BLOCKS!!\n");
  126. }
  127. }
  128. /* Should be called immediately after GC_read_dirty and GC_read_changed. */
  129. void GC_check_dirty()
  130. {
  131. register int index;
  132. register unsigned i;
  133. register struct hblk *h;
  134. register ptr_t start;
  135. GC_check_blocks();
  136. GC_n_dirty_errors = 0;
  137. GC_n_changed_errors = 0;
  138. GC_n_clean = 0;
  139. GC_n_dirty = 0;
  140. index = 0;
  141. for (i = 0; i < GC_n_heap_sects; i++) {
  142. start = GC_heap_sects[i].hs_start;
  143. for (h = (struct hblk *)start;
  144. h < (struct hblk *)(start + GC_heap_sects[i].hs_bytes);
  145. h++) {
  146. GC_update_check_page(h, index);
  147. index++;
  148. if (index >= NSUMS) goto out;
  149. }
  150. }
  151. out:
  152. GC_printf("Checked %lu clean and %lu dirty pages\n",
  153. (unsigned long) GC_n_clean, (unsigned long) GC_n_dirty);
  154. if (GC_n_dirty_errors > 0) {
  155. GC_printf("Found %lu dirty bit errors\n",
  156. (unsigned long)GC_n_dirty_errors);
  157. }
  158. if (GC_n_changed_errors > 0) {
  159. GC_printf("Found %lu changed bit errors\n",
  160. (unsigned long)GC_n_changed_errors);
  161. GC_printf("These may be benign (provoked by nonpointer changes)\n");
  162. # ifdef THREADS
  163. GC_printf(
  164. "Also expect 1 per thread currently allocating a stubborn obj.\n");
  165. # endif
  166. }
  167. }
  168. # else
  169. extern int GC_quiet;
  170. /* ANSI C doesn't allow translation units to be empty. */
  171. /* So we guarantee this one is nonempty. */
  172. # endif /* CHECKSUMS */