8. MarkAndCompactGC
followAll
Arena
Precondition: all objects unseen
from
old
VMGarbageCollector subclass: #MarkAndCompactGC
unseen: “natural” state in Arena
9. MarkAndCompactGC
followAll
Arena
Recognize & Mark all living objects
from
old
VMGarbageCollector subclass: #MarkAndCompactGC
Libraries
Characters
true
false
nil
10. MarkAndCompactGC
followAll
Arena
Recognize & Mark all living objects
from
old
VMGarbageCollector subclass: #MarkAndCompactGC
Libraries
followAll
self Characters
followSKernel;
followStack;
true
followExtraRoots;
false
rescueEphemerons;
nil
fixWeakContainers;
followRescuedEphemerons
11. MarkAndCompactGC
followAll
Arena
Recognize & Mark all living objects
from
old
VMGarbageCollector subclass: #MarkAndCompactGC
Libraries
followsSKernel
self Characters
follow: self sKernel
count: self sKernelSize true
startingAt: 1 false
nil
12. MarkAndCompactGC
follow: root count: size startingAt: base
Arena
Recognize & Mark all living objects
from
old
VMGarbageCollector subclass: #MarkAndCompactGC
arenaIncludes: object
^(oldSpace includes: object) or: [fromSpace includes: object]
13. MarkAndCompactGC
follow: root count: size startingAt: base
Recognize & Mark all living objects
(self arenaIncludes: object)
ifFalse: [
object _hasBeenSeenInLibrary ifFalse: [
object _beSeenInLibrary. Libraries
self follow: object...
Characters
true
false
nil
14. MarkAndCompactGC
follow: root count: size startingAt: base
Arena
Recognize & Mark all living objects
from
old
(self arenaIncludes: object)
ifFalse: [
object _hasBeenSeenInLibrary ifFalse: [
object _beSeenInLibrary.
self follow: object...
ifTrue: [
object _threadWith: reference at: oldIndex.
object _hasBeenSeenInSpace ifFalse: [
" object _beSeenInSpace "
self follow: object...]]
15. MarkAndCompactGC
follow: root count: size startingAt: base
...
B A object _threadWith: reference at: oldIndex.
C
Z
bits
Morris, F. L. 1978. A time-and space-efficient garbage compaction algorithm.
Communications of the ACM. 21, 8, 662-665.
16. MarkAndCompactGC
follow: root count: size startingAt: base
...
B A object _threadWith: reference at: oldIndex.
bits
C
Z
Morris, F. L. 1978. A time-and space-efficient garbage compaction algorithm.
Communications of the ACM. 21, 8, 662-665.
17. MarkAndCompactGC
followAll
Arena
Recognize & Mark all living objects
from
old
VMGarbageCollector subclass: #MarkAndCompactGC
Libraries
followExtraRoots Characters
self follow: self extraRoots count: 3 startingAt: 1
true
followRescuedEphemerons false
self follow: rescuedEphemerons count:... nil
18. MarkAndCompactGC
followAll
Arena
Recognize & Mark all living objects
from
old
VMGarbageCollector subclass: #MarkAndCompactGC
Libraries
followStack Characters
super followStack
true
rescueEphemerons false
super rescueEphemerons nil
Implemented VMGarbageCollector
19. MarkAndCompactGC
collect
...
setNewPositions: oldSpace;
B A setNewPositions: fromSpace;
bits
C
Z
20. MarkAndCompactGC
collect
...
setNewPositions: oldSpace;
B A setNewPositions: fromSpace;
Z'
C
Z
bits
23. MarkAndCompactGC
collect
...
compact: oldSpace;
B A compact: fromSpace;
Z'
C
Z
bits
24. MarkAndCompactGC
collect
...
compact: oldSpace;
B A compact: fromSpace;
Z'
C
bits
25. MarkAndCompactGC
collect
...
compact: oldSpace;
compact: fromSpace;
compact: space
self objectsFrom: space base to: space nextFree do: [:object |
object _hasBeenSeenInSpace ifTrue: [| moved |
moved := auxSpace shallowCopy: object.
moved _beUnseenInSpace]]
31. Stop
We have a Smalltalk Scavenger
Written in Smalltalk
Using objects
32. Stop
We have a Smalltalk Scavenger
Written in Smalltalk
Using objects
Instantiating objects
33. Stop
We have a Smalltalk Scavenger
Written in Smalltalk
Using objects
Instantiating objects
How can it work?
34. Stop
We have a Smalltalk Scavenger
Written in Smalltalk
Using objects
Instantiating objects
How can it work?
Object Closure
35. Object Closure
What happens in VegasGC stays in VegasGC
Self contained objects graph
Created objects do not live after GC
No message new in our code
Created objects:
Block Closures
Environment Contexts
Arrays
To interface with the Host VM
36. Object Closure
BlockClosure
makeRescuedEphemeronsNonWeak
rescuedEphemerons do: [:ephemeron | ephemeron _haveNoWeaks]
Environment context
compact: space
| moved |
self objectsFrom: space base to: space nextFree do: [:object |
object _hasBeenSeenInSpace ifTrue: [
moved := auxSpace shallowCopy: object]
The VM will instantiate both at end of young space
37. Object Closure
BlockClosure
makeRescuedEphemeronsNonWeak
rescuedEphemerons do: [:ephemeron | ephemeron _haveNoWeaks]
Environment context
compact: space
| moved |
self objectsFrom: space base to: space nextFree do: [:object |
object _hasBeenSeenInSpace ifTrue: [
moved := auxSpace shallowCopy: object]
The VM will instantiate both at end of young space
we only scan up to space's size when the GC starts
38. Object Closure
Host VM interface arrays
allocateArrays
rememberSet on: oldSpace; emptyReserving: 16r100.
literalsReferences emptyReserving: 16r200.
classCheckReferences emptyReserving: 16r100.
nativizedMethods emptyReserving: 16r100.
self
allocateWeakContainersArray;
allocateEphemeronsArray;
forgetNativeArrays
allocated at end of oldSpace, just before returning
39. Object Closure
Host VM interface arrays
at: index
^contents _basicAt: index + 1
at: index put: value
^contents _basicAt: index + 1 put: value
use _primitives instead of primitives