Your SlideShare is downloading. ×
GC in Smalltalk
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

GC in Smalltalk

517
views

Published on

ESUG 2011, Edinburgh

ESUG 2011, Edinburgh

Published in: Technology, Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
517
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. GC in SmalltalkMarkAndCompactGCJavier Burroni gera
  • 2. ESUG 2010 Object subclass: #GenerationalGC generational purgeRootscollect from self generational follow: object followRoots; followStack; generational moveToOldOrTo: object to rescueEphemerons; fixWeakContainers; generational flipSpaces fixReferencesOrSetTombstone: weakContainer generational addInterrupt
  • 3. ESUG 2011Object subclass: #VMGarbageCollector VMGarbageCollector subclass: #GenerationalGC VMGarbageCollector subclass: #MarkAndCompactGC
  • 4. ESUG 2011 VMGarbageCollector subclass: #MarkAndCompactGCcollect self old unseeWellKnownObjects; followAll; setNewPositions: oldSpace; setNewPositions: fromSpace; from prepareForCompact; compact: oldSpace; compact: fromSpace; to updateOldSpace; makeRescuedEphemeronsNonWeak; resetFrom; decommitSlack; addInterrupt
  • 5. MarkAndCompactGC Three phases Follow (mark) Set new positions Compact (move)collect self ... followAll; setNewPositions: oldSpace; setNewPositions: fromSpace; prepareForCompact; compact: oldSpace; compact: fromSpace; ...
  • 6. MarkAndCompactGCfollowAll Arena Precondition: all objects unseen from oldVMGarbageCollector subclass: #MarkAndCompactGC Libraries Characters true false nil
  • 7. MarkAndCompactGCfollowAll Precondition: all objects unseenVMGarbageCollector subclass: #MarkAndCompactGC LibrariesunseeWellKnownObjects nil _beUnseenInLibrary. Characters true _beUnseenInLibrary. false _beUnseenInLibrary. true self unseeLibraryObjects; false unseeCharacters; nil unseeSKernel
  • 8. MarkAndCompactGCfollowAll Arena Precondition: all objects unseen from oldVMGarbageCollector subclass: #MarkAndCompactGC unseen: “natural” state in Arena
  • 9. MarkAndCompactGCfollowAll Arena Recognize & Mark all living objects from oldVMGarbageCollector subclass: #MarkAndCompactGC Libraries Characters true false nil
  • 10. MarkAndCompactGCfollowAll Arena Recognize & Mark all living objects from oldVMGarbageCollector subclass: #MarkAndCompactGC LibrariesfollowAll self Characters followSKernel; followStack; true followExtraRoots; false rescueEphemerons; nil fixWeakContainers; followRescuedEphemerons
  • 11. MarkAndCompactGCfollowAll Arena Recognize & Mark all living objects from oldVMGarbageCollector subclass: #MarkAndCompactGC LibrariesfollowsSKernel self Characters follow: self sKernel count: self sKernelSize true startingAt: 1 false nil
  • 12. MarkAndCompactGCfollow: root count: size startingAt: base Arena Recognize & Mark all living objects from oldVMGarbageCollector subclass: #MarkAndCompactGCarenaIncludes: object ^(oldSpace includes: object) or: [fromSpace includes: object]
  • 13. MarkAndCompactGCfollow: 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. MarkAndCompactGCfollow: 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 bitsMorris, 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 ZMorris, F. L. 1978. A time-and space-efficient garbage compaction algorithm. Communications of the ACM. 21, 8, 662-665.
  • 17. MarkAndCompactGCfollowAll Arena Recognize & Mark all living objects from oldVMGarbageCollector subclass: #MarkAndCompactGC LibrariesfollowExtraRoots Characters self follow: self extraRoots count: 3 startingAt: 1 truefollowRescuedEphemerons false self follow: rescuedEphemerons count:... nil
  • 18. MarkAndCompactGCfollowAll Arena Recognize & Mark all living objects from oldVMGarbageCollector subclass: #MarkAndCompactGC LibrariesfollowStack Characters super followStack truerescueEphemerons false super rescueEphemerons nil Implemented VMGarbageCollector
  • 19. MarkAndCompactGC collect ... setNewPositions: oldSpace;B A setNewPositions: fromSpace; bitsC Z
  • 20. MarkAndCompactGC collect ... setNewPositions: oldSpace;B A setNewPositions: fromSpace; ZC Z bits
  • 21. MarkAndCompactGC collect ... setNewPositions: oldSpace; setNewPositions: fromSpace;setNewPositions: space self seenObjectsFrom: space base to: space nextFree do: [:object :headerSize | | newPosition nextReference reference headerBits | newPosition := auxSpace nextFree + headerSize. reference := object _headerBits _unrotate. [ headerBits := reference _basicAt: 1. reference _basicAt: 1 put: newPosition _toObject. nextReference := headerBits _unrotate. nextReference _isSmallInteger] whileFalse: [reference := nextReference]. object _basicAt: -1 put: headerBits; _beSeenInSpace. auxSpace nextFree: newPosition + object _byteSize]
  • 22. MarkAndCompactGC collect Unthread references ... setNewPositions: oldSpace; setNewPositions: fromSpace;setNewPositions: space self seenObjectsFrom: space base to: space nextFree do: [:object :headerSize | | newPosition nextReference reference headerBits | newPosition := auxSpace nextFree + headerSize. reference := object _headerBits _unrotate. [ headerBits := reference _basicAt: 1. reference _basicAt: 1 put: newPosition _toObject. nextReference := headerBits _unrotate. nextReference _isSmallInteger] whileFalse: [reference := nextReference]. object _basicAt: -1 put: headerBits; _beSeenInSpace. auxSpace nextFree: newPosition + object _byteSize]
  • 23. MarkAndCompactGC collect ... compact: oldSpace;B A compact: fromSpace; ZC Z bits
  • 24. MarkAndCompactGC collect ... compact: oldSpace;B A compact: fromSpace; ZC 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]]
  • 26. MarkAndCompactGC collect ... makeRescuedEphemeronsNonWeak; updateOldSpace;makeRescuedEphemeronsNonWeak rescuedEphemerons do: [:ephemeron | ephemeron _haveNoWeaks]updateOldSpace oldSpace loadFrom: auxSpace
  • 27. MarkAndCompactGC collectFree resources ... decommitSlack; decommitSlack | limit delta | limit := self nextFree + 16rFFF bitAnd: -16r1000. delta := self commitedLimit - limit. delta < 0 ifTrue: [^self grow]. delta > 0 ifTrue: [ limit _decommit: delta. self commitedLimit: limit]
  • 28. MarkAndCompactGC collectFree resources ... decommitSlack; assembleDecommit ... return := assembler pushConstant: 16r4000; pushArg; pushR; callTo: VirtualFree from: KERNEL32.DLL; convertToNative; shortJump
  • 29. StopWe have a Smalltalk Scavenger
  • 30. StopWe have a Smalltalk Scavenger Written in Smalltalk
  • 31. StopWe have a Smalltalk Scavenger Written in Smalltalk Using objects
  • 32. StopWe have a Smalltalk Scavenger Written in Smalltalk Using objects Instantiating objects
  • 33. StopWe have a Smalltalk Scavenger Written in Smalltalk Using objects Instantiating objectsHow can it work?
  • 34. StopWe have a Smalltalk Scavenger Written in Smalltalk Using objects Instantiating objectsHow can it work? Object Closure
  • 35. Object ClosureWhat 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 BlockClosuremakeRescuedEphemeronsNonWeak rescuedEphemerons do: [:ephemeron | ephemeron _haveNoWeaks] Environment contextcompact: 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 BlockClosuremakeRescuedEphemeronsNonWeak rescuedEphemerons do: [:ephemeron | ephemeron _haveNoWeaks] Environment contextcompact: 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 spaces size when the GC starts
  • 38. Object ClosureHost VM interface arraysallocateArrays rememberSet on: oldSpace; emptyReserving: 16r100. literalsReferences emptyReserving: 16r200. classCheckReferences emptyReserving: 16r100. nativizedMethods emptyReserving: 16r100. self allocateWeakContainersArray; allocateEphemeronsArray; forgetNativeArraysallocated at end of oldSpace, just before returning
  • 39. Object Closure Host VM interface arraysat: index ^contents _basicAt: index + 1at: index put: value ^contents _basicAt: index + 1 put: value use _primitives instead of primitives
  • 40. Demo
  • 41. [Audience hasQuestions] whileTrue: [ self answer: Audience nextQuestion].Audience do: [:you | self thank: you].self returnTo: Audience

×