Bee Smalltalk RunTime: 
anchor's aweigh 
Javier Pimás 
DISARMISTA S.R.L.
Bits of Bee history 
Gerardo Richarte Javier Burroni
Bits of Bee history 
1. a JIT in smalltalk 
2. added underprimitives and a GC 
3. can we get rid of the VM?
How to start?
Start afresh 
With Objects :) 
BeeLibrary
Start afresh 
With Objects :) 
SKernel 
BBeeeeLLiibbrraarryy
Start afresh 
With Objects :) 
BBeeSeeKLLeiirbbnrreaalrryy 
NativeCode 
Array variableSubclass: #CompiledMethod 
instanceV...
Start afresh 
With Objects :) 
BBeeSeeKLLeiirbbnrreaalrryy 
NativeCode 
Object subclass: #NativeCode 
instanceVariableName...
Start afresh 
How to start? 
With Objects :) 
<16r0000> A8 01 75 0B 81 78 FC 60 C4 AB 00 75 0E EB 1B 81 
<16r0010> 3D 67 C...
Start afresh 
How to start? 
With Objects :) 
BeeLibrary 
Object subclass: #NativeCode 
instanceVariableNames: 
' code ref...
Start afresh 
How to start? 
With Objects :) 
BeeLibrary 
Object subclass: #NativeCode 
instanceVariableNames: 
' code ref...
So we got rid of the VM, right?
NO!
Working hypothesis: 
HostVM leverage 
● Basic objects 
● Method lookup 
● Primitives 
● Native Helpers
HostVM leverage – Basic Objects 
for instance: 
– true 
– false 
– nil 
– characters 
– Array 
LoadTrueBytecode>>#assemble...
HostVM leverage – Method lookup 
Direct access to VM functions 
lookupAndCall 
| selector | 
selector := self compiledMeth...
HostVM leverage - Primitives 
We used HostVM' primitives as a way to have bit-a- 
bit compatibility 
SmalltalkBytecode>>#p...
HostVM leverage - Native Helpers 
Small pieces of code in the HostVM acting as 
primitives but without their protocol. 
as...
Connecting methods: lookup 
BBeeSeeKLLeiirbbnrreaalrryy 
NativeCode 
Object>>#_lookupAndInvoke: aSymbol 
lookup
Connecting methods: lookup 
mov eax, off_427090 
push offset aGetcommandline ; "getCommandLine" 
call Object__lookupAndInv...
Smalltalk semantics: underprimitives 
behavior 
^self _isSmallInteger 
ifTrue: [SmallInteger methodDictionaries] 
ifFalse:...
Connecting methods: BlockClosure 
anySatisfy: aBlock 
BlockClosure>>#primitiveBeeValue 
self argumentCount = 0 ifFalse: [^...
Creating objects: new 
Object new 
initial lookup 
arena 
BBeeSeeKLLeiirbbnrreaalrryy 
NativeCode 
free big arena 
externa...
Creating objects: new 
Behavior>>#primitiveNew 
^self primitiveNewPointers: self instSize 
Object new 
Behavior>>#primitiv...
More primitives 
BBeeSeeKLLeiirbbnrreaalrryy 
NativeCode 
ExternalMemory Integer 
relatedTo: 
arena lookup 
primitives 
Sy...
Putting things together 
arena lookup 
primitives 
SBBKeeeeernLLiiebblrr.EaarrXyyE 
NativeCode 
generateFullKernel 
| clos...
Some magic 
arena lookup 
primitives 
BBeeSeeKLLeiirbbnrreaalrryy 
NativeCode 
PEFile new
arena lookup 
primitives 
SBBKeeeeernLLiiebblrr.EaarrXyyE 
NativeCode 
PEFile new 
Some magic
Some magic 
arena lookup 
primitives 
BBeeSeeKLLeiirbbnrreaalrryy 
NativeCode 
PEFile new
arena lookup 
primitives 
SBBKeeeeernLLiiebblrr.EaarrXyyE 
NativeCode 
PEFile new 
Some magic
Bee-ing minimal
Many small libraries 
BBeebeeeLLeii.bberrxaaerryy 
NativeCode 
BBeeaeepLLpii.bbbrrsaalrryy 
NativeCode
Adding nativizer support 
BBeebeeeLLeii.bberrxaaerryy 
NativeCode 
BBeeJeeILLTii.bbbrrsaal rryy BBeeleeibLL.iibbbrrsaal rr...
Adding compiler support 
BBeebeeeLLeii.bberrxaaerryy 
NativeCode 
BBeeJeeILLTii.bbbrrsaal rryy BBceemeepLLiiilbbr.rrbaasrr...
Demo
Working on: 
arena lookup 
primitives 
Multi 
thread 
SBBKeeeeernLLiiebblrr.EaarrXyyE 
NativeCode 
Opening 
Perf 
Browsers
arena lookup 
primitives 
Multi 
thread 
SBBKeeeeernLLiiebblrr.EaarrXyyE 
NativeCode 
GC 
Dbg 
Remoting 
Future: 
Opening ...
arena lookup 
primitives 
Multi 
thread 
SBBKeeeeernLLiiebblrr.EaarrXyyE 
NativeCode 
GC 
Dbg 
Remoting 
+ Perf 
ARM 
64 b...
[Audience hasQuestions] whileTrue: [ 
self answer: Audience nextQuestion]. 
Audience do: [:you | self thank: you]. 
self r...
Upcoming SlideShare
Loading in …5
×

Bee Smalltalk RunTime: anchor's aweigh

777 views

Published on

Title: Bee Smalltalk RunTime: anchor's aweigh
Speaker: Javier Pimás
Wed, August 20, 3:00pm – 3:30pm

Video Part1: https://www.youtube.com/watch?v=82nZ1Oo2LF0
Video Part2: https://www.youtube.com/watch?v=eQ6r5ETskKE

Description
Abstract: Bee is a Smalltalk dialect. Its runtime is exceptional in that it is completely written in Smalltalk. Bee includes a minimal kernel with on-demand loaded libraries, a JIT compiler, an FFI interface, an optimizing SSA-based compiler, a garbage collector, and native threading support among other things. Despite being written in Smalltalk, Bee achieves promising performance levels.

Bio: Javier Pimas has been programming since he was a kid. Years ago he entered Smalltalk world and started studying topics both high and low-level related. As part of his MSc thesis he studied and extended SqueakNOS operating system, and has been working on VMs and JIT compilers since then.

Published in: Software
1 Comment
0 Likes
Statistics
Notes
  • Video Part1: https://www.youtube.com/watch?v=82nZ1Oo2LF0
    Video Part2: https://www.youtube.com/watch?v=eQ6r5ETskKE
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
777
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
3
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Bee Smalltalk RunTime: anchor's aweigh

  1. 1. Bee Smalltalk RunTime: anchor's aweigh Javier Pimás DISARMISTA S.R.L.
  2. 2. Bits of Bee history Gerardo Richarte Javier Burroni
  3. 3. Bits of Bee history 1. a JIT in smalltalk 2. added underprimitives and a GC 3. can we get rid of the VM?
  4. 4. How to start?
  5. 5. Start afresh With Objects :) BeeLibrary
  6. 6. Start afresh With Objects :) SKernel BBeeeeLLiibbrraarryy
  7. 7. Start afresh With Objects :) BBeeSeeKLLeiirbbnrreaalrryy NativeCode Array variableSubclass: #CompiledMethod instanceVariableNames: ' bytecodes nativeCode class selector source flags '
  8. 8. Start afresh With Objects :) BBeeSeeKLLeiirbbnrreaalrryy NativeCode Object subclass: #NativeCode instanceVariableNames: ' code references isFresh'
  9. 9. Start afresh How to start? With Objects :) <16r0000> A8 01 75 0B 81 78 FC 60 C4 AB 00 75 0E EB 1B 81 <16r0010> 3D 67 C4 AB 00 60 C4 AB 00 74 0F B9 60 C4 AB 00 <16r0020> E9 48 C4 AB 00 90 90 90 90 90 55 8B EC 50 8B <16r0030> 68 60 C4 AB 00 68 60 C4 AB 00 68 60 C4 AB 00 68 <16r0040> 60 C4 AB 00 A1 60 C4 AB 00 68 60 C4 AB 00 FF 15 <16r0050> 60 C4 AB 00 89 45 F4 A1 60 C4 AB 00 68 60 C4 AB <16r0060> 00 FF 15 60 C4 AB 00 89 45 F0 A1 60 C4 AB 00 68 <16r0070> 60 C4 AB 00 FF 15 60 C4 AB 00 50 8B 45 F0 68 60 <16r0080> C4 AB 00 FF 15 60 C4 AB 00 FF 75 08 FF 75 F4 FF <16r0090> 75 BeeLibrary F0 8B 45 E4 68 60 C4 AB 00 FF 15 60 C4 AB 00 <16r00A0> 58 68 60 C4 AB 00 FF 15 60 C4 AB 00 8B 45 F4 68 <16r00B0> 60 C4 AB 00 FF 15 60 C4 AB 00 89 45 EC FF 35 60 <16r00C0> C4 AB 00 8B 45 EC 68 60 C4 AB 00 FF 15 60 C4 AB <16r00D0> 00 50 8B 45 E8 68 60 C4 AB 00 FF 15 60 C4 AB 00 <16r00E0> 83 C4 04 89 06 50 8B 45 EC 68 60 C4 AB 00 FF 15 <16r00F0> 60 C4 AB 00 50 FF 75 EC 8B 45 E8 68 60 C4 AB 00 <16r0100> FF 15 60 C4 AB 00 83 C4 04 8B 45 F4 68 60 C4 AB <16r0110> 00 FF 15 60 C4 AB 00 89 46 04 8B C6 68 60 C4 AB <16r0120> 00 FF 15 60 C4 AB 00 8B C6 8B E5 5D 8B 75 FC C2 <16r0130> 04 00 Object subclass: #NativeCode instanceVariableNames: ' code references isFresh'
  10. 10. Start afresh How to start? With Objects :) BeeLibrary Object subclass: #NativeCode instanceVariableNames: ' code references isFresh' test AL 1 jnz F cmp [EAX-4], ABC460 jnz 1B jmp 2A cmp [ABC467], ABC460 jz 2A mov ECX, ABC460 jmp ABC46D nop nop nop nop nop push EBP mov EBP, ESP push EAX mov ESI, EAX push ABC460 push ABC460 push ABC460 push ABC460 mov EAX, [ABC460] push ABC460 call MemNear pusha les EBP
  11. 11. Start afresh How to start? With Objects :) BeeLibrary Object subclass: #NativeCode instanceVariableNames: ' code references isFresh' test AL 1 jnz F cmp [EAX-4], ABC460 jnz 1B jmp 2A cmp [ABC467], ABC460 jz 2A mov ECX, ABC460 jmp ABC46D nop nop nop nop nop push EBP mov EBP, ESP push EAX mov ESI, EAX push ABC460 push ABC460 push ABC460 push ABC460 mov EAX, [ABC460] push ABC460 call MemNear pusha les EBP
  12. 12. So we got rid of the VM, right?
  13. 13. NO!
  14. 14. Working hypothesis: HostVM leverage ● Basic objects ● Method lookup ● Primitives ● Native Helpers
  15. 15. HostVM leverage – Basic Objects for instance: – true – false – nil – characters – Array LoadTrueBytecode>>#assemble self loadTrue
  16. 16. HostVM leverage – Method lookup Direct access to VM functions lookupAndCall | selector | selector := self compiledMethod selector. assembler loadSelector: selector oop. self holdReferenceTo: selector. assembler jumpTo: #VM_lookupAndCall from: #hostVM.dll'
  17. 17. HostVM leverage - Primitives We used HostVM' primitives as a way to have bit-a- bit compatibility SmalltalkBytecode>>#prepareFrame primitive := self nextByte. cm := self compiledMethod. assembler loadTempPointer: cm oop. self holdReferenceTo: cm; callPrimitive: primitive. super prepareFrame
  18. 18. HostVM leverage - Native Helpers Small pieces of code in the HostVM acting as primitives but without their protocol. as a bit-a-bit compatible JIT, we were using those helpers callNewArray self emitCallTo: #VM_newArray from: #'hostVM.dll'
  19. 19. Connecting methods: lookup BBeeSeeKLLeiirbbnrreaalrryy NativeCode Object>>#_lookupAndInvoke: aSymbol lookup
  20. 20. Connecting methods: lookup mov eax, off_427090 push offset aGetcommandline ; "getCommandLine" call Object__lookupAndInvokeNativeCode Object>>#_lookupAndInvoke: aSymbol | cm | cm := self _lookup: aSymbol. cm == nil ifTrue: [ cm := self _lookup: #doesNotUnderstand:. self _transferControlTo: cm noClassCheckEntrypoint _asNative]. cm prepareForExecution; patchClassCheckTo: self behavior. self _transferControlDiscardingLastArgAndPatchingTo: cm noClassCheckEntrypoint _asNative Lookup Nativizer
  21. 21. Smalltalk semantics: underprimitives behavior ^self _isSmallInteger ifTrue: [SmallInteger methodDictionaries] ifFalse: [self _basicAt: 0] assembleTestSmallInteger | integer | integer := assembler testAndJumpIfInteger. self loadObject: false. assembler uncontionalSkip: [ assembler jumpDestinationFor: integer. self loadObject: true] assembleBasicAt | nonInteger | nonInteger := assembler convertArgToIntegerOrJump assembler framelessSlotAtArg; jumpDestinationFor: nonInteger
  22. 22. Connecting methods: BlockClosure anySatisfy: aBlock BlockClosure>>#primitiveBeeValue self argumentCount = 0 ifFalse: [^self primitiveFailed]. self _transferControlTo: self code self detect: aBlock ifNone: [^false]. ^true
  23. 23. Creating objects: new Object new initial lookup arena BBeeSeeKLLeiirbbnrreaalrryy NativeCode free big arena external memory
  24. 24. Creating objects: new Behavior>>#primitiveNew ^self primitiveNewPointers: self instSize Object new Behavior>>#primitiveNewPointers: size | object | object := self allocate: size * 4 size: size. self isFixed ifTrue: [object _beFixed; _beNamed]. 1 to: size do: [:i | object _basicAt: i put: nil]. ^object
  25. 25. More primitives BBeeSeeKLLeiirbbnrreaalrryy NativeCode ExternalMemory Integer relatedTo: arena lookup primitives Symbol String perform: FFI Object FFI Et cetera
  26. 26. Putting things together arena lookup primitives SBBKeeeeernLLiiebblrr.EaarrXyyE NativeCode generateFullKernel | closure filename | builder := KernelLibraryBuilder newNamed: 'bee'. project := SmalltalkProject getProject: 'Skernel'. project buildLibraryOn: builder. self addFutureSmalltalk; addTrueFalseAndNil; addBeeKernelClasses; addMinimalKernelMethods; addLookup; addPrimitives; addArena; remapCharactersArray. aBlock value. ^builder storeNativeCode; useDllMode; writeBSL start | result | result := self initializeBee; run. self exit: result
  27. 27. Some magic arena lookup primitives BBeeSeeKLLeiirbbnrreaalrryy NativeCode PEFile new
  28. 28. arena lookup primitives SBBKeeeeernLLiiebblrr.EaarrXyyE NativeCode PEFile new Some magic
  29. 29. Some magic arena lookup primitives BBeeSeeKLLeiirbbnrreaalrryy NativeCode PEFile new
  30. 30. arena lookup primitives SBBKeeeeernLLiiebblrr.EaarrXyyE NativeCode PEFile new Some magic
  31. 31. Bee-ing minimal
  32. 32. Many small libraries BBeebeeeLLeii.bberrxaaerryy NativeCode BBeeaeepLLpii.bbbrrsaalrryy NativeCode
  33. 33. Adding nativizer support BBeebeeeLLeii.bberrxaaerryy NativeCode BBeeJeeILLTii.bbbrrsaal rryy BBeeleeibLL.iibbbrrsaal rryy NativeCode
  34. 34. Adding compiler support BBeebeeeLLeii.bberrxaaerryy NativeCode BBeeJeeILLTii.bbbrrsaal rryy BBceemeepLLiiilbbr.rrbaasrrlyy NativeCode foo Transcript show: 'hello'
  35. 35. Demo
  36. 36. Working on: arena lookup primitives Multi thread SBBKeeeeernLLiiebblrr.EaarrXyyE NativeCode Opening Perf Browsers
  37. 37. arena lookup primitives Multi thread SBBKeeeeernLLiiebblrr.EaarrXyyE NativeCode GC Dbg Remoting Future: Opening Performnc Browsers
  38. 38. arena lookup primitives Multi thread SBBKeeeeernLLiiebblrr.EaarrXyyE NativeCode GC Dbg Remoting + Perf ARM 64 bits (hoping not so) far future: Opening Performnc Browsers
  39. 39. [Audience hasQuestions] whileTrue: [ self answer: Audience nextQuestion]. Audience do: [:you | self thank: you]. self returnTo: Audience

×