SlideShare a Scribd company logo
1 of 34
Download to read offline
a JIT Smalltalk VM
        written in itself




 Javier Burroni        gera
                      (richie)
ESUG 2009 – JIT Security


                                       @1: 7F647D:   push EBP
test: arg                                  7F647E:   mov EBP, ESP
 ^self with: 0 with: inst with: arg        7F6480:   push EAX
                                           7F6481:   mov ESI, EAX
                                           ...
                                       @2:7F6492:    push 1             ;   PushSmallInteger0
   1   <13>   PushSmallInteger0            7F6497:   push [ESI]         ;   PushInstance1
                                           7F6499:   push [EBP+8]       ;   PushArgument1
   2   <8C>   PushInstance1                7F649C:   mov EAX, ESI       ;   LoadSelf
   3   <55>   PushArgument1                7F649E:   call 740207        ;   SendSelector1
   4   <0A>   LoadSelf                     7F64A3:   mov ESP, EBP       ;   Return
   5   <E2>   SendSelector1                7F64A5:   pop EBP
                                           7F64A6:   mov ESI, [EBP-4]
   6   <48>   Return                       7F64A9:   ret 4 NEAR



  BytecodeNativizerPushR              Assembler >> #pushR
   assembler pushR                     self assembleByte: 16r50 " push eax "
Closure Bug (6-Aug-2010)
testThomasMuhrNestedBlocks
  | abcdef |
  abcdef := [| var1 |
    var1 := 'AB'.
    [| var2 |                                                  BOOM!
      var2 := 'CD'.
      [| var3 |
        var3 := 'EF'.
        [var1 , var2 , var3] value] value] value] value.
  self assert: abcdef = 'ABCDEF'

                          Fix #1 (7-Aug-2010)
        IndirectEscapeBytecode >> #assemble
          type := self nextByte.
          argument := type  4 = 0
            ifTrue: [self nextIndex
                          nextIndex]        nextIndex + 1
            ifFalse: [type  4 + 3].

          type < 5 ifTrue: [^self loadEnvironmentTemporaryIndirect].
          type < 9 ifTrue: [^self pushEnvironmentTemporaryIndirect].
          ^self storeEnvironmentTemporaryIndirect
Closure Bug (6-Aug-2010)
testThomasMuhrNestedBlocks
  | abcdef |
  abcdef := [| var1 |
    var1 := 'AB'.
    [| var2 |                                              BOOM!
      var2 := 'CD'.
      [| var3 |
        var3 := 'EF'.
        [var1 , var2 , var3] value] value] value] value.
  self assert: abcdef = 'ABCDEF'

                          Fix #3 (9-Aug-2010)
         loc_1000ACFA:
         push    esi
         call    JIT_getNextIndex
         mov     edi, [esp+10h+aBytecodeNativizer]
         add     esp, 4
         dec     eax                     nop
         mov     [edi+4], eax
         jmp     short loc_1000AD29
Closure Bug (6-Aug-2010)
testThomasMuhrNestedBlocks
  | abcdef |
  abcdef := [| var1 |
    var1 := 'AB'.
    [| var2 |                                                  BOOM!
      var2 := 'CD'.
      [| var3 |
        var3 := 'EF'.
        [var1 , var2 , var3] value] value] value] value.
  self assert: abcdef = 'ABCDEF'

                          Fix #2 (9-Aug-2010)
         putCode: code
         min: min
         max: max
         range: idx
           (idx >= min and: [idx <= max])
             ifTrue: [self putNext: code - max + idx - 1]
             ifFalse: [
               self putNext: code.
               self putIndex: idx
                               idx]                  Idx + 1
Smalltalks 2009 – code freezer
GenerationalGCBuilder >> #populateInternals
(nativizer := BigNativizer new)
    addAllMethodsFor: GCSpace;
    addAllMethodsFor: ObjectGenerationalGC;
    at: #isSmallInteger default: Object >> #isSmallInteger;
    at: #isSmallInteger add: SmallInteger;
    at: #bitXor: add: SmallInteger;
    at: #between:and: add: SmallInteger;
    at: #_generation default: ExtensionBytecode class >> #_generation;
    at: #_commit: _primitive: ExtensionBytecode >> #_commit;
    ...
