-
Notifications
You must be signed in to change notification settings - Fork 14
Description
For the MicroJIT prototype, not being able to see the generated code was OK, but as we migrate to a more sophisticated JIT with control flow and various optimizations, it will become increasingly important to be able to look at the machine code we produce.
The simplest strategy is not to implement a disassembler, but just to just store stings associated with machine code addresses in a code block. Then each instruction can simply write a disassembly string for its mnemonic and its arguments. That has the added benefit that we can also write comments in the generated code (eg: which Ruby bytecode instruction is this, why are these instructions here).
Because there's overhead associated with storing disassembly strings, we will want to add a --ujit-disasm
command-line flag to enable/disable this. I would propose that we add a Ruby method to print the disassembly for a method, similar to the existing RubyVM::InstructionSequence.disasm(method(:hello))
. This would then print a listing of the machine instructions for the method, in increasing order of machine code addresses. This can be done by querying for basic blocks associated with the iseq of the method.