a bytecode set for adaptive optimizations
DESCRIPTION
A bytecode set for adaptive optimizations IWST 2014 at ESUG, CambridgeTRANSCRIPT
![Page 1: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/1.jpg)
A bytecode set for adaptive
optimizationsClément Béra & Eliot Miranda
Thursday, August 21, 14
![Page 2: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/2.jpg)
Introduction
• The Cog VM is the standard VM for:
• Pharo
• Squeak
• Newspeak
Thursday, August 21, 14
![Page 3: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/3.jpg)
Introduction• Working runtime bytecode to bytecode
optimizer for Cog’s JIT
• The optimizer
• depends the bytecode set quality
• needs new bytecode instructions
Thursday, August 21, 14
![Page 4: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/4.jpg)
Introduction
• Design of a new bytecode set
Thursday, August 21, 14
![Page 5: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/5.jpg)
Plan
• Context
• Challenges for a good bytecode set
• Current Issues
• New bytecode set
• Switching between bytecode sets
Thursday, August 21, 14
![Page 6: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/6.jpg)
Context
• Compiled methods are objects
• Shared between the VM and the image
Thursday, August 21, 14
![Page 7: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/7.jpg)
Object header (8 bytes)
literals (4 bytes per literal)
compiled method header (4 bytes)
bytecodes (variable)
source pointer (variable, usually 4 bytes)
Memory representation ofCompiled Method in 32 bits
with the new Memory Manager Spur
Thursday, August 21, 14
![Page 8: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/8.jpg)
Object header (8 bytes)
literals (4 bytes per literal)
compiled method header (4 bytes)
bytecodes (variable)
source pointer (variable, usually 4 bytes)
Memory representation ofCompiled Method in 32 bits
with the new Memory Manager Spur
Thursday, August 21, 14
![Page 9: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/9.jpg)
Bytecode set
• Stack based
• Interpreted by the StackInterpreter
• Compiled to machine code by Cogit
• Generated by the in-image compiler
Thursday, August 21, 14
![Page 10: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/10.jpg)
Challenges
• Generic challenges
• Challenges for the bytecode optimizer
Thursday, August 21, 14
![Page 11: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/11.jpg)
Generic challenges
• Platform-independent
• Compact
• Easy to decode
• Backward compatibility
Thursday, August 21, 14
![Page 12: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/12.jpg)
Optimizer challenges
...
Thursday, August 21, 14
![Page 13: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/13.jpg)
OptimizerThursday there’s a talk about it.
• Inlining
• Primitive specialization
Thursday, August 21, 14
![Page 14: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/14.jpg)
Optimizer challenges
• Inlined primitives / unsafe operations
• Large methods
• Access to non receiver instance variable
• Extendable
Thursday, August 21, 14
![Page 15: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/15.jpg)
Current issues• Large method unsupported
• Few available bytes
• Primitive encoding forbidding inlining
• DoubleExtendedDoAnything bytecode
• Immediate objects compaction
• Late addition of the closure bytecode
Thursday, August 21, 14
![Page 16: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/16.jpg)
New bytecode set
• Extendable instructions (prefix)
• Inlined primitives / unsafe operations
• Extendable (available bytes)
• Maximum number of literals increased
Thursday, August 21, 14
![Page 17: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/17.jpg)
New bytecode set• Overall bytecode size smaller
• Immediate objects compaction
• Easier decoding
• Sorted by number of bytes
• Sorted by functionalities
• Closure decoding improved
Thursday, August 21, 14
![Page 18: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/18.jpg)
Bytecode set switch
• Offline converter: hard to debug
• VM supporting two bytecode set
• Bit in compiled method header
Thursday, August 21, 14
![Page 19: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/19.jpg)
Conclusion
• Designed a bytecode set for runtime bytecode to bytecode optimizations
• Next step is to work on the optimizer
• Come at my talk thursday about it
Thursday, August 21, 14
![Page 20: A bytecode set for adaptive optimizations](https://reader035.vdocuments.us/reader035/viewer/2022062704/555bde71d8b42a38078b483c/html5/thumbnails/20.jpg)
Questions
Thursday, August 21, 14