SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
Hazelnut
dynamically create a kernel
  in a reflexive language



  Benjamin Van Ryseghem
Introduction



               2
Seed

●   PineKernel: MicroSqueak portage

●   Hazelnut: build a new kernel starting from
    Pharo kernel



●   Both based on Micro-Squeak
                        Introduction             3
Micro-Squeak
●   John Maloney's project
●   Done in 2004
●   Released in september 2010
●   Proof of concept: minimal kernel (47 Classes)




                        Introduction                4
How to create a new image in
          3 steps ?



                           5
Contents

I – Create a new kernel


II – Isolate the new kernel


III – Create the new image


                              6
Contents

I – Create a new kernel


II – Isolate the new kernel


III – Create the new image


                              7
Which classes need to be
                  collected ?
●   First approach: collect all the classes needed
    by Object to have an autonomous system
    ●   About 800 classes on 1800 (½ of the system)


●   Second approach: provide a list of classes
    ●   Start from Object
    ●   Recursively analyze dependencies
    ●   About 200 classes on 1800 (1/9 of the system)

                            Create a new kernel         8
How to to build a new kernel
             structure ?
I. Mark objects
●   Trace the objects and mark wanted ones
     –   Based on SystemTracer2


●   Filling up a list

●   Easy process
●   It works
●   No living kernel

                         Create a new kernel   9
How to to build a new kernel
             structure ?
II. A new “namespace”
●   Create a new System Dictionary
    –   HazelSmalltalk


●   Filling it up with copies of wanted classes
    –   Perform a very deep copy
    –   Take care of the class and metaclass hierarchy

●   No recompilation
●   Not handled by the system
                          Create a new kernel            10
Contents

I – Create a new kernel


II – Isolate the new kernel


III – Create the new image


                              11
Remove dependencies to unneeded
           classes
I. HazelTracer2
 ●   Detect references to
     unwanted classes

 ●   Fix them using a wrapper
     (HazelMissingVariable)




                       Isolate the new kernel   12
Remove dependencies to unneeded
           classes




            Isolate the new kernel   13
Remove dependencies to unneeded
           classes




            Isolate the new kernel   14
Remove dependencies to unneeded
           classes
II. HazelKernelBuilder
 ●   Detect references to the
     Pharo world in methods

 ●   Fix them
     –   A method: remove it
     –   A class variable: set it to nil




                              Isolate the new kernel   15
Bootstrap the new kernel
I. HazelTracer2
    Nothing to do :)




                       Isolate the new kernel   16
Bootstrap the new kernel
II. HazelKernelBuilder
●   Change Pharo references
    into Hazel dependencies
    –   Fix methods literals
    –   Change the class of
        HazelSmalltalk
    –   Change the class of the
        HazelSmalltalk associations



                           Isolate the new kernel   17
Contents

I – Create a new kernel


II – Isolate the new kernel


III – Create the new image


                              18
SystemTracer2
●   Tracing and writing process already coded
●   Collect all the needed objects
●   Check if there is in the granted list
●   Finally serialize them in a binary stream

●   Error if some objects change between traces
●   Had to fix SystemTracer2 for Pharo

                        Create the new image      19
Micro-Squeak like serialization
●   First approach
●   Collect all the needed objects
●   Parse them twice
●   Finally serialize them in a binary stream

●   Objects untraced
●   Error during the serialization
●   Code hard to debug or rewrite
                       Create the new image     20
What if we switch the SOA ?
●   Change the SOA
●   GarbageCollect unwanted objects
●   Handled by the VM

●   Can't switch some classes
●   Modify method context during execution
●   Hangs the VM

                     Create the new image    21
Next Steps
●   Load code
    ●   What is the minimal image able to go back ?
    ●   How to load code without compiler ? (Fuel ?)

●   Declarative kernel

●   Get a better definition of the kernel


                                                       22
Conclusion
●   Create a new structure

●   Isolate it

●   Create a new image




                               23

Mais conteúdo relacionado

Semelhante a Deep into Smalltalk (10)

Apache Camel in the belly of the Docker whale
Apache Camel in the belly of the Docker whaleApache Camel in the belly of the Docker whale
Apache Camel in the belly of the Docker whale
 
Attacking the WebKit Heap
Attacking the WebKit HeapAttacking the WebKit Heap
Attacking the WebKit Heap
 
Attacking the Webkit heap [Or how to write Safari exploits]
Attacking the Webkit heap [Or how to write Safari exploits]Attacking the Webkit heap [Or how to write Safari exploits]
Attacking the Webkit heap [Or how to write Safari exploits]
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4
 