Frozen Code: “Lookup”




Object >> #isNil                      UndefinedObject >> #isNil
    self class == Object                 self class == UndefinedObject




          IfFalse: [                            IfFalse: [
               ^self lookupAndSend]                  ^self lookupAndSend]


^false                                ^true
Frozen Code: “Lookup”
nativizer
    at: #isNil addAll: (Array with: Object with: UndefinedObject)




  Object >> #isNil                          UndefinedObject >> #isNil
      self class == Object                     self class == UndefinedObject




                                                       IfFalse: [
                                                            ^self lookupAndSend]


 ^false                                    ^true
Frozen Code: “Lookup”
nativizer
    at: #isNil addAll: (Array with: Object with: UndefinedObject);
    at: #isNil default: Object >> #isNil




  Object >> #isNil                          UndefinedObject >> #isNil
      self class == Object                     self class == UndefinedObject




                                                                ^false


 ^false                                    ^true
Frozen Code: “Lookup”
    nativizer
        at: #isNil addAll: (Array with: Object with: UndefinedObject);
        at: #isNil default: Object >> #isNil;
        at: #isNil add: SmallInteger


self _isSmallInteger
                                        ^false


      Object >> #isNil                           UndefinedObject >> #isNil
          self class == Object                      self class == UndefinedObject




                                                                    ^false


     ^false                                      ^true
New Goal


Smalltalk VM
New Goal


Smalltalk VM
  Written in Smalltalk
New Goal


Smalltalk VM
  Written in Smalltalk
     Compatible with Digitalk's (VS)
New Goal


Smalltalk VM
  Written in Smalltalk
     Compatible with Digitalk's (VS)
         Leveraging the environment
Smalltalk VM

Written in Smalltalk
 .exe generation
Method lookup
Object format
Memory management
 Object creation / copy
 GC
 Become
Primitives
FFI
Processes
Callbacks
etc
PE (.exe) generation
PEFile
                                 _commit: newSize
                                  assembler
 directories




                imports
                                    loadArgFromContext: index;
                exports             convertArgToNative;
                                    pushArg;
               relocations
                                    convertToNative;
                                    pushR;
                  code              pushConstant: 4;
                                    pushConstant: 4096;
 sections




                exports             pushArg;
                                    pushR;
                imports             callTo: 'VirtualAlloc' from: 'KERNEL32.DLL';
                                    convertToSmalltalk
                  code



nativizer
  addAllMethodsFor:
     (Array with: GenerationalGC with: GenerationalGC class with: GCSpace);
  at: #_commit: _primitive: ExtensionBytecode >> #_commit
GCSpace
Object subclass: #GCSpace             old
 InstanceVariableNames: '
   contents
   base
   nextFree                            A
   commitLimit                          flip spaces
   reservedLimit '
 classVariableNames: ''                B
 poolDictionaries: ''



 includes: anObject
   ^anObject isSmallInteger not
      and: [anObject _oop between: self base and: self commitedLimit]


  reset
    self nextFree: self base
GCSpace
                                              old includes: anObject
Object subclass: #GCSpace             old
 InstanceVariableNames: '                     to reset
   contents
   base                                       from isReferredBy: object
   nextFree                            A
   commitLimit                                old growTo: newLimit
   reservedLimit '
 classVariableNames: ''                B      moved := to shallowCopy: object
 poolDictionaries: ''
                                              from flipWith: to


 includes: anObject
   ^anObject isSmallInteger not
      and: [anObject _oop between: self base and: self commitedLimit]


  reset
    self nextFree: self base
GenerationalGC
Object subclass: #GenerationalGC   old
 InstanceVariableNames: '
   old from to
   roots literalsReferences        from
   weakContainers ephemerons
   rescuedEphemerons '
 classVariableNames: ''
 poolDictionaries: ''               to



   collect
     self
       followRoots;
       walkStack;
       rescueEphemerons;
       traverseWeakContainers;
       flipSpaces
GenerationalGC
                                          flipper purgeRoots
