summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
AgeCommit message (Collapse)Author
2020-07-10Fixed another typoNobuyoshi Nakada
2020-07-10Fixed typosNobuyoshi Nakada
2020-07-10vm_push_frame_debug_counter_inc: use branches卜部昌平
Ko1 doesn't like previous code. Notes: Merged: https://github.com/ruby/ruby/pull/3296
2020-07-10vm_push_frame: move assignments around卜部昌平
Struct assignment using a compound literal is more readable than before, to me at least. It seems compilers reorder assignments anyways. Neither speedup nor slowdown is observed on my machine. Notes: Merged: https://github.com/ruby/ruby/pull/3296
2020-07-10vm_push_frame: move assertions out of the function卜部昌平
These assertions are purely static. Ned not be checked on-the-fly. Notes: Merged: https://github.com/ruby/ruby/pull/3296
2020-07-10vm_push_frame: hoist out debug codes卜部昌平
Made it a bit readable. Notes: Merged: https://github.com/ruby/ruby/pull/3296
2020-07-10nobody uses the return value of vm_push_frame卜部昌平
Surprised to see such a waste of time in this super duper hot path. Notes: Merged: https://github.com/ruby/ruby/pull/3296
2020-07-03Use ID instead of GENTRY for gvars. (#3278)Koichi Sasada
Use ID instead of GENTRY for gvars. Global variables are compiled into GENTRY (a pointer to struct rb_global_entry). This patch replace this GENTRY to ID and make the code simple. We need to search GENTRY from ID every time (st_lookup), so additional overhead will be introduced. However, the performance of accessing global variables is not important now a day and this simplicity helps Ractor development. Notes: Merged-By: ko1 <ko1@atdot.net>
2020-06-30Extracted METHOD_ENTRY_CACHEABLE macroNobuyoshi Nakada
2020-06-29vm_getivar: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-25Decide JIT-ed insn based on cached cfuncTakashi Kokubun
for opt_* insns. opt_eq handles rb_obj_equal inside opt_eq, and all other cfunc is handled by opt_send_without_block. Therefore we can't decide which insn should be generated by checking whether it's cfunc cc or not. ``` $ benchmark-driver -v --rbenv 'before --jit;after --jit' benchmark/mjit_opt_cc_insns.yml --repeat-count=4 before --jit: ruby 2.8.0dev (2020-06-26T05:21:43Z master 9dbc2294a6) +JIT [x86_64-linux] after --jit: ruby 2.8.0dev (2020-06-26T06:30:18Z master 75cece1b0b) +JIT [x86_64-linux] last_commit=Decide JIT-ed insn based on cached cfunc Calculating ------------------------------------- before --jit after --jit mjit_nil?(1) 73.878M 74.021M i/s - 40.000M times in 0.541432s 0.540391s mjit_not(1) 72.635M 74.601M i/s - 40.000M times in 0.550702s 0.536187s mjit_eq(1, nil) 7.331M 7.445M i/s - 8.000M times in 1.091211s 1.074596s mjit_eq(nil, 1) 49.450M 64.711M i/s - 8.000M times in 0.161781s 0.123627s Comparison: mjit_nil?(1) after --jit: 74020528.4 i/s before --jit: 73878185.9 i/s - 1.00x slower mjit_not(1) after --jit: 74600882.0 i/s before --jit: 72634507.6 i/s - 1.03x slower mjit_eq(1, nil) after --jit: 7444657.4 i/s before --jit: 7331304.3 i/s - 1.02x slower mjit_eq(nil, 1) after --jit: 64710790.6 i/s before --jit: 49449507.4 i/s - 1.31x slower ```
2020-06-21Verify builtin inline annotation with VM_CHECK_MODE (#3244)Takashi Kokubun
* Verify builtin inline annotation with VM_CHECK_MODE * Remove static to fix the link issue on MJIT Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2020-06-21Fix -Wmaybe-uninitialized at vm_invoke_blockTakashi Kokubun
2020-06-17Replaced accessors of `Struct` with `invokebuiltin`Nobuyoshi Nakada
2020-06-16Revert "Replaced accessors of `Struct` with `invokebuiltin`"Nobuyoshi Nakada
This reverts commit 19cabe8b09d92d033c244f32ff622b8e513375f1, which didn't support tool/lib/iseq_loader_checker.rb.
2020-06-16Replaced accessors of `Struct` with `invokebuiltin`Nobuyoshi Nakada
2020-06-10vm_call_method: avoid marking on-stack object卜部昌平
This callcache is on stack, must not be GCed. However its contents are copied from other materials, which can be an ordinal object. Should set a flag to make sure it is properly skipped by the GC.
2020-06-09rb_eql_opt,rb_equal_opt: purge stale cc卜部昌平
When on USE_EMBED_CI, cd is stored statically. Previous use could cache stale cd->cc, which could have already been GCed. Need flush them. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_ccs_push: do not cache non-heap entries卜部昌平
Entires not GC-able must be considered to be volatile. Not eligible for later use. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09VM_CI_NEW_ID: USE_EMBED_CI could be false卜部昌平
It was a wrong idea to assume CIs are always embedded. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09eliminate C99 compound literals卜部昌平
Ko1 prefers variables be assgined, instead of bare literals in function arguments. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_call_method: use struct assignment卜部昌平
This further reduces the generated binary of vm_call_method from 566 bytes to 545 bytes on my machine, according to nm(1). Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09rb_vm_call0: on-stack call info卜部昌平
This changeset reduces the generated binary of rb_vm_call0 from 281 bytes to 211 bytes on my machine. Should reduce GC pressure as well. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_yield_setup_args: refactor use macro卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_call_method: no call vm_cc_fill卜部昌平
This changeset reduces the generated binary of vm_call_method from 600 bytes to 566 bytes on my machine, accroding to nm(1). Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_call_refined: no call vm_cc_fill卜部昌平
This changeset reduces the generated binary of vm_call_method_each_type from 2,442 bytes to 2,378 bytes on my machine, accroding to nm(1). Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_call_zsuper: no call vm_cc_fill卜部昌平
This changeset reduces the generated binary of vm_call_method_each_type from 2,522 bytes to 2,442 bytes on my machine, accroding to nm(1). Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_call_method_missing_body: on-stack call info卜部昌平
This changeset reduces the generated binary of vm_call_method_missing_body from 604 bytes to 532 bytes on my machine. Should reduce GC pressure as well. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_call_symbol: on-stack call info卜部昌平
This changeset reduces the generated binary of vm_call_symbol from 808 bytes to 798 bytes on my machine. Should reduce GC pressure as well. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_call_alias: no call vm_cc_fill卜部昌平
This changeset reduces the generated binary of vm_call_alias from 188 bytes to 149 bytes on my machine, accroding to nm(1). Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09rb_eql_opt: fully static call data卜部昌平
This changeset reduces the generated binary of rb_eql_opt from 86 bytes to 20 bytes on my machine, according to nm(1). Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09rb_vm_search_method_slowpath: skip vm_empty_cc卜部昌平
Now that vm_empty_cc is statically allocated outside of the object space. It shall not be GCed. Here, because vm_search_cc can return that. Must not be blindly passed to RB_OBJ_WRITE, unless assertions fail on RGENGC_CHECK_MODE, like this: -- C level backtrace information ------------------------------------------- ruby(rb_print_backtrace+0x19) [0x5555557fd579] vm_dump.c:757 ruby(rb_vm_bugreport+0x151) [0x5555557fd6f1] vm_dump.c:955 ruby(rb_bug+0x1d6) [0x5555558d6396] error.c:660 ruby(check_rvalue_consistency_force+0x707) [0x5555555adb97] gc.c:1289 ruby(check_rvalue_consistency+0x1a) [0x555555598a0a] gc.c:1305 ruby(RVALUE_OLD_P+0x15) [0x5555555975d5] gc.c:1382 ruby(rb_gc_writebarrier+0x9f) [0x55555559753f] gc.c:6882 ruby(rb_obj_written+0x3a) [0x5555557a025a] include/ruby/internal/rgengc.h:180 ruby(rb_obj_write+0x41) [0x5555557a1a81] include/ruby/internal/rgengc.h:195 ruby(rb_vm_search_method_slowpath+0x5a) [0x5555557a125a] vm_insnhelper.c:1603 ruby(vm_search_method_fastpath+0x197) [0x5555557d8027] vm_insnhelper.c:1638 ruby(vm_search_method+0xea) [0x5555557d7d2a] vm_insnhelper.c:1650 ruby(vm_search_method_wrap+0x29) [0x5555557dbaf9] vm_insnhelper.c:4091 ruby(vm_sendish+0xa9) [0x5555557dba39] vm_insnhelper.c:4143 ruby(vm_exec_core+0xe357) [0x5555557b0757] insns.def:801 ruby(rb_vm_exec+0x12c) [0x5555557d17cc] vm.c:1942 ruby(invoke_block+0xea) [0x5555557f42fa] vm.c:1058 ruby(invoke_iseq_block_from_c+0x16e) [0x5555557f3eae] vm.c:1130 ruby(invoke_block_from_c_bh) vm.c:1148 ruby(vm_yield+0x71) [0x5555557f3c41] vm.c:1193 ruby(rb_yield_0+0x25) [0x5555557ca615] vm_eval.c:1141 ruby(rb_yield_1+0x27) [0x5555557ca5c7] vm_eval.c:1147 ruby(rb_yield+0x34) [0x5555557ca654] vm_eval.c:1157 ruby(rb_ary_collect+0xb0) [0x555555828320] array.c:3186 ruby(call_cfunc_0+0x29) [0x5555557f0f39] vm_insnhelper.c:2385 ruby(vm_call_cfunc_with_frame+0x278) [0x5555557eca98] vm_insnhelper.c:2553 ruby(vm_sendish+0xd0) [0x5555557dba60] vm_insnhelper.c:4146 ruby(vm_exec_core+0xe0f8) [0x5555557b04f8] insns.def:782 ruby(rb_vm_exec+0x12c) [0x5555557d17cc] vm.c:1942 ruby(invoke_block+0xea) [0x5555557f42fa] vm.c:1058 ruby(invoke_iseq_block_from_c+0x16e) [0x5555557f3eae] vm.c:1130 ruby(invoke_block_from_c_bh) vm.c:1148 ruby(vm_yield+0x71) [0x5555557f3c41] vm.c:1193 ruby(rb_yield_0+0x25) [0x5555557ca615] vm_eval.c:1141 ruby(rb_yield_1+0x27) [0x5555557ca5c7] vm_eval.c:1147 ruby(rb_yield+0x34) [0x5555557ca654] vm_eval.c:1157 ruby(rb_ary_each+0xa5) [0x55555581c795] array.c:2242 ruby(call_cfunc_0+0x29) [0x5555557f0f39] vm_insnhelper.c:2385 ruby(vm_call_cfunc_with_frame+0x278) [0x5555557eca98] vm_insnhelper.c:2553 ruby(vm_sendish+0xd0) [0x5555557dba60] vm_insnhelper.c:4146 ruby(vm_exec_core+0xe0f8) [0x5555557b04f8] insns.def:782 ruby(rb_vm_exec+0x12c) [0x5555557d17cc] vm.c:1942 ruby(invoke_block+0xea) [0x5555557f42fa] vm.c:1058 ruby(invoke_iseq_block_from_c+0x16e) [0x5555557f3eae] vm.c:1130 ruby(invoke_block_from_c_bh) vm.c:1148 ruby(vm_yield+0x71) [0x5555557f3c41] vm.c:1193 ruby(rb_yield_0+0x25) [0x5555557ca615] vm_eval.c:1141 ruby(rb_yield_1+0x27) [0x5555557ca5c7] vm_eval.c:1147 ruby(rb_yield+0x34) [0x5555557ca654] vm_eval.c:1157 ruby(rb_ary_each+0xa5) [0x55555581c795] array.c:2242 ruby(call_cfunc_0+0x29) [0x5555557f0f39] vm_insnhelper.c:2385 ruby(vm_call_cfunc_with_frame+0x278) [0x5555557eca98] vm_insnhelper.c:2553 ruby(vm_sendish+0xd0) [0x5555557dba60] vm_insnhelper.c:4146 ruby(vm_exec_core+0xe0f8) [0x5555557b04f8] insns.def:782 ruby(rb_vm_exec+0x19f) [0x5555557d183f] vm.c:1951 ruby(rb_iseq_eval+0x30) [0x5555557d2530] vm.c:2190 ruby(load_iseq_eval+0xd6) [0x5555555fa7e6] load.c:592 ruby(require_internal+0x25e) [0x5555555f7f5e] load.c:1022 ruby(rb_require_string+0x27) [0x5555555f74e7] load.c:1094 ruby(rb_f_require_relative+0x5f) [0x5555555f758f] load.c:837 ruby(call_cfunc_1+0x30) [0x5555557f0f70] vm_insnhelper.c:2391 ruby(vm_call_cfunc_with_frame+0x278) [0x5555557eca98] vm_insnhelper.c:2553 ruby(vm_call_cfunc+0xad) [0x5555557e521d] vm_insnhelper.c:2574 ruby(vm_call_method_each_type+0xc7) [0x5555557e4af7] vm_insnhelper.c:3040 ruby(vm_call_method+0x19c) [0x5555557e45dc] vm_insnhelper.c:3144 ruby(vm_call_general+0x2d) [0x5555557c8c3d] vm_insnhelper.c:3176 ruby(vm_sendish+0xd0) [0x5555557dba60] vm_insnhelper.c:4146 ruby(vm_exec_core+0xe357) [0x5555557b0757] insns.def:801 ruby(rb_vm_exec+0x12c) [0x5555557d17cc] vm.c:1942 ruby(rb_iseq_eval_main+0x30) [0x5555557d2670] vm.c:2201 ruby(rb_ec_exec_node+0x16b) [0x55555557e39b] eval.c:296 ruby(ruby_run_node+0x72) [0x55555557e1f2] eval.c:354 ruby(main+0x78) [0x55555557a5d8] main.c:50 Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09rb_equal_opt: fully static call data卜部昌平
This changeset reduces the generated binary of rb_equal_opt from 129 bytes to 17 bytes on my machine, according to nm(1). Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09vm_search_method_fastpath: avoid rb_vm_empty_cc()卜部昌平
This is such a hot path that it's worth eliminating a function call. Use the static variable directly instead. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-09check_cfunc: add assertions卜部昌平
For debug. Must not change generated binary unless VM_ASSERT is on. Notes: Merged: https://github.com/ruby/ruby/pull/3179
2020-06-04Properly resolve refinements in defined? on private call [Bug #16932]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3180
2020-06-04Properly resolve refinements in defined? on method call [Bug #16932]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3180
2020-06-03vm_invoke_proc_block: reduce recursion卜部昌平
According to nobu recursion can be longer than my expectation. Limit them here. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_call_symbol: check stack overflow卜部昌平
VM stack could overflow here. The condition is when a symbol is passed to a block-taking method via &variable, and that symbol has never been used for actual method names (thus yielding that results in calling method_missing), and the VM stack is full (no single word left). This is a once-in-a-blue-moon event. Yet there is a very tiny room of stack overflow. We need to check that. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_invoke_block: remove auto qualifier卜部昌平
Was (harmless but) redundant. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_insnhelper.c: add space [ci skip]卜部昌平
Just cosmetic change to improve readability. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_invoke_symbol_block: reduce MEMCPY卜部昌平
This commit changes the number of calls of MEMCPY from... | send | &:sym -------------------------|-------|------- Symbol already interned | once | twice Symbol not pinned yet | none | once to: | send | &:sym -------------------------|-------|------- Symbol already interned | once | none Symbol not pinned yet | twice | once So it sacrifices exceptional situation for normal path. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_invoke_symbol_block: call vm_call_opt_send卜部昌平
Symbol#to_proc and Object#send are closely related each other. Why not share their implementations. By doing so we can skip recursive call of vm_exec(), which could benefit for speed. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_invoke_block: force indirect jump卜部昌平
This changeset slightly speeds up on my machine. Calculating ------------------------------------- before after Optcarrot Lan_Master.nes 38.33488426546287 40.89825082589147 fps 40.91288557922081 41.48687465359386 40.96591995270991 41.98499064664184 41.20461943032173 43.67314690779162 42.38344888176518 44.02777536251875 43.43563728880915 44.88695892714136 43.88082889062643 45.11226186242523 Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_invoke_block: insertion of unused args卜部昌平
This makes it possible for vm_invoke_block to pass its passed arguments verbatimly to calling functions. Because they are tail-called the function calls can be strength-recuced into indirect jumps, which is a huge win. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_invoke_block: eliminate goto卜部昌平
Use recursion for better readability. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-03vm_invoke_block: move logics around卜部昌平
Moved block handler -> captured block conversion from vm_invokeblock to each vm_invoke_*_block functions. Notes: Merged: https://github.com/ruby/ruby/pull/3152
2020-06-02Fixed `defined?` against protected method callNobuyoshi Nakada
Protected methods are restricted to be called according to the class/module in where it is defined, not the actual receiver's class. [Bug #16931]
2020-06-02vm_insnhelper.c: merge opt_eq_func / opt_eql_func卜部昌平
These two function were almost identical, except in case of T_STRING/T_FLOAT. Why not merge them into one, and let the difference be handled in normal method calls (slowpath). This does not improve runtime performance for me, but at least reduces for instance rb_eql_opt from 653 bytes to 86 bytes on my machine, according to nm(1). Notes: Merged: https://github.com/ruby/ruby/pull/3169
2020-05-26Mark vm_stackoverflow as NOINLINE COLDFUNC on JITTakashi Kokubun
to reduce code size and improve locality of hot code.