SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
GC in Smalltalk
MarkAndCompactGC




Javier Burroni   gera
ESUG 2010

   Object subclass: #GenerationalGC




                                        generational purgeRoots
collect                          from
  self                                  generational follow: object
    followRoots;
    followStack;                        generational moveToOldOrTo: object
                                  to
    rescueEphemerons;
    fixWeakContainers;                  generational
    flipSpaces                            fixReferencesOrSetTombstone:
                                          weakContainer

                                        generational addInterrupt
ESUG 2011

Object subclass: #VMGarbageCollector




         VMGarbageCollector subclass: #GenerationalGC




         VMGarbageCollector subclass: #MarkAndCompactGC
ESUG 2011

       VMGarbageCollector subclass: #MarkAndCompactGC




collect
  self                                old
    unseeWellKnownObjects;
    followAll;
    setNewPositions: oldSpace;
    setNewPositions: fromSpace;      from
    prepareForCompact;
    compact: oldSpace;
    compact: fromSpace;               to
    updateOldSpace;
    makeRescuedEphemeronsNonWeak;
    resetFrom;
    decommitSlack;
    addInterrupt
MarkAndCompactGC

      Three phases

          Follow (mark)
          Set new positions
          Compact (move)



collect
  self
    ...
    followAll;
    setNewPositions: oldSpace;
    setNewPositions: fromSpace;
    prepareForCompact;
    compact: oldSpace;
    compact: fromSpace;
    ...
MarkAndCompactGC
followAll
                                                   Arena
     Precondition: all objects unseen
                                                   from


                                                    old
VMGarbageCollector subclass: #MarkAndCompactGC

                                                 Libraries


                                                 Characters


                                                   true
                                                   false
                                                    nil
MarkAndCompactGC
followAll


     Precondition: all objects unseen




VMGarbageCollector subclass: #MarkAndCompactGC

                                                 Libraries

unseeWellKnownObjects
 nil _beUnseenInLibrary.                         Characters
 true _beUnseenInLibrary.
 false _beUnseenInLibrary.
                                                   true
 self unseeLibraryObjects;
                                                   false
   unseeCharacters;
                                                    nil
   unseeSKernel
MarkAndCompactGC
followAll
                                                 Arena
     Precondition: all objects unseen
                                                 from


                                                  old
VMGarbageCollector subclass: #MarkAndCompactGC




     unseen: “natural” state in Arena
MarkAndCompactGC
followAll
                                                   Arena
     Recognize & Mark all living objects
                                                   from


                                                    old
VMGarbageCollector subclass: #MarkAndCompactGC

                                                 Libraries


                                                 Characters


                                                   true
                                                   false
                                                    nil
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
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
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]
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
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...]]
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.
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.
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
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
MarkAndCompactGC
                    collect
                      ...
                        setNewPositions: oldSpace;
B    A                  setNewPositions: fromSpace;



         bits



C


                Z
MarkAndCompactGC
                    collect
                      ...
                        setNewPositions: oldSpace;
B    A                  setNewPositions: fromSpace;




                          Z'

C


         Z



             bits
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]
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]
MarkAndCompactGC
                    collect
                      ...
                        compact: oldSpace;
B    A                  compact: fromSpace;




                          Z'

C


         Z



             bits
MarkAndCompactGC
           collect
             ...
               compact: oldSpace;
B    A         compact: fromSpace;




                 Z'

C

                  bits
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]]
MarkAndCompactGC
                                collect
                                  ...
                                    makeRescuedEphemeronsNonWeak;
                                    updateOldSpace;




makeRescuedEphemeronsNonWeak
 rescuedEphemerons do: [:ephemeron | ephemeron _haveNoWeaks]



updateOldSpace
 oldSpace loadFrom: auxSpace
MarkAndCompactGC
                                     collect
Free 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]
MarkAndCompactGC
                                       collect
Free resources                           ...
                                           decommitSlack;




 assembleDecommit
   ...
   return := assembler
     pushConstant: 16r4000;
     pushArg;
     pushR;
     callTo: 'VirtualFree' from: 'KERNEL32.DLL';
     convertToNative;
     shortJump
Stop

We have a Smalltalk Scavenger
Stop

We have a Smalltalk Scavenger

 Written in Smalltalk
Stop

We have a Smalltalk Scavenger

 Written in Smalltalk

  Using objects
Stop

We have a Smalltalk Scavenger

 Written in Smalltalk

  Using objects

    Instantiating objects
Stop

We have a Smalltalk Scavenger

 Written in Smalltalk

  Using objects

    Instantiating objects

How can it work?
Stop

We have a Smalltalk Scavenger

 Written in Smalltalk

  Using objects

    Instantiating objects

How can it work?


         Object Closure
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
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
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
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
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
Demo
[Audience hasQuestions] whileTrue: [
  self answer: Audience nextQuestion].

Audience do: [:you | self thank: you].

self returnTo: Audience

Weitere ähnliche Inhalte

Mehr von ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

Mehr von ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Kürzlich hochgeladen

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Kürzlich hochgeladen (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

GC in Smalltalk

  • 2. ESUG 2010 Object subclass: #GenerationalGC generational purgeRoots collect from self generational follow: object followRoots; followStack; generational moveToOldOrTo: object to rescueEphemerons; fixWeakContainers; generational flipSpaces fixReferencesOrSetTombstone: weakContainer generational addInterrupt
  • 3. ESUG 2011 Object subclass: #VMGarbageCollector VMGarbageCollector subclass: #GenerationalGC VMGarbageCollector subclass: #MarkAndCompactGC
  • 4. ESUG 2011 VMGarbageCollector subclass: #MarkAndCompactGC collect 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. MarkAndCompactGC followAll Arena Precondition: all objects unseen from old VMGarbageCollector subclass: #MarkAndCompactGC Libraries Characters true false nil
  • 7. MarkAndCompactGC followAll Precondition: all objects unseen VMGarbageCollector subclass: #MarkAndCompactGC Libraries unseeWellKnownObjects nil _beUnseenInLibrary. Characters true _beUnseenInLibrary. false _beUnseenInLibrary. true self unseeLibraryObjects; false unseeCharacters; nil unseeSKernel
  • 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
  • 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; 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]]
  • 26. MarkAndCompactGC collect ... makeRescuedEphemeronsNonWeak; updateOldSpace; makeRescuedEphemeronsNonWeak rescuedEphemerons do: [:ephemeron | ephemeron _haveNoWeaks] updateOldSpace oldSpace loadFrom: auxSpace
  • 27. MarkAndCompactGC collect Free 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 collect Free resources ... decommitSlack; assembleDecommit ... return := assembler pushConstant: 16r4000; pushArg; pushR; callTo: 'VirtualFree' from: 'KERNEL32.DLL'; convertToNative; shortJump
  • 29. Stop We have a Smalltalk Scavenger
  • 30. Stop We have a Smalltalk Scavenger Written in Smalltalk
  • 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
  • 40. Demo
  • 41. [Audience hasQuestions] whileTrue: [ self answer: Audience nextQuestion]. Audience do: [:you | self thank: you]. self returnTo: Audience