@@ -41,15 +41,7 @@ is a function call, one stack frame is pushed.
4141When doing `return`, one stack frame will be popped.
4242Figure 1 shows the really simplified appearance of the machine stack.
4343
44- <div class="image">
45- <img src="images/ch_gc_macstack.jpg" alt="(macstack)"><br>
46- Figure 1: Machine Stack
47- * 上(先端)above (top)
48- * 下(末端)below (bottom)
49- * スタックフレーム stack frame
50- * 現在実行中の関数フレーム presently executing function frame
51- </div>
52-
44+ !images/ch_gc_macstack.jpg(Machine Stack)!
5345
5446In this picture, "above" is written above the top of the stack,
5547but this it is not necessarily always the case that the machine stack goes
@@ -89,13 +81,7 @@ if there are the memories allocated for the functions already finished,
8981free them by using `free()`.
9082
9183
92- <div class="image">
93- <img src="images/ch_gc_calloca.jpg" alt="(calloca)"><br>
94- Figure 2: The behavior of an `alloca()` implemented in C
95- * D->alloca(8)の対応を記録 record the relation D-> alloca(8)
96- * B->alloca(32)の対応を記録 record the relation B-> alloca(32)
97- * Dで割り当てたメモりを解放 release the memory allocated in D
98- </div>
84+ !images/ch_gc_calloca.jpg(The behavior of an `alloca()` implemented in C)!
9985
10086
10187The @missing/alloca.c@ of @ruby@ is an example of an emulated @alloca()@ .
@@ -159,7 +145,7 @@ To make descriptions more concrete,
159145let's simplify the structure by assuming that there are only objects and links.
160146This would look as shown in Figure 3.
161147
162- !images/ch_gc_objects.jpg(Figure 3: Objects)!
148+ !images/ch_gc_objects.jpg(Objects)!
163149
164150
165151The objects pointed to by global variables and the objects on the stack of a
@@ -177,14 +163,7 @@ These objects colored black are the
177163necessary objects. The rest of the objects can be released.
178164
179165
180- <div class="image">
181- <img src="images/ch_gc_gcimage.jpg" alt="(gcimage)"><br>
182- Figure 4: necessary objects and unnecessary objects
183- * ルートオブジェクト root objects
184- * 不要なオブジェクト unnecessary objects
185- * ルートオブジェクトから参照されているオブジェクト objects referenced by the
186- root objects
187- </div>
166+ !images/ch_gc_gcimage.jpg(necessary objects and unnecessary objects)!
188167
189168
190169In technical terms, "the surely necessary objects" are called "the roots of GC".
@@ -233,15 +212,15 @@ areas. To simplify this description, assume there are two areas @A@ and @B@ here
233212And put an "active" mark on the one of the areas.
234213When creating an object, create it only in the "active" one. (Figure 5)
235214
236- !images/ch_gc_stop2.jpg(Figure 5: Stop and Copy (1))!
215+ !images/ch_gc_stop2.jpg(Stop and Copy (1))!
237216
238217
239218When the GC starts, follow links from the roots in the same manner as
240219mark-and-sweep. However, move objects to another area instead of marking them
241220(Figure 6). When all the links have been followed, discard the all elements
242221which remain in @A@, and make @B@ active next.
243222
244- !images/ch_gc_stop3.jpg(Figure 6: Stop and Copy (2))!
223+ !images/ch_gc_stop3.jpg(Stop and Copy (2))!
245224
246225
247226Stop and Copy also has two advantages:
@@ -270,7 +249,7 @@ increased. When quitting to refer, decrease the counter.
270249When the counter of an object becomes zero, release the object.
271250This is the method called reference counting (Figure 7).
272251
273- !images/ch_gc_refcnt.jpg(Figure 7: Reference counting)!
252+ !images/ch_gc_refcnt.jpg(Reference counting)!
274253
275254
276255This method also has two advantages:
@@ -288,7 +267,7 @@ a cycle of references as shown in Figure 8.
288267If this is the case the counters will never decrease
289268and the objects will never be released.
290269
291- !images/ch_gc_cycle.jpg(Figure 8: Cycle)!
270+ !images/ch_gc_cycle.jpg(Cycle)!
292271
293272
294273By the way, latest Python(2.2) uses reference counting GC but it can free cycles.
@@ -422,14 +401,14 @@ Hereafter, let's call this an object heap.
422401the each contained array is probably each @heap@.
423402Each element of @heap@ is each @slot@ (Figure 9).
424403
425- !images/ch_gc_heapitems.jpg(Figure 9: `heaps`, `heap`, `slot`)!
404+ !images/ch_gc_heapitems.jpg(`heaps`, `heap`, `slot`)!
426405
427406The length of @heaps@ is @heap_length@ and it can be changed. The number of
428407the slots actually in use is @heaps_used@. The length of each heap
429408is in the corresponding @heaps_limits[index]@.
430409Figure 10 shows the structure of the object heap.
431410
432- !images/ch_gc_heaps.jpg(Figure 10: conceptual diagram of `heaps` in memory)!
411+ !images/ch_gc_heaps.jpg(conceptual diagram of `heaps` in memory)!
433412
434413This structure has a necessity to be this way.
435414For instance, if all structs are stored in an array,
@@ -1705,13 +1684,7 @@ However, when there are links from old-generation to new-generation,
17051684the new-generation objects will not be marked. (Figure 11)
17061685
17071686
1708- <div class="image">
1709- <img src="images/ch_gc_gengc.jpg" alt="(gengc)"><br>
1710- Figure 11: reference over generations
1711- * ルートオブジェクト the root objects
1712- * 新世代 new-generation
1713- * 旧世代 old-generation
1714- </div>
1687+ !images/ch_gc_gengc.jpg(reference over generations)!
17151688
17161689
17171690This is not good, so at the moment when an old-generational object refers to a new-generational object,
@@ -1752,13 +1725,7 @@ But as trade-offs, accessing speed slows down and the compatibility of
17521725extension libraries is lost.
17531726
17541727
1755- <div class="image">
1756- <img src="images/ch_gc_objid.jpg" alt="(objid)"><br>
1757- Figure 12: reference through the object ID
1758- * アドレスを入れる store addresses
1759- * インデックスを入れる store indexes
1760- * 移動できる can be moved
1761- </div>
1728+ !images/ch_gc_objid.jpg(reference through the object ID)!
17621729
17631730
17641731Then, the next way is to allow moving the struct only when they are pointed
@@ -1769,15 +1736,7 @@ In the ordinary programs, there are not so many objects that
17691736object structs is quite high.
17701737
17711738
1772- <div class="image">
1773- <img src="images/ch_gc_mostcopy.jpg" alt="(mostcopy)"><br>
1774- Figure 13: Mostly-copying garbage collection
1775- * (above) Since there's a possibility of being referred to by non-VALUE,
1776- this object is not moved.
1777- * (bottom) Since it is sure that this is referred only VALUEs,
1778- this object can be moved.
1779- * 移動 move
1780- </div>
1739+ !images/ch_gc_mostcopy.jpg(Mostly-copying garbage collection)!
17811740
17821741
17831742Moreover and moreover, by enabling to move the struct,
0 commit comments