Skip to content

Commit

Permalink
Remove old idea about implementation of GenGC. Create stub for new one.
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek committed Feb 1, 2011
1 parent 7cb3dca commit 49afb77
Showing 1 changed file with 27 additions and 172 deletions.
199 changes: 27 additions & 172 deletions src/gc/gc_gms.c
Expand Up @@ -10,22 +10,33 @@ src/gc/gc_gms.c - Generational M&S
Generational, non-compacting, mark and sweep GC.
Objects are stored in 3 different lists; one for each generation.
PObj_GC_generation_0_FLAG and PObj_GC_generation_1_FLAG determine which
generation an object is in. PObj_GC_generation_2_FLAG is set when an object
has survived first collection in a particular generation.
GC algorithm WILL BE:
1. After C<gc_threshold> allocates memory, we trigger the collection of any young objects.
2. Objects which have survived without PObj_GC_generation_2_FLAG set will have that flag set.
3. Objects which have survived and have PObj_GC_generation_2_FLAG set will be moved to the next oldest generation.
4. After ... we trigger collection of older objects with same approach.
5. After ... we trigger collection of ancient objects.
Objects in old generations have wb_variant_vtable as primary vtable.
WB (WriteBarrier) vtables trigger Parrot_gc_write_barrier(self) which will add
SELF into root_objects list.
Objects are stored in N (up to 8) different lists; one for each generation.
PObj_GC_generation_0_FLAG, PObj_GC_generation_1_FLAG, PObj_GC_generation_2_FLAG
determine which generation an object is in.
PObj_GC_on_dirty_list_FLAG is set by Write Barrier.
"Dirty" objects are moved into "dirty_list" out of C<generation> list.
Invariant: new reference from old-to-new generation can be introduced either:
- from objects already in "dirty_list"
- or with moving referent object into "dirty_list"
We keep this invariant by "sealing" all objects in old generations with Write
Barriers. Write Barrier will:
- Unseal object
- Set "dirty" flag
- Move object into "dirty_list"
Corollary: objects in "dirty_list" either:
- not referenced at all
- referenced from same or younger generation
- their referents are on "dirty_list" too
(Proof is very simple and left as exercise for reader)
GC algorithm WILL be:
1. Collect roots.
2. ...
3. Profit!
Pictures of GC steps.
Expand All @@ -35,162 +46,6 @@ Notation
2. gn: generation n.
3. R: root set.
Before collection:
R: *A1:B2 *B2 *C0 *D0:E1
g0: F0 G0:E1 H0:Z2 L0:A1 M0:L0 N0 P0 Q0
g1: E1 I1:Z2 J1:Y2 K1:J1
g2: Y2 Z2
Consider collecting generation 1. During VTABLE_mark we will skip all objects from the
older generations.
After marking the root set:
R: *A1:B2 *B2 *C0 *D0:E1 *F0 *I1:Z2
g0: G0:E1 H0:Z2 L0:A1 M0:L0 N0 P0 Q0
g1: E1 J1:Y2 K1:J1
g2: Y2 Z2
During this phase we move objects from objects[n] into root_objects.
Afterward, root_objects will contain only black surviving objects. The three
generations will contain a mix of dead and live objects.
"Shuffling-marking-and-reffing" phase.
Replace C«interp->gc_sys->mark» with C<gc_gms_magical_mark>.
Recursively (until I figure out a non-recursive algorithm) process root_objects
and do the following:
1. Decide which generation (C<next_gen>) the current object will be assigned
to. It can be a fixed algorithm or a heuristic to avoid "eager" propagation.
2. Move the object into C<next_gen>.
3. Set C<tmp_gen> to C«self->current_generation».
4. Set C«self->current_generation» to C<next_gen>.
5. Invoke VTABLE_mark on the object (which is magical_mark).
6. Set C«self->current_generation» to C<tmp_gen>.
"Magical mark" will do next:
0. Return if object is live.
1. Mark it live.
2. Do nothing if object's generation is greater than or equal to C«self->current_generation».
3. Mark object as referenced from C«self->current_generation».
4. Set self->current_generation to obj->generation.
5. Invoke VTABLE_mark on the object.
6. Set self->current_generation back.
After this phase we will have objects moved to proper generation with
referenced_generation set to proper one.
Pictures:
0. Take object A1.
1. next_gen = 2.
2. Move object
R: *B2 *C0 *D0:E1 *F0 *I1:Z2
g0: G0:E1 H0:Z2 L0:A1 M0:L0 N0 P0 Q0
g1: E1 J1:Y2 K1:J1
g2: *A2:B2 Y2 Z2
3. tmp_gen = 1
4. self->current_generation = 2
5. Magical mark:
5a. Marking L0:A1.
5b. It became *L0:A2.
5c. self->current_generation = 0
5d. VTABLE_mark(L0)
5e. Marking M0:L0.
5f. It became *M0:L0
5h. self->current_generation = 2
6. self->current_generation = 1
Picture after processing A1:
R: *B2 *C0 *D0:E1 *F0 *I1:Z2
g0: G0:E1 H0:Z2 *L0:A2 *M0:L0 N0 P0 Q0
g1: E1 J1:Y2 K1:J1
g2: *A2:B2 Y2 Z2
Picture after B2:
R: *C0 *D0:E1 *F0 *I1:Z2
g0: G0:E1 H0:Z2 *L0:A2 *M0:L0 N0 P0 Q0
g1: E1 J1:Y2 K1:J1
g2: *B2 *A2:B2 Y2 Z2
Picture after C0:
R: *D0:E1 *F0 *I1:Z2
g0: G0:E1 H0:Z2 *L0:A2 *M0:L0 N0 P0 Q0
g1: *C1 E1 J1:Y2 K1:J1
g2: *B2 *A2:B2 Y2 Z2
Picture after D0:
R: *F0 *I1:Z2
g0: G0:E1 H0:Z2 *L0:A2 *M0:L0 N0 P0 Q0
g1: *D1:E1 *C1 E1 J1:Y2 K1:J1
g2: *B2 *A2:B2 Y2 Z2
Picture after F0:
R: *I1:Z2
g0: G0:E1 H0:Z2 *L0:A2 *M0:L0 N0 P0 Q0
g1: *F1 *D1:E1 *C1 E1 J1:Y2 K1:J1
g2: *B2 *A2:B2 Y2 Z2
Picture after I1:
R:
g0: G0:E1 H0:Z2 *L0:A2 *M0:L0 N0 P0 Q0
g1: *F1 *D1:E1 *C1 E1 J1:Y2 K1:J1
g2: *I2:Z2 *B2 *A2:B2 Y2 Z2
Additional marking:
Starting from old-generation-start (G0 E1 Y2) invoke same magical mark on
current generation. NB: VTABLE_mark will not mark object, only children.
In our example we will skip E1. J1:Y2 will not be marked live. K1:J1 will be
marked live.
R:
g0: G0:E1 H0:Z2 *L0:A1 *M0:L0 N0 P0 Q0
g1: *F1 *D1:E1 *C1 E1 J1:Y2 *K1:J1
g2: *I2:Z2 *B2 *A2:B2 Y2 Z2
Sweeping dead objects.
Sweep current-or-younger generations.
0. Paint object white.
1. If object is live - skip it.
2. If object is referenced from old generation - skip it.
3. Otherwise - destroy it.
Sweeping g0:
R:
g0: G0:E1 H0:Z2 L0:A1 M0:L0
g1: *F1 *D1:E1 *C1 E1 J1:Y2 *K1:J1
g2: *I2:Z2 *B2 *A2:B2 Y2 Z2
Sweeping g1:
R:
g0: G0:E1 H0:Z2 L0:A1 M0:L0
g1: F1 D1:E1 C1 J1:Y2 K1:J1
g2: *I2:Z2 *B2 *A2:B2 Y2 Z2
Last step - painting older generation white. Starting from old-generation-head (Y2)
R:
g0: G0:E1 H0:Z2 L0:A1 M0:L0
g1: F1 D1:E1 C1 J1:Y2 K1:J1
g2: I2:Z2 B2 A2:B2 Y2 Z2
Done!
=cut
Expand Down

0 comments on commit 49afb77

Please sign in to comment.