summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Implement --ujit-stats and instructoin countingAlan Wu2021-10-207-12/+86
| | | | | | VM and ujit instruction counting in debug builds. shopify/ruby#19
* Set T_FIXNUM type tags in opt_plus, opt_minusMaxime Chevalier-Boisvert2021-10-202-2/+9
|
* Optimize putobject codegenMaxime Chevalier-Boisvert2021-10-201-8/+24
|
* Eliminate type checks in opt_ltMaxime Chevalier-Boisvert2021-10-201-4/+10
|
* Fix bug, block added with wrong blockid.Maxime Chevalier-Boisvert2021-10-204-6/+8
|
* Tweak ujit disasm outputMaxime Chevalier-Boisvert2021-10-201-3/+3
|
* Keep track of multiple versions per blockidMaxime Chevalier-Boisvert2021-10-201-3/+20
|
* Fix issue with block address accessor. Print absolute addresses.Maxime Chevalier-Boisvert2021-10-202-4/+5
|
* Make find_block_version() do list searchMaxime Chevalier-Boisvert2021-10-201-10/+24
|
* Minor changes to disasm output. Fix GCC warning.Maxime Chevalier-Boisvert2021-10-202-3/+8
|
* Update dependenciesAlan Wu2021-10-201-1/+2
|
* Fix cast warningAlan Wu2021-10-201-1/+1
|
* Declare instead of define data varaibles in headerAlan Wu2021-10-201-2/+2
|
* Write ctx_diff() function to compate ctx_t objectsMaxime Chevalier-Boisvert2021-10-202-5/+44
|
* conditionally add libcapstoneAaron Patterson2021-10-203-19/+19
|
* Directly link libcapstone for easier developmentAaron Patterson2021-10-206-35/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This lets us use libcapstone directly from miniruby so we don't need a Ruby Gem to to dev work. Example usage: ```ruby def foo(x) if x < 1 "wow" else "neat" end end iseq = RubyVM::InstructionSequence.of(method(:foo)) puts UJIT.disasm(iseq) 100.times { foo 1 } puts UJIT.disasm(iseq) ``` Then in the terminal ``` $ ./miniruby test.rb == disasm: #<ISeq:foo@test.rb:1 (1,0)-(7,3)> (catch: FALSE) local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] x@0<Arg> 0000 getlocal_WC_0 x@0 ( 2)[LiCa] 0002 putobject_INT2FIX_1_ 0003 opt_lt <calldata!mid:<, argc:1, ARGS_SIMPLE> 0005 branchunless 10 0007 putstring "wow" ( 3)[Li] 0009 leave ( 7)[Re] 0010 putstring "neat" ( 5)[Li] 0012 leave ( 7)[Re] == ISEQ RANGE: 10 -> 10 ======================================================== 0x0: movabs rax, 0x7fe816e2d1a0 0xa: mov qword ptr [rdi], rax 0xd: mov r8, rax 0x10: mov r9, rax 0x13: mov r11, r12 0x16: jmp qword ptr [rax] == ISEQ RANGE: 0 -> 7 ========================================================== 0x0: mov rax, qword ptr [rdi + 0x20] 0x4: mov rax, qword ptr [rax - 0x18] 0x8: mov qword ptr [rdx], rax 0xb: mov qword ptr [rdx + 8], 3 0x13: movabs rax, 0x7fe817808200 0x1d: test byte ptr [rax + 0x3e6], 1 0x24: jne 0x3ffff7b 0x2a: test byte ptr [rdx], 1 0x2d: je 0x3ffff7b 0x33: test byte ptr [rdx + 8], 1 0x37: je 0x3ffff7b 0x3d: mov rax, qword ptr [rdx] 0x40: cmp rax, qword ptr [rdx + 8] 0x44: movabs rax, 0 0x4e: movabs rcx, 0x14 0x58: cmovl rax, rcx 0x5c: mov qword ptr [rdx], rax 0x5f: test qword ptr [rdx], -9 0x66: jne 0x3ffffd5 ``` Make sure to `brew install pkg-config capstone`
* Add support for multiple versions per blockMaxime Chevalier-Boisvert2021-10-204-24/+44
|
* Added comments. Fixed compiler warning.Maxime Chevalier-Boisvert2021-10-204-30/+29
|
* add a helper script for ujit disasmAaron Patterson2021-10-201-0/+34
|
* Expose methods for inspecting Micro JIT code blocksAaron Patterson2021-10-201-0/+102
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a module `UJIT`. The module allows you to insert the initial Micro JIT instruction in to an arbitrary iseq like this: ```ruby def foo(x) if x < 1 "less than one" else "something else" end end iseq = RubyVM::InstructionSequence.of(method(:foo)) UJIT.insert(iseq) # Add initial jump ``` After the initial jump is added, we can make Micro JIT do some work: ```ruby 100.times { foo(0) } ``` The `UJIT` module also exposes a method for finding all compiled blocks for a given iseq, like this: ```ruby blocks = UJIT.blocks_for(iseq) ``` We can sort the blocks by address and use the Crabstone gem (which is a wrapper around `capstone`) to disassemble the generated code. Here is the full code example: ```ruby def foo(x) if x < 1 "less than one" else "something else" end end iseq = RubyVM::InstructionSequence.of(method(:foo)) UJIT.insert(iseq) # Add initial jump 100.times { foo(0) } blocks = UJIT.blocks_for(iseq) # brew install capstone # gem install crabstone require "crabstone" cs = Crabstone::Disassembler.new(Crabstone::ARCH_X86, Crabstone::MODE_64) puts iseq.disasm blocks.sort_by(&:address).reverse.each do |block| puts "== ISEQ RANGE: #{block.iseq_start_index} -> #{block.iseq_end_index} ".ljust(80, "=") cs.disasm(block.code, 0).each do |i| printf( "\t0x%<address>x:\t%<instruction>s\t%<details>s\n", address: i.address, instruction: i.mnemonic, details: i.op_str ) end end ``` Here is the output: ``` $ ./ruby test.rb == disasm: #<ISeq:foo@test.rb:1 (1,0)-(7,3)> (catch: FALSE) local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] x@0<Arg> 0000 getlocal_WC_0 x@0 ( 2)[LiCa] 0002 putobject_INT2FIX_1_ 0003 opt_lt <calldata!mid:<, argc:1, ARGS_SIMPLE> 0005 branchunless 10 0007 putstring "less than one" ( 3)[Li] 0009 leave ( 7)[Re] 0010 putstring "something else" ( 5)[Li] 0012 leave ( 7)[Re] == ISEQ RANGE: 7 -> 7 ========================================================== 0x0: movabs rax, 0x7fcd014cd518 0xa: mov qword ptr [rdi], rax 0xd: mov r8, rax 0x10: mov r9, rax 0x13: mov r11, r12 0x16: jmp qword ptr [rax] == ISEQ RANGE: 0 -> 7 ========================================================== 0x0: mov rax, qword ptr [rdi + 0x20] 0x4: mov rax, qword ptr [rax - 0x18] 0x8: mov qword ptr [rdx], rax 0xb: mov qword ptr [rdx + 8], 3 0x13: movabs rax, 0x7fcd0180ac00 0x1d: test byte ptr [rax + 0x3e6], 1 0x24: jne 0x3ffe0da 0x2a: test byte ptr [rdx], 1 0x2d: je 0x3ffe0da 0x33: test byte ptr [rdx + 8], 1 0x37: je 0x3ffe0da 0x3d: mov rax, qword ptr [rdx] 0x40: cmp rax, qword ptr [rdx + 8] 0x44: movabs rax, 0 0x4e: movabs rcx, 0x14 0x58: cmovl rax, rcx 0x5c: mov qword ptr [rdx], rax 0x5f: test qword ptr [rdx], -9 0x66: je 0x3ffe111 0x6c: jmp 0xffffffffffffffa3 ```
* Remove assert that doesn't compileAlan Wu2021-10-201-2/+0
|
* Implement branchif in ujitMaxime Chevalier-Boisvert2021-10-201-2/+63
|
* Update dependenciesAlan Wu2021-10-201-2/+601
|
* Prototype type-specialization for temp valuesMaxime Chevalier-Boisvert2021-10-203-23/+60
|
* Take VM lock in branch_stub_hit(), fix ractor deadlock.Maxime Chevalier-Boisvert2021-10-204-3/+18
|
* Fix ujit block hash table bugMaxime Chevalier-Boisvert2021-10-201-1/+2
|
* Fix bug with ujit code invalidationMaxime Chevalier-Boisvert2021-10-201-8/+16
|
* Added gen_direct_jump() for unary branchesMaxime Chevalier-Boisvert2021-10-203-65/+88
|
* Complete refactoring to eliminate recursion in ujit's compilationMaxime Chevalier-Boisvert2021-10-204-106/+121
|
* End current block after opt_send_without_blockMaxime Chevalier-Boisvert2021-10-203-116/+133
|
* Added block end indexMaxime Chevalier-Boisvert2021-10-202-0/+6
|
* Fix ujit cc/cme invalidation code for opt_send_without_blockMaxime Chevalier-Boisvert2021-10-206-32/+35
|
* Sketch code to invalidate basic blocks. Rename version_t to block_t.Maxime Chevalier-Boisvert2021-10-204-77/+142
|
* Keep track of incoming branches in ujitMaxime Chevalier-Boisvert2021-10-203-43/+86
|
* Refactor ujit logic for generating iseq entry pointsMaxime Chevalier-Boisvert2021-10-205-43/+55
|
* Progress on code invalidationMaxime Chevalier-Boisvert2021-10-204-9/+41
|
* Introduce version_t struct. Will be needed for code invalidation.Maxime Chevalier-Boisvert2021-10-207-172/+187
|
* Fix hash map key issueMaxime Chevalier-Boisvert2021-10-202-8/+13
|
* Fix uint cast bug caught by AlanMaxime Chevalier-Boisvert2021-10-201-5/+1
|
* Refactorings in ujit. Implement Ruby jump instruction.Maxime Chevalier-Boisvert2021-10-203-20/+130
|
* Avoid generating redundant interpreter exit code after branchesMaxime Chevalier-Boisvert2021-10-203-56/+87
|
* Fix sneaky ujit side-exit bug. Reduce ujit call threshold to 1.Maxime Chevalier-Boisvert2021-10-202-7/+20
|
* Use a versioning context when compiling blocksMaxime Chevalier-Boisvert2021-10-204-12/+18
|
* Split out context object into jitstate_t and ctx_tMaxime Chevalier-Boisvert2021-10-205-114/+111
|
* Split out compile_entry() from compile_block()Maxime Chevalier-Boisvert2021-10-205-35/+61
|
* Fixed one bug in compile_block.Maxime Chevalier-Boisvert2021-10-202-12/+20
|
* Stub logic working for fib test, but still crashing in other casesMaxime Chevalier-Boisvert2021-10-203-39/+71
|
* Implement branch stub logicMaxime Chevalier-Boisvert2021-10-204-39/+69
|
* WIP branch generation codeMaxime Chevalier-Boisvert2021-10-204-60/+189
|
* Thread insn_idx through context objectMaxime Chevalier-Boisvert2021-10-204-30/+27
|