Object subclass: #GenerationalGC   old
 InstanceVariableNames: '                 flipper follow: object
   old from to
   roots literalsReferences               flipper moveToOldOrTo: object
                                   from
   weakContainers ephemerons
   rescuedEphemerons '                    flipper
 classVariableNames: ''                      fixReferencesOrSetTombstone:
 poolDictionaries: ''               to       weakContainer

                                          flipper addInterrupt

   collect
     self
       followRoots;
       walkStack;
       rescueEphemerons;
       traverseWeakContainers;
       flipSpaces
GenerationalGC
                                        collect
GenerationalGC old     from    to         self
                                            followRoots;
                                            walkStack;

   follow: object
     | size |
     size := 0.
     object _isBytes ifFalse: [
       object _hasWeaks
         ifTrue: [self addWeakOrEphemeron: object]
         ifFalse: [size := object _size]].
     self follow: object count: 1 + size startingAt: 0
GenerationalGC
                                        collect
GenerationalGC old     from    to         self
                                            followRoots;
                                            walkStack;


    follow: objects count: size startingAt: base
      | index |
      index := base - 1.
      size timesRepeat: [| object |
        index := index + 1.
        object := objects _basicAt: index.
        (fromSpace includes: object) ifTrue: [
          object _isProxy
            ifTrue: [objects _basicAt: index put: object _proxee]
            ifFalse: [| moved |
              moved := self moveToOldOrTo: object.
              objects _basicAt: index put: moved.
              self follow: moved]]
GenerationalGC
                                        collect
GenerationalGC old     from    to         self
                                            followRoots;
                                            walkStack;


    follow: objects count: size startingAt: base
      | index |
      index := base - 1.
      size timesRepeat: [| object |
        index := index + 1.
        object := objects _basicAt: index.
        (fromSpace includes: object) ifTrue: [
          object _isProxy
            ifTrue: [objects _basicAt: index put: object _proxee]
            ifFalse: [| moved |
              moved := self moveToOldOrTo: object.
              objects _basicAt: index put: moved.
              self follow: moved]]]
GenerationalGC
                                        collect
GenerationalGC old     from    to         self
                                            traverseWeakContainers

   traverseWeakContainers
   weakContainers
       do: [:weakContainer |
            self fixReferencesOrSetTombstone: weakContainer]
   self reset: weakContainers

   fixReferencesOrSetTombstone: weakContainer
     | size |
     size := weakContainer _size.
     1 to: size do: [:index | | instance |
       instance := weakContainer _basicAt: index.
       (instance isSmallInteger not and: [fromSpace includes: instance])
         ifTrue: [| referenceOrThombstone |
           referenceOrThombstone := instance _isProxy
             ifTrue: [instance _proxee]
             ifFalse: [residueObject].
           weakContainer _basicAt: index put: referenceOrThombstone]]
GenerationalGC
                                     collect
GenerationalGC old   from    to        self
                                         rescueEphemerons


  rescueEphemerons
    | unknowns rescan |
    unknowns := self localStack.
    rescan := false.
    [ephemerons isEmpty] whileFalse: [
      rescan := self followEphemeronsCollectingIn: unknowns.
      rescan
        ifTrue: [ephemerons addAll: unknowns]
        IfFalse: [
          unknowns do: [:ephemeron | self rescueEphemeron: ephemeron]].
      self reset: unknowns]




    [Hayes1997] Barry Hayes, Ephemerons: a new finalization mechanism
GenerationalGC
                                    collect
GenerationalGC old     from   to      self
                                        flipSpaces

  flipSpaces
     fromSpace flipWith: toSpace.
     toSpace reset.



   GCSpace >> flipWith: space
    | aux |

     aux := space base.
     space base: self base.
     self base: aux.
     ...
GenerationalGC
                                     collect
GenerationalGC old    from    to       self
                                         flipSpaces




          A                                  B

          nextFree := base + size            nextFree := base



                                    copy
               contents A                         contents B
GenerationalGC
                                 collect
GenerationalGC old   from   to     self
                                     flipSpaces




           A                             B




               contents A                     contents B
GenerationalGC
                                  collect
GenerationalGC old   from   to      self
                                      flipSpaces




           A                              B




               contents A                      contents B




               VM assumption: from.commitLimit < to.base
GenerationalGC: testing
                                               collect
GenerationalGC old        from      to           self
                                                   followRoots

    testFollowObject
      | flipper from array string byteArray root flipSize currentSize |
      flipper := self defaultFlipper.
      from := flipper fromSpace.
      array := from shallowCopy: (Array new: 3).
      string := from shallowCopy: 'a String' copy.
      from shallowCopy: 'leaked' copy.
      byteArray := from shallowCopy: #[1 2 3] copy.
      array
         at: 1 put: 1;
         at: 2 put: string;
         at: 3 put: byteArray.
      root := Array with: array.
      string := byteArray := array := nil.
      flipper addRoot: root; followRoots.
      flipSize := flipper toSpace nextFree - flipper toSpace base.
      currentSize := flipper fromSpace nextFree - flipper fromSpace base.
      self
         assert: flipSize < currentSize;
         assert: currentSize - flipSize = (8 + ('leaked' size roundTo: 4))
GenerationalGC: testing
testFollowObject
  | flipper from array string byteArray root flipSize currentSize |
  flipper := self defaultFlipper.
  from := flipper fromSpace.
  array := from shallowCopy: (Array new: 3).
  string := from shallowCopy: 'a String' copy.
  from shallowCopy: 'leaked' copy.
  byteArray := from shallowCopy: #[1 2 3] copy.


testFollowObject
  | flipper from array string byteArray root flipSize currentSize |
  flipper := self defaultFlipper.
  self
     execute: [:from |
       array := from shallowCopy: (Array new: 3).
       string := from shallowCopy: 'a String' copy.
       from shallowCopy: 'leaked' copy.
       byteArray := from shallowCopy: #[1 2 3] copy]
     proxying: flipper fromSpace.
a demo




VMBuilder installGenerational
What now?

Release OpenSource
 Education!!!

Closure for JIT

Memory Management
 Mark & Sweep
 new
 become:

Method Lookup (strategies)

etc.
¡gracias!

More Related Content

What's hot

What's hot (20)

Dlr
DlrDlr
Dlr
 
Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Annotation processing and code gen
Annotation processing and code genAnnotation processing and code gen
Annotation processing and code gen
 
Polyglot JVM
Polyglot JVMPolyglot JVM
Polyglot JVM
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with Kotlin
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
Bottom Up
Bottom UpBottom Up
Bottom Up
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programming
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)
 
Arduino、Web 到 IoT
Arduino、Web 到 IoTArduino、Web 到 IoT
Arduino、Web 到 IoT
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 

Viewers also liked

From Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
From Legacy Database to Domain Layer Using a New Cincom VisualWorks ToolFrom Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
From Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
ESUG
 
How To Do Almost Smalltalking To Develop iOs Apps
How To Do Almost Smalltalking To Develop iOs AppsHow To Do Almost Smalltalking To Develop iOs Apps
How To Do Almost Smalltalking To Develop iOs Apps
ESUG
 
How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: A...
How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: A...How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: A...
How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: A...
ESUG
 
More XP-rience
More XP-rienceMore XP-rience
More XP-rience
ESUG
 

Viewers also liked (20)

From Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
From Legacy Database to Domain Layer Using a New Cincom VisualWorks ToolFrom Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
From Legacy Database to Domain Layer Using a New Cincom VisualWorks Tool
 
A Weak Pharo Story
A Weak Pharo StoryA Weak Pharo Story
A Weak Pharo Story
 
GemStone/64 product update and road map
GemStone/64 product update and road mapGemStone/64 product update and road map
GemStone/64 product update and road map
 
How To Do Almost Smalltalking To Develop iOs Apps
How To Do Almost Smalltalking To Develop iOs AppsHow To Do Almost Smalltalking To Develop iOs Apps
How To Do Almost Smalltalking To Develop iOs Apps
 
Smalltalk on the JVM
Smalltalk on the JVMSmalltalk on the JVM
Smalltalk on the JVM
 
Project planning
Project planningProject planning
Project planning
 
Retrobjects - Fun with C64 and NES
Retrobjects - Fun with C64 and NESRetrobjects - Fun with C64 and NES
Retrobjects - Fun with C64 and NES
 
How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: A...
How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: A...How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: A...
How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: A...
 
CommunityExplorer: A Framework for Visualizing Collaboration Networks
CommunityExplorer: A Framework for Visualizing Collaboration NetworksCommunityExplorer: A Framework for Visualizing Collaboration Networks
CommunityExplorer: A Framework for Visualizing Collaboration Networks
 
Intro to GemStone/S
Intro to GemStone/SIntro to GemStone/S
Intro to GemStone/S
 
Sista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performanceSista: Improving Cog’s JIT performance
Sista: Improving Cog’s JIT performance
 
Explicit Composition Constructs in DSLs - The case of the epidemiological lan...
Explicit Composition Constructs in DSLs - The case of the epidemiological lan...Explicit Composition Constructs in DSLs - The case of the epidemiological lan...
Explicit Composition Constructs in DSLs - The case of the epidemiological lan...
 
You Can’t Do That With Smalltalk!
You Can’t Do That With Smalltalk!You Can’t Do That With Smalltalk!
You Can’t Do That With Smalltalk!
 
seamless – Object Oriented CMS System
seamless – Object Oriented CMS Systemseamless – Object Oriented CMS System
seamless – Object Oriented CMS System
 
Smalltalk Metaprogramming supports Probabilistic Program Analysis
Smalltalk Metaprogramming supports Probabilistic Program AnalysisSmalltalk Metaprogramming supports Probabilistic Program Analysis
Smalltalk Metaprogramming supports Probabilistic Program Analysis
 
Pillar: one language for all supports
Pillar: one language for all supportsPillar: one language for all supports
Pillar: one language for all supports
 
Talking about bugs with bugs
Talking about bugs with bugsTalking about bugs with bugs
Talking about bugs with bugs
 
More XP-rience
More XP-rienceMore XP-rience
More XP-rience
 
The Glamorous Toolkit: Towards a novel live IDE
The Glamorous Toolkit: Towards a novel live IDEThe Glamorous Toolkit: Towards a novel live IDE
The Glamorous Toolkit: Towards a novel live IDE
 
Pharo Update
Pharo Update Pharo Update
Pharo Update
 

Similar to A JIT Smalltalk VM written in itself

Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerabilityCsw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
CanSecWest
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 
iOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful BackendiOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful Backend
Stefano Zanetti
 

Similar to A JIT Smalltalk VM written in itself (20)

Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Bee Smalltalk RunTime: anchor's aweigh
Bee Smalltalk RunTime: anchor's aweighBee Smalltalk RunTime: anchor's aweigh
Bee Smalltalk RunTime: anchor's aweigh
 
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerabilityCsw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
 
NativeBoost
NativeBoostNativeBoost
NativeBoost
 
NativeBoost
NativeBoostNativeBoost
NativeBoost
 
Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Front End Development: The Important Parts
Front End Development: The Important PartsFront End Development: The Important Parts
Front End Development: The Important Parts
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113Conf soat tests_unitaires_Mockito_jUnit_170113
Conf soat tests_unitaires_Mockito_jUnit_170113
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
From C++ to Objective-C
From C++ to Objective-CFrom C++ to Objective-C
From C++ to Objective-C
 
Tests unitaires mock_kesako_20130516
Tests unitaires mock_kesako_20130516Tests unitaires mock_kesako_20130516
Tests unitaires mock_kesako_20130516
 
[A 3]Javascript oop for xpages developers - public
[A 3]Javascript oop for xpages developers - public[A 3]Javascript oop for xpages developers - public
[A 3]Javascript oop for xpages developers - public
 
iOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful BackendiOS App with Parse.com as RESTful Backend
iOS App with Parse.com as RESTful Backend
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
 
How to Vim - for beginners
How to Vim - for beginnersHow to Vim - for beginners
How to Vim - for beginners
 
Herding types with Scala macros
Herding types with Scala macrosHerding types with Scala macros
Herding types with Scala macros
 
Introduction to underscore.js
Introduction to underscore.jsIntroduction to underscore.js
Introduction to underscore.js
 

More from 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 programming
ESUG
 
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
ESUG
 
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 results
ESUG
 
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
ESUG
 
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
ESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
ESUG
 
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
ESUG
 
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
ESUG
 
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
ESUG
 
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
ESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
ESUG
 
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
ESUG
 

More from 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
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

A JIT Smalltalk VM written in itself

  • 1. a JIT Smalltalk VM written in itself Javier Burroni gera (richie)
  • 2. ESUG 2009 – JIT Security @1: 7F647D: push EBP test: arg 7F647E: mov EBP, ESP ^self with: 0 with: inst with: arg 7F6480: push EAX 7F6481: mov ESI, EAX ... @2:7F6492: push 1 ; PushSmallInteger0 1 <13> PushSmallInteger0 7F6497: push [ESI] ; PushInstance1 7F6499: push [EBP+8] ; PushArgument1 2 <8C> PushInstance1 7F649C: mov EAX, ESI ; LoadSelf 3 <55> PushArgument1 7F649E: call 740207 ; SendSelector1 4 <0A> LoadSelf 7F64A3: mov ESP, EBP ; Return 5 <E2> SendSelector1 7F64A5: pop EBP 7F64A6: mov ESI, [EBP-4] 6 <48> Return 7F64A9: ret 4 NEAR BytecodeNativizerPushR Assembler >> #pushR assembler pushR self assembleByte: 16r50 " push eax "
  • 3. Closure Bug (6-Aug-2010) testThomasMuhrNestedBlocks | abcdef | abcdef := [| var1 | var1 := 'AB'. [| var2 | BOOM! var2 := 'CD'. [| var3 | var3 := 'EF'. [var1 , var2 , var3] value] value] value] value. self assert: abcdef = 'ABCDEF' Fix #1 (7-Aug-2010) IndirectEscapeBytecode >> #assemble type := self nextByte. argument := type 4 = 0 ifTrue: [self nextIndex nextIndex] nextIndex + 1 ifFalse: [type 4 + 3]. type < 5 ifTrue: [^self loadEnvironmentTemporaryIndirect]. type < 9 ifTrue: [^self pushEnvironmentTemporaryIndirect]. ^self storeEnvironmentTemporaryIndirect
  • 4. Closure Bug (6-Aug-2010) testThomasMuhrNestedBlocks | abcdef | abcdef := [| var1 | var1 := 'AB'. [| var2 | BOOM! var2 := 'CD'. [| var3 | var3 := 'EF'. [var1 , var2 , var3] value] value] value] value. self assert: abcdef = 'ABCDEF' Fix #3 (9-Aug-2010) loc_1000ACFA: push esi call JIT_getNextIndex mov edi, [esp+10h+aBytecodeNativizer] add esp, 4 dec eax nop mov [edi+4], eax jmp short loc_1000AD29
  • 5. Closure Bug (6-Aug-2010) testThomasMuhrNestedBlocks | abcdef | abcdef := [| var1 | var1 := 'AB'. [| var2 | BOOM! var2 := 'CD'. [| var3 | var3 := 'EF'. [var1 , var2 , var3] value] value] value] value. self assert: abcdef = 'ABCDEF' Fix #2 (9-Aug-2010) putCode: code min: min max: max range: idx (idx >= min and: [idx <= max]) ifTrue: [self putNext: code - max + idx - 1] ifFalse: [ self putNext: code. self putIndex: idx idx] Idx + 1
  • 6. Smalltalks 2009 – code freezer GenerationalGCBuilder >> #populateInternals (nativizer := BigNativizer new) addAllMethodsFor: GCSpace; addAllMethodsFor: ObjectGenerationalGC; at: #isSmallInteger default: Object >> #isSmallInteger; at: #isSmallInteger add: SmallInteger; at: #bitXor: add: SmallInteger; at: #between:and: add: SmallInteger; at: #_generation default: ExtensionBytecode class >> #_generation; at: #_commit: _primitive: ExtensionBytecode >> #_commit; ...
  • 7. Frozen Code: “Lookup” Object >> #isNil UndefinedObject >> #isNil self class == Object self class == UndefinedObject IfFalse: [ IfFalse: [ ^self lookupAndSend] ^self lookupAndSend] ^false ^true
  • 8. Frozen Code: “Lookup” nativizer at: #isNil addAll: (Array with: Object with: UndefinedObject) Object >> #isNil UndefinedObject >> #isNil self class == Object self class == UndefinedObject IfFalse: [ ^self lookupAndSend] ^false ^true
  • 9. Frozen Code: “Lookup” nativizer at: #isNil addAll: (Array with: Object with: UndefinedObject); at: #isNil default: Object >> #isNil Object >> #isNil UndefinedObject >> #isNil self class == Object self class == UndefinedObject ^false ^false ^true
  • 10. Frozen Code: “Lookup” nativizer at: #isNil addAll: (Array with: Object with: UndefinedObject); at: #isNil default: Object >> #isNil; at: #isNil add: SmallInteger self _isSmallInteger ^false Object >> #isNil UndefinedObject >> #isNil self class == Object self class == UndefinedObject ^false ^false ^true
  • 12. New Goal Smalltalk VM Written in Smalltalk
  • 13. New Goal Smalltalk VM Written in Smalltalk Compatible with Digitalk's (VS)
  • 14. New Goal Smalltalk VM Written in Smalltalk Compatible with Digitalk's (VS) Leveraging the environment
  • 15. Smalltalk VM Written in Smalltalk .exe generation Method lookup Object format Memory management Object creation / copy GC Become Primitives FFI Processes Callbacks etc
  • 16. PE (.exe) generation PEFile _commit: newSize assembler directories imports loadArgFromContext: index; exports convertArgToNative; pushArg; relocations convertToNative; pushR; code pushConstant: 4; pushConstant: 4096; sections exports pushArg; pushR; imports callTo: 'VirtualAlloc' from: 'KERNEL32.DLL'; convertToSmalltalk code nativizer addAllMethodsFor: (Array with: GenerationalGC with: GenerationalGC class with: GCSpace); at: #_commit: _primitive: ExtensionBytecode >> #_commit
  • 17. GCSpace Object subclass: #GCSpace old InstanceVariableNames: ' contents base nextFree A commitLimit flip spaces reservedLimit ' classVariableNames: '' B poolDictionaries: '' includes: anObject ^anObject isSmallInteger not and: [anObject _oop between: self base and: self commitedLimit] reset self nextFree: self base
  • 18. GCSpace old includes: anObject Object subclass: #GCSpace old InstanceVariableNames: ' to reset contents base from isReferredBy: object nextFree A commitLimit old growTo: newLimit reservedLimit ' classVariableNames: '' B moved := to shallowCopy: object poolDictionaries: '' from flipWith: to includes: anObject ^anObject isSmallInteger not and: [anObject _oop between: self base and: self commitedLimit] reset self nextFree: self base
  • 19. GenerationalGC Object subclass: #GenerationalGC old InstanceVariableNames: ' old from to roots literalsReferences from weakContainers ephemerons rescuedEphemerons ' classVariableNames: '' poolDictionaries: '' to collect self followRoots; walkStack; rescueEphemerons; traverseWeakContainers; flipSpaces
  • 20. GenerationalGC flipper purgeRoots Object subclass: #GenerationalGC old InstanceVariableNames: ' flipper follow: object old from to roots literalsReferences flipper moveToOldOrTo: object from weakContainers ephemerons rescuedEphemerons ' flipper classVariableNames: '' fixReferencesOrSetTombstone: poolDictionaries: '' to weakContainer flipper addInterrupt collect self followRoots; walkStack; rescueEphemerons; traverseWeakContainers; flipSpaces
  • 21. GenerationalGC collect GenerationalGC old from to self followRoots; walkStack; follow: object | size | size := 0. object _isBytes ifFalse: [ object _hasWeaks ifTrue: [self addWeakOrEphemeron: object] ifFalse: [size := object _size]]. self follow: object count: 1 + size startingAt: 0
  • 22. GenerationalGC collect GenerationalGC old from to self followRoots; walkStack; follow: objects count: size startingAt: base | index | index := base - 1. size timesRepeat: [| object | index := index + 1. object := objects _basicAt: index. (fromSpace includes: object) ifTrue: [ object _isProxy ifTrue: [objects _basicAt: index put: object _proxee] ifFalse: [| moved | moved := self moveToOldOrTo: object. objects _basicAt: index put: moved. self follow: moved]]
  • 23. GenerationalGC collect GenerationalGC old from to self followRoots; walkStack; follow: objects count: size startingAt: base | index | index := base - 1. size timesRepeat: [| object | index := index + 1. object := objects _basicAt: index. (fromSpace includes: object) ifTrue: [ object _isProxy ifTrue: [objects _basicAt: index put: object _proxee] ifFalse: [| moved | moved := self moveToOldOrTo: object. objects _basicAt: index put: moved. self follow: moved]]]
  • 24. GenerationalGC collect GenerationalGC old from to self traverseWeakContainers traverseWeakContainers weakContainers do: [:weakContainer | self fixReferencesOrSetTombstone: weakContainer] self reset: weakContainers fixReferencesOrSetTombstone: weakContainer | size | size := weakContainer _size. 1 to: size do: [:index | | instance | instance := weakContainer _basicAt: index. (instance isSmallInteger not and: [fromSpace includes: instance]) ifTrue: [| referenceOrThombstone | referenceOrThombstone := instance _isProxy ifTrue: [instance _proxee] ifFalse: [residueObject]. weakContainer _basicAt: index put: referenceOrThombstone]]
  • 25. GenerationalGC collect GenerationalGC old from to self rescueEphemerons rescueEphemerons | unknowns rescan | unknowns := self localStack. rescan := false. [ephemerons isEmpty] whileFalse: [ rescan := self followEphemeronsCollectingIn: unknowns. rescan ifTrue: [ephemerons addAll: unknowns] IfFalse: [ unknowns do: [:ephemeron | self rescueEphemeron: ephemeron]]. self reset: unknowns] [Hayes1997] Barry Hayes, Ephemerons: a new finalization mechanism
  • 26. GenerationalGC collect GenerationalGC old from to self flipSpaces flipSpaces fromSpace flipWith: toSpace. toSpace reset. GCSpace >> flipWith: space | aux | aux := space base. space base: self base. self base: aux. ...
  • 27. GenerationalGC collect GenerationalGC old from to self flipSpaces A B nextFree := base + size nextFree := base copy contents A contents B
  • 28. GenerationalGC collect GenerationalGC old from to self flipSpaces A B contents A contents B
  • 29. GenerationalGC collect GenerationalGC old from to self flipSpaces A B contents A contents B VM assumption: from.commitLimit < to.base
  • 30. GenerationalGC: testing collect GenerationalGC old from to self followRoots testFollowObject | flipper from array string byteArray root flipSize currentSize | flipper := self defaultFlipper. from := flipper fromSpace. array := from shallowCopy: (Array new: 3). string := from shallowCopy: 'a String' copy. from shallowCopy: 'leaked' copy. byteArray := from shallowCopy: #[1 2 3] copy. array at: 1 put: 1; at: 2 put: string; at: 3 put: byteArray. root := Array with: array. string := byteArray := array := nil. flipper addRoot: root; followRoots. flipSize := flipper toSpace nextFree - flipper toSpace base. currentSize := flipper fromSpace nextFree - flipper fromSpace base. self assert: flipSize < currentSize; assert: currentSize - flipSize = (8 + ('leaked' size roundTo: 4))
  • 31. GenerationalGC: testing testFollowObject | flipper from array string byteArray root flipSize currentSize | flipper := self defaultFlipper. from := flipper fromSpace. array := from shallowCopy: (Array new: 3). string := from shallowCopy: 'a String' copy. from shallowCopy: 'leaked' copy. byteArray := from shallowCopy: #[1 2 3] copy. testFollowObject | flipper from array string byteArray root flipSize currentSize | flipper := self defaultFlipper. self execute: [:from | array := from shallowCopy: (Array new: 3). string := from shallowCopy: 'a String' copy. from shallowCopy: 'leaked' copy. byteArray := from shallowCopy: #[1 2 3] copy] proxying: flipper fromSpace.
  • 33. What now? Release OpenSource Education!!! Closure for JIT Memory Management Mark & Sweep new become: Method Lookup (strategies) etc.