Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

200 rindas
7.9KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>User GC (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="User GC (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="User GC (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Type-Information.html#Type-Information" rel="up" title="Type Information">
  30. <link href="GGC-Roots.html#GGC-Roots" rel="next" title="GGC Roots">
  31. <link href="Inheritance-and-GTY.html#Inheritance-and-GTY" rel="prev" title="Inheritance and GTY">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="User-GC"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="GGC-Roots.html#GGC-Roots" accesskey="n" rel="next">GGC Roots</a>, Previous: <a href="Inheritance-and-GTY.html#Inheritance-and-GTY" accesskey="p" rel="prev">Inheritance and GTY</a>, Up: <a href="Type-Information.html#Type-Information" accesskey="u" rel="up">Type Information</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Support-for-user_002dprovided-GC-marking-routines"></a>
  68. <h3 class="section">23.3 Support for user-provided GC marking routines</h3>
  69. <a name="index-user-gc"></a>
  70. <p>The garbage collector supports types for which no automatic marking
  71. code is generated. For these types, the user is required to provide
  72. three functions: one to act as a marker for garbage collection, and
  73. two functions to act as marker and pointer walker for pre-compiled
  74. headers.
  75. </p>
  76. <p>Given a structure <code>struct GTY((user)) my_struct</code>, the following functions
  77. should be defined to mark <code>my_struct</code>:
  78. </p>
  79. <div class="smallexample">
  80. <pre class="smallexample">void gt_ggc_mx (my_struct *p)
  81. {
  82. /* This marks field 'fld'. */
  83. gt_ggc_mx (p-&gt;fld);
  84. }
  85. void gt_pch_nx (my_struct *p)
  86. {
  87. /* This marks field 'fld'. */
  88. gt_pch_nx (tp-&gt;fld);
  89. }
  90. void gt_pch_nx (my_struct *p, gt_pointer_operator op, void *cookie)
  91. {
  92. /* For every field 'fld', call the given pointer operator. */
  93. op (&amp;(tp-&gt;fld), cookie);
  94. }
  95. </pre></div>
  96. <p>In general, each marker <code>M</code> should call <code>M</code> for every
  97. pointer field in the structure. Fields that are not allocated in GC
  98. or are not pointers must be ignored.
  99. </p>
  100. <p>For embedded lists (e.g., structures with a <code>next</code> or <code>prev</code>
  101. pointer), the marker must follow the chain and mark every element in
  102. it.
  103. </p>
  104. <p>Note that the rules for the pointer walker <code>gt_pch_nx (my_struct
  105. *, gt_pointer_operator, void *)</code> are slightly different. In this
  106. case, the operation <code>op</code> must be applied to the <em>address</em> of
  107. every pointer field.
  108. </p>
  109. <a name="User_002dprovided-marking-routines-for-template-types"></a>
  110. <h4 class="subsection">23.3.1 User-provided marking routines for template types</h4>
  111. <p>When a template type <code>TP</code> is marked with <code>GTY</code>, all
  112. instances of that type are considered user-provided types. This means
  113. that the individual instances of <code>TP</code> do not need to be marked
  114. with <code>GTY</code>. The user needs to provide template functions to mark
  115. all the fields of the type.
  116. </p>
  117. <p>The following code snippets represent all the functions that need to
  118. be provided. Note that type <code>TP</code> may reference to more than one
  119. type. In these snippets, there is only one type <code>T</code>, but there
  120. could be more.
  121. </p>
  122. <div class="smallexample">
  123. <pre class="smallexample">template&lt;typename T&gt;
  124. void gt_ggc_mx (TP&lt;T&gt; *tp)
  125. {
  126. extern void gt_ggc_mx (T&amp;);
  127. /* This marks field 'fld' of type 'T'. */
  128. gt_ggc_mx (tp-&gt;fld);
  129. }
  130. template&lt;typename T&gt;
  131. void gt_pch_nx (TP&lt;T&gt; *tp)
  132. {
  133. extern void gt_pch_nx (T&amp;);
  134. /* This marks field 'fld' of type 'T'. */
  135. gt_pch_nx (tp-&gt;fld);
  136. }
  137. template&lt;typename T&gt;
  138. void gt_pch_nx (TP&lt;T *&gt; *tp, gt_pointer_operator op, void *cookie)
  139. {
  140. /* For every field 'fld' of 'tp' with type 'T *', call the given
  141. pointer operator. */
  142. op (&amp;(tp-&gt;fld), cookie);
  143. }
  144. template&lt;typename T&gt;
  145. void gt_pch_nx (TP&lt;T&gt; *tp, gt_pointer_operator, void *cookie)
  146. {
  147. extern void gt_pch_nx (T *, gt_pointer_operator, void *);
  148. /* For every field 'fld' of 'tp' with type 'T', call the pointer
  149. walker for all the fields of T. */
  150. gt_pch_nx (&amp;(tp-&gt;fld), op, cookie);
  151. }
  152. </pre></div>
  153. <p>Support for user-defined types is currently limited. The following
  154. restrictions apply:
  155. </p>
  156. <ol>
  157. <li> Type <code>TP</code> and all the argument types <code>T</code> must be
  158. marked with <code>GTY</code>.
  159. </li><li> Type <code>TP</code> can only have type names in its argument list.
  160. </li><li> The pointer walker functions are different for <code>TP&lt;T&gt;</code> and
  161. <code>TP&lt;T *&gt;</code>. In the case of <code>TP&lt;T&gt;</code>, references to
  162. <code>T</code> must be handled by calling <code>gt_pch_nx</code> (which
  163. will, in turn, walk all the pointers inside fields of <code>T</code>).
  164. In the case of <code>TP&lt;T *&gt;</code>, references to <code>T *</code> must be
  165. handled by calling the <code>op</code> function on the address of the
  166. pointer (see the code snippets above).
  167. </li></ol>
  168. <hr>
  169. <div class="header">
  170. <p>
  171. Next: <a href="GGC-Roots.html#GGC-Roots" accesskey="n" rel="next">GGC Roots</a>, Previous: <a href="Inheritance-and-GTY.html#Inheritance-and-GTY" accesskey="p" rel="prev">Inheritance and GTY</a>, Up: <a href="Type-Information.html#Type-Information" accesskey="u" rel="up">Type Information</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  172. </div>
  173. </body>
  174. </html>