/libs/headers/gc/gc_mark.h

http://github.com/nddrylliog/ooc · C++ Header · 201 lines · 52 code · 19 blank · 130 comment · 1 complexity · 4aaa35de76b4d0cfe7db368c06f6d506 MD5 · raw file

  1. /*
  2. * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
  3. * Copyright (c) 2001 by Hewlett-Packard Company. All rights reserved.
  4. *
  5. * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  6. * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
  7. *
  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.
  13. *
  14. */
  15. /*
  16. * This contains interfaces to the GC marker that are likely to be useful to
  17. * clients that provide detailed heap layout information to the collector.
  18. * This interface should not be used by normal C or C++ clients.
  19. * It will be useful to runtimes for other languages.
  20. *
  21. * This is an experts-only interface! There are many ways to break the
  22. * collector in subtle ways by using this functionality.
  23. */
  24. #ifndef GC_MARK_H
  25. # define GC_MARK_H
  26. # ifndef GC_H
  27. # include "gc.h"
  28. # endif
  29. /* A client supplied mark procedure. Returns new mark stack pointer. */
  30. /* Primary effect should be to push new entries on the mark stack. */
  31. /* Mark stack pointer values are passed and returned explicitly. */
  32. /* Global variables decribing mark stack are not necessarily valid. */
  33. /* (This usually saves a few cycles by keeping things in registers.) */
  34. /* Assumed to scan about GC_PROC_BYTES on average. If it needs to do */
  35. /* much more work than that, it should do it in smaller pieces by */
  36. /* pushing itself back on the mark stack. */
  37. /* Note that it should always do some work (defined as marking some */
  38. /* objects) before pushing more than one entry on the mark stack. */
  39. /* This is required to ensure termination in the event of mark stack */
  40. /* overflows. */
  41. /* This procedure is always called with at least one empty entry on the */
  42. /* mark stack. */
  43. /* Currently we require that mark procedures look for pointers in a */
  44. /* subset of the places the conservative marker would. It must be safe */
  45. /* to invoke the normal mark procedure instead. */
  46. /* WARNING: Such a mark procedure may be invoked on an unused object */
  47. /* residing on a free list. Such objects are cleared, except for a */
  48. /* free list link field in the first word. Thus mark procedures may */
  49. /* not count on the presence of a type descriptor, and must handle this */
  50. /* case correctly somehow. */
  51. # define GC_PROC_BYTES 100
  52. struct GC_ms_entry;
  53. typedef struct GC_ms_entry * (*GC_mark_proc) (
  54. GC_word * addr, struct GC_ms_entry * mark_stack_ptr,
  55. struct GC_ms_entry * mark_stack_limit, GC_word env);
  56. # define GC_LOG_MAX_MARK_PROCS 6
  57. # define GC_MAX_MARK_PROCS (1 << GC_LOG_MAX_MARK_PROCS)
  58. /* In a few cases it's necessary to assign statically known indices to */
  59. /* certain mark procs. Thus we reserve a few for well known clients. */
  60. /* (This is necessary if mark descriptors are compiler generated.) */
  61. #define GC_RESERVED_MARK_PROCS 8
  62. # define GC_GCJ_RESERVED_MARK_PROC_INDEX 0
  63. /* Object descriptors on mark stack or in objects. Low order two */
  64. /* bits are tags distinguishing among the following 4 possibilities */
  65. /* for the high order 30 bits. */
  66. #define GC_DS_TAG_BITS 2
  67. #define GC_DS_TAGS ((1 << GC_DS_TAG_BITS) - 1)
  68. #define GC_DS_LENGTH 0 /* The entire word is a length in bytes that */
  69. /* must be a multiple of 4. */
  70. #define GC_DS_BITMAP 1 /* 30 (62) bits are a bitmap describing pointer */
  71. /* fields. The msb is 1 iff the first word */
  72. /* is a pointer. */
  73. /* (This unconventional ordering sometimes */
  74. /* makes the marker slightly faster.) */
  75. /* Zeroes indicate definite nonpointers. Ones */
  76. /* indicate possible pointers. */
  77. /* Only usable if pointers are word aligned. */
  78. #define GC_DS_PROC 2
  79. /* The objects referenced by this object can be */
  80. /* pushed on the mark stack by invoking */
  81. /* PROC(descr). ENV(descr) is passed as the */
  82. /* last argument. */
  83. # define GC_MAKE_PROC(proc_index, env) \
  84. (((((env) << GC_LOG_MAX_MARK_PROCS) \
  85. | (proc_index)) << GC_DS_TAG_BITS) | GC_DS_PROC)
  86. #define GC_DS_PER_OBJECT 3 /* The real descriptor is at the */
  87. /* byte displacement from the beginning of the */
  88. /* object given by descr & ~DS_TAGS */
  89. /* If the descriptor is negative, the real */
  90. /* descriptor is at (*<object_start>) - */
  91. /* (descr & ~DS_TAGS) - GC_INDIR_PER_OBJ_BIAS */
  92. /* The latter alternative can be used if each */
  93. /* object contains a type descriptor in the */
  94. /* first word. */
  95. /* Note that in multithreaded environments */
  96. /* per object descriptors maust be located in */
  97. /* either the first two or last two words of */
  98. /* the object, since only those are guaranteed */
  99. /* to be cleared while the allocation lock is */
  100. /* held. */
  101. #define GC_INDIR_PER_OBJ_BIAS 0x10
  102. extern void * GC_least_plausible_heap_addr;
  103. extern void * GC_greatest_plausible_heap_addr;
  104. /* Bounds on the heap. Guaranteed valid */
  105. /* Likely to include future heap expansion. */
  106. /* Handle nested references in a custom mark procedure. */
  107. /* Check if obj is a valid object. If so, ensure that it is marked. */
  108. /* If it was not previously marked, push its contents onto the mark */
  109. /* stack for future scanning. The object will then be scanned using */
  110. /* its mark descriptor. */
  111. /* Returns the new mark stack pointer. */
  112. /* Handles mark stack overflows correctly. */
  113. /* Since this marks first, it makes progress even if there are mark */
  114. /* stack overflows. */
  115. /* Src is the address of the pointer to obj, which is used only */
  116. /* for back pointer-based heap debugging. */
  117. /* It is strongly recommended that most objects be handled without mark */
  118. /* procedures, e.g. with bitmap descriptors, and that mark procedures */
  119. /* be reserved for exceptional cases. That will ensure that */
  120. /* performance of this call is not extremely performance critical. */
  121. /* (Otherwise we would need to inline GC_mark_and_push completely, */
  122. /* which would tie the client code to a fixed collector version.) */
  123. /* Note that mark procedures should explicitly call FIXUP_POINTER() */
  124. /* if required. */
  125. struct GC_ms_entry *GC_mark_and_push(void * obj,
  126. struct GC_ms_entry * mark_stack_ptr,
  127. struct GC_ms_entry * mark_stack_limit,
  128. void * *src);
  129. #define GC_MARK_AND_PUSH(obj, msp, lim, src) \
  130. (((GC_word)obj >= (GC_word)GC_least_plausible_heap_addr && \
  131. (GC_word)obj <= (GC_word)GC_greatest_plausible_heap_addr)? \
  132. GC_mark_and_push(obj, msp, lim, src) : \
  133. msp)
  134. extern size_t GC_debug_header_size;
  135. /* The size of the header added to objects allocated through */
  136. /* the GC_debug routines. */
  137. /* Defined as a variable so that client mark procedures don't */
  138. /* need to be recompiled for collector version changes. */
  139. #define GC_USR_PTR_FROM_BASE(p) ((void *)((char *)(p) + GC_debug_header_size))
  140. /* And some routines to support creation of new "kinds", e.g. with */
  141. /* custom mark procedures, by language runtimes. */
  142. /* The _inner versions assume the caller holds the allocation lock. */
  143. /* Return a new free list array. */
  144. void ** GC_new_free_list(void);
  145. void ** GC_new_free_list_inner(void);
  146. /* Return a new kind, as specified. */
  147. unsigned GC_new_kind(void **free_list, GC_word mark_descriptor_template,
  148. int add_size_to_descriptor, int clear_new_objects);
  149. /* The last two parameters must be zero or one. */
  150. unsigned GC_new_kind_inner(void **free_list,
  151. GC_word mark_descriptor_template,
  152. int add_size_to_descriptor,
  153. int clear_new_objects);
  154. /* Return a new mark procedure identifier, suitable for use as */
  155. /* the first argument in GC_MAKE_PROC. */
  156. unsigned GC_new_proc(GC_mark_proc);
  157. unsigned GC_new_proc_inner(GC_mark_proc);
  158. /* Allocate an object of a given kind. Note that in multithreaded */
  159. /* contexts, this is usually unsafe for kinds that have the descriptor */
  160. /* in the object itself, since there is otherwise a window in which */
  161. /* the descriptor is not correct. Even in the single-threaded case, */
  162. /* we need to be sure that cleared objects on a free list don't */
  163. /* cause a GC crash if they are accidentally traced. */
  164. void * GC_generic_malloc(size_t lb, int k);
  165. typedef void (*GC_describe_type_fn) (void *p, char *out_buf);
  166. /* A procedure which */
  167. /* produces a human-readable */
  168. /* description of the "type" of object */
  169. /* p into the buffer out_buf of length */
  170. /* GC_TYPE_DESCR_LEN. This is used by */
  171. /* the debug support when printing */
  172. /* objects. */
  173. /* These functions should be as robust */
  174. /* as possible, though we do avoid */
  175. /* invoking them on objects on the */
  176. /* global free list. */
  177. # define GC_TYPE_DESCR_LEN 40
  178. void GC_register_describe_type_fn(int kind, GC_describe_type_fn knd);
  179. /* Register a describe_type function */
  180. /* to be used when printing objects */
  181. /* of a particular kind. */
  182. #endif /* GC_MARK_H */