Keeping your build tool updated in a multi repository world
A bytecode set for adaptive optimizations
1. A bytecode set
for adaptive
optimizations
Clément Béra & Eliot Miranda
Thursday, August 21, 14
2. Introduction
• The Cog VM is the standard VM for:
• Pharo
• Squeak
• Newspeak
Thursday, August 21, 14
3. 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
5. Plan
• Context
• Challenges for a good bytecode set
• Current Issues
• New bytecode set
• Switching between bytecode sets
Thursday, August 21, 14
6. Context
• Compiled methods are objects
• Shared between the VM and the image
Thursday, August 21, 14
7. Memory representation of
Compiled Method in 32 bits
with the new Memory Manager Spur
Object header (8 bytes)
compiled method header (4 bytes)
literals (4 bytes per literal)
bytecodes (variable)
source pointer (variable, usually 4 bytes)
Thursday, August 21, 14
8. Memory representation of
Compiled Method in 32 bits
with the new Memory Manager Spur
Object header (8 bytes)
compiled method header (4 bytes)
literals (4 bytes per literal)
bytecodes (variable)
source pointer (variable, usually 4 bytes)
Thursday, August 21, 14
9. Bytecode set
• Stack based
• Interpreted by the StackInterpreter
• Compiled to machine code by Cogit
• Generated by the in-image compiler
Thursday, August 21, 14
10. Challenges
• Generic challenges
• Challenges for the bytecode optimizer
Thursday, August 21, 14
11. Generic challenges
• Platform-independent
• Compact
• Easy to decode
• Backward compatibility
Thursday, August 21, 14
13. Optimizer
Thursday there’s a talk about it.
• Inlining
• Primitive specialization
Thursday, August 21, 14
14. Optimizer challenges
• Inlined primitives / unsafe operations
• Large methods
• Access to non receiver instance variable
• Extendable
Thursday, August 21, 14
15. 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
16. New bytecode set
• Extendable instructions (prefix)
• Inlined primitives / unsafe operations
• Extendable (available bytes)
• Maximum number of literals increased
Thursday, August 21, 14
17. 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
18. Bytecode set switch
• Offline converter: hard to debug
• VM supporting two bytecode set
• Bit in compiled method header
Thursday, August 21, 14
19. 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