Node.js
Node.jsNode.js
Node.js
 
[20210325] Kotlin - Class
[20210325] Kotlin - Class[20210325] Kotlin - Class
[20210325] Kotlin - Class
 
Building ovs
Building ovsBuilding ovs
Building ovs
 
javathreads
javathreadsjavathreads
javathreads
 
Doctrine Php Object Relational Mapper
Doctrine Php Object Relational MapperDoctrine Php Object Relational Mapper
Doctrine Php Object Relational Mapper
 
Locally run a FIWARE Lab Instance In another Hypervisors
Locally run a FIWARE Lab Instance In another HypervisorsLocally run a FIWARE Lab Instance In another Hypervisors
Locally run a FIWARE Lab Instance In another Hypervisors
 

Deep into Smalltalk

  • 1. Hazelnut dynamically create a kernel in a reflexive language Benjamin Van Ryseghem
  • 3. Seed ● PineKernel: MicroSqueak portage ● Hazelnut: build a new kernel starting from Pharo kernel ● Both based on Micro-Squeak Introduction 3
  • 4. Micro-Squeak ● John Maloney's project ● Done in 2004 ● Released in september 2010 ● Proof of concept: minimal kernel (47 Classes) Introduction 4
  • 5. How to create a new image in 3 steps ? 5
  • 6. Contents I – Create a new kernel II – Isolate the new kernel III – Create the new image 6
  • 7. Contents I – Create a new kernel II – Isolate the new kernel III – Create the new image 7
  • 8. Which classes need to be collected ? ● First approach: collect all the classes needed by Object to have an autonomous system ● About 800 classes on 1800 (½ of the system) ● Second approach: provide a list of classes ● Start from Object ● Recursively analyze dependencies ● About 200 classes on 1800 (1/9 of the system) Create a new kernel 8
  • 9. How to to build a new kernel structure ? I. Mark objects ● Trace the objects and mark wanted ones – Based on SystemTracer2 ● Filling up a list ● Easy process ● It works ● No living kernel Create a new kernel 9
  • 10. How to to build a new kernel structure ? II. A new “namespace” ● Create a new System Dictionary – HazelSmalltalk ● Filling it up with copies of wanted classes – Perform a very deep copy – Take care of the class and metaclass hierarchy ● No recompilation ● Not handled by the system Create a new kernel 10
  • 11. Contents I – Create a new kernel II – Isolate the new kernel III – Create the new image 11
  • 12. Remove dependencies to unneeded classes I. HazelTracer2 ● Detect references to unwanted classes ● Fix them using a wrapper (HazelMissingVariable) Isolate the new kernel 12
  • 13. Remove dependencies to unneeded classes Isolate the new kernel 13
  • 14. Remove dependencies to unneeded classes Isolate the new kernel 14
  • 15. Remove dependencies to unneeded classes II. HazelKernelBuilder ● Detect references to the Pharo world in methods ● Fix them – A method: remove it – A class variable: set it to nil Isolate the new kernel 15
  • 16. Bootstrap the new kernel I. HazelTracer2 Nothing to do :) Isolate the new kernel 16
  • 17. Bootstrap the new kernel II. HazelKernelBuilder ● Change Pharo references into Hazel dependencies – Fix methods literals – Change the class of HazelSmalltalk – Change the class of the HazelSmalltalk associations Isolate the new kernel 17
  • 18. Contents I – Create a new kernel II – Isolate the new kernel III – Create the new image 18
  • 19. SystemTracer2 ● Tracing and writing process already coded ● Collect all the needed objects ● Check if there is in the granted list ● Finally serialize them in a binary stream ● Error if some objects change between traces ● Had to fix SystemTracer2 for Pharo Create the new image 19
  • 20. Micro-Squeak like serialization ● First approach ● Collect all the needed objects ● Parse them twice ● Finally serialize them in a binary stream ● Objects untraced ● Error during the serialization ● Code hard to debug or rewrite Create the new image 20
  • 21. What if we switch the SOA ? ● Change the SOA ● GarbageCollect unwanted objects ● Handled by the VM ● Can't switch some classes ● Modify method context during execution ● Hangs the VM Create the new image 21
  • 22. Next Steps ● Load code ● What is the minimal image able to go back ? ● How to load code without compiler ? (Fuel ?) ● Declarative kernel ● Get a better definition of the kernel 22
  • 23. Conclusion ● Create a new structure ● Isolate it ● Create a new image 23